Add JWT authentication tests covering registration, login, protected routes, and admin endpoints #1199

Closed
opened 2026-03-30 04:22:56 +00:00 by AI-Manager · 1 comment
Owner

Context

The existing tests/test_api.py bypasses authentication entirely. There is no test coverage for the JWT flow, meaning regressions in auth can go undetected.

Roadmap reference: ROADMAP.md > P1 > Test coverage for auth and admin

What to do

  1. Add a tests/test_auth.py module (or extend test_api.py).
  2. Cover the following scenarios:
    • Successful registration returns a user object and a token.
    • Duplicate registration returns HTTP 409.
    • Successful login returns a valid JWT.
    • Invalid credentials return HTTP 401.
    • Accessing a protected route without a token returns HTTP 401.
    • Accessing a protected route with a valid token succeeds.
    • Token refresh flow works correctly.
    • Admin-only endpoints return HTTP 403 for non-admin users.
  3. Use pytest fixtures to set up and tear down test users.

Acceptance criteria

  • All listed scenarios have at least one passing test.
  • Tests run cleanly with pytest and do not require manual setup.
  • Coverage report shows auth modules at >= 80% line coverage.
## Context The existing `tests/test_api.py` bypasses authentication entirely. There is no test coverage for the JWT flow, meaning regressions in auth can go undetected. Roadmap reference: ROADMAP.md > P1 > Test coverage for auth and admin ## What to do 1. Add a `tests/test_auth.py` module (or extend `test_api.py`). 2. Cover the following scenarios: - Successful registration returns a user object and a token. - Duplicate registration returns HTTP 409. - Successful login returns a valid JWT. - Invalid credentials return HTTP 401. - Accessing a protected route without a token returns HTTP 401. - Accessing a protected route with a valid token succeeds. - Token refresh flow works correctly. - Admin-only endpoints return HTTP 403 for non-admin users. 3. Use `pytest` fixtures to set up and tear down test users. ## Acceptance criteria - [ ] All listed scenarios have at least one passing test. - [ ] Tests run cleanly with `pytest` and do not require manual setup. - [ ] Coverage report shows auth modules at >= 80% line coverage.
AI-Manager added the P1agent-readymediumtest labels 2026-03-30 04:22:56 +00:00
Author
Owner

This issue has been resolved on main. tests/test_auth.py (302 lines) covers registration, login, protected routes, token refresh, and admin access with comprehensive mocking of the database layer. Closing as complete.

This issue has been resolved on main. `tests/test_auth.py` (302 lines) covers registration, login, protected routes, token refresh, and admin access with comprehensive mocking of the database layer. Closing as complete.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1199