/** * AUDIT F (pre-publish, 28 Nov 2026; assets/security/AUDIT-F-JOBS.md): the jobs doors as an attacker sees them. A call * with a job's scheme and a credential that is not genuine must answer the same whatever stands behind the door: * F1 whether the kind is switched on for the account (the switch was read before the credential: off said 410, on 401) * F2 whether the slug holds a personal database at all (the shut door said 410 unread, a real one 401) * and a genuine credential for another account opens nothing. Invented accounts only. */import { env, runInDurableObject, SELF } from"cloudflare:test";import { describe, expect, it } from"vitest";importtype { Business } from"../src/business.ts";import { ADMIN, http, personalObject } from"./personal.ts";const call = (slug: string, path: string, authorization: string) => SELF.fetch(`https://jobs.internal/b/${slug}${path}`, { method: "POST", headers: { authorization } }).then(async (r) => ({ status: r.status, code: ((await r.json().catch(() => ({}))) as { code?: string }).code }));const GARBAGE = "CottonJob j1.eyJ2IjoxfQ.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";describe("the jobs doors give a stranger nothing (AUDIT F)", { timeout: 300_000 }, () => { it("F1: a credential that is not genuine answers the same whether the step kind is on or off", async () => {const slug = "jobs-audit-f1";await personalObject(slug);const off = await call(slug, "/v1/jobs/step/media_drop", GARBAGE); expect((await http(slug, "PUT", "/v1/admin/business", { jobs: { media_drop: "on" } }, ADMIN)).status).toBe(200);const on = await call(slug, "/v1/jobs/step/media_drop", GARBAGE); expect(off, "off and on alike").toEqual(on); expect(on.status).toBe(401); }); it("F1: the mail door, too: the same answer with mail jobs off as a genuine door refusing the credential", async () => {const slug = "jobs-audit-f1-mail";await personalObject(slug);const off = await call(slug, "/v1/jobs/mail/begin", GARBAGE); expect(off.status).toBe(401); }); it("F2: a slug with no personal database answers as one with a database and a bad credential", async () => {await personalObject("jobs-audit-f2-real");for (const path of ["/v1/jobs/step/media_drop", "/v1/jobs/mail/begin"]) {const real = await call("jobs-audit-f2-real", path, GARBAGE);const none = await call("jobs-audit-f2-nobody-here", path, GARBAGE); expect(none, path).toEqual(real); expect(none.status, path).toBe(401); } }); it("a genuine credential for one account opens nothing at another's door", async () => {const a = "jobs-audit-cross-a";const b = "jobs-audit-cross-b";for (const slug of [a, b]) {await personalObject(slug); expect((await http(slug, "PUT", "/v1/admin/business", { jobs: { media_drop: "on" } }, ADMIN)).status).toBe(200); }const message = await runInDurableObject(env.BUSINESS.get(env.BUSINESS.idFromName(a)), (instance: Business) => instance.stepJobMessage("media_drop"));const there = await call(b, "/v1/jobs/step/media_drop", `CottonJob ${message.token}`); expect(there.status).toBe(401); });});