Public: anyone can read this; the crew can change it.
Full suite red: test/security-sweep.test.ts #15313
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15298-full-suite-red-test-security-sweep-test → main 0 commits fork
1 file
changed +10
−4
test/security-sweep.test.ts +10 −4
| @@ -54,6 +54,12 @@ const USERNAME = "ada"; | ||
| 54 | 54 | const PASSWORD = "correct-horse-battery"; |
| 55 | 55 | const EVIL = "https://evil.example"; |
| 56 | 56 | const FLOOR = ["content-security-policy", "x-content-type-options", "referrer-policy"] as const; |
| 57 | /** | |
| 58 | * A ceiling for a sweep, not a measure: the work is bounded by the route | |
| 59 | * table, and the default 6 s test limit reddened the full suite when four | |
| 60 | * files shared the machine (#15298). It only stops a hung server. | |
| 61 | */ | |
| 62 | const SWEEP_LIMIT = 120_000; | |
| 57 | 63 | const MUTATING = new Set(["POST", "PUT", "PATCH", "DELETE"]); |
| 58 | 64 | |
| 59 | 65 | /** |
| @@ -144,7 +150,7 @@ async function send(method: string, path: string, headers: Record<string, string | ||
| 144 | 150 | headers: { "accept-encoding": "identity", ...headers }, |
| 145 | 151 | body, |
| 146 | 152 | redirect: "manual", |
| 147 | signal: AbortSignal.timeout(5_000), | |
| 153 | signal: AbortSignal.timeout(60_000), | |
| 148 | 154 | }); |
| 149 | 155 | await res.body?.cancel().catch(() => {}); |
| 150 | 156 | return { |
| @@ -204,7 +210,7 @@ test("every registered route and verb, asked anonymously, answers with the floor | ||
| 204 | 210 | expect(statuses).toContain(404); |
| 205 | 211 | expect(statuses.some((s) => s >= 400 && s < 500 && s !== 404)).toBe(true); |
| 206 | 212 | expect(anonymous.some((s) => s.type.startsWith("text/event-stream"))).toBe(true); |
| 207 | }); | |
| 213 | }, SWEEP_LIMIT); | |
| 208 | 214 | |
| 209 | 215 | test("an API path asked with a verb it does not take answers 405, naming the ones it does, with the floor", async () => { |
| 210 | 216 | const api = buildApiRouter(); |
| @@ -231,7 +237,7 @@ test("an API path asked with a verb it does not take answers 405, naming the one | ||
| 231 | 237 | .map(({ s }) => `${s.label} allow=${s.allow}`); |
| 232 | 238 | expect(wrongAnswers).toEqual([]); |
| 233 | 239 | expect(wrongMethod.at(-1)!.status).toBe(405); // the home page takes GET, so a PATCH is a wrong method, not a miss |
| 234 | }); | |
| 240 | }, SWEEP_LIMIT); | |
| 235 | 241 | |
| 236 | 242 | test("a cross-origin mutation with a session cookie is refused before any handler, and the session lives on", async () => { |
| 237 | 243 | const mutations = routes().filter((r) => MUTATING.has(r.method)); |
| @@ -243,7 +249,7 @@ test("a cross-origin mutation with a session cookie is refused before any handle | ||
| 243 | 249 | expect(seen.filter((s) => s.cookies.length > 0).map((s) => `${s.label} sets ${s.cookies.map(cookieName).join(", ")}`)).toEqual([]); |
| 244 | 250 | const still = sessionOf(app.db, token); |
| 245 | 251 | expect(still.ok && still.value.user.username).toBe(USERNAME); |
| 246 | }); | |
| 252 | }, SWEEP_LIMIT); | |
| 247 | 253 | |
| 248 | 254 | test("signing in from the forge's own page sets the session cookie HttpOnly, with the floor", async () => { |
| 249 | 255 | const form = await send( |
new above
offline