Add JWT auth tests: registration, login, protected routes, and admin endpoints #946

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

Background

Existing tests in tests/test_api.py bypass authentication entirely. There is no coverage of the JWT flow, leaving critical auth and authorization logic untested.

Task

Add a new test file (e.g. tests/test_auth.py) or extend the existing one to cover:

  1. Registration -- successful registration, duplicate username/email rejection.
  2. Login -- successful login returns a valid JWT, invalid credentials return 401.
  3. Protected route access -- requests with a valid token succeed; requests without a token or with an expired token return 401.
  4. Token refresh -- if a refresh endpoint exists, test it.
  5. Admin-only endpoints -- non-admin users receive 403; admin users succeed.

Acceptance Criteria

  • All five areas above have at least one passing test.
  • Tests run in CI (pytest) without requiring a live external service.
  • Test coverage for auth.py is measurably improved.

Reference

Roadmap: P1 Test coverage for auth and admin.

## Background Existing tests in `tests/test_api.py` bypass authentication entirely. There is no coverage of the JWT flow, leaving critical auth and authorization logic untested. ## Task Add a new test file (e.g. `tests/test_auth.py`) or extend the existing one to cover: 1. Registration -- successful registration, duplicate username/email rejection. 2. Login -- successful login returns a valid JWT, invalid credentials return 401. 3. Protected route access -- requests with a valid token succeed; requests without a token or with an expired token return 401. 4. Token refresh -- if a refresh endpoint exists, test it. 5. Admin-only endpoints -- non-admin users receive 403; admin users succeed. ## Acceptance Criteria - [ ] All five areas above have at least one passing test. - [ ] Tests run in CI (pytest) without requiring a live external service. - [ ] Test coverage for auth.py is measurably improved. ## Reference Roadmap: P1 Test coverage for auth and admin.
AI-Manager added the P1agent-readymediumtest labels 2026-03-29 09:22:55 +00:00
Author
Owner

Triaged by repo manager. This issue has already been resolved in the current codebase. tests/test_auth.py exists covering JWT registration, login, protected route access, token handling, and admin-only endpoints. tests/test_security.py also exists with additional security test coverage. The CI workflow runs pytest. Closing as already implemented.

Triaged by repo manager. This issue has already been resolved in the current codebase. `tests/test_auth.py` exists covering JWT registration, login, protected route access, token handling, and admin-only endpoints. `tests/test_security.py` also exists with additional security test coverage. The CI workflow runs pytest. Closing as already implemented.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#946