Files
archie/ui/test/source-signing.test.ts
T

62 lines
2.0 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { captureSignature } from "../src/pages/events/inspector/lib/capture-signature.ts";
import {
signingKind,
signingLabel,
} 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<[{ verification?: string }, string, string]> = [
[{ verification: "signed" }, "Signed", "ok"],
[{ verification: "token" }, "Token", "ok"],
[{ verification: "unsigned" }, "Unsigned", "warn"],
[{}, "Unverified", "idle"],
[{ verification: "" }, "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"],
["token", "bearer token", "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 task started by an unsigned event says so on its timeline", () => {
const line = describeTimelineEvent({
kind: "binding_started",
data: { source: "firewall", binding_name: "fw", capture_id: "c1", unsigned: true },
});
assert.deepEqual(line, {
title: "Started by an unsigned event",
detail: "source firewall",
tone: "warn",
links: [
{ label: "binding fw", to: "/events/bindings" },
{ label: "captured event", to: "/events/inspector?capture=c1" },
],
});
assert.equal(
describeTimelineEvent({ kind: "stage_start", stage: "plan" }).tone,
undefined,
);
});