Test operator writes against approved pending roster reader
2 files changed,
+48
−2
internal/operator/directory_test.go+2 −1internal/operator/verification_test.go+46 −1
CI failed — run details
diff --git a/internal/operator/directory_test.go b/internal/operator/directory_test.go| index 33821db..2bd3fdc 100644 |
| --- a/internal/operator/directory_test.go |
| +++ b/internal/operator/directory_test.go |
| @@ -20,6 +20,7 @@ type directoryFixture struct { |
| directory *Directory |
| ownerKey *family.Keypair |
| attempt byte |
| + bearer string |
| } |
| func newDirectoryFixture(t *testing.T) *directoryFixture { |
| @@ -52,7 +53,7 @@ func newDirectoryFixture(t *testing.T) *directoryFixture { |
| if e != nil { |
| t.Fatal(e) |
| } |
| - return &directoryFixture{f, d, owner, 20} |
| + return &directoryFixture{engineFixture: f, directory: d, ownerKey: owner, attempt: 20} |
| } |
| func (f *directoryFixture) input(t *testing.T, action string, build func(InputBase) any) []byte { |
| t.Helper() |
diff --git a/internal/operator/verification_test.go b/internal/operator/verification_test.go| index bcb9262..15227b8 100644 |
| --- a/internal/operator/verification_test.go |
| +++ b/internal/operator/verification_test.go |
| @@ -8,6 +8,7 @@ import ( |
| "testing" |
| "time" |
| + "amadan.net/oficina/home/internal/home/directorydata" |
| "github.com/go-json-experiment/json" |
| ) |
| @@ -21,9 +22,15 @@ func pendingFixture(t *testing.T) (*directoryFixture, VerificationInput) { |
| raw := f.input(t, "directory.provision-consumer", func(b InputBase) any { |
| return ProvisionInput{b, token(10), "Uk", "docs", "alpha-docs", "https://alpha.docs.oficina.works", 0} |
| }) |
| - if _, err := f.directory.Execute(context.Background(), raw); err != nil { |
| + out, err := f.directory.Execute(context.Background(), raw) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var result Result |
| + if err = json.Unmarshal(out, &result); err != nil { |
| t.Fatal(err) |
| } |
| + f.bearer = result.Bearer |
| var digest []byte |
| if err := f.db.QueryRow("SELECT record_digest FROM directory_operator_consumer_records").Scan(&digest); err != nil { |
| t.Fatal(err) |
| @@ -152,3 +159,41 @@ func TestActivationRejectsChangedStateAndEvidence(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +func TestOperatorWindowControlsActualRosterReader(t *testing.T) { |
| + f, in := pendingFixture(t) |
| + source, err := directorydata.NewRosterSource(f.db, f.engine.sealer, f.directory.policy, f.directory.owner.directory) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req := directorydata.RosterRequest{Token: f.bearer, Team: "Uk", Fetch: token(92)} |
| + check := func(want int) { |
| + t.Helper() |
| + _, status, err := source.Read(context.Background(), req, *f.now) |
| + if status != want || (want == 200 && err != nil) { |
| + t.Fatalf("reader status %d want %d: %v", status, want, err) |
| + } |
| + } |
| + check(503) |
| + raw, _, window := openWindow(t, f, in) |
| + check(200) |
| + *f.now = f.now.Add(599 * time.Second) |
| + check(200) |
| + *f.now = f.now.Add(time.Second) |
| + check(503) |
| + if _, err = f.directory.Execute(context.Background(), raw); err != nil { |
| + t.Fatal(err) |
| + } |
| + check(503) |
| + in.Issued = f.now.Unix() |
| + in.Expires = in.Issued + 600 |
| + _, _, window = openWindow(t, f, in) |
| + check(200) |
| + proof := activation(in, window.Attempt) |
| + raw = f.input(t, "directory.activate-consumer", func(b InputBase) any { return ActivationInput{b, proof} }) |
| + if _, err = f.directory.Execute(context.Background(), raw); err != nil { |
| + t.Fatal(err) |
| + } |
| + *f.now = f.now.Add(601 * time.Second) |
| + check(200) |
| +} |