fix: demo claims ready without a mailer when Keymail can finish
Allow claim readiness when the browser Keymail path can complete. Keep email-code starts gated on mail readiness per request. Cover mailer-less readiness and create availability, agent and browser starts, and unchanged shared send-limit state. Preserve cache and deadline coverage. Validation: targeted TestDemoClaim(Readiness|Email|Fragment|Browser|Shared) tests with nice; go vet ./internal/console; gofmt. Refs #527.
3 files changed,
+102
−18
internal/console/demo_claim_no_mailer_test.go+70 −0internal/console/demo_claim_ready.go+3 −3internal/console/demo_claim_ready_test.go+29 −15
CI cancelled — superseded by a newer push — run details
Intent
Attributed to this commit: 13.9 g CO₂e (1,793,844 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on demo-claim-keymail-ready, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/demo_claim_no_mailer_test.go b/internal/console/demo_claim_no_mailer_test.go| new file mode 100644 |
| index 000000000..ca5926913 |
| --- /dev/null |
| +++ b/internal/console/demo_claim_no_mailer_test.go |
| @@ -0,0 +1,70 @@ |
| +package console |
| + |
| +import ( |
| + "encoding/json" |
| + "net/url" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func claimNoMailerServer(t *testing.T) (*Server, string) { |
| + t.Helper() |
| + s, _, token := claimTestServer(t) |
| + claimActivationFixture(t, s) |
| + s.consoleMail = nil |
| + fk := newFakeKeymail(t, "shop@example.com") |
| + fk.mu.Lock() |
| + fk.lookupStatus["shop@example.com"] = 404 |
| + fk.mu.Unlock() |
| + s.km = NewKeymail(fk.srv.URL, s.cfg.Origin) |
| + return s, token |
| +} |
| + |
| +func claimNoSendBudget(t *testing.T, s *Server) { |
| + t.Helper() |
| + s.limits.mu.Lock() |
| + defer s.limits.mu.Unlock() |
| + if len(s.limits.addrSends.hits) != 0 || len(s.limits.ipSends.hits) != 0 || len(s.limits.globalSend) != 0 { |
| + t.Fatal("claim start changed shared send-limit state") |
| + } |
| +} |
| + |
| +func TestDemoClaimEmailNoMailer(t *testing.T) { |
| + s, token := claimNoMailerServer(t) |
| + claimNoSendBudget(t, s) |
| + for range 31 { |
| + _, w := claimStart(t, s, token, "shop@example.com", "") |
| + var reply struct{ Error string } |
| + if w.Code != 503 || json.Unmarshal(w.Body.Bytes(), &reply) != nil || reply.Error != demoClaimUnavailable { |
| + t.Fatalf("no mailer: %d %s", w.Code, w.Body) |
| + } |
| + claimNoSendBudget(t, s) |
| + } |
| + if claimBrowserCount(t, s, "demo_claim_flows") != 0 { |
| + t.Fatal("unavailable email start created a flow") |
| + } |
| + _, w := claimStart(t, s, token, "shop@"+s.km.Host(), "") |
| + var reply struct{ State, ClaimURL string } |
| + if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &reply) != nil || reply.State != "browser_required" || reply.ClaimURL != s.cfg.Origin+"/demo/claim#"+token { |
| + t.Fatalf("Keymail without mailer: %d %s", w.Code, w.Body) |
| + } |
| + claimNoSendBudget(t, s) |
| +} |
| + |
| +func TestDemoClaimBrowserNoMailer(t *testing.T) { |
| + s, token := claimNoMailerServer(t) |
| + b := newClaimBrowser(t, s, token) |
| + claimNoSendBudget(t, s) |
| + for range 31 { |
| + w := b.post("/demo/claim/prove", url.Values{"email": {"shop@example.com"}}) |
| + if w.Code != 503 || !strings.HasPrefix(w.Header().Get("Content-Type"), "text/html") || !strings.Contains(w.Body.String(), `<p role="alert">`+demoClaimUnavailable+`</p>`) { |
| + t.Fatalf("no mailer: %d %s", w.Code, w.Body) |
| + } |
| + claimNoSendBudget(t, s) |
| + } |
| + w := b.post("/demo/claim/prove", url.Values{"email": {"shop@" + s.km.Host()}}) |
| + if w.Code != 303 || w.Header().Get("Location") != "/auth/signin?next=%2Fdemo%2Fclaim" { |
| + t.Fatalf("Keymail without mailer: %d %s", w.Code, w.Body) |
| + } |
| + claimNoSendBudget(t, s) |
| +} |
diff --git a/internal/console/demo_claim_ready.go b/internal/console/demo_claim_ready.go| index 2dfd66f5a..0115f0fb4 100644 |
| --- a/internal/console/demo_claim_ready.go |
| +++ b/internal/console/demo_claim_ready.go |
| @@ -33,9 +33,9 @@ func (s *Server) demoClaimReady(ctx context.Context) error { |
| func (s *Server) checkDemoClaimReady(ctx context.Context) error { |
| refuse := func() error { return errors.New(demoClaimUnavailable) } |
| - // Keymail discovery has its existing email fallback. Do not probe a person's |
| - // identity or add provider polling: require the OAuth path and ready mailer. |
| - if !s.mailReady(ctx) || s.km == nil || s.km.Host() == "" || s.cfg.AppsDomain == "" || |
| + // Readiness means the browser Keymail path can complete. Email-code starts |
| + // are refused per request when no mailer is ready. |
| + if s.km == nil || s.km.Host() == "" || s.cfg.AppsDomain == "" || |
| len(s.cfg.Key) != ed25519.PrivateKeySize || len(s.cfg.ReleasePub) != ed25519.PublicKeySize || |
| s.cfg.Releases == nil || s.cfg.SeedData == nil || !s.leftoverCheckApplies(s.cfg.Region, "") { |
| return refuse() |
diff --git a/internal/console/demo_claim_ready_test.go b/internal/console/demo_claim_ready_test.go| index d789b65ff..aa5bfda7f 100644 |
| --- a/internal/console/demo_claim_ready_test.go |
| +++ b/internal/console/demo_claim_ready_test.go |
| @@ -34,7 +34,7 @@ func claimActivationFixture(t *testing.T, s *Server) { |
| } |
| func TestDemoClaimReadiness(t *testing.T) { |
| - for _, missing := range []string{"", "mail", "keymail", "worker", "seed", "moved", "policy", "delivery", "data", "placement"} { |
| + for _, missing := range []string{"", "mail", "keymail", "mailAndKeymail", "keymailHost", "worker", "seed", "moved", "policy", "delivery", "data", "placement"} { |
| t.Run(missing, func(t *testing.T) { |
| s, _, _ := claimTestServer(t) |
| claimActivationFixture(t, s) |
| @@ -43,6 +43,11 @@ func TestDemoClaimReadiness(t *testing.T) { |
| s.consoleMail = nil |
| case "keymail": |
| s.km = nil |
| + case "mailAndKeymail": |
| + s.consoleMail = nil |
| + s.km = nil |
| + case "keymailHost": |
| + s.km = NewKeymail("", s.cfg.Origin) |
| case "worker": |
| s.demoJobs.peers["box"].ready.ClaimCapability = "" |
| case "seed": |
| @@ -62,10 +67,11 @@ func TestDemoClaimReadiness(t *testing.T) { |
| ctx, cancel := context.WithCancel(t.Context()) |
| cancel() |
| err := s.demoClaimReady(ctx) |
| - if (err != nil) != (missing != "") { |
| + ready := missing == "" || missing == "mail" |
| + if (err == nil) != ready { |
| t.Fatalf("readiness %q: %v", missing, err) |
| } |
| - if s.demoClaimEnabled() != (missing == "") { |
| + if s.demoClaimEnabled() != ready { |
| t.Fatal("enabled ignores readiness") |
| } |
| }) |
| @@ -81,7 +87,8 @@ func TestDemoClaimReadinessCache(t *testing.T) { |
| t.Fatal(err) |
| } |
| gets, lists := counted.gets.Load(), counted.lists.Load() |
| - s.consoleMail = nil |
| + km := s.km |
| + s.km = nil |
| for range 3 { |
| if err := s.demoClaimReady(t.Context()); err != nil { |
| t.Fatal(err) |
| @@ -97,7 +104,7 @@ func TestDemoClaimReadinessCache(t *testing.T) { |
| if s.demoClaimReady(t.Context()) == nil { |
| t.Fatal("stale success") |
| } |
| - s.consoleMail = &fakeConsoleMail{ready: true} |
| + s.km = km |
| if s.demoClaimReady(t.Context()) == nil { |
| t.Fatal("failure not cached") |
| } |
| @@ -124,13 +131,14 @@ func TestDemoClaimRecoveryRoutes(t *testing.T) { |
| } |
| } |
| -func TestDemoClaimAvailabilityResponse(t *testing.T) { |
| +func TestDemoClaimReadinessAvailabilityResponse(t *testing.T) { |
| for _, ready := range []bool{false, true} { |
| t.Run(map[bool]string{false: "notReady", true: "ready"}[ready], func(t *testing.T) { |
| s, _ := demoJobServer(t) |
| claimActivationFixture(t, s) |
| + s.consoleMail = nil |
| if !ready { |
| - s.consoleMail = nil |
| + s.km = nil |
| } |
| r := httptest.NewRequest("POST", "/api/demo/apps", bytes.NewReader(demoHTTPSource(t))) |
| r.RemoteAddr = "192.0.2.1:1" |
| @@ -148,28 +156,34 @@ func TestDemoClaimAvailabilityResponse(t *testing.T) { |
| } |
| } |
| -type claimDeadlineMail struct { |
| - *fakeConsoleMail |
| - t *testing.T |
| +type claimDeadlineStore struct { |
| + release.Store |
| + t *testing.T |
| + checked bool |
| } |
| -func (m claimDeadlineMail) Ready(ctx context.Context) bool { |
| - m.t.Helper() |
| +func (s *claimDeadlineStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + s.t.Helper() |
| deadline, ok := ctx.Deadline() |
| if !ok || time.Until(deadline) > 10*time.Second || time.Until(deadline) < 9*time.Second || ctx.Err() != nil { |
| - m.t.Fatal("readiness did not receive its own ten-second context") |
| + s.t.Fatal("readiness did not receive its own ten-second context") |
| } |
| - return true |
| + s.checked = true |
| + return s.Store.Get(ctx, key) |
| } |
| func TestDemoClaimReadinessDeadline(t *testing.T) { |
| s, _, _ := claimTestServer(t) |
| claimActivationFixture(t, s) |
| - s.consoleMail = claimDeadlineMail{fakeConsoleMail: &fakeConsoleMail{ready: true}, t: t} |
| + store := &claimDeadlineStore{Store: s.cfg.Releases, t: t} |
| + s.cfg.Releases = store |
| ctx, cancel := context.WithCancel(t.Context()) |
| cancel() |
| if err := s.demoClaimReady(ctx); err != nil { |
| t.Fatal(err) |
| } |
| + if !store.checked { |
| + t.Fatal("readiness did not check the deployment store") |
| + } |
| } |
| func TestDemoClaimReadinessWithPurgedStrays(t *testing.T) { |