test: |Worker| add junk_mail_policy regression tests for issue #1084 (#1089)

Cover the junk-mail policy behavior fixed in #1085:
- none/neutral results for SPF/DKIM/DMARC are treated as the method
  being absent and do not trigger JUNK_MAIL_CHECK_LIST rejection
- explicit fail results are still rejected
- JUNK_MAIL_FORCE_PASS_LIST only accepts an explicit pass

Run with: node --test-isolation=none --test worker/src/email/junk_mail_policy.test.mjs

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Josh Tsai
2026-07-25 20:21:46 +08:00
committed by GitHub
parent 0581632b59
commit 7eaa3b3b8e
3 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
import assert from "node:assert/strict";
import test from "node:test";
import { isJunkMailByHeaders } from "./junk_mail_policy.ts";
const authenticationResultsHeader = (results) => [{
key: "Authentication-Results",
value: `mx.example; ${results}`,
}];
test("issue #1084: dmarc=none does not reject an otherwise passing message", () => {
const headers = authenticationResultsHeader(
"spf=pass smtp.mailfrom=sender.example; " +
"dkim=pass header.d=sender.example; " +
"dmarc=none; arc=pass"
);
assert.equal(
isJunkMailByHeaders(
headers,
["spf", "dkim", "dmarc"],
["spf"],
),
false,
);
});
for (const [method, result] of [
["spf", "none"],
["spf", "neutral"],
["dkim", "none"],
["dkim", "neutral"],
["dmarc", "none"],
["dmarc", "neutral"],
]) {
test(`${method}=${result} is absent for JUNK_MAIL_CHECK_LIST`, () => {
assert.equal(
isJunkMailByHeaders(
authenticationResultsHeader(`${method}=${result}`),
[method],
[],
),
false,
);
});
}
for (const method of ["spf", "dkim", "dmarc"]) {
test(`${method}=fail is junk when the method is checked`, () => {
assert.equal(
isJunkMailByHeaders(
authenticationResultsHeader(`${method}=fail`),
[method],
[],
),
true,
);
});
}
test("JUNK_MAIL_FORCE_PASS_LIST requires an explicit pass result", () => {
for (const result of ["none", "neutral", "fail"]) {
assert.equal(
isJunkMailByHeaders(
authenticationResultsHeader(`spf=${result}`),
[],
["spf"],
),
true,
);
}
assert.equal(
isJunkMailByHeaders(
authenticationResultsHeader("spf=pass"),
[],
["spf"],
),
false,
);
});