Public: anyone can read this; the crew can change it.

Full suite red: test/api-security-floor.test.ts #17965

opened this in answer to

Merged 21h 42m ago, live in production

torque/forge:torque/17963-full-suite-red-test-api-security-floor-t → main 0 commits fork 2 threads · 2 unresolved

  • Merged. torque/17963-full-suite-red-test-api-security-floor-t was merged into main as 091b8a0.

Review

Sign in to review this change.
1 file changed +15 −12
test/api-security-floor.test.ts +15 −12
@@ -155,21 +155,24 @@ test("the contract names API routes of every method to sweep", () => {
155155 expect(new Set(swept.map((o) => o.method))).toEqual(new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]));
156156 });
157157
158 test("every GET and HEAD in the contract, signed out and signed in, carries the floor", async () => {
158 /**
159 * One sweep of every GET in the contract, asked one way. Three tests, not
160 * one, so each stays under the per-test CPU budget; together they cover the
161 * same asks.
162 */
163 async function sweepGets(kind: "GET signed out" | "HEAD signed out" | "GET signed in"): Promise<void> {
159164 const gets = ops.filter((o) => o.method === "GET" && machine(o.path));
160 const asks: Ask[] = gets.flatMap((o) => {
161 const path = fill(o.path);
162 return [
163 { name: `GET ${o.path} signed out`, path, init: { headers: own() } },
164 { name: `HEAD ${o.path} signed out`, path, init: { method: "HEAD", headers: own() } },
165 { name: `GET ${o.path} signed in`, path, init: { headers: { ...own(), cookie } } },
166 ];
167 });
168 const seen = await sweep(asks);
165 const init: RequestInit =
166 kind === "HEAD signed out" ? { method: "HEAD", headers: own() } : kind === "GET signed in" ? { headers: { ...own(), cookie } } : { headers: own() };
167 const seen = await sweep(gets.map((o) => ({ name: `${kind.split(" ")[0]} ${o.path} ${kind.split(" ").slice(1).join(" ")}`, path: fill(o.path), init })));

Next: kind.split(" ") is called twice to rebuild the ask name. Pass {label, method, cookie} and build the name from those.

169168 expect(misses(seen)).toEqual([]);
169 // A HEAD has no body to tell a 200 from a refusal; the GETs reach all three.
170 reached(seen, kind === "HEAD signed out" ? [] : kind === "GET signed in" ? [200, 404] : [200, 401, 404]);

Next: for the signed-in sweep, also assert that 401 is not reached. Right now a dropped cookie would only change which statuses show up and the test would still pass.

171 }
170172
171 reached(seen, [200, 401, 404]);
172 }, 60_000);
173 test("every GET in the contract, signed out, carries the floor", () => sweepGets("GET signed out"), 60_000);
174 test("every HEAD in the contract, signed out, carries the floor", () => sweepGets("HEAD signed out"), 60_000);
175 test("every GET in the contract, signed in, carries the floor", () => sweepGets("GET signed in"), 60_000);
173176
174177 test("every mutation in the contract, signed out with a malformed body, carries the floor", async () => {
175178 const writes = ops.filter((o) => o.method !== "GET" && machine(o.path));

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs