Lines 5–57 at 306 (were 5–24 at 305)
55import { tmpdir } from "node:os"; 66import { join } from "node:path"; 77import { test } from "node:test"; 8−import { handoffText, patFromFile, siteFor, webHandoff } from "../src/web-session.ts";
8+import { handoffText, patFromFile, siteFor, webHandoff, webLogin } from "../src/web-session.ts"; 1010const SITE = "https://abso-website-staging.chrisazy.workers.dev"; 11+const STAGING = "https://abso-staging.chrisazy.workers.dev"; 1112const BOX = `abso_bx_${"C".repeat(43)}`; 13+const PAT = `abso_pat_${"A".repeat(40)}`; 1214const NOW = Date.UTC(2026, 9, 16, 9, 0, 0); 14−test("the website is the staging one beside the server, or --site; prod has none, since agents never sign in there", () => {
15− assert.equal(siteFor("https://abso-staging.chrisazy.workers.dev"), SITE);
16− assert.equal(siteFor("https://avcs-staging.chrisazy.workers.dev/"), SITE);
17− assert.throws(() => siteFor("https://api.abso.dev"), /for staging.*never sign in to the website on prod/);
18− assert.equal(siteFor("https://api.abso.dev", "http://localhost:8871/x"), "http://localhost:8871");
19− assert.throws(() => siteFor("https://api.abso.dev", "http://elsewhere.example"), /https/);
16+test("the credential goes only to the staging website beside the folder's staging server (Security condition 6)", () => { 17+ assert.equal(siteFor(STAGING, undefined, "box"), SITE); 18+ assert.equal(siteFor("https://avcs-staging.chrisazy.workers.dev/", undefined, "pat"), SITE); 19+ // A server that isn't staging is refused, prod included, whatever is asked. 21+ () => siteFor("https://api.abso.dev", undefined, "box"), 22+ /for staging.*never sign in to the website on prod/, 24+ assert.throws(() => siteFor("https://api.abso.dev", "http://localhost:8871", "pat"), /for staging/); 25+ // A box's sign-in takes no --site, not even the staging website's own address. 26+ assert.throws(() => siteFor(STAGING, SITE, "box"), /isn't taken with a box's sign-in/); 27+ assert.throws(() => siteFor(STAGING, "http://localhost:8871", "box"), /isn't taken with a box's sign-in/); 28+ // A PAT may name this machine over http, and nothing else. 29+ assert.equal(siteFor(STAGING, "http://localhost:8871/x", "pat"), "http://localhost:8871"); 30+ assert.equal(siteFor(STAGING, "http://127.0.0.1:8871", "pat"), "http://127.0.0.1:8871"); 31+ for (const elsewhere of ["https://anywhere.example", SITE, "https://localhost:8871", "not a url"]) 32+ assert.throws(() => siteFor(STAGING, elsewhere, "pat"), /names this machine only/, elsewhere); 35+test("a refused handoff reads no credential and sends no request", async () => { 36+ const sent: string[] = []; 37+ const fetcher = (async (url: string) => (sent.push(url), Response.json({}))) as unknown as typeof fetch; 39+ const credential = () => (read++, BOX); 40+ for (const asked of [ 41+ { server: "https://api.abso.dev", site: undefined, kind: "box" as const }, 42+ { server: STAGING, site: "https://anywhere.example", kind: "box" as const }, 43+ { server: STAGING, site: SITE, kind: "box" as const }, 44+ { server: "https://api.abso.dev", site: "http://localhost:8871", kind: "pat" as const }, 45+ { server: STAGING, site: "https://anywhere.example", kind: "pat" as const }, 47+ await assert.rejects(webLogin({ ...asked, credential, fetcher }), /Nothing was sent/, JSON.stringify(asked)); 48+ assert.deepEqual(sent, []); 49+ assert.equal(read, 0); 50+ // Allowed, it goes to the staging website only. 51+ await webLogin({ server: STAGING, site: undefined, kind: "pat", credential: () => PAT, fetcher }).catch(() => {}); 52+ assert.deepEqual(sent, [`${SITE}/login/handoff`]); 2255test("the credential goes in Authorization only, and the answer is the one link and who it signs in as", async () => { 2356 const seen: { url: string; authorization: string | null; body: unknown }[] = []; 2457 const fetcher = (async (url: string, init: RequestInit) => {