oficina / suite Public

Clone
git clone https://amadan.net/oficina/suite

Plain git — no account needed to clone.

Download

Download this file

1package suite
2
3import (
4 "encoding/json"
5 "os"
6 "testing"
7)
8
9type hostCase struct {
10 Host string `json:"host"`
11 Why string `json:"why"`
12}
13
14type redirectCase struct {
15 From string `json:"from"`
16 To string `json:"to"`
17 Why string `json:"why"`
18}
19
20type hostileHosts struct {
21 Team string `json:"team"`
22 Refuse []hostCase `json:"refuse"`
23 Reach []hostCase `json:"reach"`
24 Redirect redirectCase `json:"redirect"`
25 Comment []string `json:"comment"`
26}
27
28func loadHostileHosts(t *testing.T) hostileHosts {
29 t.Helper()
30 raw, err := os.ReadFile("fixtures/hostile_hosts.json")
31 if err != nil {
32 t.Fatalf("reading fixture: %v", err)
33 }
34 var f hostileHosts
35 if err := json.Unmarshal(raw, &f); err != nil {
36 t.Fatalf("parsing fixture: %v", err)
37 }
38 return f
39}
40
41// The hostile-hostname fixture is the shared list, so every app runs gate 4
42// against the same hosts rather than each inventing its own. This test is the
43// module holding itself to the fixture it publishes.
44func TestHostileHostFixture(t *testing.T) {
45 f := loadHostileHosts(t)
46 if f.Redirect.From == "" || f.Redirect.To == "" {
47 t.Error("fixture has no redirect case; TestSiblingClientRefusesAFixtureRedirect needs one")
48 }
49 if len(f.Refuse) == 0 || len(f.Reach) == 0 {
50 t.Fatal("fixture has no cases; a gate that asserts nothing passes everything")
51 }
52
53 for _, c := range f.Refuse {
54 if err := CheckSiblingHost(f.Team, c.Host); err == nil {
55 t.Errorf("reached %q, want it refused — %s", c.Host, c.Why)
56 }
57 }
58 for _, c := range f.Reach {
59 if err := CheckSiblingHost(f.Team, c.Host); err != nil {
60 t.Errorf("refused %q (%v), want it reached — %s", c.Host, err, c.Why)
61 }
62 }
63}
64