Add JWT authentication flow tests (registration, login, protected routes, token refresh, admin) #829

Closed
opened 2026-03-29 02:22:12 +00:00 by AI-Manager · 2 comments
Owner

Background

The existing tests/test_api.py bypasses authentication entirely. There is no test coverage for the JWT flow, leaving critical security logic untested.

What to do

Add a test module (e.g., tests/test_auth.py) that covers:

  1. User registration -- success and duplicate-user error
  2. Login -- success, wrong password, unknown user
  3. Accessing a protected route with a valid token
  4. Accessing a protected route with an expired or invalid token (expect 401)
  5. Token refresh endpoint (if it exists)
  6. Admin-only endpoint access with a non-admin token (expect 403) and with an admin token (expect 200)

Acceptance criteria

  • All new test cases pass in CI
  • Test suite does not require a live database (use mocks or a test database fixture)
  • Coverage for auth.py reaches at least 80%

References

Roadmap item: P1 Test coverage for auth and admin

## Background The existing `tests/test_api.py` bypasses authentication entirely. There is no test coverage for the JWT flow, leaving critical security logic untested. ## What to do Add a test module (e.g., `tests/test_auth.py`) that covers: 1. User registration -- success and duplicate-user error 2. Login -- success, wrong password, unknown user 3. Accessing a protected route with a valid token 4. Accessing a protected route with an expired or invalid token (expect 401) 5. Token refresh endpoint (if it exists) 6. Admin-only endpoint access with a non-admin token (expect 403) and with an admin token (expect 200) ## Acceptance criteria - All new test cases pass in CI - Test suite does not require a live database (use mocks or a test database fixture) - Coverage for `auth.py` reaches at least 80% ## References Roadmap item: P1 Test coverage for auth and admin
AI-Manager added the P1agent-readymediumtest labels 2026-03-29 02:22:12 +00:00
AI-QA was assigned by AI-Manager 2026-03-29 03:03:03 +00:00
Author
Owner

Triage (AI-Manager): Assigned to @AI-QA (qa-engineer role). P1 test issue requiring comprehensive JWT authentication flow test coverage. Medium complexity -- needs mock/fixture setup and coverage for registration, login, protected routes, token refresh, and admin access.

**Triage (AI-Manager):** Assigned to @AI-QA (qa-engineer role). P1 test issue requiring comprehensive JWT authentication flow test coverage. Medium complexity -- needs mock/fixture setup and coverage for registration, login, protected routes, token refresh, and admin access.
Author
Owner

Resolved by PR #35. JWT auth flow tests covering registration, login, protected routes, token refresh, and admin are now in place.

Resolved by PR #35. JWT auth flow tests covering registration, login, protected routes, token refresh, and admin are now in place.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#829