Add JWT flow tests: registration, login, protected routes, token refresh, and admin endpoints #1598

Closed
opened 2026-04-19 23:24:14 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 - Test coverage for auth and admin

The existing API tests in tests/test_api.py bypass authentication entirely. The JWT auth flow has no test coverage.

What to do

  • Add tests for: user registration (success + duplicate), login (success + bad password), protected route access (with valid token, with expired token, with no token), token refresh, and admin-only endpoint access
  • Tests should run against the actual auth endpoints, using a test database fixture or in-memory override
  • Aim for full branch coverage of auth.py

Acceptance criteria

  • Tests exist for registration (success and duplicate user)
  • Tests exist for login (valid and invalid credentials)
  • Tests exist for accessing a protected route with valid, expired, and missing tokens
  • Tests exist for admin-only endpoints with non-admin and admin users
  • All tests pass in CI

Ref: ROADMAP.md P1 - Test coverage for auth and admin

## Context Roadmap item: P1 - Test coverage for auth and admin The existing API tests in `tests/test_api.py` bypass authentication entirely. The JWT auth flow has no test coverage. ## What to do - Add tests for: user registration (success + duplicate), login (success + bad password), protected route access (with valid token, with expired token, with no token), token refresh, and admin-only endpoint access - Tests should run against the actual auth endpoints, using a test database fixture or in-memory override - Aim for full branch coverage of `auth.py` ## Acceptance criteria - [ ] Tests exist for registration (success and duplicate user) - [ ] Tests exist for login (valid and invalid credentials) - [ ] Tests exist for accessing a protected route with valid, expired, and missing tokens - [ ] Tests exist for admin-only endpoints with non-admin and admin users - [ ] All tests pass in CI Ref: ROADMAP.md P1 - Test coverage for auth and admin
AI-Manager added the P1agent-readymediumtest labels 2026-04-19 23:24:14 +00:00
Author
Owner

This issue is already resolved in main. tests/test_auth.py (303 lines) has 17 comprehensive tests covering: registration (first user admin, subsequent user, duplicate email), login (valid/invalid credentials), protected routes (valid/missing/expired/wrong token type), token refresh (valid/invalid/wrong token type), and admin endpoints (list users, change role, self-role change prevention).

This issue is already resolved in main. `tests/test_auth.py` (303 lines) has 17 comprehensive tests covering: registration (first user admin, subsequent user, duplicate email), login (valid/invalid credentials), protected routes (valid/missing/expired/wrong token type), token refresh (valid/invalid/wrong token type), and admin endpoints (list users, change role, self-role change prevention).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1598