Files
magpie/internal/redact/second_pass_test.go
T
yetone db58a88a83 gateway: a request masked by another build with the same settings is not masked again (Luxzinw on X)
Cause: X-Magpie-Masked-As carried this build's version and the other
magpie skipped its pass only on an exact match, so 0.1.3771 into 0.1.3638
(or any two builds) masked twice. Now the settings fingerprint must match
and the sender's build must be >= maskerSince (3584, the last masker
change), whichever build is newer; the header is passed on as it came
(it named the passing magpie's build, which never masked). Old-format
headers (v0.1.N/fp) parse the same.

Stand-ins: a user name's made-up name, public-ip- names and {{}}
placeholders are left alone by a process that has none of them in memory
(TestSecondProcessLeavesStandInsAlone). A made-up key looks like a key and
is masked again by such a process; the header skip covers that between
magpies with the same settings, not different ones.

Run (mote): go test -run 'MaskedBefore|RemoteMagpie' ./internal/gateway ok;
internal/redact SecondProcess ok. Broken by hand: maskerSince=999999 turns
the new tests red. Not tried: a real two-machine hop; full suite after tag.
2026-11-12 01:01:32 +08:00

26 lines
1.0 KiB
Go

package redact
import "testing"
// A text masked by one magpie and masked again by another process, which
// has none of the first's made-up names in memory, comes out as it came:
// a user name's made-up name, an address's public-ip- name and the
// placeholders are no values to find. (A made-up key looks like a key, so a
// process that doesn't know it masks it again; what keeps that from
// happening between magpies is MaskedAsHeader, maskedBefore.) (Luxzinw on X).
func TestSecondProcessLeavesStandInsAlone(t *testing.T) {
Forget()
t.Cleanup(Forget)
o := Options{Personal: true, Secrets: true, Shape: true, Kinds: map[string]bool{"ip": true, "username": true, "email": true}}
msg := "ssh root@47.96.123.45 as /Users/eerttreeeert/work, mail jo@quill.dev"
first, n := Mask(msg, o)
if n == 0 || first == msg {
t.Fatalf("nothing masked: %q", first)
}
Forget() // another process
second, n2 := Mask(first, o)
if second != first || n2 != 0 {
t.Errorf("masked again (%d): first %q, second %q", n2, first, second)
}
}