redact: TestMoreKinds' gone check looks past the made-up user name (#4345)

TestMoreKinds checks that each masked value is no longer in what is
sent, after taking out the {{KIND_…}} placeholders. A user name goes as
a made-up name instead, eight lowercase letters from a key that is new
each run, and that name can spell a short user name: on ubuntu CI at
500f39886, "ops" was still in "scp a.txt zpxopsat@{{HOSTNAME_…}}". The
check now takes out the made-up name for the value first; the test
still checks separately that the made-up name is what was sent.

The other tests that check a user name is gone use names of eight or
more letters (developer, rinakato), which eight random letters spell
with odds around 26^-8, so they are left as they are.

Run on mote at this head (origin/main 256910f17):
- A probe test searched for a key whose made-up name for "ops"
  contains "ops" (key 2207: dopsubnz), set it, and ran TestMoreKinds:
  red with the old check ("ops" still in "dopsubnz@…", CI's red), ok
  with this one. The probe is not committed.
- go test -count=1 ./internal/redact: ok. gofmt -l clean.

Fixes #4345.
This commit is contained in:
yetone
2026-11-16 03:38:48 +08:00
parent dd77094ca2
commit 8765ca1758
+4 -1
View File
@@ -93,7 +93,10 @@ 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(unmarked(out), g.value) {
// The made-up name is eight random letters, a new key each
// run, and can spell a short user name: "ops" was still in
// "zpxopsat@…" on ubuntu CI at 500f39886 (#4345).
if strings.Contains(strings.ReplaceAll(unmarked(out), standInOf(g.value), ""), g.value) {
t.Errorf("%q: %q still in %q", c.in, g.value, out)
}
p := placeholder(g.kind, g.value)