{"file":"client/test/web-session.test.ts","version":318,"total":106,"from":1,"to":106,"lines":[{"n":1,"text":"// abso login --web: a staging website session handed to a browser as a one-use link, with no secret printed.","atom":"a2926","author":"box-grants","version":302},{"n":2,"text":"","atom":"a2926","author":"box-grants","version":302},{"n":3,"text":"import assert from \"node:assert/strict\";","atom":"a2926","author":"box-grants","version":302},{"n":4,"text":"import { mkdtempSync, writeFileSync } from \"node:fs\";","atom":"a2926","author":"box-grants","version":302},{"n":5,"text":"import { tmpdir } from \"node:os\";","atom":"a2926","author":"box-grants","version":302},{"n":6,"text":"import { join } from \"node:path\";","atom":"a2926","author":"box-grants","version":302},{"n":7,"text":"import { test } from \"node:test\";","atom":"a2926","author":"box-grants","version":302},{"n":8,"text":"import { handoffText, patFromFile, siteFor, webHandoff, webLogin } from \"../src/web-session.ts\";","atom":"a2948","author":"box-grants","version":306},{"n":9,"text":"","atom":"a2926","author":"box-grants","version":302},{"n":10,"text":"const SITE = \"https://abso-website-staging.chrisazy.workers.dev\";","atom":"a2926","author":"box-grants","version":302},{"n":11,"text":"const STAGING = \"https://abso-staging.chrisazy.workers.dev\";","atom":"a2948","author":"box-grants","version":306},{"n":12,"text":"const BOX = `abso_bx_${\"C\".repeat(43)}`;","atom":"a2926","author":"box-grants","version":302},{"n":13,"text":"const PAT = `abso_pat_${\"A\".repeat(40)}`;","atom":"a2948","author":"box-grants","version":306},{"n":14,"text":"const NOW = Date.UTC(2026, 9, 16, 9, 0, 0);","atom":"a2926","author":"box-grants","version":302},{"n":15,"text":"","atom":"a2926","author":"box-grants","version":302},{"n":16,"text":"test(\"the credential goes only to the staging website beside the folder's staging server (Security condition 6)\", () => {","atom":"a2948","author":"box-grants","version":306},{"n":17,"text":"\tassert.equal(siteFor(STAGING, undefined, \"box\"), SITE);","atom":"a2948","author":"box-grants","version":306},{"n":18,"text":"\tassert.equal(siteFor(\"https://avcs-staging.chrisazy.workers.dev/\", undefined, \"pat\"), SITE);","atom":"a2948","author":"box-grants","version":306},{"n":19,"text":"\t// A server that isn't staging is refused, prod included, whatever is asked.","atom":"a2948","author":"box-grants","version":306},{"n":20,"text":"\tassert.throws(","atom":"a2954","author":"box-grants","version":306},{"n":21,"text":"\t\t() => siteFor(\"https://api.abso.dev\", undefined, \"box\"),","atom":"a2954","author":"box-grants","version":306},{"n":22,"text":"\t\t/for staging.*never sign in to the website on prod/,","atom":"a2954","author":"box-grants","version":306},{"n":23,"text":"\t);","atom":"a2954","author":"box-grants","version":306},{"n":24,"text":"\tassert.throws(() => siteFor(\"https://api.abso.dev\", \"http://localhost:8871\", \"pat\"), /for staging/);","atom":"a2948","author":"box-grants","version":306},{"n":25,"text":"\t// A box's sign-in takes no --site, not even the staging website's own address.","atom":"a2948","author":"box-grants","version":306},{"n":26,"text":"\tassert.throws(() => siteFor(STAGING, SITE, \"box\"), /isn't taken with a box's sign-in/);","atom":"a2948","author":"box-grants","version":306},{"n":27,"text":"\tassert.throws(() => siteFor(STAGING, \"http://localhost:8871\", \"box\"), /isn't taken with a box's sign-in/);","atom":"a2948","author":"box-grants","version":306},{"n":28,"text":"\t// A PAT may name this machine over http, and nothing else.","atom":"a2948","author":"box-grants","version":306},{"n":29,"text":"\tassert.equal(siteFor(STAGING, \"http://localhost:8871/x\", \"pat\"), \"http://localhost:8871\");","atom":"a2948","author":"box-grants","version":306},{"n":30,"text":"\tassert.equal(siteFor(STAGING, \"http://127.0.0.1:8871\", \"pat\"), \"http://127.0.0.1:8871\");","atom":"a2948","author":"box-grants","version":306},{"n":31,"text":"\tfor (const elsewhere of [\"https://anywhere.example\", SITE, \"https://localhost:8871\", \"not a url\"])","atom":"a2948","author":"box-grants","version":306},{"n":32,"text":"\t\tassert.throws(() => siteFor(STAGING, elsewhere, \"pat\"), /names this machine only/, elsewhere);","atom":"a2948","author":"box-grants","version":306},{"n":33,"text":"});","atom":"a2948","author":"box-grants","version":306},{"n":34,"text":"","atom":"a2948","author":"box-grants","version":306},{"n":35,"text":"test(\"a refused handoff reads no credential and sends no request\", async () => {","atom":"a2948","author":"box-grants","version":306},{"n":36,"text":"\tconst sent: string[] = [];","atom":"a2948","author":"box-grants","version":306},{"n":37,"text":"\tconst fetcher = (async (url: string) => (sent.push(url), Response.json({}))) as unknown as typeof fetch;","atom":"a2948","author":"box-grants","version":306},{"n":38,"text":"\tlet read = 0;","atom":"a2948","author":"box-grants","version":306},{"n":39,"text":"\tconst credential = () => (read++, BOX);","atom":"a2948","author":"box-grants","version":306},{"n":40,"text":"\tfor (const asked of [","atom":"a2948","author":"box-grants","version":306},{"n":41,"text":"\t\t{ server: \"https://api.abso.dev\", site: undefined, kind: \"box\" as const },","atom":"a2948","author":"box-grants","version":306},{"n":42,"text":"\t\t{ server: STAGING, site: \"https://anywhere.example\", kind: \"box\" as const },","atom":"a2948","author":"box-grants","version":306},{"n":43,"text":"\t\t{ server: STAGING, site: SITE, kind: \"box\" as const },","atom":"a2948","author":"box-grants","version":306},{"n":44,"text":"\t\t{ server: \"https://api.abso.dev\", site: \"http://localhost:8871\", kind: \"pat\" as const },","atom":"a2948","author":"box-grants","version":306},{"n":45,"text":"\t\t{ server: STAGING, site: \"https://anywhere.example\", kind: \"pat\" as const },","atom":"a2948","author":"box-grants","version":306},{"n":46,"text":"\t])","atom":"a2948","author":"box-grants","version":306},{"n":47,"text":"\t\tawait assert.rejects(webLogin({ ...asked, credential, fetcher }), /Nothing was sent/, JSON.stringify(asked));","atom":"a2948","author":"box-grants","version":306},{"n":48,"text":"\tassert.deepEqual(sent, []);","atom":"a2948","author":"box-grants","version":306},{"n":49,"text":"\tassert.equal(read, 0);","atom":"a2948","author":"box-grants","version":306},{"n":50,"text":"\t// Allowed, it goes to the staging website only.","atom":"a2948","author":"box-grants","version":306},{"n":51,"text":"\tawait webLogin({ server: STAGING, site: undefined, kind: \"pat\", credential: () => PAT, fetcher }).catch(() => {});","atom":"a2948","author":"box-grants","version":306},{"n":52,"text":"\tassert.deepEqual(sent, [`${SITE}/login/handoff`]);","atom":"a2948","author":"box-grants","version":306},{"n":53,"text":"});","atom":"a2926","author":"box-grants","version":302},{"n":54,"text":"","atom":"a2926","author":"box-grants","version":302},{"n":55,"text":"test(\"the credential goes in Authorization only, and the answer is the one link and who it signs in as\", async () => {","atom":"a2926","author":"box-grants","version":302},{"n":56,"text":"\tconst seen: { url: string; authorization: string | null; body: unknown }[] = [];","atom":"a2926","author":"box-grants","version":302},{"n":57,"text":"\tconst fetcher = (async (url: string, init: RequestInit) => {","atom":"a2926","author":"box-grants","version":302},{"n":58,"text":"\t\tseen.push({ url, authorization: new Headers(init.headers).get(\"authorization\"), body: init.body ?? null });","atom":"a2926","author":"box-grants","version":302},{"n":59,"text":"\t\treturn Response.json({","atom":"a2926","author":"box-grants","version":302},{"n":60,"text":"\t\t\turl: `${SITE}/login/handoff#${\"t\".repeat(50)}`,","atom":"a2926","author":"box-grants","version":302},{"n":61,"text":"\t\t\texpiresAt: new Date(NOW + 60_000).toISOString(),","atom":"a2926","author":"box-grants","version":302},{"n":62,"text":"\t\t\taccount: \"acct_person1\",","atom":"a2926","author":"box-grants","version":302},{"n":63,"text":"\t\t\tname: \"christopher\",","atom":"a2926","author":"box-grants","version":302},{"n":64,"text":"\t\t\tsessionEnds: \"2026-10-16T21:00:00.000Z\",","atom":"a2926","author":"box-grants","version":302},{"n":65,"text":"\t\t});","atom":"a2926","author":"box-grants","version":302},{"n":66,"text":"\t}) as typeof fetch;","atom":"a2926","author":"box-grants","version":302},{"n":67,"text":"\tconst h = await webHandoff(SITE, BOX, fetcher);","atom":"a2926","author":"box-grants","version":302},{"n":68,"text":"\tassert.deepEqual(seen, [{ url: `${SITE}/login/handoff`, authorization: `Bearer ${BOX}`, body: null }]);","atom":"a2926","author":"box-grants","version":302},{"n":69,"text":"\tconst text = handoffText(h, SITE, true, NOW);","atom":"a2938","author":"box-grants","version":304},{"n":70,"text":"\tassert.match(text, /within 60 seconds/);","atom":"a2926","author":"box-grants","version":302},{"n":71,"text":"\tassert.match(text, /as christopher, until 2026-10-16T21:00:00.000Z, and works once/);","atom":"a2926","author":"box-grants","version":302},{"n":72,"text":"\tassert.match(text, /only to the projects this box was granted, at most as a writer/);","atom":"a2938","author":"box-grants","version":304},{"n":73,"text":"\tassert.match(handoffText(h, SITE, false, NOW), /It reaches at most as a writer:/);","atom":"a2938","author":"box-grants","version":304},{"n":74,"text":"\tassert.match(text, /\\/login\\/handoff#t{50}$/);","atom":"a2926","author":"box-grants","version":302},{"n":75,"text":"\tassert.doesNotMatch(text + JSON.stringify(h), /abso_bx_/);","atom":"a2926","author":"box-grants","version":302},{"n":76,"text":"});","atom":"a2926","author":"box-grants","version":302},{"n":77,"text":"","atom":"a2926","author":"box-grants","version":302},{"n":78,"text":"test(\"a refusal says why without the credential; an answer that isn't the site's own link is refused\", async () => {","atom":"a2926","author":"box-grants","version":302},{"n":79,"text":"\tconst echo = (async () =>","atom":"a2926","author":"box-grants","version":302},{"n":80,"text":"\t\tResponse.json({ error: `that key was refused: ${BOX}` }, { status: 401 })) as unknown as typeof fetch;","atom":"a2926","author":"box-grants","version":302},{"n":81,"text":"\tawait assert.rejects(webHandoff(SITE, BOX, echo), (err: Error) => {","atom":"a2926","author":"box-grants","version":302},{"n":82,"text":"\t\tassert.match(err.message, /refused: that key was refused: \\[the credential\\]/);","atom":"a2926","author":"box-grants","version":302},{"n":83,"text":"\t\tassert.doesNotMatch(err.message, /abso_bx_/);","atom":"a2926","author":"box-grants","version":302},{"n":84,"text":"\t\treturn true;","atom":"a2926","author":"box-grants","version":302},{"n":85,"text":"\t});","atom":"a2926","author":"box-grants","version":302},{"n":86,"text":"\tconst off = (async () => Response.json({ error: \"not found\" }, { status: 404 })) as unknown as typeof fetch;","atom":"a2926","author":"box-grants","version":302},{"n":87,"text":"\tawait assert.rejects(webHandoff(SITE, BOX, off), /doesn't hand out sign-in links/);","atom":"a2926","author":"box-grants","version":302},{"n":88,"text":"\tconst elsewhere = (async () =>","atom":"a2926","author":"box-grants","version":302},{"n":89,"text":"\t\tResponse.json({","atom":"a2926","author":"box-grants","version":302},{"n":90,"text":"\t\t\turl: \"https://elsewhere.example/login/handoff#x\",","atom":"a2926","author":"box-grants","version":302},{"n":91,"text":"\t\t\texpiresAt: new Date(NOW).toISOString(),","atom":"a2926","author":"box-grants","version":302},{"n":92,"text":"\t\t\taccount: \"acct_x\",","atom":"a2926","author":"box-grants","version":302},{"n":93,"text":"\t\t})) as unknown as typeof fetch;","atom":"a2926","author":"box-grants","version":302},{"n":94,"text":"\tawait assert.rejects(webHandoff(SITE, BOX, elsewhere), /isn't a sign-in link/);","atom":"a2926","author":"box-grants","version":302},{"n":95,"text":"});","atom":"a2926","author":"box-grants","version":302},{"n":96,"text":"","atom":"a2926","author":"box-grants","version":302},{"n":97,"text":"test(\"--pat-file reads a PAT from its file, and refuses a file that doesn't hold one\", () => {","atom":"a2926","author":"box-grants","version":302},{"n":98,"text":"\tconst dir = mkdtempSync(join(tmpdir(), \"abso-web-\"));","atom":"a2926","author":"box-grants","version":302},{"n":99,"text":"\tconst good = join(dir, \"pat\");","atom":"a2926","author":"box-grants","version":302},{"n":100,"text":"\twriteFileSync(good, `abso_pat_${\"A\".repeat(40)}\\n`);","atom":"a2926","author":"box-grants","version":302},{"n":101,"text":"\tassert.equal(patFromFile(good), `abso_pat_${\"A\".repeat(40)}`);","atom":"a2926","author":"box-grants","version":302},{"n":102,"text":"\tconst bad = join(dir, \"not\");","atom":"a2926","author":"box-grants","version":302},{"n":103,"text":"\twriteFileSync(bad, \"hello\");","atom":"a2926","author":"box-grants","version":302},{"n":104,"text":"\tassert.throws(() => patFromFile(bad), /doesn't hold a PAT/);","atom":"a2926","author":"box-grants","version":302},{"n":105,"text":"\tassert.throws(() => patFromFile(join(dir, \"missing\")), /can't read/);","atom":"a2926","author":"box-grants","version":302},{"n":106,"text":"});","atom":"a2926","author":"box-grants","version":302}],"atoms":[{"atom":"a2926","author":"box-grants","message":"","time":1792172498126,"timeIso":"2026-10-16T17:41:38.126Z","publish":{"draft":null,"version":302,"agent":"box-grants","message":"abso login --web: a staging website session in an agent's own browser with no secret in its hands. It sends this box's sign-in (or, with --pat-file, a test account's PAT read from that file) to the staging website's /login/handoff and prints only the one-use link it answers, which signs whichever browser opens it in as that person, within a minute. Prod has no website for it: agents never sign in there. Tests: client/test/web-session.test.ts.","time":1792172641933,"timeIso":"2026-10-16T17:44:01.933Z"}},{"atom":"a2938","author":"box-grants","message":"","time":1792174936266,"timeIso":"2026-10-16T18:22:16.266Z","publish":{"draft":null,"version":304,"agent":"box-grants","message":"abso login --web says what the link reaches: a box's only the projects the box was granted, at most as a writer, until the box is revoked or ends (abso 1464, website 1125, Security); a PAT's at most as a writer. The help says the same, and that it writes issues, replies, answers, groups and announcements and changes no members, roles, visibility, keys, boxes or settings. Tests: client/test/web-session.test.ts (4).","time":1792174936899,"timeIso":"2026-10-16T18:22:16.899Z"}},{"atom":"a2948","author":"box-grants","message":"","time":1792178538762,"timeIso":"2026-10-16T19:22:18.762Z","publish":{"draft":null,"version":306,"agent":"box-grants","message":"abso login --web sends a credential only to the staging website beside the folder's own staging server (Security condition 6, Code Review's Medium on 302). The pairing is the fixed list in web-session.ts; any other server, prod included, is refused and nothing is sent. A box's sign-in takes no --site at all. --site is only for --pat-file, and only http://localhost or 127.0.0.1. webLogin settles the website before it reads the credential, so a refusal reads and sends nothing. Tests: client/test/web-session.test.ts (5), including that every refused case reads no credential and sends no request; tsc exits 0.","time":1792178581623,"timeIso":"2026-10-16T19:23:01.623Z"}},{"atom":"a2954","author":"box-grants","message":"","time":1792178581121,"timeIso":"2026-10-16T19:23:01.121Z","publish":{"draft":null,"version":306,"agent":"box-grants","message":"abso login --web sends a credential only to the staging website beside the folder's own staging server (Security condition 6, Code Review's Medium on 302). The pairing is the fixed list in web-session.ts; any other server, prod included, is refused and nothing is sent. A box's sign-in takes no --site at all. --site is only for --pat-file, and only http://localhost or 127.0.0.1. webLogin settles the website before it reads the credential, so a refusal reads and sends nothing. Tests: client/test/web-session.test.ts (5), including that every refused case reads no credential and sends no request; tsc exits 0.","time":1792178581623,"timeIso":"2026-10-16T19:23:01.623Z"}}]}