5 files changed,
+29
−5
connect/choose.go
+3 −1
connect/linkstore/choice_test.go
+15 −0
connect/linkstore/store.go
+4 −2
connect/routes.go
+1 −1
connect/routes_test.go
+6 −1
CI cancelled — superseded by a newer push
— run details
| index 8ebd952..b905394 100644 |
| --- a/connect/choose.go |
| +++ b/connect/choose.go |
| @@ -138,15 +138,17 @@ func (b *Bridge) ChoosePost(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| taken, err := b.links.TakeChoice(r.Context(), secret, b.now()) |
| - setHomeCookie(w, homeChoiceCookie, "", -1) |
| switch { |
| case errors.Is(err, linkstore.ErrRefused): |
| + setHomeCookie(w, homeChoiceCookie, "", -1) |
| b.fail(w, r, http.StatusForbidden) |
| return |
| case err != nil: |
| + // Nothing was consumed: the same proof may be tried again. |
| b.fail(w, r, http.StatusServiceUnavailable) |
| return |
| } |
| + setHomeCookie(w, homeChoiceCookie, "", -1) |
| if choice == "connect" { |
| if b.rememberUnknown != nil { |
| b.rememberUnknown(w) |
| index ccacfff..e11830b 100644 |
| --- a/connect/linkstore/choice_test.go |
| +++ b/connect/linkstore/choice_test.go |
| @@ -84,3 +84,18 @@ func TestChoiceProofRaceHasOneWinner(t *testing.T) { |
| t.Fatalf("%d winners", won) |
| } |
| } |
| + |
| +// Sweep, at boot and inside every link flow, drops expired proofs. |
| +func TestSweepDropsExpiredChoiceProofs(t *testing.T) { |
| + s, _ := fixture(t) |
| + if _, err := s.StartChoice(ctx, Choice{Subject: "pr_member", AuthTime: testNow}, testNow); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := s.Sweep(ctx, testNow.Add(11*time.Minute)); err != nil { |
| + t.Fatal(err) |
| + } |
| + var n int |
| + if err := s.db.QueryRow("SELECT COUNT(*) FROM home_choice_proofs").Scan(&n); err != nil || n != 0 { |
| + t.Fatal("expired proof kept", n, err) |
| + } |
| +} |
| index 5036cc0..9f8eb79 100644 |
| --- a/connect/linkstore/store.go |
| +++ b/connect/linkstore/store.go |
| @@ -158,8 +158,10 @@ func commit(tx *sql.Tx) error { |
| return nil |
| } |
| func sweep(ctx context.Context, tx *sql.Tx, high int64) error { |
| - if _, err := tx.ExecContext(ctx, "DELETE FROM home_link_flows WHERE expires_at <= ?", high); err != nil { |
| - return ErrStorage |
| + for _, table := range []string{"home_link_flows", "home_choice_proofs"} { |
| + if _, err := tx.ExecContext(ctx, "DELETE FROM "+table+" WHERE expires_at <= ?", high); err != nil { |
| + return ErrStorage |
| + } |
| } |
| return nil |
| } |
| index 24feb5a..14060e6 100644 |
| --- a/connect/routes.go |
| +++ b/connect/routes.go |
| @@ -211,7 +211,7 @@ func (h *Routes) ConfirmPost(w http.ResponseWriter, r *http.Request) { |
| // here, as before. |
| func (h *Routes) Signout(w http.ResponseWriter, r *http.Request) { |
| h.cfg.SignOut(w, r) |
| - for _, name := range []string{homeInitCookie, homeProofCookie, localLinkNavigationCookie, homeReturnCookie, "__Host-oficina-assertion-pending", "__Host-oficina-assertion-inbox"} { |
| + for _, name := range []string{homeInitCookie, homeProofCookie, homeChoiceCookie, localLinkNavigationCookie, homeReturnCookie, "__Host-oficina-assertion-pending", "__Host-oficina-assertion-inbox"} { |
| localNavigationCookie(w, name, "", -1) |
| } |
| w.Header().Set("Cache-Control", "no-store") |
| index ce2a9ef..9b0b27d 100644 |
| --- a/connect/routes_test.go |
| +++ b/connect/routes_test.go |
| @@ -107,13 +107,18 @@ func assertSignoutCleared(t *testing.T, w *httptest.ResponseRecorder) { |
| if w.Header().Get("Cache-Control") != "no-store" { |
| t.Fatal("sign-out cacheable") |
| } |
| - if len(w.Result().Cookies()) != 6 { |
| + if len(w.Result().Cookies()) != 7 { |
| t.Fatal("handoff pointers left behind") |
| } |
| + choice := false |
| for _, c := range w.Result().Cookies() { |
| if c.MaxAge != -1 || !c.Secure || !c.HttpOnly { |
| t.Fatal("cookie not cleared safely") |
| } |
| + choice = choice || c.Name == homeChoiceCookie |
| + } |
| + if !choice { |
| + t.Fatal("a pending member choice survived sign-out") |
| } |
| } |
| |