{"file":"client/test/init-credential.test.ts","version":318,"total":171,"from":1,"to":171,"lines":[{"n":1,"text":"// abso init and join sign in with the box sign-in, and use this machine's ~/.abso/token only with --token-file. A","atom":"a2683","author":"readspeed","version":268},{"n":2,"text":"// project is never made or joined with a shared credential that happened to be in a file, and both say what they sign","atom":"a2683","author":"readspeed","version":268},{"n":3,"text":"// in with. The client runs as its own process with its own home, so nothing on this machine is read.","atom":"a2683","author":"readspeed","version":268},{"n":4,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":5,"text":"import assert from \"node:assert/strict\";","atom":"a2683","author":"readspeed","version":268},{"n":6,"text":"import { execFile } from \"node:child_process\";","atom":"a2683","author":"readspeed","version":268},{"n":7,"text":"import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from \"node:fs\";","atom":"a2683","author":"readspeed","version":268},{"n":8,"text":"import { createServer, type IncomingHttpHeaders, type Server } from \"node:http\";","atom":"a2683","author":"readspeed","version":268},{"n":9,"text":"import type { AddressInfo } from \"node:net\";","atom":"a2683","author":"readspeed","version":268},{"n":10,"text":"import { tmpdir } from \"node:os\";","atom":"a2683","author":"readspeed","version":268},{"n":11,"text":"import { join, resolve } from \"node:path\";","atom":"a2683","author":"readspeed","version":268},{"n":12,"text":"import { after, before, describe, it } from \"node:test\";","atom":"a2683","author":"readspeed","version":268},{"n":13,"text":"import { parseArgs } from \"../src/args.ts\";","atom":"a2683","author":"readspeed","version":268},{"n":14,"text":"import { writeBox } from \"../src/box.ts\";","atom":"a2683","author":"readspeed","version":268},{"n":15,"text":"import { tokenCredential } from \"../src/join-commands.ts\";","atom":"a2683","author":"readspeed","version":268},{"n":16,"text":"import { type Fake, startFake } from \"./fake-server.ts\";","atom":"a2683","author":"readspeed","version":268},{"n":17,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":18,"text":"const CLIENT = resolve(import.meta.dirname, \"..\", \"abso.ts\");","atom":"a2683","author":"readspeed","version":268},{"n":19,"text":"const TOKEN = \"file-token-not-secret\";","atom":"a2683","author":"readspeed","version":268},{"n":20,"text":"const CREDENTIAL = \"abso_bx_box-credential-not-secret\";","atom":"a2683","author":"readspeed","version":268},{"n":21,"text":"let fake: Fake;","atom":"a2683","author":"readspeed","version":268},{"n":22,"text":"// Stands in for a server that takes box sign-ins: it notes each request, then answers 500 so the run stops there.","atom":"a2683","author":"readspeed","version":268},{"n":23,"text":"let boxes: Server;","atom":"a2683","author":"readspeed","version":268},{"n":24,"text":"let boxesUrl: string;","atom":"a2683","author":"readspeed","version":268},{"n":25,"text":"const heard: { url: string; headers: IncomingHttpHeaders }[] = [];","atom":"a2683","author":"readspeed","version":268},{"n":26,"text":"const dirs: string[] = [];","atom":"a2683","author":"readspeed","version":268},{"n":27,"text":"const temp = () => {","atom":"a2683","author":"readspeed","version":268},{"n":28,"text":"\tconst dir = mkdtempSync(join(tmpdir(), \"abso-test-init-credential-\"));","atom":"a2683","author":"readspeed","version":268},{"n":29,"text":"\tdirs.push(dir);","atom":"a2683","author":"readspeed","version":268},{"n":30,"text":"\treturn dir;","atom":"a2683","author":"readspeed","version":268},{"n":31,"text":"};","atom":"a2683","author":"readspeed","version":268},{"n":32,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":33,"text":"before(async () => {","atom":"a2683","author":"readspeed","version":268},{"n":34,"text":"\tfake = await startFake(0, TOKEN);","atom":"a2683","author":"readspeed","version":268},{"n":35,"text":"\tboxes = createServer((req, res) => {","atom":"a2683","author":"readspeed","version":268},{"n":36,"text":"\t\theard.push({ url: req.url ?? \"\", headers: req.headers });","atom":"a2683","author":"readspeed","version":268},{"n":37,"text":"\t\tres.writeHead(500, { \"content-type\": \"application/json\" }).end('{\"error\":\"stop here\"}');","atom":"a2683","author":"readspeed","version":268},{"n":38,"text":"\t});","atom":"a2683","author":"readspeed","version":268},{"n":39,"text":"\tawait new Promise<void>((done) => boxes.listen(0, \"127.0.0.1\", done));","atom":"a2683","author":"readspeed","version":268},{"n":40,"text":"\tboxesUrl = `http://127.0.0.1:${(boxes.address() as AddressInfo).port}`;","atom":"a2683","author":"readspeed","version":268},{"n":41,"text":"});","atom":"a2683","author":"readspeed","version":268},{"n":42,"text":"after(async () => {","atom":"a2683","author":"readspeed","version":268},{"n":43,"text":"\tawait fake.close();","atom":"a2683","author":"readspeed","version":268},{"n":44,"text":"\tboxes.close();","atom":"a2683","author":"readspeed","version":268},{"n":45,"text":"\tfor (const dir of dirs) rmSync(dir, { recursive: true, force: true });","atom":"a2683","author":"readspeed","version":268},{"n":46,"text":"});","atom":"a2683","author":"readspeed","version":268},{"n":47,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":48,"text":"/** A home holding a token file, and a box sign-in for `boxFor` when given. */","atom":"a2683","author":"readspeed","version":268},{"n":49,"text":"function home(boxFor?: string): string {","atom":"a2683","author":"readspeed","version":268},{"n":50,"text":"\tconst dir = temp();","atom":"a2683","author":"readspeed","version":268},{"n":51,"text":"\tmkdirSync(join(dir, \".abso\"), { recursive: true });","atom":"a2683","author":"readspeed","version":268},{"n":52,"text":"\twriteFileSync(join(dir, \".abso\", \"token\"), `${TOKEN}\\n`);","atom":"a2683","author":"readspeed","version":268},{"n":53,"text":"\tif (boxFor)","atom":"a2683","author":"readspeed","version":268},{"n":54,"text":"\t\twriteBox(","atom":"a2683","author":"readspeed","version":268},{"n":55,"text":"\t\t\t{","atom":"a2683","author":"readspeed","version":268},{"n":56,"text":"\t\t\t\tserver: boxFor,","atom":"a2683","author":"readspeed","version":268},{"n":57,"text":"\t\t\t\tid: \"b_0123abcd\",","atom":"a2683","author":"readspeed","version":268},{"n":58,"text":"\t\t\t\tcredential: CREDENTIAL,","atom":"a2683","author":"readspeed","version":268},{"n":59,"text":"\t\t\t\tgrant: { projects: [], scopes: [{ kind: \"member-all\", role: \"owner\" }] },","atom":"a2683","author":"readspeed","version":268},{"n":60,"text":"\t\t\t\texpiresAt: Date.now() + 86_400_000,","atom":"a2683","author":"readspeed","version":268},{"n":61,"text":"\t\t\t},","atom":"a2683","author":"readspeed","version":268},{"n":62,"text":"\t\t\tdir,","atom":"a2683","author":"readspeed","version":268},{"n":63,"text":"\t\t);","atom":"a2683","author":"readspeed","version":268},{"n":64,"text":"\treturn dir;","atom":"a2683","author":"readspeed","version":268},{"n":65,"text":"}","atom":"a2683","author":"readspeed","version":268},{"n":66,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":67,"text":"function client(","atom":"a2687","author":"readspeed","version":268},{"n":68,"text":"\thomeDir: string,","atom":"a2687","author":"readspeed","version":268},{"n":69,"text":"\tcwd: string,","atom":"a2687","author":"readspeed","version":268},{"n":70,"text":"\t...args: string[]","atom":"a2687","author":"readspeed","version":268},{"n":71,"text":"): Promise<{ code: number; stdout: string; stderr: string }> {","atom":"a2687","author":"readspeed","version":268},{"n":72,"text":"\tconst env: Record<string, string> = {","atom":"a2683","author":"readspeed","version":268},{"n":73,"text":"\t\tPATH: process.env.PATH ?? \"\",","atom":"a2683","author":"readspeed","version":268},{"n":74,"text":"\t\tHOME: homeDir,","atom":"a2683","author":"readspeed","version":268},{"n":75,"text":"\t\tUSERPROFILE: homeDir,","atom":"a2683","author":"readspeed","version":268},{"n":76,"text":"\t\tAVCS_SERVERS_FILE: \"no-servers.json\",","atom":"a2683","author":"readspeed","version":268},{"n":77,"text":"\t\tABSO_NO_BROWSER: \"1\",","atom":"a2683","author":"readspeed","version":268},{"n":78,"text":"\t};","atom":"a2683","author":"readspeed","version":268},{"n":79,"text":"\tif (process.env.CLAUDE_CONFIG_DIR) env.CLAUDE_CONFIG_DIR = process.env.CLAUDE_CONFIG_DIR;","atom":"a2683","author":"readspeed","version":268},{"n":80,"text":"\tif (process.env.SystemRoot) env.SystemRoot = process.env.SystemRoot;","atom":"a2683","author":"readspeed","version":268},{"n":81,"text":"\treturn new Promise((done) => {","atom":"a2683","author":"readspeed","version":268},{"n":82,"text":"\t\texecFile(process.execPath, [CLIENT, ...args], { cwd, env }, (error, stdout, stderr) =>","atom":"a2683","author":"readspeed","version":268},{"n":83,"text":"\t\t\tdone({ code: typeof error?.code === \"number\" ? error.code : 0, stdout, stderr }),","atom":"a2683","author":"readspeed","version":268},{"n":84,"text":"\t\t);","atom":"a2683","author":"readspeed","version":268},{"n":85,"text":"\t});","atom":"a2683","author":"readspeed","version":268},{"n":86,"text":"}","atom":"a2683","author":"readspeed","version":268},{"n":87,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":88,"text":"function folder(): string {","atom":"a2683","author":"readspeed","version":268},{"n":89,"text":"\tconst dir = temp();","atom":"a2683","author":"readspeed","version":268},{"n":90,"text":"\twriteFileSync(join(dir, \"a.txt\"), \"hi\\n\");","atom":"a2683","author":"readspeed","version":268},{"n":91,"text":"\treturn dir;","atom":"a2683","author":"readspeed","version":268},{"n":92,"text":"}","atom":"a2683","author":"readspeed","version":268},{"n":93,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":94,"text":"const FLAGS = { \"token-file\": \"boolean\" } as const;","atom":"a2683","author":"readspeed","version":268},{"n":95,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":96,"text":"describe(\"what init and join sign in with\", () => {","atom":"a2683","author":"readspeed","version":268},{"n":97,"text":"\tit(\"the token file only with --token-file, never into a folder with a key; ABSO_TOKEN as given\", () => {","atom":"a2683","author":"readspeed","version":268},{"n":98,"text":"\t\tconst server = \"http://127.0.0.1:1\";","atom":"a2683","author":"readspeed","version":268},{"n":99,"text":"\t\tconst file = () => TOKEN;","atom":"a2683","author":"readspeed","version":268},{"n":100,"text":"\t\tconst none = parseArgs(\"init\", [], FLAGS);","atom":"a2683","author":"readspeed","version":268},{"n":101,"text":"\t\tconst asked = parseArgs(\"init\", [\"--token-file\"], FLAGS);","atom":"a2683","author":"readspeed","version":268},{"n":102,"text":"\t\tassert.equal(tokenCredential(none, {}, server, temp(), file), undefined, \"a token file alone is not used\");","atom":"a2683","author":"readspeed","version":268},{"n":103,"text":"\t\tassert.deepEqual(tokenCredential(asked, {}, server, temp(), file), {","atom":"a2683","author":"readspeed","version":268},{"n":104,"text":"\t\t\ttoken: TOKEN,","atom":"a2683","author":"readspeed","version":268},{"n":105,"text":"\t\t\twords: \"the token file, ~/.abso/token, as --token-file asks\",","atom":"a2683","author":"readspeed","version":268},{"n":106,"text":"\t\t});","atom":"a2683","author":"readspeed","version":268},{"n":107,"text":"\t\tassert.throws(() => tokenCredential(asked, {}, server, temp(), () => undefined), /this machine has none/);","atom":"a2683","author":"readspeed","version":268},{"n":108,"text":"\t\tconst keyed = temp();","atom":"a2683","author":"readspeed","version":268},{"n":109,"text":"\t\tmkdirSync(join(keyed, \".abso\"));","atom":"a2683","author":"readspeed","version":268},{"n":110,"text":"\t\twriteFileSync(join(keyed, \".abso\", \"key\"), \"{}\");","atom":"a2683","author":"readspeed","version":268},{"n":111,"text":"\t\tassert.throws(() => tokenCredential(asked, {}, server, keyed, file), /already has a key/);","atom":"a2683","author":"readspeed","version":268},{"n":112,"text":"\t\tassert.equal(tokenCredential(none, { ABSO_TOKEN: \"env-token\" }, server, temp(), file)?.words, \"ABSO_TOKEN\");","atom":"a2683","author":"readspeed","version":268},{"n":113,"text":"\t});","atom":"a2683","author":"readspeed","version":268},{"n":114,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":115,"text":"\tit(\"init with a token file and a box sign-in, no flag: signs in with the box, and says so\", async () => {","atom":"a2683","author":"readspeed","version":268},{"n":116,"text":"\t\tconst run = await client(home(boxesUrl), folder(), \"init\", \"--project\", \"made\", \"--server\", boxesUrl);","atom":"a2683","author":"readspeed","version":268},{"n":117,"text":"\t\tassert.match(run.stderr, /Signing in with this box's sign-in, b_0123abcd\\./);","atom":"a2683","author":"readspeed","version":268},{"n":118,"text":"\t\tassert.ok(heard.length > 0);","atom":"a2683","author":"readspeed","version":268},{"n":119,"text":"\t\tassert.ok(","atom":"a2683","author":"readspeed","version":268},{"n":120,"text":"\t\t\theard.every((h) => h.headers.authorization === `Box ${CREDENTIAL}`),","atom":"a2683","author":"readspeed","version":268},{"n":121,"text":"\t\t\t\"every request carried the box's sign-in\",","atom":"a2683","author":"readspeed","version":268},{"n":122,"text":"\t\t);","atom":"a2683","author":"readspeed","version":268},{"n":123,"text":"\t\tassert.ok(","atom":"a2687","author":"readspeed","version":268},{"n":124,"text":"\t\t\theard.every((h) => !String(h.headers.authorization).includes(TOKEN)),","atom":"a2687","author":"readspeed","version":268},{"n":125,"text":"\t\t\t\"the token file was never sent\",","atom":"a2687","author":"readspeed","version":268},{"n":126,"text":"\t\t);","atom":"a2687","author":"readspeed","version":268},{"n":127,"text":"\t});","atom":"a2683","author":"readspeed","version":268},{"n":128,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":129,"text":"\tit(\"init with only a token file, no flag: refused before anything is made, naming --token-file\", async () => {","atom":"a2683","author":"readspeed","version":268},{"n":130,"text":"\t\tconst run = await client(home(), folder(), \"init\", \"--project\", \"unasked\", \"--agent\", \"me\", \"--server\", fake.url);","atom":"a2683","author":"readspeed","version":268},{"n":131,"text":"\t\tassert.notEqual(run.code, 0);","atom":"a2683","author":"readspeed","version":268},{"n":132,"text":"\t\tassert.match(run.stderr, /abso login signs it in\\. ~\\/\\.abso\\/token is used only with --token-file\\./);","atom":"a2683","author":"readspeed","version":268},{"n":133,"text":"\t\tconst status = await fetch(`${fake.url}/p/unasked/status`, { headers: { authorization: `Bearer ${TOKEN}` } });","atom":"a2683","author":"readspeed","version":268},{"n":134,"text":"\t\tassert.equal(status.status, 404, \"no project was made\");","atom":"a2683","author":"readspeed","version":268},{"n":135,"text":"\t});","atom":"a2683","author":"readspeed","version":268},{"n":136,"text":"","atom":"a2683","author":"readspeed","version":268},{"n":137,"text":"\tit(\"init and join with --token-file: sign in with the file, and say so\", async () => {","atom":"a2683","author":"readspeed","version":268},{"n":138,"text":"\t\tconst homeDir = home();","atom":"a2683","author":"readspeed","version":268},{"n":139,"text":"\t\tconst made = await client(","atom":"a2683","author":"readspeed","version":268},{"n":140,"text":"\t\t\thomeDir,","atom":"a2683","author":"readspeed","version":268},{"n":141,"text":"\t\t\tfolder(),","atom":"a2683","author":"readspeed","version":268},{"n":142,"text":"\t\t\t\"init\",","atom":"a2683","author":"readspeed","version":268},{"n":143,"text":"\t\t\t\"--project\",","atom":"a2683","author":"readspeed","version":268},{"n":144,"text":"\t\t\t\"asked\",","atom":"a2683","author":"readspeed","version":268},{"n":145,"text":"\t\t\t\"--agent\",","atom":"a2683","author":"readspeed","version":268},{"n":146,"text":"\t\t\t\"me\",","atom":"a2683","author":"readspeed","version":268},{"n":147,"text":"\t\t\t\"--token-file\",","atom":"a2683","author":"readspeed","version":268},{"n":148,"text":"\t\t\t\"--server\",","atom":"a2683","author":"readspeed","version":268},{"n":149,"text":"\t\t\tfake.url,","atom":"a2683","author":"readspeed","version":268},{"n":150,"text":"\t\t);","atom":"a2683","author":"readspeed","version":268},{"n":151,"text":"\t\tassert.equal(made.code, 0, made.stderr);","atom":"a2683","author":"readspeed","version":268},{"n":152,"text":"\t\tassert.match(made.stderr, /Signing in with the token file, ~\\/\\.abso\\/token, as --token-file asks\\./);","atom":"a2683","author":"readspeed","version":268},{"n":153,"text":"\t\tassert.match(made.stdout, /Created project asked/);","atom":"a2683","author":"readspeed","version":268},{"n":154,"text":"\t\tconst unasked = await client(homeDir, temp(), \"join\", \"asked\", \"--agent\", \"other\", \"--server\", fake.url);","atom":"a2683","author":"readspeed","version":268},{"n":155,"text":"\t\tassert.notEqual(unasked.code, 0, \"join without the flag sends no token\");","atom":"a2683","author":"readspeed","version":268},{"n":156,"text":"\t\tassert.match(unasked.stderr, /~\\/\\.abso\\/token is used only with --token-file\\./);","atom":"a2683","author":"readspeed","version":268},{"n":157,"text":"\t\tconst joined = await client(","atom":"a2683","author":"readspeed","version":268},{"n":158,"text":"\t\t\thomeDir,","atom":"a2683","author":"readspeed","version":268},{"n":159,"text":"\t\t\ttemp(),","atom":"a2683","author":"readspeed","version":268},{"n":160,"text":"\t\t\t\"join\",","atom":"a2683","author":"readspeed","version":268},{"n":161,"text":"\t\t\t\"asked\",","atom":"a2683","author":"readspeed","version":268},{"n":162,"text":"\t\t\t\"--agent\",","atom":"a2683","author":"readspeed","version":268},{"n":163,"text":"\t\t\t\"other\",","atom":"a2683","author":"readspeed","version":268},{"n":164,"text":"\t\t\t\"--token-file\",","atom":"a2683","author":"readspeed","version":268},{"n":165,"text":"\t\t\t\"--server\",","atom":"a2683","author":"readspeed","version":268},{"n":166,"text":"\t\t\tfake.url,","atom":"a2683","author":"readspeed","version":268},{"n":167,"text":"\t\t);","atom":"a2683","author":"readspeed","version":268},{"n":168,"text":"\t\tassert.equal(joined.code, 0, joined.stderr);","atom":"a2683","author":"readspeed","version":268},{"n":169,"text":"\t\tassert.match(joined.stderr, /Signing in with the token file/);","atom":"a2683","author":"readspeed","version":268},{"n":170,"text":"\t});","atom":"a2683","author":"readspeed","version":268},{"n":171,"text":"});","atom":"a2683","author":"readspeed","version":268}],"atoms":[{"atom":"a2683","author":"readspeed","message":"","time":1792100068653,"timeIso":"2026-10-15T21:34:28.653Z","publish":{"draft":null,"version":268,"agent":"readspeed","message":"abso init and join sign in with the box sign-in; ~/.abso/token only with --token-file\n\nBefore, abso init used ~/.abso/token whenever the file existed, ahead of the box sign-in. So a project could be made with whatever credential happened to be in that file, without the agent knowing. abso join with --agent fell back to the same file.\n\n- init signs in with the box sign-in when there is one. A token named in the environment (ABSO_TOKEN, or a pipeline run's ABSO_KEY_FILE) is used as given.\n- ~/.abso/token is used only with the new --token-file flag, on init and on join, and never by itself. Without the flag and with nothing else to sign in with, init refuses before it makes anything (\"~/.abso/token is used only with --token-file\"), and so does join's sign-in error.\n- --token-file is refused in a folder that already has a key.\n- Both say what they sign in with before they make or join anything: \"this box's sign-in, b_...\", \"a new key from this box's sign-in\", \"this folder's key\", \"ABSO_TOKEN\", or \"the token file, ~/.abso/token, as --token-file asks\".\n- config.ts: trustedToken and tokenFile are exported, and readConfig takes tokenFileOk (default true, so other commands are unchanged).\n\nTests: client/test/init-credential.test.ts (4). With a token file and a box sign-in, init sends only the box's credential. With only a token file, init is refused and no project is made. With --token-file, init and join use the file and say so. All client tests pass (440).\n\nCloses issue 25.","time":1792100173679,"timeIso":"2026-10-15T21:36:13.679Z"}},{"atom":"a2687","author":"readspeed","message":"","time":1792100173165,"timeIso":"2026-10-15T21:36:13.165Z","publish":{"draft":null,"version":268,"agent":"readspeed","message":"abso init and join sign in with the box sign-in; ~/.abso/token only with --token-file\n\nBefore, abso init used ~/.abso/token whenever the file existed, ahead of the box sign-in. So a project could be made with whatever credential happened to be in that file, without the agent knowing. abso join with --agent fell back to the same file.\n\n- init signs in with the box sign-in when there is one. A token named in the environment (ABSO_TOKEN, or a pipeline run's ABSO_KEY_FILE) is used as given.\n- ~/.abso/token is used only with the new --token-file flag, on init and on join, and never by itself. Without the flag and with nothing else to sign in with, init refuses before it makes anything (\"~/.abso/token is used only with --token-file\"), and so does join's sign-in error.\n- --token-file is refused in a folder that already has a key.\n- Both say what they sign in with before they make or join anything: \"this box's sign-in, b_...\", \"a new key from this box's sign-in\", \"this folder's key\", \"ABSO_TOKEN\", or \"the token file, ~/.abso/token, as --token-file asks\".\n- config.ts: trustedToken and tokenFile are exported, and readConfig takes tokenFileOk (default true, so other commands are unchanged).\n\nTests: client/test/init-credential.test.ts (4). With a token file and a box sign-in, init sends only the box's credential. With only a token file, init is refused and no project is made. With --token-file, init and join use the file and say so. All client tests pass (440).\n\nCloses issue 25.","time":1792100173679,"timeIso":"2026-10-15T21:36:13.679Z"}}]}