| index f44ea2815..43d802303 100644 |
| --- a/internal/console/plancaps_doors_test.go |
| +++ b/internal/console/plancaps_doors_test.go |
| @@ -244,20 +244,16 @@ func accountCount(t *testing.T, fx *consoleFixture) int { |
| func TestNewAccountRefusedForASecondFreeAccount(t *testing.T) { |
| fx := newConsoleFixture(t) |
| fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| - token := cliToken(t, fx, "paul@keymail.dev", "code-cap-acct") |
| - // Paul owns ops, which is exempt from plans (2026-10-28): his first |
| - // free account is allowed beside it. |
| - status, out := postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": "first"}, token) |
| - if status != http.StatusOK { |
| - t.Fatalf("CLI first free account beside ops = %d %v, want 200", status, out) |
| - } |
| + // Dana's first sign-in mints her first free account; she owns nothing |
| + // else, ops included. |
| + token := cliToken(t, fx, "dana@keymail.dev", "code-cap-acct") |
| before := accountCount(t, fx) |
| - status, out = postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": "second"}, token) |
| - if status != http.StatusConflict || out["code"] != "cap" { |
| + status, out := postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": "second"}, token) |
| + if status != http.StatusConflict || out["code"] != "cap" || out["error"] != capMessage("cli.cap.free_account") { |
| t.Fatalf("CLI second free account = %d %v, want 409 cap", status, out) |
| } |
| - c := signInPaul(t, fx) |
| - st, loc, _ := postForm(t, c, fx.ts.URL+"/accounts/new", url.Values{"csrf": {sessionToken(t, fx, c)}, "name": {"thirdtry"}}) |
| + c, raw := signInAs(t, fx, "dana@keymail.dev", "code-cap-acct-browser") |
| + st, loc, _ := postForm(t, c, fx.ts.URL+"/accounts/new", url.Values{"csrf": {raw}, "name": {"thirdtry"}}) |
| if st != http.StatusSeeOther || loc != "/accounts/new" { |
| t.Fatalf("browser second free account = %d -> %q, want the flash redirect back to /accounts/new", st, loc) |
| } |
| @@ -266,6 +262,59 @@ func TestNewAccountRefusedForASecondFreeAccount(t *testing.T) { |
| } |
| } |
| |
| +// TestOpsOwnerSkipsTheFreeAccountCap is #500's exemption for accounts: an |
| +// owner of the ops account creates free accounts past the allowance through |
| +// both doors, because the platform owner makes accounts for the platform's |
| +// own sites. Each new account starts on the default plan; only ops itself |
| +// is exempt. Owning some other account is not enough: carol owns a free |
| +// account and is still refused on both doors. |
| +func TestOpsOwnerSkipsTheFreeAccountCap(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| + token := cliToken(t, fx, "paul@keymail.dev", "code-ops-owner-acct") |
| + for _, name := range []string{"first", "second", "third"} { |
| + status, out := postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": name}, token) |
| + if status != http.StatusOK { |
| + t.Fatalf("ops owner CLI account %s = %d %v, want no free-account cap", name, status, out) |
| + } |
| + a, err := fx.st.AccountBySqid(str(t, out, "sqid")) |
| + if err != nil || a == nil { |
| + t.Fatalf("account %s: %v, %v", name, a, err) |
| + } |
| + if l, err := fx.srv.EffectiveLimits(a); err != nil || l == nil { |
| + t.Fatalf("account %s limits = %v, %v; want the default plan's, not exempt", name, l, err) |
| + } |
| + } |
| + c := signInPaul(t, fx) |
| + before := accountCount(t, fx) |
| + st, loc, _ := postForm(t, c, fx.ts.URL+"/accounts/new", url.Values{"csrf": {sessionToken(t, fx, c)}, "name": {"fourth"}}) |
| + if st != http.StatusSeeOther || loc == "/accounts/new" { |
| + t.Fatalf("ops owner browser account = %d -> %q, want the new account", st, loc) |
| + } |
| + if after := accountCount(t, fx); after != before+1 { |
| + t.Fatalf("accounts %d -> %d, want one more", before, after) |
| + } |
| + |
| + const demoID = 4242 |
| + if err := fx.st.CreateAccount(demoID, "cdef", "Demo", "carol@keymail.dev", planNow); err != nil { |
| + t.Fatal(err) |
| + } |
| + carol := cliToken(t, fx, "carol@keymail.dev", "code-demo-owner-acct") |
| + before = accountCount(t, fx) |
| + status, out := postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": "carol-two"}, carol) |
| + if status != http.StatusConflict || out["code"] != "cap" || out["error"] != capMessage("cli.cap.free_account") { |
| + t.Fatalf("demo owner CLI account = %d %v, want 409 cap: only ops owners skip it", status, out) |
| + } |
| + cc, raw := signInAs(t, fx, "carol@keymail.dev", "code-demo-owner-browser") |
| + st, loc, _ = postForm(t, cc, fx.ts.URL+"/accounts/new", url.Values{"csrf": {raw}, "name": {"carol-web"}}) |
| + if st != http.StatusSeeOther || loc != "/accounts/new" { |
| + t.Fatalf("demo owner browser account = %d -> %q, want the flash redirect back to /accounts/new", st, loc) |
| + } |
| + if after := accountCount(t, fx); after != before { |
| + t.Fatalf("accounts %d -> %d: carol got one past the cap", before, after) |
| + } |
| +} |
| + |
| func TestFirstAccountIsNeverRefused(t *testing.T) { |
| fx := newConsoleFixture(t) |
| fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| @@ -360,15 +409,19 @@ func TestPlatformHostnamesStayFreeOnFreePlans(t *testing.T) { |
| } |
| |
| // Astra plans-3a finding 2: concurrent creates by one person who owns only |
| -// paid accounts must not mint more free accounts than the allowance. |
| +// paid accounts must not mint more free accounts than the allowance. Carol |
| +// does not own ops, whose owners have no allowance to exceed. |
| func TestFreeAccountCapIsExactUnderConcurrentCreates(t *testing.T) { |
| fx := newConsoleFixture(t) |
| fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| - ops, _ := fx.st.AccountBySqid(fx.sqid) |
| - if _, err := fx.st.SetAccountPlan(ops.ID, "personal", nil, 0, PlanSourceOperator, nil, "r", "ops@example.com", planNow); err != nil { |
| + const paidID = 4242 |
| + if err := fx.st.CreateAccount(paidID, "cdef", "Paid", "carol@keymail.dev", planNow); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := fx.st.SetAccountPlan(paidID, "personal", nil, 0, PlanSourceOperator, nil, "r", "ops@example.com", planNow); err != nil { |
| t.Fatal(err) |
| } |
| - token := cliToken(t, fx, "paul@keymail.dev", "code-cap-acct-race") |
| + token := cliToken(t, fx, "carol@keymail.dev", "code-cap-acct-race") |
| var mu sync.Mutex |
| created := 0 |
| var wg sync.WaitGroup |