Public: anyone can read this; the crew can change it.
Full suite red: test/security-floor-routes.test.ts #18234
Merged 11h 10m ago, live in production
torque/forge:torque/18231-full-suite-red-test-security-floor-route → main 0 commits fork
1 file
changed +16
−9
test/security-floor-routes.test.ts +16 −9
| @@ -256,17 +256,22 @@ const paramsOf = (pattern: string): string[] => | ||
| 256 | 256 | [...pattern.matchAll(/[:*]([a-z_]+)/g)].map((m) => m[1]!); |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | * The GET table in five parts, each walked by its own tests so none runs the | |
| 260 | * whole table under the 2 s test budget: a repository's pages in two halves, the rest of the | |
| 261 | * pages in two halves, and the API. Together they are every GET pattern (checked below). | |
| 259 | * The GET table in seven parts, each walked by its own tests so none runs the | |
| 260 | * whole table under the 2 s test budget: a repository's pages in four quarters (the first half | |
| 261 | * alone took 2.48 s of CPU, #18231), the rest of the pages in two halves, and the API. Together | |
| 262 | * they are every GET pattern (checked below). | |
| 262 | 263 | */ |
| 263 | 264 | const PARTS = { |
| 264 | "repository pages, first half": () => repoPages().slice(0, Math.ceil(repoPages().length / 2)), | |
| 265 | "repository pages, second half": () => repoPages().slice(Math.ceil(repoPages().length / 2)), | |
| 265 | "repository pages, first quarter": () => quarter(repoPages(), 0), | |
| 266 | "repository pages, second quarter": () => quarter(repoPages(), 1), | |
| 267 | "repository pages, third quarter": () => quarter(repoPages(), 2), | |
| 268 | "repository pages, last quarter": () => quarter(repoPages(), 3), | |
| 266 | 269 | "other pages, first half": () => otherPages().slice(0, Math.ceil(otherPages().length / 2)), |
| 267 | 270 | "other pages, second half": () => otherPages().slice(Math.ceil(otherPages().length / 2)), |
| 268 | 271 | "API": () => getPatternsFrom(buildApiRouter), |
| 269 | 272 | } as const; |
| 273 | /** The `i`th of four near-equal slices of a list. */ | |
| 274 | const quarter = (all: string[], i: number): string[] => all.slice(Math.ceil((all.length * i) / 4), Math.ceil((all.length * (i + 1)) / 4)); | |
| 270 | 275 | function repoPages(): string[] { |
| 271 | 276 | return getPatternsFrom(buildRouter).filter((p) => p.startsWith("/:owner/:name")); |
| 272 | 277 | } |
| @@ -319,8 +324,10 @@ const FLOOR = ["content-security-policy", "x-content-type-options", "referrer-po | ||
| 319 | 324 | |
| 320 | 325 | /** Each part's GET paths, and an unknown path that part's router answers. */ |
| 321 | 326 | const UNKNOWN: Record<Part, string> = { |
| 322 | "repository pages, first half": "/ada/notes/no/such/page", | |
| 323 | "repository pages, second half": "/ada/notes/no/such/page", | |
| 327 | "repository pages, first quarter": "/ada/notes/no/such/page", | |
| 328 | "repository pages, second quarter": "/ada/notes/no/such/page", | |
| 329 | "repository pages, third quarter": "/ada/notes/no/such/page", | |
| 330 | "repository pages, last quarter": "/ada/notes/no/such/page", | |
| 324 | 331 | "other pages, first half": "/no/such/path/at/all", |
| 325 | 332 | "other pages, second half": "/no/such/path/at/all", |
| 326 | 333 | "API": "/api/v1/no-such-route", |
| @@ -341,10 +348,10 @@ for (const part of PART_NAMES) { | ||
| 341 | 348 | }, 9_000); |
| 342 | 349 | } |
| 343 | 350 | |
| 344 | test("the five parts together walk every GET pattern, each a real share of it", () => { | |
| 351 | test("the parts together walk every GET pattern, each a real share of it", () => { | |
| 345 | 352 | const walked = new Set(PART_NAMES.flatMap((part) => PARTS[part]())); |
| 346 | 353 | expect(getPatterns().filter((p) => !walked.has(p))).toEqual([]); |
| 347 | for (const part of PART_NAMES) expect(`${part} ${PARTS[part]().length > 50}`).toBe(`${part} true`); | |
| 354 | for (const part of PART_NAMES) expect(`${part} ${PARTS[part]().length > 25}`).toBe(`${part} true`); | |
| 348 | 355 | }); |
| 349 | 356 | |
| 350 | 357 | test("the patterns the seed cannot fill are exactly the ones named, each with a reason", () => { |
new above
offline