carlos / platform Public

console: the final review's minor fixes

- TestCopyTextFillsPlaceholders passes replacements and checks the
  whole filled text.
- The sweep test's bound is 300+1-limitSweepBudget.
- The invite end-to-end test submits the signed-out page's own hidden
  next.
- The claim probe checker's synthetic flash uses team.bad_address.
- consoleName sits above dnsTargets' doc comment, not inside it.
- notifyCLIIssued's comment says it reaches email users too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 6769dec60bcc08aa33ba41ece81b4534996a67e8 parent 1df9ce6
6 files changed, +46 −15
  • internal/console/authcli.go +8 −7
  • internal/console/claim_invariant_probes_test.go +1 −1
  • internal/console/emailsignin_limits_test.go +1 −1
  • internal/console/invite_delivery_test.go +13 −1
  • internal/console/server.go +0 −5
  • internal/console/signincopy_test.go +23 −0
diff --git a/internal/console/authcli.go b/internal/console/authcli.go
index f70397288..b18c7763f 100644
--- a/internal/console/authcli.go
+++ b/internal/console/authcli.go
@@ -1294,22 +1294,23 @@ func (s *Server) handleCLIPoll(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, out)
}
-// notifyCLIIssued tells the human, in their own Keymail inbox, that a terminal
-// now holds their identity — naming it, where it dialled from, and how to kill
-// it.
+// notifyCLIIssued tells the human that a terminal now holds their identity —
+// naming it, where it dialled from, and how to kill it. Someone who signed in
+// with Keymail hears in their own Keymail inbox, through their grant; someone
+// who signed in by email (no grant) hears through deliver: Keymail first if
+// the address turns out to have a mailbox there, else the console's own email.
//
// This is the control that makes a phished approval DETECTABLE. Every other
// defence in this flow is preventive and therefore fallible; a message that
// arrives whether or not the approval was a good idea is what turns "somebody
// has been me for two months" into "I revoked that within the hour". Same
-// sealed-envelope channel as sign-in confirmations and invites — the platform
-// still emails nobody.
+// channels as invites.
//
// Off the request goroutine on purpose: a slow Keymail must never stall the
// poll the CLI is waiting on. Issuance has already happened and the request row
// is burnt, so a CLI that gave up would otherwise leave a token nobody
-// collected. Best-effort throughout — a user who has never completed the OAuth
-// ceremony has no grant to send with, and that is not a reason to fail a login.
+// collected. Best-effort throughout: a notice that cannot be delivered is
+// logged, never a reason to fail a login.
func (s *Server) notifyCLIIssued(address, rawToken string) {
defer func() {
if s.cliNotified != nil {
diff --git a/internal/console/claim_invariant_probes_test.go b/internal/console/claim_invariant_probes_test.go
index 77914218c..5bdfc3939 100644
--- a/internal/console/claim_invariant_probes_test.go
+++ b/internal/console/claim_invariant_probes_test.go
@@ -492,7 +492,7 @@ func TestClaimProbeRejectsWhatIsNotAnAcceptance(t *testing.T) {
{"sign-in redirect", redirect, claimReply{Status: 303, Loc: "/auth/signin"}, "auth redirect"},
{"unfinished step-up", redirect, claimReply{Status: 303, Loc: keymail + "/oauth/authorize?x=1"}, "auth redirect"},
{"a redirect somewhere else", redirect, claimReply{Status: 303, Loc: "/a/bab/settings"}, "redirected to"},
- {"an error behind a redirect", redirect, claimReply{Status: 303, Loc: "/a/bab/team", Flash: "err", Note: "That doesn't look like a keymail address."}, "flashed an error"},
+ {"an error behind a redirect", redirect, claimReply{Status: 303, Loc: "/a/bab/team", Flash: "err", Note: copyText("team.bad_address")}, "flashed an error"},
} {
t.Run(c.name, func(t *testing.T) {
problems := claimReplyProblems(c.p, c.r, keymail)
diff --git a/internal/console/emailsignin_limits_test.go b/internal/console/emailsignin_limits_test.go
index ddc5e46ed..644fb2110 100644
--- a/internal/console/emailsignin_limits_test.go
+++ b/internal/console/emailsignin_limits_test.go
@@ -410,7 +410,7 @@ func TestSigninSendSweepCleansStaleAcrossCalls(t *testing.T) {
c.advance(25 * time.Hour)
l.submit("11.0.0.1")
left := limitKeyCount(l)
- if left == 0 || left < 300-limitSweepBudget-1 {
+ if left == 0 || left < 300+1-limitSweepBudget {
t.Fatalf("one submit left %d of 301 keys; want a bounded step (dropped at most %d)", left, limitSweepBudget)
}
for i := 0; i < 20 && limitKeyCount(l) > 1; i++ {
diff --git a/internal/console/invite_delivery_test.go b/internal/console/invite_delivery_test.go
index 3d631b97a..a07ced3e8 100644
--- a/internal/console/invite_delivery_test.go
+++ b/internal/console/invite_delivery_test.go
@@ -4,10 +4,12 @@ import (
"bytes"
"context"
"fmt"
+ "html"
"log"
"net/http"
"net/url"
"os"
+ "regexp"
"strings"
"sync"
"testing"
@@ -434,8 +436,18 @@ func TestInviteEmailInviteeAcceptsEndToEnd(t *testing.T) {
t.Fatalf("signed-out invite page = %d, missing %q:\n%s", status, want, page)
}
}
+ // The form carries the invite back as its hidden next; submit what the
+ // page rendered, not what the test knows.
+ nm := regexp.MustCompile(`name="next" value="([^"]*)"`).FindStringSubmatch(page)
+ if nm == nil {
+ t.Fatalf("signed-out invite page has no hidden next:\n%s", page)
+ }
+ formNext := html.UnescapeString(nm[1])
+ if formNext != next {
+ t.Fatalf("the form's next = %q, want %q", formNext, next)
+ }
// Sign in by code; the invite is where it lands.
- code, _ := askSignin(t, fx, m, guest, "new@example.com", next)
+ code, _ := askSignin(t, fx, m, guest, "new@example.com", formNext)
status, loc, _ := postCode(t, fx, guest, code)
if status != http.StatusSeeOther || loc != next {
t.Fatalf("code sign-in = %d to %q, want 303 to %q", status, loc, next)
diff --git a/internal/console/server.go b/internal/console/server.go
index 745c5f5e0..3cdb57843 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -1181,11 +1181,6 @@ type edgeFoldCache struct {
ips []string
}
-// dnsTargets is what every custom-domain guidance string in this console is
-// built from (view.go's domainGuidance): the deployment's edge addresses and
-// its steering hostname, read from ONE place so the app page, the Settings
-// page and the /domains API can never disagree about where a member should
-// point DNS.
// consoleName is what the console's emails call it: the operator's
// CARLOS_CONSOLE_NAME, else today's wording.
func (s *Server) consoleName() string {
diff --git a/internal/console/signincopy_test.go b/internal/console/signincopy_test.go
index 3b9884af7..18506f808 100644
--- a/internal/console/signincopy_test.go
+++ b/internal/console/signincopy_test.go
@@ -3,6 +3,7 @@ package console
import (
"encoding/json"
"os"
+ "strings"
"testing"
)
@@ -52,6 +53,28 @@ func TestCopyTextFillsPlaceholders(t *testing.T) {
t.Errorf("copyText(%q) with no arguments changed the text", id)
}
}
+ for _, tc := range []struct {
+ id string
+ kv []string
+ want string
+ }{
+ {"check.sent", []string{"address", "bob@example.com"},
+ "A sign-in link and code are on their way to bob@example.com. Both work once, for 15 minutes."},
+ {"email.signin.body", []string{"console", "Example Console", "address", "bob@example.com",
+ "link", "https://console.example.com/auth/email/link?t=TOKEN", "code", "123456"},
+ "Someone, hopefully you, asked to sign in to Example Console as bob@example.com.\n\n" +
+ "Open this link to sign in:\n\nhttps://console.example.com/auth/email/link?t=TOKEN\n\n" +
+ "Or type this code on the page that's waiting: 123456\n\n" +
+ "The link and the code work once, for 15 minutes. If this wasn't you, ignore this email. Nothing happens without the link or the code."},
+ } {
+ got := copyText(tc.id, tc.kv...)
+ if got != tc.want {
+ t.Errorf("copyText(%q, %q) = %q, want %q", tc.id, tc.kv, got, tc.want)
+ }
+ if strings.ContainsAny(got, "{}") {
+ t.Errorf("copyText(%q) left a placeholder: %q", tc.id, got)
+ }
+ }
defer func() {
if recover() == nil {
t.Error("copyText of an unknown id did not panic")