Project sequence evidence through item mappings
This commit is contained in:
@@ -230,6 +230,77 @@ func TestReplacedProjectedSensitiveRecordRemainsRedacted(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMappedUpsertProjectsSensitiveReplacementEvidence(t *testing.T) {
|
||||
lowerRoot := parseCompositionDocument(t, "lower", `records:
|
||||
- id: first
|
||||
- id: middle
|
||||
- id: last
|
||||
token: MAPPED-SECRET-CANARY
|
||||
`)
|
||||
higherRoot := parseCompositionDocument(t, "higher", `records:
|
||||
- id: last
|
||||
token: visible
|
||||
- id: first
|
||||
- id: added
|
||||
`)
|
||||
lower, _ := documentAtPath(lowerRoot, Keys("records"))
|
||||
higher, _ := documentAtPath(higherRoot, Keys("records"))
|
||||
combined, diagnostics := combineSequence(
|
||||
lower, higher,
|
||||
sequenceCombinationPolicy(sequenceModeUpsert, "id"),
|
||||
sequenceCombinationContext{destination: Keys("records")},
|
||||
)
|
||||
if len(diagnostics) != 0 {
|
||||
t.Fatalf("combine diagnostics = %#v", diagnostics)
|
||||
}
|
||||
secretPath := Keys("records").Index(2).Key("token")
|
||||
secretNode, present := documentAtPath(lowerRoot, Keys("records").Index(2).Key("token"))
|
||||
if !present {
|
||||
t.Fatal("sensitive source token is missing")
|
||||
}
|
||||
secretNode.Sensitive = true
|
||||
application := historyApplication{
|
||||
layer: LayerOverlay, value: higherRoot,
|
||||
sequences: []sequenceHistoryContribution{{
|
||||
path: Keys("records"), mode: sequenceHistoryMapped,
|
||||
items: combined.higherItems, replacements: combined.replacements,
|
||||
}},
|
||||
}
|
||||
application.sequencesByPath = indexSequenceHistoryContributions(application.sequences)
|
||||
applications := []historyApplication{{value: lowerRoot}, application}
|
||||
replayed := &document.Node{Kind: document.Mapping}
|
||||
for _, current := range applications {
|
||||
applyHistoryApplication(&replayed, current, new(mappingIndex))
|
||||
}
|
||||
replayedRecords, _ := documentAtPath(replayed, Keys("records"))
|
||||
if !reflect.DeepEqual(replayedRecords.Sequence, combined.value.Sequence) {
|
||||
t.Fatalf("replayed value = %#v, want combination = %#v", replayedRecords.Sequence, combined.value.Sequence)
|
||||
}
|
||||
finalRoot := document.Clone(lowerRoot)
|
||||
finalRecords, _ := documentAtPath(finalRoot, Keys("records"))
|
||||
finalRecords.Sequence = document.Clone(combined.value).Sequence
|
||||
|
||||
var metadata Metadata
|
||||
finalizeMetadataPaths(&metadata, finalRoot, applications)
|
||||
inspection := &Inspection{
|
||||
metadata: metadata, baseline: &document.Node{Kind: document.Mapping},
|
||||
input: finalRoot, final: finalRoot, applications: applications,
|
||||
}
|
||||
secretRule := func(candidate Path) bool { return reflect.DeepEqual(candidate, secretPath) }
|
||||
inspection.secrets = classifySecretPaths(nil, secretRule, metadata, finalRoot, applications)
|
||||
explanation, ok := inspection.Explain(secretPath)
|
||||
if !ok || !explanation.Effective.Redacted {
|
||||
t.Fatalf("mapped replacement explanation = %#v, %v", explanation, ok)
|
||||
}
|
||||
var rendered bytes.Buffer
|
||||
if err := inspection.WriteExplanation(&rendered, secretPath); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(rendered.String(), "MAPPED-SECRET-CANARY") || !strings.Contains(rendered.String(), "[REDACTED]") {
|
||||
t.Fatalf("mapped replacement history leaked or was not redacted: %s", rendered.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSequenceHistoryReplaysCombinationEvidence(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user