console: wrong-code tests use a value no code can be
Co-Authored-By: Claude <noreply@anthropic.com>
1 file changed,
+10
−7
internal/console/emailsignin_test.go+10 −7
diff --git a/internal/console/emailsignin_test.go b/internal/console/emailsignin_test.go| index bfb360fa4..4448ebd70 100644 |
| --- a/internal/console/emailsignin_test.go |
| +++ b/internal/console/emailsignin_test.go |
| @@ -1137,7 +1137,7 @@ func TestEmailCodeRefusedReadsAsSent(t *testing.T) { |
| lookupAnswers(fx, addr, http.StatusNotFound) |
| sent := newBrowser(t) |
| - code, _ := askSignin(t, fx, m, sent, addr, next) |
| + askSignin(t, fx, m, sent, addr, next) |
| // At once, from a fresh browser: the per-address gap refuses the send. |
| refused := newBrowser(t) |
| if status, _, body := postContinue(t, fx, refused, url.Values{"address": {addr}, "next": {next}}); status != http.StatusOK || |
| @@ -1147,7 +1147,10 @@ func TestEmailCodeRefusedReadsAsSent(t *testing.T) { |
| if n := len(m.sentCopy()); n != 1 { |
| t.Fatalf("mailer got %d messages, want 1", n) |
| } |
| - for _, try := range []string{wrongCode(code), "abcdef"} { |
| + // The refused browser's challenge has a random code nobody saw, so every |
| + // wrong code here is one no six-digit code can be: wrongCode(code) is |
| + // wrong only for the sent browser. |
| + for _, try := range []string{"abcdef", "12345"} { |
| sStatus, sHdr, sBody := postCheckCode(t, fx, sent, try, addr, next) |
| rStatus, rHdr, rBody := postCheckCode(t, fx, refused, try, addr, next) |
| if sStatus != http.StatusOK || !strings.Contains(sBody, esc(copyText("check.code_wrong"))) { |
| @@ -1163,8 +1166,8 @@ func TestEmailCodeRefusedReadsAsSent(t *testing.T) { |
| // The refused browser's challenge can never sign in: nobody has its code |
| // or link, and the five attempts burn it as they would a sent one. |
| for i := 3; i <= emailCodeAttempts; i++ { |
| - _, _, sBody := postCheckCode(t, fx, sent, wrongCode(code), addr, next) |
| - _, _, rBody := postCheckCode(t, fx, refused, wrongCode(code), addr, next) |
| + _, _, sBody := postCheckCode(t, fx, sent, "abcdef", addr, next) |
| + _, _, rBody := postCheckCode(t, fx, refused, "abcdef", addr, next) |
| if rBody != sBody { |
| t.Fatalf("attempt %d differs:\nrefused:\n%s\nsent:\n%s", i, rBody, sBody) |
| } |
| @@ -1182,15 +1185,15 @@ func TestEmailCodeRefusedReadsAsSent(t *testing.T) { |
| asker := newBrowser(t) |
| askSignin(t, fx, m, asker, a, "") |
| sentB := newBrowser(t) |
| - codeB, _ := askSignin(t, fx, m, sentB, b, "") |
| + askSignin(t, fx, m, sentB, b, "") |
| // ben was just sent one, so asker's request for ben is refused. |
| before := len(m.sentCopy()) |
| postContinue(t, fx, asker, url.Values{"address": {b}}) |
| if len(m.sentCopy()) != before { |
| t.Fatal("the refused request for ben sent mail") |
| } |
| - _, _, sBody := postCheckCode(t, fx, sentB, wrongCode(codeB), b, "") |
| - _, _, rBody := postCheckCode(t, fx, asker, wrongCode(codeB), b, "") |
| + _, _, sBody := postCheckCode(t, fx, sentB, "abcdef", b, "") |
| + _, _, rBody := postCheckCode(t, fx, asker, "abcdef", b, "") |
| if rBody != sBody || !strings.Contains(sBody, esc(copyText("check.sent", "address", b))) { |
| t.Fatalf("a wrong code after a refusal beside a live challenge differs:\nrefused:\n%s\nsent:\n%s", rBody, sBody) |
| } |