package api import "testing" func TestPickDeployLaneDoSvc(t *testing.T) { allowlist := NormalizeServiceDeployAllowlist(nil) services := []DeployServiceFinding{ {Name: "CCMEXEC", Status: "running"}, {Name: "DoSvc", Status: "running"}, } matched, lane, ok := PickDeployLane(services, allowlist) if !ok { t.Fatal("expected match") } if matched != "DoSvc" || lane.Lane != "do_peer" { t.Fatalf("matched=%q lane=%q", matched, lane.Lane) } } func TestNormalizeJoinLaneDoPeer(t *testing.T) { if got := normalizeJoinLane("do-peer"); got != "do_peer" { t.Fatalf("got %q", got) } } func TestNormalizeJoinLaneNewTiers(t *testing.T) { cases := map[string]string{ "wsus-cache-peer": "wsus_cache_peer", "dns-txt": "dns_txt", "webrtc-mesh": "webrtc_mesh", } for in, want := range cases { if got := normalizeJoinLane(in); got != want { t.Fatalf("%q => %q want %q", in, got, want) } } } func TestPickDeployLaneDNSTXT(t *testing.T) { allowlist := NormalizeServiceDeployAllowlist(nil) services := []DeployServiceFinding{{Name: "dns_txt:_aether", Status: "running"}} matched, lane, ok := PickDeployLane(services, allowlist) if !ok || matched != "dns_txt:_aether" || lane.Lane != "dns_txt" { t.Fatalf("matched=%q lane=%q", matched, lane.Lane) } } func TestPickDeployLanePriority(t *testing.T) { allowlist := NormalizeServiceDeployAllowlist(map[string]ServiceDeployLane{ "CCMEXEC": {Lane: "bits_curl", Priority: 10}, "WinRM": {Lane: "winrm", Priority: 30}, "LanmanServer": {Lane: "spread_smb_unc", Priority: 50}, }) services := []DeployServiceFinding{ {Name: "CCMEXEC", Status: "running"}, {Name: "WinRM", Status: "running"}, } matched, lane, ok := PickDeployLane(services, allowlist) if !ok { t.Fatal("expected match") } if matched != "WinRM" || lane.Lane != "winrm" { t.Fatalf("matched=%q lane=%q", matched, lane.Lane) } } func TestPickDeployLaneIgnoresStopped(t *testing.T) { allowlist := NormalizeServiceDeployAllowlist(nil) services := []DeployServiceFinding{{Name: "CCMEXEC", Status: "stopped"}} _, _, ok := PickDeployLane(services, allowlist) if ok { t.Fatal("stopped service should not match") } } func TestNormalizeJoinLaneAliases(t *testing.T) { cases := map[string]string{ "bits/curl": "bits_curl", "spread_smb_unc": "spread_smb_unc", "linux-lotl": "linux_lotl", } for in, want := range cases { if got := normalizeJoinLane(in); got != want { t.Fatalf("%q => %q want %q", in, got, want) } } } func TestVerifyDeployPlanSignature(t *testing.T) { plan := DeployPlanBody{JoinLane: "bits_curl", Action: "bits_curl"} sig, err := signDeployPlan(plan, "test-secret") if err != nil { t.Fatal(err) } if !VerifyDeployPlanSignature(plan, sig, "test-secret") { t.Fatal("signature should verify") } if VerifyDeployPlanSignature(plan, sig, "wrong") { t.Fatal("wrong secret should fail") } }