package service import ( "strings" "testing" ) func TestGetActiveConfigForAgentIncludesPoWConfig(t *testing.T) { setupServiceTestDB(t) _, err := CreateProxyRoute(ProxyRouteInput{ Domain: "pow-agent.example.com", OriginURL: "https://origin.internal", Enabled: true, PoWEnabled: true, PoWConfig: `{"difficulty":4,"algorithm":"fast","session_ttl":86400,"challenge_ttl":300,"whitelist":{"paths":["/.well-known/*","/favicon.ico","/robots.txt"],"user_agents":["Googlebot","bingbot","Baiduspider"]},"blacklist":{"ips":[],"ip_cidrs":[],"paths":[],"path_regexes":[],"user_agents":[]}}`, }) if err != nil { t.Fatalf("CreateProxyRoute failed: %v", err) } if _, err := PublishConfigVersion("root", false); err != nil { t.Fatalf("PublishConfigVersion failed: %v", err) } activeConfig, err := GetActiveConfigForAgent() if err != nil { t.Fatalf("GetActiveConfigForAgent failed: %v", err) } foundPowConfig := false for _, file := range activeConfig.SupportFiles { if file.Path != "pow_config.json" { continue } foundPowConfig = true if file.Content == "" { t.Fatal("expected pow_config.json content to be populated") } } if !foundPowConfig { t.Fatal("expected agent config to include pow_config.json support file") } } func TestGetActiveConfigForAgentIncludesWAFConfig(t *testing.T) { setupServiceTestDB(t) _, err := CreateProxyRoute(ProxyRouteInput{ Domain: "waf-agent.example.com", OriginURL: "https://origin.internal", Enabled: true, }) if err != nil { t.Fatalf("CreateProxyRoute failed: %v", err) } if _, err := PublishConfigVersion("root", false); err != nil { t.Fatalf("PublishConfigVersion failed: %v", err) } activeConfig, err := GetActiveConfigForAgent() if err != nil { t.Fatalf("GetActiveConfigForAgent failed: %v", err) } for _, file := range activeConfig.SupportFiles { if file.Path == "waf_config.json" { if !strings.Contains(file.Content, `"rule_groups"`) { t.Fatalf("expected waf_config.json content to include rule groups, got %s", file.Content) } return } } t.Fatal("expected agent config to include waf_config.json support file") } func TestGetActiveConfigForAgentUsesTenMinutePoWSessionDefault(t *testing.T) { setupServiceTestDB(t) _, err := CreateProxyRoute(ProxyRouteInput{ Domain: "pow-default.example.com", OriginURL: "https://origin.internal", Enabled: true, PoWEnabled: true, PoWConfig: `{}`, }) if err != nil { t.Fatalf("CreateProxyRoute failed: %v", err) } if _, err := PublishConfigVersion("root", false); err != nil { t.Fatalf("PublishConfigVersion failed: %v", err) } activeConfig, err := GetActiveConfigForAgent() if err != nil { t.Fatalf("GetActiveConfigForAgent failed: %v", err) } for _, file := range activeConfig.SupportFiles { if file.Path == "pow_config.json" { if !strings.Contains(file.Content, `"session_ttl":600`) { t.Fatalf("expected default PoW session TTL to be 600 seconds, got %s", file.Content) } return } } t.Fatal("expected agent config to include pow_config.json support file") }