Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 2 to 318

Compare

+96 −0 in 1 place
new file, 96 lines
1+// A pipeline run's key (ABSO_KEY_FILE): read from the file the runner wrote, sent only where a token may go,
2+// held in memory only, and a run key's refusals reach the job as the server wrote them.
3+
4+import assert from "node:assert/strict";
5+import { mkdtempSync, writeFileSync } from "node:fs";
6+import { createServer } from "node:http";
7+import type { AddressInfo } from "node:net";
8+import { tmpdir } from "node:os";
9+import { join } from "node:path";
10+import { test } from "node:test";
11+import { Api, ApiError } from "../src/api.ts";
12+import { credentialLabel, installKey, readConfig, runKey, tokenFor, writeConfig } from "../src/config.ts";
14+const KEY = "abso_sk_runkeyabcdefghijklmnopqrstuvwx";
15+const LOCAL = "http://127.0.0.1:8787";
17+function keyFile(text: string): string {
18+ const path = join(mkdtempSync(join(tmpdir(), "abso-run-key-")), "key");
19+ writeFileSync(path, text);
20+ return path;
21+}
23+function folder(server = LOCAL) {
24+ const root = mkdtempSync(join(tmpdir(), "abso-run-key-"));
25+ writeConfig(root, { server, project: "p", agent: "run-7-check-test" });
26+ return root;
27+}
29+const NO_SERVERS = { ABSO_SERVERS_FILE: "no-servers.json" };
31+test("ABSO_KEY_FILE's key is the credential when no token or folder key is set", () => {
32+ const env = { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) };
33+ assert.equal(runKey(env), KEY);
34+ assert.equal(tokenFor(LOCAL, env, folder()), KEY);
35+ assert.deepEqual(credentialLabel(folder(), LOCAL, env), { kind: "pipeline run key", id: null });
36+ assert.equal(readConfig(folder(), env).token, KEY);
37+});
39+test("a trailing newline in the key file is not part of the key", () => {
40+ assert.equal(runKey({ ABSO_KEY_FILE: keyFile(`${KEY}\n`) }), KEY);
41+});
43+test("ABSO_TOKEN and a folder's own key both come before the run key", () => {
44+ const env = { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY), ABSO_TOKEN: "shared-token-value" };
45+ assert.equal(tokenFor(LOCAL, env, folder()), "shared-token-value");
46+ assert.deepEqual(credentialLabel(folder(), LOCAL, env), { kind: "shared token", id: null });
47+ const root = folder();
48+ installKey(root, JSON.stringify({ key: "abso_sk_folderkeyabcdefghijklmnopqrstu", id: "k_ab12cd34" }));
49+ assert.equal(
50+ tokenFor(LOCAL, { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) }, root),
51+ "abso_sk_folderkeyabcdefghijklmnopqrstu",
52+ );
53+});
55+test("the run key goes only where a token may, and the refusal doesn't hold it", () => {
56+ const env = { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) };
57+ assert.throws(
58+ () => tokenFor("https://someone-else.example", env, folder("https://someone-else.example")),
59+ (err: Error) => /sends your token only to/.test(err.message) && !err.message.includes(KEY),
60+ );
61+});
63+test("a key file abso can't read, or that holds no key, is named without its contents", () => {
64+ const missing = join(tmpdir(), "abso-no-such-key-file");
65+ assert.throws(() => runKey({ ABSO_KEY_FILE: missing }), /can't read/);
66+ const wrong = keyFile("not-a-key secret-looking-text");
67+ assert.throws(
68+ () => runKey({ ABSO_KEY_FILE: wrong }),
69+ (err: Error) => /doesn't hold an abso key/.test(err.message) && !err.message.includes("secret-looking-text"),
70+ );
71+});
73+test("a run key's refusal reaches the job as the server wrote it, and without the key", async () => {
74+ let sent = "";
75+ const server = createServer((req, res) => {
76+ sent = req.headers.authorization ?? "";
77+ res.writeHead(403, { "content-type": "application/json" });
78+ res.end(JSON.stringify({ error: "a pipeline run's key can't land" }));
79+ });
80+ await new Promise<void>((ok) => server.listen(0, "127.0.0.1", ok));
81+ try {
82+ const url = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
83+ const config = readConfig(folder(url), { ...NO_SERVERS, ABSO_KEY_FILE: keyFile(KEY) });
84+ await assert.rejects(
85+ new Api(config).land("try"),
86+ (err: Error) =>
87+ err instanceof ApiError &&
88+ err.status === 403 &&
89+ /a pipeline run's key can't land/.test(err.message) &&
90+ !err.message.includes(KEY),
91+ );
92+ assert.equal(sent, `Bearer ${KEY}`);
93+ } finally {
94+ server.close();
95+ }
96+});
MCP
compare on this site's /mcp
CLI
abso diff 2 318 client/test/run-key.test.ts --json
JSON
/christopher/abso-core/compare/2..318?file=client%2Ftest%2Frun-key.test.ts&format=json