Files
mesh-catalog/modules/gitea/internal/forgeaccount/user_test.go
T
mesh-tools 3a2560dc51
mesh/merge-gate head 3a2560dc51fc merged into trunk 82df3bd58913 — pass: builds gitea → novox; no bus step; every machine composes with the change as it di…
mesh/repo-check head 3a2560dc51fc merged into trunk 82df3bd58913 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
One forge user, nox-agent, for every machine's agents' SSH pushes, each machine's key titled by machine (issue 991, ADR 0410)
2026-10-17 00:46:43 +00:00

40 lines
1.3 KiB
Go

package forgeaccount
import "testing"
func TestForgeUserOfAMachineAccountIsTheOneAgentUser(t *testing.T) {
if got := ForgeUser("g14", "machine"); got != "nox-agent" {
t.Fatalf("ForgeUser = %q", got)
}
if got := ForgeUser("g14", "other"); got != "" {
t.Fatalf("a kind not built yet has no forge user, got %q", got)
}
if got := ForgeUser("ace", "machine"); got != "nox-agent" {
t.Fatalf("every machine shares one forge user, got %q", got)
}
if got := NodeAccount("g14"); got != "agent-g14" {
t.Fatalf("the token tool's per-node account = %q", got)
}
}
func TestRemoveKeysTitledTakesOnlyTheMeshKeysOfThatTitle(t *testing.T) {
f := &keyForge{keys: map[string][]heldKey{"agent-g14": {
{ID: 1, Title: "mesh:g14.nox", Key: keyA},
{ID: 2, Title: "mesh:g14.other", Key: keyB},
{ID: 3, Title: "by hand", Key: "ssh-ed25519 CCCC"},
}}, next: 3}
a := keyAccounts(t, f)
if _, err := a.RemoveKeysTitled(t.Context(), "agent-g14", "mesh:g14.nox"); err != nil {
t.Fatal(err)
}
if got := f.keys["agent-g14"]; len(got) != 2 || got[0].ID != 2 || got[1].ID != 3 {
t.Fatalf("held = %v", got)
}
if _, err := a.RemoveKeysTitled(t.Context(), "agent-g14", "by hand"); err != nil {
t.Fatal(err)
}
if len(f.keys["agent-g14"]) != 2 {
t.Fatal("a key that is not the mesh's was removed")
}
}