From f0453192033d750bb9cc117cad78cc9a5884c3e1 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 10 Oct 2026 22:43:34 +0800 Subject: [PATCH] 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 --- internal/redact/more_test.go | 2 +- internal/redact/redact_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/redact/more_test.go b/internal/redact/more_test.go index 0485e12f0..5c4e9a09a 100644 --- a/internal/redact/more_test.go +++ b/internal/redact/more_test.go @@ -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) { diff --git a/internal/redact/redact_test.go b/internal/redact/redact_test.go index dba75320f..1379f36ac 100644 --- a/internal/redact/redact_test.go +++ b/internal/redact/redact_test.go @@ -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) } }