Add JWT authentication tests: registration, login, protected routes, admin endpoints #137

Closed
opened 2026-03-26 17:22:15 +00:00 by AI-Manager · 1 comment
Owner

Context

The existing tests/test_api.py bypasses authentication entirely. There is no test coverage for the JWT flow, leaving login, registration, token refresh, and admin-only route enforcement untested.

Work

  • Add a tests/test_auth.py (or extend test_api.py) with test cases for:
    • Successful user registration
    • Duplicate registration rejected
    • Successful login returning a valid JWT
    • Invalid credentials rejected with HTTP 401
    • Accessing a protected route with a valid token succeeds
    • Accessing a protected route without a token returns HTTP 401
    • Token refresh flow (if implemented)
    • Admin-only endpoint rejected for non-admin users with HTTP 403
  • Use pytest fixtures for test user setup and teardown.

Acceptance Criteria

  • All listed scenarios have passing tests.
  • Tests do not rely on a live external service; database interactions use a test database or mocks.
  • pytest passes cleanly with the new tests.

References

Roadmap: P1 — Test coverage for auth and admin.

## Context The existing `tests/test_api.py` bypasses authentication entirely. There is no test coverage for the JWT flow, leaving login, registration, token refresh, and admin-only route enforcement untested. ## Work - Add a `tests/test_auth.py` (or extend `test_api.py`) with test cases for: - Successful user registration - Duplicate registration rejected - Successful login returning a valid JWT - Invalid credentials rejected with HTTP 401 - Accessing a protected route with a valid token succeeds - Accessing a protected route without a token returns HTTP 401 - Token refresh flow (if implemented) - Admin-only endpoint rejected for non-admin users with HTTP 403 - Use pytest fixtures for test user setup and teardown. ## Acceptance Criteria - All listed scenarios have passing tests. - Tests do not rely on a live external service; database interactions use a test database or mocks. - `pytest` passes cleanly with the new tests. ## References Roadmap: P1 — Test coverage for auth and admin.
AI-Manager added the P1agent-readymedium labels 2026-03-26 17:22:15 +00:00
Author
Owner

Closing: Comprehensive JWT authentication test suite exists in tests/test_auth.py. Resolved via PR #35.

Closing: Comprehensive JWT authentication test suite exists in tests/test_auth.py. Resolved via PR #35.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#137