/continue spends the kept return page when it follows the invitation
forgetReturn ran after continueInvitation had written its redirect, so the clearing cookie was never sent and a second /continue landed on the stale page (Fable on #46, cfa7636). continueInvitation now forgets it once it has decided to answer, before anything writes the response. The Oficina-from-the-join-cookie test asserts the cleared cookie and that a second /continue lands on the list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+15
−2
internal/calls/auth.go+0 −1internal/calls/handlers_join.go+3 −0internal/calls/signin_door_calls_test.go+12 −1
CI passed — run details
CI log
=== vet === go vet ./... go vet -tags browser ./internal/calls/ ./internal/callstest/ === fmt === === test === go test ./... ok amadan.net/oficina/calls/callscore (cached) ok amadan.net/oficina/calls/cmd/calls 13.403s ? amadan.net/oficina/calls/cmd/calls-contract [no test files] ok amadan.net/oficina/calls/cmd/quality-summary (cached) ? amadan.net/oficina/calls/gen [no test files] ok amadan.net/oficina/calls/gen/locales (cached) ok amadan.net/oficina/calls/internal/calls 14.854s ok amadan.net/oficina/calls/internal/calls/apns (cached) ok amadan.net/oficina/calls/internal/calls/hub (cached) ? amadan.net/oficina/calls/internal/calls/icons [no test files] ? amadan.net/oficina/calls/internal/calls/keymailtest [no test files] ok amadan.net/oficina/calls/internal/calls/relay (cached) ok amadan.net/oficina/calls/internal/calls/seal (cached) ? amadan.net/oficina/calls/internal/calls/teamstate [no test files] ok amadan.net/oficina/calls/internal/callstest 12.778s ok amadan.net/oficina/calls/protocol (cached) ? amadan.net/oficina/calls/scripts/writeestilo [no test files] === migration-check === go run amadan.net/rastrillo/rastrillo/cmd/rastrillo migration check rastrillo migration check: models and migrations agree === race === CGO_ENABLED=1 go test -race ./internal/... ok amadan.net/oficina/calls/internal/calls 110.798s ok amadan.net/oficina/calls/internal/calls/apns (cached) ok amadan.net/oficina/calls/internal/calls/hub (cached) ? amadan.net/oficina/calls/internal/calls/icons [no test files] ? amadan.net/oficina/calls/internal/calls/keymailtest [no test files] ok amadan.net/oficina/calls/internal/calls/relay (cached) ok amadan.net/oficina/calls/internal/calls/seal (cached) ? amadan.net/oficina/calls/internal/calls/teamstate [no test files] ok amadan.net/oficina/calls/internal/callstest 50.572s
Intent
diff --git a/internal/calls/auth.go b/internal/calls/auth.go| index d79e501..e1d4b45 100644 |
| --- a/internal/calls/auth.go |
| +++ b/internal/calls/auth.go |
| @@ -321,7 +321,6 @@ func (a *app) continueSignedIn(w http.ResponseWriter, r *http.Request) { |
| // for it: an Oficina ID sign-in from the join cookie's door lands here |
| // (signin_admission.go's oficinaJoinLanding). |
| if a.continueInvitation(w, r) { |
| - a.forgetReturn(w) |
| return |
| } |
| // Where the person was going when they were asked to sign in |
diff --git a/internal/calls/handlers_join.go b/internal/calls/handlers_join.go| index a30549a..9ded776 100644 |
| --- a/internal/calls/handlers_join.go |
| +++ b/internal/calls/handlers_join.go |
| @@ -116,6 +116,9 @@ func (a *app) continueInvitation(w http.ResponseWriter, r *http.Request) bool { |
| if !signedIn { |
| return false |
| } |
| + // Answering now: the kept return page was this sign-in's, and is spent |
| + // before anything below writes the response. |
| + a.forgetReturn(w) |
| var host *teammode.Access |
| if a.team != nil { |
| if host, ok = a.teamLinkHost(w, r, m); !ok { |
diff --git a/internal/calls/signin_door_calls_test.go b/internal/calls/signin_door_calls_test.go| index 179fc2f..6282a6d 100644 |
| --- a/internal/calls/signin_door_calls_test.go |
| +++ b/internal/calls/signin_door_calls_test.go |
| @@ -7,6 +7,7 @@ package calls |
| import ( |
| "context" |
| "net/http" |
| + "net/http/httptest" |
| "net/url" |
| "regexp" |
| "strings" |
| @@ -178,6 +179,10 @@ func TestAnOficinaSigninFromTheJoinCookieLandsOnTheInvitation(t *testing.T) { |
| homeSignout(t, f.do(http.MethodPost, "/signout", "")) |
| sqid, token := doorMeeting(t, f, true) |
| redirectsTo(t, f.get("/j/"+token), "/signin") |
| + // A page kept by an earlier attempt, which the invitation spends. |
| + w := httptest.NewRecorder() |
| + f.app.rememberReturn(w, "/settings") |
| + f.cookies[f.app.returnCookieName()] = w.Result().Cookies()[0] |
| start := homeRedirect(t, f.get("/signin/oficina?return_to=%2Fsettings")) |
| if !strings.Contains(start, "return_to=%2Fcontinue") { |
| t.Fatalf("the exchange starts for %q, want /continue", start) |
| @@ -186,10 +191,16 @@ func TestAnOficinaSigninFromTheJoinCookieLandsOnTheInvitation(t *testing.T) { |
| if landing != "/continue" { |
| t.Fatalf("the exchange landed on %q", landing) |
| } |
| - redirectsTo(t, f.get(landing), "/m/"+sqid+"/join") |
| + cont := f.get(landing) |
| + redirectsTo(t, cont, "/m/"+sqid+"/join") |
| if f.cookies[joinCookieName] != nil { |
| t.Fatal("the join cookie outlived the sign-in") |
| } |
| + if !clears(cont, f.app.returnCookieName()) || f.returnPath() != "" { |
| + t.Fatal("/continue followed the invitation and kept the return page") |
| + } |
| + // A second /continue lands on the list, not the stale page. |
| + redirectsTo(t, f.get("/continue"), "/") |
| }) |
| t.Run("team", func(t *testing.T) { |
| tf := newTeamFixture(t) |