Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,17 @@ func contentSearch(report *Report, possiblyRemoved []string, oldIndex map[string
}
}

// Compare copies: doDiff redacts or decodes the secrets it reports itself,
// and a secret that is already redacted does not parse a second time.
oldCandidate, newCandidate := *oldContent, *newContent
switch {
case options.ShowSecretsDecoded:
decodeSecrets(oldContent, newContent)
decodeSecrets(&oldCandidate, &newCandidate)
case !options.ShowSecrets:
redactSecrets(oldContent, newContent)
redactSecrets(&oldCandidate, &newCandidate)
}

diff := diffMappingResults(oldContent, newContent, options.StripTrailingCR)
diff := diffMappingResults(&oldCandidate, &newCandidate, options.StripTrailingCR)
delta := actualChanges(diff)
if delta == 0 || len(diff) == 0 {
continue
Expand Down
90 changes: 90 additions & 0 deletions diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1796,3 +1796,93 @@ spec:
require.Contains(t, buf.String(), "has been added")
})
}

func TestRenameDetectionWithRedactedSecrets(t *testing.T) {
ansi.DisableColors(true)

specs := func() (map[string]*manifest.MappingResult, map[string]*manifest.MappingResult) {
oldSpec := map[string]*manifest.MappingResult{
"default, foo, Secret (v1)": {
Name: "default, foo, Secret (v1)",
Kind: "Secret",
Content: `
apiVersion: v1
kind: Secret
metadata:
name: foo
type: Opaque
data:
key1: dmFsdWUx
key2: dmFsdWUy
`,
},
}
newSpec := map[string]*manifest.MappingResult{
"default, bar, Secret (v1)": {
Name: "default, bar, Secret (v1)",
Kind: "Secret",
Content: `
apiVersion: v1
kind: Secret
metadata:
name: bar
type: Opaque
data:
key1: dmFsdWUxY2hhbmdlZA==
key2: dmFsdWUy
`,
},
}
return oldSpec, newSpec
}

t.Run("rename detected", func(t *testing.T) {
var buf bytes.Buffer
opts := &Options{OutputFormat: "diff", OutputContext: 10, FindRenames: 0.5}

oldSpec, newSpec := specs()
require.True(t, Manifests(oldSpec, newSpec, opts, &buf))
require.Equal(t, `default, foo, Secret (v1) has changed:
apiVersion: v1
kind: Secret
metadata:
- name: foo
+ name: bar
data:
- key1: '-------- # (6 bytes)'
+ key1: '++++++++ # (13 bytes)'
key2: 'REDACTED # (6 bytes)'
type: Opaque
`, buf.String())
})

t.Run("rename rejected", func(t *testing.T) {
var buf bytes.Buffer
opts := &Options{OutputFormat: "diff", OutputContext: 10, FindRenames: 0.1}

oldSpec, newSpec := specs()
require.True(t, Manifests(oldSpec, newSpec, opts, &buf))
require.Equal(t, `default, foo, Secret (v1) has been removed:
- apiVersion: v1
- kind: Secret
- metadata:
- name: foo
- data:
- key1: '-------- # (6 bytes)'
- key2: '-------- # (6 bytes)'
- type: Opaque
default, bar, Secret (v1) has been added:
+ apiVersion: v1
+ kind: Secret
+ metadata:
+ name: bar
+ data:
+ key1: '++++++++ # (13 bytes)'
+ key2: '++++++++ # (6 bytes)'
+ type: Opaque
`, buf.String())
})
}
Loading