| index 7b996d7d7..8fce3d98c 100644 |
| --- a/internal/console/egressfleet_test.go |
| +++ b/internal/console/egressfleet_test.go |
| @@ -2,6 +2,7 @@ package console |
| |
| import ( |
| "context" |
| + "crypto/ed25519" |
| "encoding/json" |
| "errors" |
| "maps" |
| @@ -369,8 +370,15 @@ func TestPolicyDoorWritesNothingWhenTheCheckRefuses(t *testing.T) { |
| // answers them. |
| type reportCountingStore struct { |
| *release.DirStore |
| - mu sync.Mutex |
| - calls map[string]int // "<op> <key or prefix>" |
| + mu sync.Mutex |
| + calls map[string]int // "<op> <key or prefix>" |
| + failIndex bool // every read of the change index fails |
| +} |
| + |
| +func (c *reportCountingStore) indexDown(on bool) { |
| + c.mu.Lock() |
| + defer c.mu.Unlock() |
| + c.failIndex = on |
| } |
| |
| func (c *reportCountingStore) note(op, key string) { |
| @@ -414,6 +422,12 @@ func (c *reportCountingStore) Get(ctx context.Context, key string) ([]byte, stri |
| |
| func (c *reportCountingStore) GetIfChanged(ctx context.Context, key, etag string) ([]byte, string, bool, error) { |
| c.note("Get", key) |
| + c.mu.Lock() |
| + down := c.failIndex && key == release.ChangeIndexKey |
| + c.mu.Unlock() |
| + if down { |
| + return nil, "", false, errors.New("index unreachable") |
| + } |
| return c.DirStore.GetIfChanged(ctx, key, etag) |
| } |
| |
| @@ -669,6 +683,73 @@ func TestEgressReportRunsOnEdgesGeneration(t *testing.T) { |
| } |
| } |
| |
| +// A pass that ran while the watch could not vouch marked no generation, so |
| +// the watch's recovery is due: an edges write made in between is read on |
| +// the first tick after it, not at the backstop. |
| +func TestEgressReportRunsWhenTheWatchRecovers(t *testing.T) { |
| + t.Parallel() |
| + fx := newReportFx(t, "code-egress-report-recover") |
| + fx.mustPut(t, "shop", `{"egress_allow":["10.0.5.20"]}`, policyCreate) |
| + putEdgesAddrs(t, fx.cs, "annie", []string{"10.0.1.5"}) |
| + v := armRecordView(t, fx.srv, fx.cs) |
| + fx.cs.indexDown(true) |
| + _ = v.Refresh(context.Background()) // the poll fails: the watch cannot vouch |
| + if v.Watch().Usable() { |
| + t.Fatal("the watch is still usable; the fixture tests nothing") |
| + } |
| + if !fx.tick(t) { |
| + t.Fatal("no first pass") |
| + } |
| + if fx.tick(t) { |
| + t.Fatal("a tick with the watch still unusable ran a pass") |
| + } |
| + |
| + putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"}) |
| + fx.cs.indexDown(false) |
| + if err := v.Refresh(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if !fx.tick(t) { |
| + t.Fatal("the tick after the watch recovered ran no pass") |
| + } |
| + if got := fx.srv.egressConflicts(); got["10.0.5.20"] != "betty" || len(fx.sent()) != 1 { |
| + t.Fatalf("the recovery pass = %v, pages %q", got, fx.sent()) |
| + } |
| + if fx.tick(t) { |
| + t.Fatal("a second tick on the recovered generation ran a pass") |
| + } |
| +} |
| + |
| +// A policy row that does not open (here: the console's key has changed |
| +// since it was signed) is not checked, and the pass says so, on the |
| +// schedule, with no request of the bucket. |
| +func TestEgressReportLogsRowsThatDoNotOpen(t *testing.T) { |
| + t.Parallel() |
| + fx := newReportFx(t, "code-egress-report-unopened") |
| + fx.mustPut(t, "shop", `{"egress_allow":["10.0.5.20"]}`, policyCreate) |
| + putEdgesAddrs(t, fx.cs, "betty", []string{"10.0.5.20"}) |
| + _, other, err := ed25519.GenerateKey(nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + fx.srv.cfg.Key = other |
| + fx.cs.taken() |
| + if !fx.tick(t) { |
| + t.Fatal("no pass with a row that does not open") |
| + } |
| + fx.logs.has(t, "console: egress report: not checked, the recorded policy does not open: "+fx.sqid+"/shop") |
| + passes := fx.ticks(t, reportDay) |
| + if passes < 43 || passes > 48 { |
| + t.Fatalf("%d diagnostic passes in a day, want the backstop's 43 to 48", passes) |
| + } |
| + if total, under := fx.cs.taken(); total != 0 { |
| + t.Fatalf("diagnostic passes made %d requests: %v", total, under) |
| + } |
| + if got := fx.srv.egressConflicts(); got == nil || len(got) != 0 || len(fx.sent()) != 0 { |
| + t.Fatalf("conflicts %v, pages %q", got, fx.sent()) |
| + } |
| +} |
| + |
| // The report is read-only and runs on every console (ruling C6): a console |
| // that is not the policy writer, and whose writer lease would be refused, |
| // still reports, and asks for no lease to do it. |