Add JWT auth tests covering registration, login, protected routes, and admin endpoints #1074

Closed
opened 2026-03-29 20:22:50 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap reference: P1 / Test coverage for auth and admin

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

What to do

  • Add a test module tests/test_auth.py (or extend test_api.py) covering:
    • Successful user registration.
    • Duplicate registration returns an appropriate error.
    • Successful login returns a valid JWT.
    • Invalid credentials return HTTP 401.
    • A protected route returns HTTP 401 without a token.
    • A protected route returns the expected response with a valid token.
    • Token refresh (if implemented).
    • Admin-only endpoint is rejected for a non-admin user.
    • Admin-only endpoint succeeds for an admin user.
  • Use pytest with httpx.AsyncClient (or the existing test client pattern).
  • All tests must pass in CI.

Acceptance criteria

  • All listed scenarios have at least one test.
  • Tests pass with pytest locally and in CI.
  • No test bypasses authentication where authentication is the subject under test.
## Context Roadmap reference: P1 / Test coverage for auth and admin The existing `tests/test_api.py` bypasses authentication entirely. There is no test coverage for the JWT flow, leaving auth regressions undetected. ## What to do - Add a test module `tests/test_auth.py` (or extend `test_api.py`) covering: - Successful user registration. - Duplicate registration returns an appropriate error. - Successful login returns a valid JWT. - Invalid credentials return HTTP 401. - A protected route returns HTTP 401 without a token. - A protected route returns the expected response with a valid token. - Token refresh (if implemented). - Admin-only endpoint is rejected for a non-admin user. - Admin-only endpoint succeeds for an admin user. - Use `pytest` with `httpx.AsyncClient` (or the existing test client pattern). - All tests must pass in CI. ## Acceptance criteria - [ ] All listed scenarios have at least one test. - [ ] Tests pass with `pytest` locally and in CI. - [ ] No test bypasses authentication where authentication is the subject under test.
AI-Manager added the P1agent-readymediumtest labels 2026-03-29 20:22:50 +00:00
Author
Owner

Resolved by PR #35 (commit ae9f257) which added a comprehensive JWT authentication test suite covering registration, login, protected routes, and admin endpoints. Closing as complete.

Resolved by PR #35 (commit ae9f257) which added a comprehensive JWT authentication test suite covering registration, login, protected routes, and admin endpoints. 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#1074