fix: Displace prior password-reset tokens when minting a new one #76
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
rosa/vernier!76
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/single-valid-reset-token"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #59.
Problem
run_password_resetinserts a password-reset confirmation, then enqueues the reset email as a separate fallible call. The apalis handler maps every failure to a retryable error, and prior reset tokens were never removed — so a transient mailer-enqueue failure after the insert re-ran the flow and minted an additional simultaneously-valid 30-minute token per retry.Fix
create_password_reset_confirmationnow atomically displaces priorpassword_resetconfirmations for the same user: the Postgres adapter deletes them and inserts the new row in one transaction, and the in-memory mock mirrors the semantics. At most one reset link is valid per user at any time, and retried jobs converge on a single valid token.Untouched, per the brief: email-confirmation rows for the same user, other users' reset tokens, the unknown-email quiet-success path, the apalis retry policy, and the 30-minute TTL.
Tests
crates/infra/tests/confirmation_repository_conformance.rs(Postgres + in-memory): minting displaces the prior reset but not the email confirmation, and displacement is scoped to the requesting user.run_password_resettwice leaves the older token failing verification and the newer one succeeding; a pending email-confirmation survives a reset request.mise run cipasses.