Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui ssh row with target snippets, docs for the per-agent switch

This commit is contained in:
atlas 2026-11-16 18:38:10 +01:00 • committed by mara
commit e621397252

View file

@ -0,0 +1,62 @@
// An opened agent card's SSH row: the badge, the PUT body and the target
// snippets. Run by `npm test` with Node's type stripping.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
authorizedKeysLine,
sshBody,
sshSummary,
targetSnippet,
} from "../src/agent/detail/ssh.ts";
const ca = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOHf\n";
test("the badge reads absent as off", () => {
assert.equal(sshSummary(undefined), "off");
assert.equal(sshSummary(false), "off");
assert.equal(sshSummary(true), "on");
});
test("the PUT carries the stored permission list so it is not reset", () => {
assert.deepEqual(sshBody(undefined, true), { ssh: true });
assert.deepEqual(sshBody(["meta"], false), {
permissions: ["meta"],
ssh: false,
});
// Nothing else is sent: the internet and repository fields stay as stored.
assert.deepEqual(Object.keys(sshBody(["meta"], true)).sort(), [
"permissions",
"ssh",
]);
});
test("the authorized_keys line trusts the CA for one principal only", () => {
assert.equal(
authorizedKeysLine("atlas", ca),
'cert-authority,principals="atlas" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOHf',
);
});
test("each target form names the agent and the CA key, and keeps <user> for the operator", () => {
for (const form of ["nixos", "home-manager", "ssh"]) {
const text = targetSnippet(form, "atlas", ca);
assert.ok(text.includes("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOHf"), form);
assert.ok(text.includes("atlas"), form);
}
assert.ok(targetSnippet("nixos", "atlas", ca).includes("<user>"));
assert.ok(
targetSnippet("nixos", "atlas", ca).includes(
'authorizedPrincipals = [ "atlas" ]',
),
);
assert.ok(targetSnippet("nixos", "atlas", ca).includes("TrustedUserCAKeys"));
assert.ok(
targetSnippet("home-manager", "atlas", ca).includes(
'home.file.".ssh/authorized_keys"',
),
);
// No trailing newline of the CA key leaks into a line.
assert.ok(!targetSnippet("ssh", "atlas", ca).includes("\n\n"));
// The control: another agent gets its own principal.
assert.ok(targetSnippet("ssh", "maia", ca).includes('principals="maia"'));
});