package governance import ( "testing" "time" ) func TestValidProductionWeKnoraBaseURL(t *testing.T) { base := CreateUISettingsCandidateRequest{ DocumentRefreshSeconds: 15, ResourceRefreshSeconds: 30, StalledAfterSeconds: 1800, FinalizingAfterSeconds: 7200, IngestionConcurrency: 2, UpdatedBy: "admin-1", Now: time.Date(2026, 9, 18, 9, 0, 0, 0, time.UTC), } if !base.Valid() { t.Fatal("an empty endpoint means \"not configured\" and must stay legal") } configured := base configured.ProductionWeKnoraBaseURL = "https://weknora.prod.example:8443/weknora" if !configured.Valid() { t.Fatalf("bare http(s) origin rejected: %q", configured.ProductionWeKnoraBaseURL) } for _, unsafe := range []string{ "weknora.prod.example", "ftp://weknora.prod.example", "https://user:pass@weknora.prod.example", "https://weknora.prod.example/?token=abc", "https://weknora.prod.example/#frag", " https://weknora.prod.example", "https://weknora.prod.example\r\nX-Injected: 1", } { candidate := base candidate.ProductionWeKnoraBaseURL = unsafe if candidate.Valid() { t.Fatalf("unsafe endpoint accepted: %q", unsafe) } } } // The other three service fields carry the same "empty means not configured" // rule and their own shape: an origin for the test endpoint, decimal digits for // the tenant, and a token without whitespace or URL pieces for the knowledge base. func TestValidServiceTargetFields(t *testing.T) { base := CreateUISettingsCandidateRequest{ DocumentRefreshSeconds: 15, ResourceRefreshSeconds: 30, StalledAfterSeconds: 1800, FinalizingAfterSeconds: 7200, IngestionConcurrency: 2, UpdatedBy: "admin-1", Now: time.Date(2026, 9, 18, 9, 0, 0, 0, time.UTC), } configured := base configured.TestWeKnoraBaseURL = "https://weknora.test.example:8443/weknora" configured.ProductionTenantID = "10000" configured.ProductionKnowledgeBaseID = "1b52c140-2e18-4676-afc5-4c7d8d190a8c" if !configured.Valid() { t.Fatalf("valid service targets rejected: %#v", configured) } for _, unsafe := range []string{"weknora.test.example", "https://user:pass@weknora.test.example", "https://weknora.test.example?token=abc", "ftp://weknora.test.example"} { candidate := base candidate.TestWeKnoraBaseURL = unsafe if candidate.Valid() { t.Fatalf("unsafe test endpoint accepted: %q", unsafe) } } for _, unsafe := range []string{"abc", "10 000", "-1", "0", "10000.5", "10000000000000000000000", "10000\n20000"} { candidate := base candidate.ProductionTenantID = unsafe if candidate.Valid() { t.Fatalf("unsafe production tenant id accepted: %q", unsafe) } } for _, unsafe := range []string{"kb/abc", "kb abc", "kb-abc?x", "kb#frag", "https://weknora.prod.example/kb", `kb\abc`} { candidate := base candidate.ProductionKnowledgeBaseID = unsafe if candidate.Valid() { t.Fatalf("unsafe knowledge base id accepted: %q", unsafe) } } }