Files
AetherForge/server/internal/clearance/clearance_test.go
AetherForge f89ba94cb7 Add L0-L4 security clearance for fleet commands and AI elevation.
Gate manual and AI commands by per-agent clearance, auto-elevate stuck hosts to L4 when AI mode allows, and surface clearance in Access Depth and LOTL timeline.
2026-06-07 02:30:00 -07:00

47 lines
1.2 KiB
Go

package clearance
import (
"testing"
)
func TestL2AgentCannotExecShellWithoutElevation(t *testing.T) {
const agentClearance = L2
cases := []struct {
cmdType string
args map[string]interface{}
}{
{"exec_shell", nil},
{"agent_command", map[string]interface{}{"action": "exec"}},
{"agent_command", map[string]interface{}{"action": "powershell"}},
}
for _, tc := range cases {
if err := EnforceClearance(tc.cmdType, tc.args, agentClearance); err == nil {
t.Fatalf("expected clearance error for %s %+v at L2", tc.cmdType, tc.args)
}
}
if err := EnforceClearance("discover_and_join", nil, agentClearance); err != nil {
t.Fatalf("L2 should allow spread: %v", err)
}
if err := EnforceAction("exec", agentClearance); err == nil {
t.Fatal("L2 should block exec action")
}
if err := EnforceAction("pause", agentClearance); err != nil {
t.Fatalf("L2 should allow pause: %v", err)
}
}
func TestCommandRequiredLevels(t *testing.T) {
if CommandRequiredLevel("restart_mining", nil) != L1 {
t.Fatal("restart_mining should be L1")
}
if CommandRequiredLevel("spread_now", nil) != L2 {
t.Fatal("spread_now should be L2")
}
if CommandRequiredLevel("set_agent_version", nil) != L4 {
t.Fatal("set_agent_version should be L4")
}
}