Render final configuration through native snapshots
This commit is contained in:
65
internal/config/inspection_snapshot_test.go
Normal file
65
internal/config/inspection_snapshot_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInspectionSnapshotPreservesFinalValuesWithoutResolvingCredentialsAgain(t *testing.T) {
|
||||
const name = "NARRATIO_SNAPSHOT_TEST_KEY"
|
||||
const secret = "synthetic-snapshot-secret"
|
||||
t.Setenv(name, secret)
|
||||
path := writePipelineFixture(t, t.TempDir(), "pipeline.yml", `audita:
|
||||
credentials: [NARRATIO_SNAPSHOT_TEST_KEY]
|
||||
scriptorium:
|
||||
artifacts:
|
||||
recap:
|
||||
vars:
|
||||
exact: 9007199254740993
|
||||
nothing: null
|
||||
empty: []
|
||||
`)
|
||||
cfg, err := LoadPipeline(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
artifact := cfg.Scriptorium.Artifacts["recap"]
|
||||
artifact.Vars["config"] = map[string]any{"extends": "ordinary-data"}
|
||||
cfg.Scriptorium.Artifacts["recap"] = artifact
|
||||
if err := os.Unsetenv(name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := recomputePipelineEffectiveDigest(cfg); err != nil {
|
||||
t.Fatalf("snapshot resolved credentials again: %v", err)
|
||||
}
|
||||
data, err := MarshalEffectivePipeline(cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, expected := range []string{name, "9007199254740993", "ordinary-data", "nothing: null", "empty: []"} {
|
||||
if !strings.Contains(string(data), expected) {
|
||||
t.Fatalf("snapshot missing %q: %s", expected, data)
|
||||
}
|
||||
}
|
||||
if strings.Contains(string(data), secret) {
|
||||
t.Fatal("snapshot exposed resolved credential")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInspectionSnapshotKeepsEmptyCredentialListDistinctFromNull(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
nullPath := writePipelineFixture(t, dir, "null.yml", "audita: {credentials: null}\n")
|
||||
emptyPath := writePipelineFixture(t, dir, "empty.yml", "audita: {credentials: []}\n")
|
||||
nullConfig, err := LoadPipeline(nullPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
emptyConfig, err := LoadPipeline(emptyPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if EffectivePipelineDigest(nullConfig) == EffectivePipelineDigest(emptyConfig) {
|
||||
t.Fatal("null and empty credentials have the same digest")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user