Verify inherited credential safety
This commit is contained in:
@@ -432,7 +432,7 @@ func TestPipelineOverlayDoesNotRequireUnusedBaseCredentials(t *testing.T) {
|
||||
for _, credential := range []string{testingKey, "null"} {
|
||||
t.Run(credential, func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n credentials: ["+production+"]\n")
|
||||
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://transcription.example.test/transcribe\naudita:\n credentials: ["+production+"]\nscriptorium:\n extends: audita\n")
|
||||
selected := "[" + credential + "]"
|
||||
if credential == "null" {
|
||||
selected = credential
|
||||
@@ -447,8 +447,13 @@ func TestPipelineOverlayDoesNotRequireUnusedBaseCredentials(t *testing.T) {
|
||||
if len(cfg.Audita.Credentials) != 0 {
|
||||
t.Fatal("profile did not remove the base credential")
|
||||
}
|
||||
if len(cfg.Scriptorium.Credentials) != 0 {
|
||||
t.Fatal("inherited profile credential was not removed")
|
||||
}
|
||||
} else if len(cfg.Audita.Credentials) != 1 || cfg.Audita.Credentials[0].EnvName() != testingKey || !cfg.Audita.Credentials[0].IsResolved() {
|
||||
t.Fatal("profile credential was not resolved")
|
||||
} else if len(cfg.Scriptorium.Credentials) != 1 || cfg.Scriptorium.Credentials[0].EnvName() != testingKey || cfg.Scriptorium.Credentials[0].Value() != "synthetic-test-key" {
|
||||
t.Fatal("inherited profile credential was not resolved")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -63,3 +63,61 @@ func TestScriptoriumCredentialsComposeAndSerializeSafely(t *testing.T) {
|
||||
t.Fatal("empty selected credential accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestScriptoriumInheritsResolvedTypedCredentialsSafely(t *testing.T) {
|
||||
const envName = "NARRATIO_TEST_API_KEY"
|
||||
const secret = "synthetic-inherited-secret"
|
||||
t.Setenv(envName, secret)
|
||||
dir := t.TempDir()
|
||||
root := writePipelineFixture(t, dir, "pipeline.yml", "whisperx:\n transcribe_url: https://example.test/transcribe\naudita:\n credentials: [NARRATIO_TEST_API_KEY]\nscriptorium:\n extends: audita\n")
|
||||
cfg, err := LoadPipeline(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(cfg.Audita.Credentials) != 1 || cfg.Audita.Credentials[0].EnvName() != envName || !cfg.Audita.Credentials[0].IsResolved() || cfg.Audita.Credentials[0].Value() != secret {
|
||||
t.Fatal("audita credential was not resolved")
|
||||
}
|
||||
if len(cfg.Scriptorium.Credentials) != 1 || cfg.Scriptorium.Credentials[0].EnvName() != envName || !cfg.Scriptorium.Credentials[0].IsResolved() || cfg.Scriptorium.Credentials[0].Value() != secret {
|
||||
t.Fatal("scriptorium did not inherit the resolved typed credential")
|
||||
}
|
||||
for name, marshal := range map[string]func() ([]byte, error){
|
||||
"config": func() ([]byte, error) { return yaml.Marshal(cfg) },
|
||||
"effective": func() ([]byte, error) { return MarshalEffectivePipeline(cfg) },
|
||||
} {
|
||||
data, err := marshal()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(data), envName) || strings.Contains(string(data), secret) {
|
||||
t.Fatalf("%s serialization did not safely expose credential identity", name)
|
||||
}
|
||||
var serialized struct {
|
||||
Scriptorium struct {
|
||||
Credentials []string `yaml:"credentials"`
|
||||
} `yaml:"scriptorium"`
|
||||
}
|
||||
if err := yaml.Unmarshal(data, &serialized); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(serialized.Scriptorium.Credentials) != 1 || serialized.Scriptorium.Credentials[0] != envName {
|
||||
t.Fatalf("%s serialization omitted the inherited Scriptorium credential", name)
|
||||
}
|
||||
}
|
||||
values, err := EffectivePipelineValues(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inspection, err := yaml.Marshal(values)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundInheritedCredential := false
|
||||
for _, value := range values {
|
||||
if value.Path == "scriptorium.credentials" && strings.Contains(value.Value, envName) {
|
||||
foundInheritedCredential = true
|
||||
}
|
||||
}
|
||||
if !foundInheritedCredential || strings.Contains(string(inspection), secret) {
|
||||
t.Fatal("effective inspection did not safely expose inherited credential identity")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user