Add verified snapshots and harden archive identity

This commit is contained in:
DonVoo 2026-07-17 00:37:02 +02:00
parent c6de214ac8
commit 68b9cee880
9 changed files with 1372 additions and 52 deletions

View file

@ -25,6 +25,56 @@ func TestMessageIDFallsBackToBodyHash(t *testing.T) {
}
}
func TestNormalizeMessageIDExtractsBracketedIDBeforeBrokenComment(t *testing.T) {
tests := map[string]string{
"<normal@example.com>": "normal@example.com",
"bracketless@example.com": "bracketless@example.com",
" <5486CB7400AF1FB7@mr001msb.fastweb.it> (added by postmaster) ": "5486CB7400AF1FB7@mr001msb.fastweb.it",
"comment <embedded@example.com> trailing": "embedded@example.com",
}
for input, want := range tests {
if got := normalizeMessageID(input); got != want {
t.Errorf("normalizeMessageID(%q)=%q, want %q", input, got, want)
}
}
}
func TestIdentityKeepsOldMalformedHeaderNormalizationAsAlias(t *testing.T) {
tests := []struct {
header string
clean string
legacy string
}{
{
header: `<476BDFDB019289BE@mail21.bluewin.ch> (added by postmaster@bluewin.ch)`,
clean: `476BDFDB019289BE@mail21.bluewin.ch`,
legacy: `476BDFDB019289BE@mail21.bluewin.ch> (added by postmaster@bluewin.ch)`,
},
{
header: `<22578196653698419217.BB8A0E8F48F3F290@dr-gold.de>+D271B1409C3C6028`,
clean: `22578196653698419217.BB8A0E8F48F3F290@dr-gold.de`,
legacy: `22578196653698419217.BB8A0E8F48F3F290@dr-gold.de>+D271B1409C3C6028`,
},
}
for _, tt := range tests {
body := []byte("Message-ID: " + tt.header + "\r\nSubject: malformed ID\r\n\r\nbody")
identity := identityForRawMessage(RawMessage{MessageID: messageID(body), Body: body})
if identity.MessageID != tt.clean {
t.Fatalf("MessageID=%q, want %q", identity.MessageID, tt.clean)
}
found := false
for _, alias := range identity.LegacyMessageIDs {
if alias == tt.legacy {
found = true
break
}
}
if !found {
t.Fatalf("legacy alias %q missing from %#v", tt.legacy, identity.LegacyMessageIDs)
}
}
}
func TestBodySHA256IsStableAcrossMboxNormalization(t *testing.T) {
raw := []byte("From: a@example.com\r\nSubject: Test\r\n\r\nFirst\r\nFrom escaped\r\n\r\n")
record := mboxRecord(RawMessage{Body: raw})