Add JWT authentication tests covering registration, login, and protected routes #1406

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

Context

Roadmap item: P1 -- Test coverage for auth and admin

The existing tests/test_api.py bypasses JWT authentication entirely. There are no tests that exercise the actual auth flow, leaving critical security logic untested.

What to do

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

  • User registration: success, duplicate username/email rejection.
  • Login: valid credentials return a JWT; invalid credentials return 401.
  • Protected route access: valid token allows access; missing or expired token returns 401/403.
  • Token refresh: if a refresh endpoint exists, test it.
  • Admin-only endpoints: non-admin token is rejected with 403.

Acceptance criteria

  • All listed scenarios have at least one test case.
  • Tests run in CI without requiring external services (use test database or mocks).
  • pytest exits 0 with all new tests passing.
## Context Roadmap item: P1 -- Test coverage for auth and admin The existing `tests/test_api.py` bypasses JWT authentication entirely. There are no tests that exercise the actual auth flow, leaving critical security logic untested. ## What to do Add a test file (e.g., `tests/test_auth.py`) that covers: - User registration: success, duplicate username/email rejection. - Login: valid credentials return a JWT; invalid credentials return 401. - Protected route access: valid token allows access; missing or expired token returns 401/403. - Token refresh: if a refresh endpoint exists, test it. - Admin-only endpoints: non-admin token is rejected with 403. ## Acceptance criteria - [ ] All listed scenarios have at least one test case. - [ ] Tests run in CI without requiring external services (use test database or mocks). - [ ] `pytest` exits 0 with all new tests passing.
AI-Manager added the P1agent-readymediumtest labels 2026-03-30 18:22:36 +00:00
Author
Owner

Triage: Already resolved in main.

Comprehensive JWT auth tests exist in tests/test_auth.py covering: registration (first user admin, subsequent user, duplicate email), login (valid/invalid credentials), protected routes (/auth/me with valid/missing/expired/wrong-type tokens), token refresh (valid/invalid/wrong-type), and admin endpoints (list users, change role, self-role-change prevention, unauthorized access). 16 test cases total. Closing as complete.

**Triage: Already resolved in main.** Comprehensive JWT auth tests exist in `tests/test_auth.py` covering: registration (first user admin, subsequent user, duplicate email), login (valid/invalid credentials), protected routes (`/auth/me` with valid/missing/expired/wrong-type tokens), token refresh (valid/invalid/wrong-type), and admin endpoints (list users, change role, self-role-change prevention, unauthorized access). 16 test cases total. 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#1406