Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not sanitzie secrets with 3 or less chars #2680

Merged
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
2 changes: 1 addition & 1 deletion pipeline/shared/replace_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewSecretsReplacer(secrets []string) *strings.Replacer {
var oldnew []string
for _, old := range secrets {
old = strings.TrimSpace(old)
if len(old) == 0 {
if len(old) <= 3 {
continue
}
// since replacer is executed on each line we have to split multi-line-secrets
Expand Down
18 changes: 13 additions & 5 deletions pipeline/shared/replace_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,42 @@ import (

func TestNewSecretsReplacer(t *testing.T) {
tc := []struct {
name string
log string
secrets []string
expect string
}{{
name: "dont replace secrets with less than 3 chars",
log: "start log\ndone",
secrets: []string{""},
secrets: []string{"", "d", "art"},
expect: "start log\ndone",
}, {
name: "single line passwords",
log: `this IS secret: password`,
secrets: []string{"password", " IS "},
expect: `this ******** secret: ********`,
expect: `this IS secret: ********`,
}, {
name: "secret with one newline",
log: "start log\ndone\nnow\nan\nmulti line secret!! ;)",
secrets: []string{"an\nmulti line secret!!"},
expect: "start log\ndone\nnow\n********\n******** ;)",
}, {
name: "secret with multible lines with no match",
log: "start log\ndone\nnow\nan\nmulti line secret!! ;)",
secrets: []string{"Test\nwith\n\ntwo new lines"},
expect: "start log\ndone\nnow\nan\nmulti line secret!! ;)",
}, {
name: "secret with multible lines with match",
log: "start log\ndone\nnow\nan\nmulti line secret!! ;)\nwith\ntwo\n\nnewlines",
secrets: []string{"an\nmulti line secret!!", "two\n\nnewlines"},
expect: "start log\ndone\nnow\n********\n******** ;)\nwith\n********\n\n********",
}}

for _, c := range tc {
rep := NewSecretsReplacer(c.secrets)
result := rep.Replace(c.log)
assert.EqualValues(t, c.expect, result)
t.Run(c.name, func(t *testing.T) {
rep := NewSecretsReplacer(c.secrets)
result := rep.Replace(c.log)
assert.EqualValues(t, c.expect, result)
})
}
}