fix: Report not-found and unauthorized from revoke_access_token #74

Merged
rosa merged 1 commit from fix/revoke-token-ownership-errors into main 2026-07-03 21:33:35 +00:00
Owner

Fixes #62.

revoke_access_token returned Ok(()) when the token id did not exist or belonged to another user, and the account page flashed "Access token revoked." unconditionally — a foreign or nonexistent id reported success while any such token stayed live.

Changes

  • New RevokeTokenError enum (NotFound, Unauthorized, Unknown) in crates/domain/src/errors.rs, following the shape of the other owner-gated mutation errors (DeletePostError, DeleteWebmentionError).
  • revoke_access_token now returns RevokeTokenError instead of anyhow::Error: not-found and not-owned ids are reported instead of silently succeeding.
  • From<RevokeTokenError> for AppError in crates/web/src/error.rs maps NotFound → 404 and Unauthorized → forbidden, consistent with the sibling mappings, so the handler's ? short-circuits before the success flash.
  • Service-level tests against the mock repository: nonexistent id → NotFound; another user's token → Unauthorized with the token remaining live; revoking one's own token still deletes it (existing test).

The ci mise task passes.

Fixes #62. `revoke_access_token` returned `Ok(())` when the token id did not exist or belonged to another user, and the account page flashed "Access token revoked." unconditionally — a foreign or nonexistent id reported success while any such token stayed live. ## Changes - New `RevokeTokenError` enum (`NotFound`, `Unauthorized`, `Unknown`) in `crates/domain/src/errors.rs`, following the shape of the other owner-gated mutation errors (`DeletePostError`, `DeleteWebmentionError`). - `revoke_access_token` now returns `RevokeTokenError` instead of `anyhow::Error`: not-found and not-owned ids are reported instead of silently succeeding. - `From<RevokeTokenError> for AppError` in `crates/web/src/error.rs` maps `NotFound` → 404 and `Unauthorized` → forbidden, consistent with the sibling mappings, so the handler's `?` short-circuits before the success flash. - Service-level tests against the mock repository: nonexistent id → `NotFound`; another user's token → `Unauthorized` with the token remaining live; revoking one's own token still deletes it (existing test). The `ci` mise task passes.
fix: Report not-found and unauthorized from revoke_access_token
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
a916b2c4ca
revoke_access_token silently returned Ok(()) when the token id did not
exist or belonged to another user, and the account page flashed 'Access
token revoked.' regardless. Introduce RevokeTokenError with NotFound,
Unauthorized, and Unknown variants, matching the other owner-gated
mutations, and map it to the web layer's 404/forbidden responses so the
success flash only appears when a token was actually revoked.

Fixes #62
rosa merged commit a0fc7f032a into main 2026-07-03 21:33:35 +00:00
rosa deleted branch fix/revoke-token-ownership-errors 2026-07-03 21:33:35 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rosa/vernier!74
No description provided.