| index 8fce3d98c..327382cad 100644 |
| --- a/internal/console/egressfleet_test.go |
| +++ b/internal/console/egressfleet_test.go |
| @@ -373,6 +373,7 @@ type reportCountingStore struct { |
| mu sync.Mutex |
| calls map[string]int // "<op> <key or prefix>" |
| failIndex bool // every read of the change index fails |
| + failGet string // a Get of this key fails |
| } |
| |
| func (c *reportCountingStore) indexDown(on bool) { |
| @@ -417,9 +418,21 @@ func (c *reportCountingStore) ListETags(ctx context.Context, prefix string) ([]r |
| |
| func (c *reportCountingStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| c.note("Get", key) |
| + c.mu.Lock() |
| + fail := key == c.failGet |
| + c.mu.Unlock() |
| + if fail { |
| + return nil, "", errors.New("get refused") |
| + } |
| return c.DirStore.Get(ctx, key) |
| } |
| |
| +func (c *reportCountingStore) failGetOf(key string) { |
| + c.mu.Lock() |
| + defer c.mu.Unlock() |
| + c.failGet = key |
| +} |
| + |
| func (c *reportCountingStore) GetIfChanged(ctx context.Context, key, etag string) ([]byte, string, bool, error) { |
| c.note("Get", key) |
| c.mu.Lock() |
| @@ -887,3 +900,74 @@ func TestEgressReportKeepsTheRequestBudget(t *testing.T) { |
| t.Fatalf("the pass after one edges write made %d requests (%v), want 1 ETag listing and 1 Get", total, under) |
| } |
| } |
| + |
| +// TestEgressReportKeepsAConflictItCannotRead is final review F4: an |
| +// established finding survives a pass that cannot read the box's whole |
| +// address list (its changed file's Get fails; it republishes with no |
| +// addrs; another file is unreadable after the box's went), with no new |
| +// alert, and is cleared only once a pass establishes the end: the box's |
| +// file read without the address, or gone from a listing with nothing |
| +// unreadable, or the address no longer allowed. |
| +func TestEgressReportKeepsAConflictItCannotRead(t *testing.T) { |
| + t.Parallel() |
| + fx := newReportFx(t, "code-egress-report-keep") |
| + first := fx.mustPut(t, "shop", `{"egress_allow":["10.0.5.20","10.0.5.21"]}`, policyCreate) |
| + putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"}) |
| + putEdgesAddrs(t, fx.cs, "annie", []string{"10.0.1.5"}) |
| + held := map[string]string{"10.0.5.20": "betty"} |
| + pass := func(step string, want map[string]string) { |
| + t.Helper() |
| + if n := fx.ticks(t, reportBackstopTo); n != 1 { |
| + t.Fatalf("%s: %d passes, want 1", step, n) |
| + } |
| + if got := fx.srv.egressConflicts(); !maps.Equal(got, want) { |
| + t.Fatalf("%s: conflicts = %v, want %v", step, got, want) |
| + } |
| + } |
| + if !fx.tick(t) { |
| + t.Fatal("no first pass") |
| + } |
| + if got := fx.srv.egressConflicts(); !maps.Equal(got, held) || len(fx.sent()) != 1 { |
| + t.Fatalf("established: conflicts %v, pages %q", got, fx.sent()) |
| + } |
| + |
| + // betty's file changes and cannot be fetched: kept. |
| + putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.9.9"}) |
| + fx.cs.failGetOf(edgesfile.Key("betty")) |
| + pass("betty's changed file unreadable", held) |
| + fx.cs.failGetOf("") |
| + |
| + // betty republishes with no address list: kept. |
| + putEdgesAddrs(t, fx.cs, "betty", nil) |
| + pass("betty publishes addrs null", held) |
| + if got := fx.sent(); len(got) != 1 { |
| + t.Fatalf("a kept finding paged again: %q", got) |
| + } |
| + |
| + // betty's file read in full, without the address: cleared. |
| + putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.9.9"}) |
| + pass("betty read without it", map[string]string{}) |
| + |
| + // Again; then betty's file goes while annie's cannot be read: kept, |
| + // since the unreadable file might be betty's. |
| + putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"}) |
| + pass("betty holds it again", held) |
| + if err := fx.cs.DirStore.Delete(context.Background(), edgesfile.Key("betty")); err != nil { |
| + t.Fatal(err) |
| + } |
| + putEdgesAddrs(t, fx.cs, "annie", []string{"10.0.1.6"}) |
| + fx.cs.failGetOf(edgesfile.Key("annie")) |
| + pass("betty's file gone, annie's unreadable", held) |
| + fx.cs.failGetOf("") |
| + |
| + // Every listed file read and betty's not among them: cleared. |
| + pass("betty's file gone, every file read", map[string]string{}) |
| + |
| + // A kept finding goes with its allow. |
| + putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"}) |
| + pass("betty back", held) |
| + putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20", "10.0.9.9"}) |
| + fx.cs.failGetOf(edgesfile.Key("betty")) |
| + fx.mustPut(t, "shop", `{"egress_allow":["10.0.5.21"]}`, policyIfMatch(first.ETag)) |
| + pass("the allow narrowed while betty is unreadable", map[string]string{}) |
| +} |