fix(auth): a cancel at Google lands where the browser is; the probe says why it refused

A refused session keeps its cookie, so the cancel branch, keyed on the cookie's account, sent a
signed-out browser to the in-app toast the login page never shows: it now asks whether the
session holds. The probe's log line named every refusal 'its account no longer holds'; it now
carries the reason. The pruning docstring says again that a renewal may land a request's time
after the revoke, and the test pins the day of margin. The test clock clamps in the zone asked for.
This commit is contained in:
2026-11-14 20:07:13 +01:00
parent 7dd50db9b7
commit 7a1487f554
6 changed files with 98 additions and 19 deletions
+23
View File
@@ -59,6 +59,29 @@ def _sign_in(client, google, state: str | None = None, **userinfo):
)
@pytest.mark.parametrize("session", ["holds", "refused"])
def test_a_cancel_at_google_lands_where_the_browser_is(client, google, make_user, session):
# Signed in, the cancel is a toast in the app; signed out, the login page's banner. A refused
# session keeps its cookie and its account id, and its browser is on the login page.
import base64
import json
from itsdangerous import TimestampSigner
make_user(email="cancel@example.com", password=_PW)
_password_login(client, "cancel@example.com")
if session == "refused":
signer = TimestampSigner(str(settings.secret_key))
payload = json.loads(base64.b64decode(signer.unsign(client.cookies["session"])))
payload.pop("sid") # a cookie from before session ids
refused = signer.sign(base64.b64encode(json.dumps(payload).encode())).decode()
client.cookies.clear()
client.cookies.set("session", refused)
r = _sign_in(client, google, state="not-this-flow")
expected = "/?oauth=cancelled" if session == "holds" else "/?login=oauth_cancelled"
assert r.headers["location"] == expected
def _rows(db, model, column, value):
db.expire_all()
return db.execute(select(model).where(column == value)).scalars().all()