| index 0832374ce..ad52064fd 100644 |
| --- a/internal/console/apiplatformcustomers_test.go |
| +++ b/internal/console/apiplatformcustomers_test.go |
| @@ -916,8 +916,8 @@ func TestPlatformCredentialRefusedAtOrdinaryDoors(t *testing.T) { |
| } |
| } |
| |
| -// heldPromise is what a refused finish must leave: one pending mint for |
| -// ref, counted, and no manifest naming the platform anywhere. |
| +// wantHeldPromise fails unless a refused finish left one pending mint for |
| +// ref, counted, and count-1 manifests naming the platform. |
| func wantHeldPromise(t *testing.T, fx *consoleFixture, platform, ref string, count int) { |
| t.Helper() |
| if p := pendingMints(t, fx.st, platform); len(p) != 1 || p[0].Ref != ref { |
| @@ -1081,10 +1081,24 @@ func TestCustomerHeldPromiseFailsOnlyItsOwnRef(t *testing.T) { |
| strings.Repeat("cd", 16), time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| - // The gate on every door goes on past it. |
| + // The gate on every door goes on past it, and finishing it writes |
| + // nothing: no manifest carries its mint id (the ref is refused before |
| + // the mint, Astra A3). |
| + bucketBefore, err := fx.rel.List(ctx, "accounts/") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| if err := fx.srv.finishPendingMints(ctx, acct); err != nil { |
| t.Fatalf("finishing with a held promise = %v, want nil", err) |
| } |
| + if after, err := fx.rel.List(ctx, "accounts/"); err != nil || !slices.Equal(after, bucketBefore) { |
| + t.Fatalf("bucket accounts/ after the held finish %v %v, was %v: want nothing written", after, err, bucketBefore) |
| + } |
| + for _, m := range platformManifests(t, fx.rel, acct.Sqid) { |
| + if m.PlatformMint == strings.Repeat("ab", 16) { |
| + t.Fatalf("manifest %+v carries the held promise's mint id", m) |
| + } |
| + } |
| |
| // A create for another ref succeeds. |
| status, out, raw := createCustomer(t, fx.ts.URL, acct.Sqid, tok, map[string]any{"name": "cafe", "ref": "4813"}) |
| @@ -1294,3 +1308,58 @@ func TestCustomerCreateFinishesAPromiseMadeAfterItsGate(t *testing.T) { |
| t.Fatalf("pending mints %+v, want none", p) |
| } |
| } |
| + |
| +// TestCustomerHeldRefRefusalFinishesNothingElse is fix round 3 (Astra): a |
| +// create for a held promise's ref is refused before the platform's other |
| +// promises are finished, so the refused request writes nothing. |
| +func TestCustomerHeldRefRefusalFinishesNothingElse(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + acct := planAccount(t, fx, 501) |
| + grantPlatformAccount(t, fx, acct.Sqid, 5) |
| + tok := platformToken(t, fx, acct.ID, "cms") |
| + ctx := context.Background() |
| + by := "service:" + acct.Sqid + "/cms" |
| + // A: held, because a live customer holds its ref. B: finishable. |
| + for _, m := range []PendingMint{ |
| + {MintID: strings.Repeat("ab", 16), Platform: acct.Sqid, Ref: "4812", Name: "shop", By: by, CreatedAt: time.Now()}, |
| + {MintID: strings.Repeat("ef", 16), Platform: acct.Sqid, Ref: "4900", Name: "cafe", By: by, CreatedAt: time.Now()}, |
| + } { |
| + if err := fx.st.ReservePlatformMint(ctx, m); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + holder := testAccountID() |
| + if _, err := fx.st.EnsureLinkedAccount(holder, domains.Sqid(holder), "held", acct.Sqid, "4812", |
| + strings.Repeat("cd", 16), time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + snapshot := func() string { |
| + t.Helper() |
| + keys, err := fx.rel.List(ctx, "accounts/") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var accounts, plans, audit int |
| + for q, n := range map[string]*int{ |
| + `SELECT COUNT(*) FROM accounts`: &accounts, |
| + `SELECT COUNT(*) FROM account_plans`: &plans, |
| + `SELECT COUNT(*) FROM audit`: &audit, |
| + } { |
| + if err := fx.st.db.QueryRowContext(ctx, q).Scan(n); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + return fmt.Sprintf("manifests %v, accounts %d, plans %d, audit rows %d", keys, accounts, plans, audit) |
| + } |
| + before := snapshot() |
| + |
| + status, out, _ := createCustomer(t, fx.ts.URL, acct.Sqid, tok, map[string]any{"name": "shop", "ref": "4812"}) |
| + wantPlatformError(t, "create for the held ref", status, out, http.StatusBadGateway, "create.failed") |
| + if after := snapshot(); after != before { |
| + t.Fatalf("the refused create wrote: %s, was %s", after, before) |
| + } |
| + p := pendingMints(t, fx.st, acct.Sqid) |
| + if len(p) != 2 { |
| + t.Fatalf("pending mints %+v, want A and B both still pending", p) |
| + } |
| +} |