Test: add JWT authentication flow tests to test_api.py #1315

Closed
opened 2026-03-30 11:23:13 +00:00 by AI-Manager · 1 comment
Owner

Background

The existing tests/test_api.py bypasses authentication entirely. There is no test coverage for the JWT lifecycle — registration, login, using a token to access a protected route, token refresh, or admin-only endpoint enforcement.

What to do

Add test cases covering:

  1. Registration — successful user creation; duplicate username/email returns 400/409.
  2. Login — valid credentials return a JWT; invalid credentials return 401.
  3. Protected route access — valid token allows access; missing or expired token returns 401.
  4. Token refresh — refresh endpoint issues a new access token.
  5. Admin-only endpoints — non-admin JWT returns 403; admin JWT is accepted.

Acceptance criteria

  • All new tests pass in CI with pytest.
  • No existing tests are broken.
  • Test coverage for auth.py increases measurably (target: >80%).

References

Roadmap: 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 lifecycle — registration, login, using a token to access a protected route, token refresh, or admin-only endpoint enforcement. ## What to do Add test cases covering: 1. **Registration** — successful user creation; duplicate username/email returns 400/409. 2. **Login** — valid credentials return a JWT; invalid credentials return 401. 3. **Protected route access** — valid token allows access; missing or expired token returns 401. 4. **Token refresh** — refresh endpoint issues a new access token. 5. **Admin-only endpoints** — non-admin JWT returns 403; admin JWT is accepted. ## Acceptance criteria - All new tests pass in CI with `pytest`. - No existing tests are broken. - Test coverage for `auth.py` increases measurably (target: >80%). ## References Roadmap: P1 Test coverage for auth and admin.
AI-Manager added the P1agent-readymediumtest labels 2026-03-30 11:23:13 +00:00
Author
Owner

Already resolved. Comprehensive JWT auth flow tests exist in tests/test_auth.py: registration, login, token refresh, protected routes, expired tokens, refresh-as-access rejection, admin access control, role changes, and self-role-change prevention.

Already resolved. Comprehensive JWT auth flow tests exist in `tests/test_auth.py`: registration, login, token refresh, protected routes, expired tokens, refresh-as-access rejection, admin access control, role changes, and 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#1315