redact: a masked-value test looks for the value outside the placeholders, whose random hash suffix can spell it
TestMoreKinds went red on macOS CI at 6c099edd:
"scp a.txt ops@db3.internal:/tmp/": "ops" still in
"scp a.txt {{USERNAME_gwaf7b44}}@{{HOSTNAME_mlopsiy3}}:/tmp/"
The username was masked; the hostname's placeholder suffix, an HMAC under
a key random per test process, happened to spell "ops". Short values in
the table (ops, raw, rinak, rkato, deploy) collide like this now and then.
The "gone" checks in TestMoreKinds and TestMask now look in the text with
placeholders taken out (placeholderRe), so a raw value left in the text
still fails them.
Ran:
- injected the CI placeholder ({{HOSTNAME_mlopsiy3}} for db3.internal) in
placeholder(): the old tests fail with CI's exact message, the new pass
- go test -count=1 ./internal/redact; -race too
- gofmt -l; go vet on darwin, GOOS=linux, GOOS=windows
This commit is contained in:
@@ -91,7 +91,7 @@ func TestMoreKinds(t *testing.T) {
|
||||
t.Errorf("%q: %d masked, want %d: %q", c.in, n, len(c.gone), out)
|
||||
}
|
||||
for _, g := range c.gone {
|
||||
if strings.Contains(out, g.value) {
|
||||
if strings.Contains(unmarked(out), g.value) {
|
||||
t.Errorf("%q: %q still in %q", c.in, g.value, out)
|
||||
}
|
||||
if p := placeholder(g.kind, g.value); !strings.Contains(out, p) {
|
||||
|
||||
@@ -13,6 +13,12 @@ const (
|
||||
ghToken = "ghp_0123456789abcdefghijABCDEFGHIJ0123"
|
||||
)
|
||||
|
||||
// unmarked is s without its placeholders. A placeholder's suffix is a keyed
|
||||
// hash, so with a random key it can spell a short value the test checks is
|
||||
// gone: "ops" in {{HOSTNAME_mlopsiy3}} turned TestMoreKinds red on macOS
|
||||
// CI at 6c099edd.
|
||||
func unmarked(s string) string { return placeholderRe.ReplaceAllString(s, "") }
|
||||
|
||||
func TestMask(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
@@ -45,7 +51,7 @@ func TestMask(t *testing.T) {
|
||||
t.Errorf("%q: %d masked, want %d: %q", c.in, n, c.count, out)
|
||||
}
|
||||
for _, g := range c.gone {
|
||||
if strings.Contains(out, g) {
|
||||
if strings.Contains(unmarked(out), g) {
|
||||
t.Errorf("%q: %q still in %q", c.in, g, out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user