package suite import ( "encoding/json" "os" "testing" ) type hostCase struct { Host string `json:"host"` Why string `json:"why"` } type redirectCase struct { From string `json:"from"` To string `json:"to"` Why string `json:"why"` } type hostileHosts struct { Team string `json:"team"` Refuse []hostCase `json:"refuse"` Reach []hostCase `json:"reach"` Redirect redirectCase `json:"redirect"` Comment []string `json:"comment"` } func loadHostileHosts(t *testing.T) hostileHosts { t.Helper() raw, err := os.ReadFile("fixtures/hostile_hosts.json") if err != nil { t.Fatalf("reading fixture: %v", err) } var f hostileHosts if err := json.Unmarshal(raw, &f); err != nil { t.Fatalf("parsing fixture: %v", err) } return f } // The hostile-hostname fixture is the shared list, so every app runs gate 4 // against the same hosts rather than each inventing its own. This test is the // module holding itself to the fixture it publishes. func TestHostileHostFixture(t *testing.T) { f := loadHostileHosts(t) if f.Redirect.From == "" || f.Redirect.To == "" { t.Error("fixture has no redirect case; TestSiblingClientRefusesAFixtureRedirect needs one") } if len(f.Refuse) == 0 || len(f.Reach) == 0 { t.Fatal("fixture has no cases; a gate that asserts nothing passes everything") } for _, c := range f.Refuse { if err := CheckSiblingHost(f.Team, c.Host); err == nil { t.Errorf("reached %q, want it refused — %s", c.Host, c.Why) } } for _, c := range f.Reach { if err := CheckSiblingHost(f.Team, c.Host); err != nil { t.Errorf("refused %q (%v), want it reached — %s", c.Host, err, c.Why) } } }