Files
archie/ui/test/source-signing.test.ts
T
sam 684ec1263a feat(eda): sources own signing, with UUIDv7 paths and approved unsigned option
A source is the capture endpoint: a UUIDv7 path by default or a unique
URL-safe custom path, signed by default with an Archie-generated secret
(encrypted via the bindings cipher), or unsigned after an approval.
Intake verifies X-Hub-Signature-256/X-Signature-256 against the source
secret before redaction; an unauthenticated event on a signed source is
captured but never dispatched, an event on an approved unsigned source
dispatches and is marked unsigned. The binding secret is retired; migration
0006 derives sources from existing binding and capture source strings,
moving each binding's secret onto its source. SourceStore crosses the
State Store gRPC contract. The dashboard gains a sources panel and flags
unsigned in the capture inspector, binding list and task timeline.
2026-09-24 14:26:21 +10:00

53 lines
2.3 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { bindingPayload, emptyDraft } from "../src/bindings/binding-draft.ts";
import { captureSignature } from "../src/captures/capture-signature.ts";
import { signingKind, signingLabel, sourceURL } from "../src/sources/source-signing.ts";
import { describeTimelineEvent } from "../src/tasks/timeline-event.ts";
test("a capture shows how it may dispatch", () => {
const cases: Array<[{ authenticated?: boolean; unsigned?: boolean }, string, string]> = [
[{ authenticated: true }, "Signed", "ok"],
[{ unsigned: true }, "Unsigned", "warn"],
[{}, "Unverified", "idle"],
[{ authenticated: false, unsigned: false }, "Unverified", "idle"],
];
for (const [capture, label, kind] of cases) {
assert.deepEqual(captureSignature(capture), { label, kind }, JSON.stringify(capture));
}
});
test("a source's signing state names itself and its tone", () => {
const cases: Array<[string | undefined, string, string]> = [
["signed", "signed", "ok"],
["unsigned_pending_approval", "unsigned pending approval", "info"],
["unsigned", "unsigned", "warn"],
["something_new", "something_new", "idle"],
[undefined, "unknown", "idle"],
];
for (const [signing, label, kind] of cases) {
assert.equal(signingLabel(signing), label, String(signing));
assert.equal(signingKind(signing), kind, String(signing));
}
});
test("a source's URL escapes nothing a valid path can hold", () => {
assert.equal(
sourceURL("https://archie.example", "0199a0b2-0000-7000-8000-000000000000"),
"https://archie.example/webhooks/capture/0199a0b2-0000-7000-8000-000000000000",
);
assert.equal(sourceURL("http://h", "a b"), "http://h/webhooks/capture/a%20b");
});
test("a task started by an unsigned event says so on its timeline", () => {
const line = describeTimelineEvent({ kind: "unsigned_event", data: { source: "firewall" } });
assert.deepEqual(line, { title: "Started by an unsigned event", detail: "source firewall", tone: "warn" });
assert.equal(describeTimelineEvent({ kind: "stage_start", stage: "plan" }).tone, undefined);
});
test("a binding no longer carries a signing secret", () => {
const payload = bindingPayload(emptyDraft());
assert.equal("secret" in payload, false);
});