Lines 16–22 at 318 (were 16–21 at 86)
1616import { tmpdir } from "node:os"; 1717import { join, resolve } from "node:path"; 1818import { after, before, describe, it } from "node:test"; 19+import { Api } from "../src/api.ts"; 1920import { writeBox } from "../src/box.ts"; 2021import { writeConfig } from "../src/config.ts"; 2122import { isPublic } from "../src/join-commands.ts"; Lines 37–53 at 318 (were 36–49 at 86)
40+ // A project's groups are its members' to read and write; a visitor sees none. 42− "publish",
46− "sync",
Lines 61–68 at 318 (were 57–62 at 86)
Lines 72–78 at 318 (were 66–72 at 86)
69− "draft-sync",
Lines 202–208 at 318 (were 196–202 at 86)
198204 credential: CREDENTIAL, 199− grant: { projects: [{ project: "abso-core", role: "writer" }], max_agents: 3 },
205+ grant: { projects: [{ project: "abso-core", role: "writer" }] }, 200206 expiresAt: Date.now() + 86_400_000, Lines 223–229 at 318 (were 217–223 at 86)
217223 assert.equal(elsewhereHeard, 0); 220− it("asks fetch for no redirect and no credentials, join's public check too (a fetch spy)", async () => {
226+ it("asks fetch to follow no redirect and sends no credential, join's public check too (a fetch spy)", async () => { 221227 const root = temp("spy"); 222228 writeConfig(root, { server: url, project: "abso-core", agent: "", visitor: true }); 223229 const real = globalThis.fetch; Lines 242–247 at 318 (were 236–242 at 86)
236242 assert.equal(calls.length, 2); 237243 for (const init of calls) { 238244 assert.equal(init.redirect, "error"); 239− assert.equal(init.credentials, "omit");
240245 const headers = new Headers(init.headers); 241246 assert.equal(headers.get("authorization"), null); 242247 assert.equal(headers.get("cookie"), null); Lines 263–291 at 318 (were 258–263 at 86)
258263 assert.match(runs[0]!.stderr, /isn't signed in to .*abso login signs it in/); 266+ it("every request its Api makes goes through one send: reads only, no redirect, no sign-in", async () => { 267+ const real = globalThis.fetch; 268+ const calls: RequestInit[] = []; 269+ globalThis.fetch = (async (_input: unknown, init?: RequestInit) => { 270+ calls.push(init ?? {}); 271+ return new Response("{}", { status: 200 }); 274+ const visitor = new Api({ server: url, project: "abso-core", agent: "", visitor: true, token: TOKEN }); 275+ await visitor.send(`${url}/p/abso-core/serve`, { headers: visitor.headers() }); 276+ await assert.rejects(visitor.send(`${url}/p/abso-core/a/x/run`, { method: "POST" }), /sends only reads/); 277+ const member = new Api({ server: url, project: "abso-core", agent: "x", token: TOKEN }); 278+ await member.send(`${url}/p/abso-core/serve`, { headers: member.headers() }); 280+ globalThis.fetch = real; 282+ assert.equal(calls.length, 2); 283+ assert.equal(calls[0]!.redirect, "error"); 284+ assert.equal(new Headers(calls[0]!.headers).get("authorization"), null); 285+ assert.equal(calls[1]!.redirect, undefined); 286+ assert.equal(new Headers(calls[1]!.headers).get("authorization"), `Bearer ${TOKEN}`); 261289 it("runs only its reads: every other command is refused before any call, and a new command fails here", async () => { 262290 const sorted = new Set([...Object.keys(VISITOR_READS), ...VISITOR_ELSEWHERE, ...REFUSED]); 263291 for (const name of Object.keys(commandTable()))