Skip to content

Commit f4e3b4a

Browse files
committed
[workers-utils] Centralised header test helpers for local explorer and miniflare
1 parent 1fbe528 commit f4e3b4a

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export const EMAIL_HEADER_NAME_CASES = [
2+
["accepts RFC token characters", "X-Custom_Header.1", true],
3+
["rejects spaces", "X Header", false],
4+
["rejects colons", "X:Header", false],
5+
["rejects an empty name", "", false],
6+
] as const;
7+
8+
export const EMAIL_HEADER_VALUE_CASES = [
9+
["accepts plain text", "custom value", true],
10+
["accepts LF-delimited lines", "first\nsecond", true],
11+
["accepts CRLF-delimited lines", "first\r\nsecond", true],
12+
[
13+
"accepts an injection-shaped line for safe folding",
14+
"safe\nBcc: victim@example.com",
15+
true,
16+
],
17+
["rejects a bare carriage return", "first\rsecond", false],
18+
["rejects a tab", "first\tsecond", false],
19+
["rejects DEL", "first\u007fsecond", false],
20+
] as const;
21+
22+
export const MANAGED_EMAIL_HEADER_CASES = [
23+
["Bcc", true],
24+
["Cc", true],
25+
["Content-Transfer-Encoding", true],
26+
["CONTENT-TYPE", true],
27+
["Date", true],
28+
["From", true],
29+
["MIME-Version", true],
30+
["Reply-To", true],
31+
["Subject", true],
32+
["mEsSaGe-Id", true],
33+
["To", true],
34+
["X-Custom-Header", false],
35+
] as const;

packages/workers-utils/src/test-helpers/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export { mockConsoleMethods, createDeferred } from "./mock";
2+
export {
3+
EMAIL_HEADER_NAME_CASES,
4+
EMAIL_HEADER_VALUE_CASES,
5+
MANAGED_EMAIL_HEADER_CASES,
6+
} from "./email-header-validation";
27
export {
38
normalizeString,
49
mockCreateDate,

0 commit comments

Comments
 (0)