fix(test): TestBccNeverAppearsInTheHeaders falhava por acaso
Procurava a sequencia "bcc" em qualquer sitio do bloco de cabecalhos, e o Message-ID e um UUID aleatorio. Quando calha conter essa sequencia -- o CI apanhou <1bcc5e82-9f6a-4e92-a1e5-65dc96b20208@mail.example.test> -- o teste falha num commit que nao lhe tocou. Sao algumas vezes em mil execucoes. Passa a procurar o campo Bcc no inicio de uma linha de cabecalho, que e o que lhe interessa, mantendo a verificacao de que o endereco em si nao aparece em lado nenhum. Confirmado por mutacao: com um cabecalho Bcc injectado, falha. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6a602ab88f
commit
3e06162fa0
1 file changed
+14
-3
@@ -102,9 +102,20 @@ func TestBccNeverAppearsInTheHeaders(t *testing.T) {
|
||||
|
||||
payload := string(buildMimeMessage(input, recipients, "mail.example.test"))
|
||||
headers, _, _ := strings.Cut(payload, "\r\n\r\n")
|
||||
if strings.Contains(strings.ToLower(headers), "bcc") ||
|
||||
strings.Contains(headers, "secret@example.test") {
|
||||
t.Errorf("bcc leaked into the headers:\n%s", headers)
|
||||
|
||||
// The field, not the letters. Searching the whole block for "bcc" matched
|
||||
// the random Message-ID whenever its UUID happened to contain that run of
|
||||
// characters - <1bcc5e82-...> is a real example - so this failed a few
|
||||
// times in a thousand on changes that had nothing to do with it.
|
||||
for _, line := range strings.Split(headers, "\r\n") {
|
||||
name, _, found := strings.Cut(line, ":")
|
||||
if found && strings.EqualFold(strings.TrimSpace(name), "bcc") {
|
||||
t.Errorf("a Bcc header was emitted:\n%s", headers)
|
||||
}
|
||||
}
|
||||
// The address itself must not appear anywhere, under any field.
|
||||
if strings.Contains(headers, "secret@example.test") {
|
||||
t.Errorf("the blind copy address leaked into the headers:\n%s", headers)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user