carlos / platform Public

free storage: fix Astra round 1 (scan by plan, day pause wins, kept first)

Summary

Astra round 1 found two P1s and a P2, all fixed. (1) The scan requirement now follows the account's plan, not what authorised the store: an approved Free account's stores are scanned too, and no store of a scan-required account can be attested client-encrypted (an existing environment store can still be repaired). (2) The day's plan pause replaces an hourly one, and every resume path (the hourly pass and carlos email status) runs the account check before lifting an hourly pause, so an hour roll never releases a spent day. (3) Until kept storage is settled for the catalog, the limits pass publishes nothing and the storage cap is left unmeasured, so no grandfathered account is published, warned or denied at 50 MB first.
Agent notes
Findings: docs/superpowers/reviews/CODEX-FINDINGS-FREE-STORAGE-1076.md. Census: round 1 approved all four envelopes; these fixes are console-only (out of census scope).
claude agent, operated by paul@keymail.dev a345a296e6de2a308241148279afcd2b95c34e29 parent 0b6a902
11 files changed, +276 −40
  • docs/superpowers/reviews/CODEX-FINDINGS-FREE-STORAGE-1076.md +36 −0
  • internal/console/apistore_provision.go +1 −1
  • internal/console/mailcounts.go +10 −0
  • internal/console/plankept.go +28 −8
  • internal/console/plankept_test.go +31 −0
  • internal/console/planlimits.go +3 −1
  • internal/console/planmail.go +10 −3
  • internal/console/planmail_hour_test.go +33 −0
  • internal/console/planmeasure.go +6 −2
  • internal/console/storeselfserve.go +51 −16
  • internal/console/storeselfserve_test.go +67 −9
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-FREE-STORAGE-1076.md b/docs/superpowers/reviews/CODEX-FINDINGS-FREE-STORAGE-1076.md
new file mode 100644
index 000000000..f00d331fd
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-FREE-STORAGE-1076.md
@@ -0,0 +1,36 @@
+1. **P1 — Forced scanning: approval provenance bypasses the requirement.**
+ [storeselfserve.go:67](/home/paulca/github.com/carlosframework/platform/.worktrees/free-storage-250/internal/console/storeselfserve.go:67) returns approved accounts without `scanRequired`, so a Free account can successfully provision an unscanned store. The attestation guard also excludes every grant whose source is not `plan` ([storeselfserve.go:210](/home/paulca/github.com/carlosframework/platform/.worktrees/free-storage-250/internal/console/storeselfserve.go:210)).
+
+ This also breaks after approval is revoked: re-running provision enables mandatory scanning under the Free plan, but the original grant source remains `account-approval`. A subsequent client-encrypted attestation succeeds and makes the sweep skip the store.
+
+ **Fix:** derive the scanning requirement from the effective plan independently of provisioning authority and historical grant source. Apply that requirement consistently to provisioning and attestation. Add coverage for approved Free accounts and approval-to-plan transitions.
+ **Fault family:** provisioning authority must not waive mandatory scanning.
+
+2. **P1 — Hourly email: an existing hourly pause prevents the daily pause from taking effect.**
+ [planmail.go:85](/home/paulca/github.com/carlosframework/platform/.worktrees/free-storage-250/internal/console/planmail.go:85) and line 95 exclude already-paused senders, even when the selected pause is now daily.
+
+ **Failure scenario:** an hourly pause lands while the daily count is below its threshold; delayed Send events then cross the daily threshold. The sender retains `plan-hour`. After the hour rolls, `carlos email status` invokes the unconditional stale-pause resume ([apimail.go:752](/home/paulca/github.com/carlosframework/platform/.worktrees/free-storage-250/internal/console/apimail.go:752)), reactivating credentials without checking the exhausted daily allowance. The added enforcement in `resumePlanMail` does not cover this status path.
+
+ **Fix:** promote hourly pauses to daily pauses when necessary, and check account limits before reactivating credentials through every resume path. Preserve manual, rate and per-instance pauses. Test delayed events followed by a status request.
+ **Fault family:** a shorter pause must not release a longer account-wide restriction.
+
+3. **P2 — Grandfathering: settlement failure still publishes reduced limits.**
+ [plankept.go:40](/home/paulca/github.com/carlosframework/platform/.worktrees/free-storage-250/internal/console/plankept.go:40) logs a settlement failure and returns without reporting it to the caller. [planlimits.go:53](/home/paulca/github.com/carlosframework/platform/.worktrees/free-storage-250/internal/console/planlimits.go:53) then continues publishing.
+
+ **Failure scenario:** an entitlement read fails part-way through settlement. Eligible accounts not yet processed receive the new 50 MB limit instead of their retained 1 GB until a successful retry. `EffectiveLimits` likewise exposes the reduced value while `Kept` is unset.
+
+ **Fix:** track unresolved settlement and preserve the previous allowance for affected accounts until eligibility is established; prevent both publication and enforcement of a premature reduction. Test a partial failure and retry.
+ **Fault family:** grandfathered allowances must survive incomplete migration.
+
+Census verdicts for `d97a24d5a061113b1d7cac13a5b843d99182bd9b`:
+
+| Envelope | Verdict | Basis |
+|---|---|---|
+| `.` | Approve | CLI reply, display and provisioning-selection changes introduce no new root reads or paths; see `store.go:234`, `apimode.go:2157`, `accounts_plan.go:225`, `mail_cli.go:1580`. |
+| `internal/mailwire` | Approve | Additive pause constant and predicate; existing pauses remain intact (`mailwire.go:32`, `:63`). |
+| `internal/objstore` | Approve | Additive provenance constant and comment change; grant authority and root-read behavior are unchanged (`objstore.go:57`, `walk.go:203`). |
+| `internal/plans` | Approve | Additive fields, validated cutoff and monotonic limit merging introduce no new root input paths (`catalog.go:292`, `:469`, `:503`). |
+
+No files changed. Diff whitespace checks passed. Targeted catalog tests could not start because the read-only sandbox refused Go’s build directory; no full suites ran.
+
+**NOT READY**
\ No newline at end of file
diff --git a/internal/console/apistore_provision.go b/internal/console/apistore_provision.go
index 65053d3ff..d7c014e6b 100644
--- a/internal/console/apistore_provision.go
+++ b/internal/console/apistore_provision.go
@@ -64,7 +64,7 @@ func (s *Server) handleAPIStoreProvision(w http.ResponseWriter, r *http.Request)
if !ok {
return
}
- if !s.storeScanPreflight(ctx, w, acct, app, auth, env) {
+ if auth, ok = s.storeScanPreflight(ctx, w, acct, app, auth, env); !ok {
return
}
rec, err := claimAppCall(s, ctx, acct, app, "store-provision", func(ctx context.Context) (*objstore.Record, error) {
diff --git a/internal/console/mailcounts.go b/internal/console/mailcounts.go
index 56e8853f5..0a31cb838 100644
--- a/internal/console/mailcounts.go
+++ b/internal/console/mailcounts.go
@@ -275,6 +275,16 @@ func (s *Server) resumeStaleCapPause(ctx context.Context, acct, app, sender stri
if sn == nil || !stale(sn) {
return sn, false, nil
}
+ // An hourly pause is lifted only if the day's is not due (Astra #1076
+ // R1 finding 2): this is every resume path's one check, so the account
+ // check runs first and turns the hourly pause into the day's when the
+ // day's sends have reached it. The stillStale check inside the write
+ // below then sees the day's pause, and lifts nothing.
+ if mail.EffectivePause(sn).LiftsAtHourRoll() {
+ if _, err := s.enforceAccountMail(ctx, acct, now); err != nil {
+ return nil, false, err
+ }
+ }
stillStale := stale
if _, err := mail.SetSenderPausedIf(ctx, s.claimMailStore(), s.cfg.MailProvisioner, acct, app, sender, false, "", now, stillStale); err != nil {
if errors.Is(err, mail.ErrNotEligible) {
diff --git a/internal/console/plankept.go b/internal/console/plankept.go
index 3048f8828..91a3d8f67 100644
--- a/internal/console/plankept.go
+++ b/internal/console/plankept.go
@@ -2,6 +2,7 @@ package console
import (
"context"
+ "errors"
"fmt"
"log"
"slices"
@@ -28,23 +29,42 @@ import (
// keeps the figure, and a later catalog without kept_storage leaves it as
// it is. Writes are revision bumps, so the publish pass that follows in the
// same run carries them to the record.
-func (s *Server) settleKeptStorage(ctx context.Context, now time.Time) {
+//
+// Until it has succeeded, nothing may act on a lowered storage figure that
+// it might yet raise (Astra #1076 R1 finding 3): the limits pass publishes
+// nothing (settleKeptStorage reports false), and the grace pass leaves the
+// storage cap unmeasured (keptUnsettled), so no account is warned or
+// denied at the new figure before its kept one is recorded.
+func (s *Server) settleKeptStorage(ctx context.Context, now time.Time) bool {
cat := s.cfg.PlanCatalog
- if cat == nil || s.cfg.Releases == nil {
- return
- }
- id := cat.ID()
- if done := s.keptSettled.Load(); done != nil && *done == id {
- return
+ if cat == nil || s.cfg.Releases == nil || !s.keptUnsettled() {
+ return true
}
if err := s.keepApprovedStorage(ctx, cat, now); err != nil {
log.Printf("console: plan limits: kept storage: %v", err)
jobFailed(ctx, fmt.Errorf("plan limits: kept storage: %w", err))
- return
+ return false
}
+ id := cat.ID()
s.keptSettled.Store(&id)
+ return true
}
+// keptUnsettled reports whether the catalog keeps storage for some plan and
+// settleKeptStorage has not yet finished for it.
+func (s *Server) keptUnsettled() bool {
+ cat := s.cfg.PlanCatalog
+ if cat == nil || !slices.ContainsFunc(sortedPlanKeys(cat), func(name string) bool { return cat.Plans[name].KeptStorage != nil }) {
+ return false
+ }
+ done := s.keptSettled.Load()
+ return done == nil || *done != cat.ID()
+}
+
+// errKeptUnsettled is the storage cap's measurement while kept storage is
+// unsettled: unknown, so the grace pass leaves the cap's row alone.
+var errKeptUnsettled = errors.New("console: kept storage is not settled yet")
+
func (s *Server) keepApprovedStorage(ctx context.Context, cat *plans.Catalog, now time.Time) error {
if !slices.ContainsFunc(sortedPlanKeys(cat), func(name string) bool { return cat.Plans[name].KeptStorage != nil }) {
return nil
diff --git a/internal/console/plankept_test.go b/internal/console/plankept_test.go
index b12a9b5ff..e0c2e7a9d 100644
--- a/internal/console/plankept_test.go
+++ b/internal/console/plankept_test.go
@@ -2,6 +2,7 @@ package console
import (
"context"
+ "errors"
"testing"
"time"
@@ -84,3 +85,33 @@ func TestKeptStorageNeedsTheCatalogField(t *testing.T) {
t.Fatalf("row = %+v, want a row with nothing kept", row)
}
}
+
+// Until kept storage is settled, nothing acts on the lowered figure (Astra
+// #1076 R1 finding 3): the limits pass publishes nothing and the storage
+// cap is unmeasured. Once the entitlements can be read, both go ahead with
+// the kept figure.
+func TestKeptStorageUnsettledHoldsBackTheNewFigure(t *testing.T) {
+ fx := newConsoleFixture(t)
+ fx.srv.cfg.PlanCatalog = draftFreeStorageCatalog(t)
+ acct := planAccount(t, fx, 621)
+ approveAt(t, fx, acct.Sqid, time.Date(2026, 11, 1, 0, 0, 0, 0, time.UTC))
+ good := fx.srv.cfg.Releases
+ fx.srv.cfg.Releases = entitlementListErrorStore{Store: good}
+ now := time.Now()
+ fx.srv.planLimitsPass(context.Background(), now)
+ if rec, _ := readLimits(t, fx, acct.Sqid); rec != nil {
+ t.Fatalf("published %+v before kept storage was settled", rec.Limits)
+ }
+ l, _ := fx.srv.EffectiveLimits(acct)
+ if _, errs := fx.srv.measureCaps(context.Background(), acct, l, now); !errors.Is(errs[capStorage], errKeptUnsettled) {
+ t.Fatalf("storage cap measured while unsettled: %v", errs[capStorage])
+ }
+ fx.srv.cfg.Releases = good
+ fx.srv.planLimitsPass(context.Background(), now)
+ if rec, _ := readLimits(t, fx, acct.Sqid); rec == nil || rec.Limits.StorageBytes != 1<<30 {
+ t.Fatalf("after the retry: %+v, want 1 GB kept", rec)
+ }
+ if _, errs := fx.srv.measureCaps(context.Background(), acct, l, now); errors.Is(errs[capStorage], errKeptUnsettled) {
+ t.Fatal("storage cap still unmeasured after settling")
+ }
+}
diff --git a/internal/console/planlimits.go b/internal/console/planlimits.go
index 3d67fae6b..bf43ad597 100644
--- a/internal/console/planlimits.go
+++ b/internal/console/planlimits.go
@@ -50,7 +50,9 @@ func (s *Server) planLimitsPass(ctx context.Context, now time.Time) {
return
}
s.settlePlanExempt(ctx, now)
- s.settleKeptStorage(ctx, now)
+ if !s.settleKeptStorage(ctx, now) {
+ return
+ }
// Page by account id: a row that cannot be published (an orphaned
// assignment) stays due, but never holds a later account back.
var after int64
diff --git a/internal/console/planmail.go b/internal/console/planmail.go
index d1cb7d87d..8ef391428 100644
--- a/internal/console/planmail.go
+++ b/internal/console/planmail.go
@@ -81,9 +81,16 @@ func (s *Server) enforceAccountMail(ctx context.Context, acct string, now time.T
paused := false
var errs []error
// A sender anything can send as, and that is not already paused: the
- // pause is read through mail.EffectivePause (decision 8).
+ // pause is read through mail.EffectivePause (decision 8). The day's
+ // pause also replaces an hourly one (Astra #1076 R1 finding 2): left as
+ // plan-hour, it would lift at the hour roll with the day's allowance
+ // spent.
+ free := func(cur *mail.Sender) bool {
+ pz := mail.EffectivePause(cur)
+ return pz == nil || (kind == mail.PauseKindPlan && pz.LiftsAtHourRoll())
+ }
eligible := func(cur *mail.Sender) bool {
- return mail.CanSend(cur) && mail.EffectivePause(cur) == nil && !cur.PerInstance
+ return mail.CanSend(cur) && free(cur) && !cur.PerInstance
}
for _, app := range apps {
senders, err := mail.ListSenders(ctx, s.cfg.Releases, acct, app)
@@ -92,7 +99,7 @@ func (s *Server) enforceAccountMail(ctx context.Context, acct string, now time.T
continue
}
for _, sn := range senders {
- if !mail.CanSend(sn) || mail.EffectivePause(sn) != nil {
+ if !mail.CanSend(sn) || !free(sn) {
continue
}
if sn.PerInstance {
diff --git a/internal/console/planmail_hour_test.go b/internal/console/planmail_hour_test.go
index a9185c579..e34961d74 100644
--- a/internal/console/planmail_hour_test.go
+++ b/internal/console/planmail_hour_test.go
@@ -115,3 +115,36 @@ func TestMailHourSendsPrunesOldRows(t *testing.T) {
t.Fatalf("hour sends %d, %v", got, err)
}
}
+
+// An hourly pause that the day's sends overtake becomes the day's, and no
+// resume path lifts it at the hour roll (Astra #1076 R1 finding 2): not
+// the hourly pass, and not `carlos email status`, whose resume is
+// resumeStaleCapPause.
+func TestHourlyPauseOvertakenByTheDay(t *testing.T) {
+ fx := hourMailFixture(t)
+ ctx := context.Background()
+ hourSends(t, fx, "blog", 5, planMailNow)
+ fx.srv.enforceAccountMail(ctx, release.OpsAccount, planMailNow)
+ if p := senderState(t, fx, "blog"); p.PauseKind != mail.PauseKindPlanHour {
+ t.Fatalf("kind %q, want the hour's", p.PauseKind)
+ }
+ sends(t, fx, "shop", 100, planMailNow) // delayed events cross the day's
+ later := planMailNow.Add(time.Hour)
+ sn, _, err := mail.GetSender(ctx, fx.rel, release.OpsAccount, "blog", mail.SenderAppID)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, resumed, err := fx.srv.resumeStaleCapPause(ctx, release.OpsAccount, "blog", mail.SenderAppID, sn, later); err != nil || resumed {
+ t.Fatalf("status-path resume = %v, %v; want no resume with the day spent", resumed, err)
+ }
+ if p := senderState(t, fx, "blog"); p.Active || p.PauseKind != mail.PauseKindPlan {
+ t.Fatalf("blog = active %v kind %q, want the day's pause", p.Active, p.PauseKind)
+ }
+ acct, _ := fx.st.AccountBySqid(fx.sqid)
+ if err := fx.srv.resumePlanMail(ctx, acct, later.Add(time.Hour)); err != nil {
+ t.Fatal(err)
+ }
+ if senderState(t, fx, "blog").Active || senderState(t, fx, "shop").Active {
+ t.Fatal("an hour roll lifted the day's pause")
+ }
+}
diff --git a/internal/console/planmeasure.go b/internal/console/planmeasure.go
index e18c1b98a..fec7cca24 100644
--- a/internal/console/planmeasure.go
+++ b/internal/console/planmeasure.go
@@ -48,8 +48,12 @@ func (s *Server) measureCaps(ctx context.Context, acct *Account, l *plans.Limits
}
}
if l.StorageBytes > 0 {
- n, err := s.accountStoreBytes(ctx, acct, now)
- put(capStorage, n, l.StorageBytes, err)
+ if s.keptUnsettled() {
+ errs[capStorage] = errKeptUnsettled
+ } else {
+ n, err := s.accountStoreBytes(ctx, acct, now)
+ put(capStorage, n, l.StorageBytes, err)
+ }
}
if l.EmailPerDay > 0 {
n, err := s.store.AccountSends(ctx, acct.Sqid, usage.DayOf(now))
diff --git a/internal/console/storeselfserve.go b/internal/console/storeselfserve.go
index 2798f63c2..0d983b83a 100644
--- a/internal/console/storeselfserve.go
+++ b/internal/console/storeselfserve.go
@@ -54,9 +54,24 @@ func (s *Server) storeSelfServe(acct *Account) (selfServe, scanRequired bool, er
return true, l.StorageScanRequired, nil
}
+// storeScanRequired reports whether acct's plan requires its stores
+// scanned (#1076), whatever authorised them (Astra #1076 R1 finding 1): an
+// approved Free account's stores are scanned as a self-serve one's are. A
+// sponsored row is not held to it, as it is not offered self-serve: its
+// stores keep the behaviour they had before #1076.
+func (s *Server) storeScanRequired(acct *Account) (bool, error) {
+ l, err := s.EffectiveLimits(acct)
+ if err != nil || l == nil || !l.StorageScanRequired {
+ return false, err
+ }
+ sp, err := s.planSponsored(acct)
+ return err == nil && !sp, err
+}
+
// storeProvisionAuthority answers the provision door: the account's
// approval when it has one, else its plan's self-serve storage, else the
-// existing refusal. actor is the member asking.
+// existing refusal. actor is the member asking. Either way the plan
+// decides whether the store must be scanned.
func (s *Server) storeProvisionAuthority(ctx context.Context, w http.ResponseWriter, acct *Account, actor string) (storeAuthority, bool) {
e, _, err := objstore.GetEntitlement(ctx, s.cfg.Releases, acct.Sqid)
if err != nil {
@@ -65,7 +80,13 @@ func (s *Server) storeProvisionAuthority(ctx context.Context, w http.ResponseWri
return storeAuthority{}, false
}
if e.Approved() {
- return storeAuthority{by: e.Decision.By, source: objstore.GrantSourceAccountApproval}, true
+ scan, err := s.storeScanRequired(acct)
+ if err != nil {
+ log.Printf("console: api store provision %s: plan limits: %v", acct.Sqid, err)
+ jsonError(w, http.StatusBadGateway, "could not read the storage application. try again")
+ return storeAuthority{}, false
+ }
+ return storeAuthority{by: e.Decision.By, source: objstore.GrantSourceAccountApproval, scanRequired: scan}, true
}
selfServe, scan, err := s.storeSelfServe(acct)
if err != nil {
@@ -89,39 +110,54 @@ func (s *Server) storeProvisionAuthority(ctx context.Context, w http.ResponseWri
// A store its member already attested client-encrypted is refused too: a
// scanner cannot read ciphertext, and the attestation is the member's to
// make, never this door's to overwrite.
-func (s *Server) storeScanPreflight(ctx context.Context, w http.ResponseWriter, acct *Account, app string, a storeAuthority, env string) bool {
+//
+// An environment store already provisioned (before #1076, or under an
+// approval) is let through unscanned so a re-run can still repair it: the
+// scan doors never covered environment stores, and refusing the repair
+// would strand its credentials. The returned authority says so.
+func (s *Server) storeScanPreflight(ctx context.Context, w http.ResponseWriter, acct *Account, app string, a storeAuthority, env string) (storeAuthority, bool) {
if !a.scanRequired {
- return true
+ return a, true
}
if env != "" {
+ cur, _, err := objstore.GetIn(ctx, s.cfg.Releases, acct.Sqid, app, env)
+ if err != nil {
+ log.Printf("console: api store provision %s/%s/%s: read record: %v", acct.Sqid, app, env, err)
+ jsonError(w, http.StatusBadGateway, "could not read the store record — try again")
+ return a, false
+ }
+ if cur != nil && cur.Provisioned != nil {
+ a.scanRequired = false
+ return a, true
+ }
jsonError(w, http.StatusConflict, copyPending("store.scan_required.environment"))
- return false
+ return a, false
}
rec, _, err := objstore.Get(ctx, s.cfg.Releases, acct.Sqid, app)
if err != nil {
log.Printf("console: api store provision %s/%s: read record: %v", acct.Sqid, app, err)
jsonError(w, http.StatusBadGateway, "could not read the store record — try again")
- return false
+ return a, false
}
if rec != nil && rec.Scanning != nil && rec.Scanning.Requested != nil && rec.Scanning.Requested.Encrypted {
jsonError(w, http.StatusConflict, copyPending("store.scan_required.encrypted"))
- return false
+ return a, false
}
if s.cfg.StoreScanner == nil {
jsonError(w, http.StatusServiceUnavailable, copyPending("store.scan_required.no_engine"))
- return false
+ return a, false
}
on, err := release.AntivirusEnabled(ctx, s.cfg.Releases)
if err != nil {
log.Printf("console: api store provision: read antivirus record: %v", err)
jsonError(w, http.StatusBadGateway, "could not read the scanning state — try again")
- return false
+ return a, false
}
if !on {
jsonError(w, http.StatusServiceUnavailable, copyPending("store.scan_required.no_engine"))
- return false
+ return a, false
}
- return true
+ return a, true
}
var (
@@ -204,15 +240,14 @@ func (s *Server) forceStoreScanning(ctx context.Context, sealer appconfig.Sealer
})
}
-// storeScanRequiredFor reports whether rec is a self-serve store whose
-// account's plan still requires scanning: such a store may not be attested
+// storeScanRequiredFor reports whether rec's account's plan requires its
+// stores scanned, whatever authorised rec: such a store may not be attested
// client-encrypted, which would leave the plan's scanning nothing to read.
func (s *Server) storeScanRequiredFor(acct *Account, rec *objstore.Record) (bool, error) {
- if rec == nil || rec.Grant == nil || rec.Grant.Source != objstore.GrantSourcePlan {
+ if rec == nil {
return false, nil
}
- _, scan, err := s.storeSelfServe(acct)
- return scan, err
+ return s.storeScanRequired(acct)
}
// copyPending stands in for a member-facing sentence that is still in
diff --git a/internal/console/storeselfserve_test.go b/internal/console/storeselfserve_test.go
index 91072feb1..9e9c133fb 100644
--- a/internal/console/storeselfserve_test.go
+++ b/internal/console/storeselfserve_test.go
@@ -1,6 +1,7 @@
package console
import (
+ "context"
"net/http"
"strings"
"testing"
@@ -87,7 +88,15 @@ func TestSelfServeRefusedWhereScanningCannotRun(t *testing.T) {
})
t.Run("attested client-encrypted", func(t *testing.T) {
fx, fake, token := selfServeArmed(t, "code-selfserve-encrypted")
+ // Attested before the plan required scanning: the scan door
+ // refuses it now.
+ cat := fx.srv.cfg.PlanCatalog
+ fx.srv.cfg.PlanCatalog = nil
requestScanning(t, fx, token, true)
+ fx.srv.cfg.PlanCatalog = cat
+ if status, _ := postJSON(t, scanURL(fx, "titogo"), map[string]any{"encrypted": true}, token); status != http.StatusConflict {
+ t.Fatalf("encrypted attestation under the plan = %d, want 409", status)
+ }
status, _ := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token)
if status != http.StatusConflict {
t.Fatalf("provision of an encrypted-attested store = %d, want 409", status)
@@ -161,16 +170,65 @@ func TestSelfServePaidPlanIsNotForcedToScan(t *testing.T) {
requestScanning(t, fx, token, true)
}
-// An approval wins over the plan: the store keeps the approval's
-// provenance, and is scanned only on request.
+// An approval is the authority, and keeps its provenance; the plan still
+// decides scanning (Astra #1076 R1 finding 1). An approved Free account's
+// store is scanned like a self-serve one, and cannot be attested
+// encrypted afterwards; an approved paid account's is not forced.
func TestApprovedAccountKeepsTheApprovalPath(t *testing.T) {
- fx, _, token := selfServeArmed(t, "code-selfserve-approved")
+ t.Run("free", func(t *testing.T) {
+ fx, _, token := selfServeArmed(t, "code-selfserve-approved-free")
+ approveStoreAccount(t, fx, "operator@keymail.dev")
+ if status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("approved provision = %d %v", status, out)
+ }
+ rec := storedRecord(t, fx, "titogo")
+ if rec.Grant.Source != objstore.GrantSourceAccountApproval || rec.Scanning == nil || rec.Scanning.Enabled == nil || rec.Scanning.Enforce == nil {
+ t.Fatalf("grant %+v scanning %+v, want the approval's grant with scanning forced", rec.Grant, rec.Scanning)
+ }
+ if status, _ := postJSON(t, scanURL(fx, "titogo"), map[string]any{"encrypted": true}, token); status != http.StatusConflict {
+ t.Fatalf("encrypted attestation on an approved Free store = %d, want 409", status)
+ }
+ })
+ t.Run("free, approval revoked after an unscanned store", func(t *testing.T) {
+ fx, _, token := selfServeArmed(t, "code-selfserve-approved-revoked")
+ fx.srv.cfg.PlanCatalog = nil // made before #1076: no plan, no scanning
+ approveStoreAccount(t, fx, "operator@keymail.dev")
+ if status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("provision = %d %v", status, out)
+ }
+ fx.srv.cfg.PlanCatalog = draftFreeStorageCatalog(t)
+ if err := fx.rel.Delete(context.Background(), objstore.EntitlementKey(fx.sqid)); err != nil {
+ t.Fatal(err)
+ }
+ if status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("re-run under the plan = %d %v", status, out)
+ }
+ if status, _ := postJSON(t, scanURL(fx, "titogo"), map[string]any{"encrypted": true}, token); status != http.StatusConflict {
+ t.Fatalf("encrypted attestation after the move to the plan = %d, want 409", status)
+ }
+ })
+ t.Run("paid", func(t *testing.T) {
+ fx, _, token := selfServeArmed(t, "code-selfserve-approved-paid")
+ if _, err := fx.st.SetAccountPlan(OpsAccountID, "personal", nil, PlanSourceOperator, nil, "test", "op", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ approveStoreAccount(t, fx, "operator@keymail.dev")
+ if status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("approved provision = %d %v", status, out)
+ }
+ if rec := storedRecord(t, fx, "titogo"); rec.Grant.Source != objstore.GrantSourceAccountApproval || rec.Scanning != nil {
+ t.Fatalf("grant %+v scanning %+v, want the approval's grant and no forced scanning", rec.Grant, rec.Scanning)
+ }
+ })
+}
+
+// An environment store provisioned before the plan required scanning can
+// still be repaired by a re-run; a new one cannot be made.
+func TestScanRequiredLetsAnExistingEnvironmentStoreRepair(t *testing.T) {
+ fx, _, token := selfServeArmed(t, "code-selfserve-env-repair")
+ grantStoreIn(t, fx, token, "beta") // an operator's grant, before
approveStoreAccount(t, fx, "operator@keymail.dev")
- if status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusOK {
- t.Fatalf("approved provision = %d %v", status, out)
- }
- rec := storedRecord(t, fx, "titogo")
- if rec.Grant.Source != objstore.GrantSourceAccountApproval || rec.Scanning != nil {
- t.Fatalf("grant %+v scanning %+v, want the approval's grant and no forced scanning", rec.Grant, rec.Scanning)
+ if status, out := postJSON(t, storeProvisionURL(fx, "titogo")+"?environment=beta", map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("repair of an existing environment store = %d %v, want 200", status, out)
}
}