Add JWT auth flow tests: registration, login, protected routes, token refresh, and admin endpoints #122

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

Context

The existing API tests in tests/test_api.py bypass authentication entirely. This means the JWT implementation (registration, login, token validation, refresh, and admin-only access control) is untested.

Work

  • Add test cases for:
    • User registration (POST /auth/register) — success and duplicate-user cases.
    • User login (POST /auth/login) — valid credentials, invalid credentials.
    • Accessing a protected route without a token — expect HTTP 401.
    • Accessing a protected route with a valid token — expect success.
    • Token refresh endpoint — valid refresh token returns new access token.
    • Admin-only endpoint accessed by a non-admin user — expect HTTP 403.
  • Use pytest fixtures for creating test users and obtaining tokens.
  • Tests must not depend on external services (mock the database if needed).

Acceptance Criteria

  • All new test cases pass in CI.
  • Protected routes return 401 without a token and 200 with a valid one.
  • Admin routes return 403 for non-admin users.
  • pytest completes without requiring a running database (use fixtures or test DB).

References

Roadmap: P1 — Test coverage for auth and admin.

## Context The existing API tests in `tests/test_api.py` bypass authentication entirely. This means the JWT implementation (registration, login, token validation, refresh, and admin-only access control) is untested. ## Work - Add test cases for: - User registration (`POST /auth/register`) — success and duplicate-user cases. - User login (`POST /auth/login`) — valid credentials, invalid credentials. - Accessing a protected route without a token — expect HTTP 401. - Accessing a protected route with a valid token — expect success. - Token refresh endpoint — valid refresh token returns new access token. - Admin-only endpoint accessed by a non-admin user — expect HTTP 403. - Use pytest fixtures for creating test users and obtaining tokens. - Tests must not depend on external services (mock the database if needed). ## Acceptance Criteria - All new test cases pass in CI. - Protected routes return 401 without a token and 200 with a valid one. - Admin routes return 403 for non-admin users. - `pytest` completes without requiring a running database (use fixtures or test DB). ## References Roadmap: P1 — Test coverage for auth and admin.
AI-Manager added the P1agent-readymedium labels 2026-03-26 16:22:39 +00:00
Author
Owner

This issue has already been resolved. Comprehensive JWT auth flow tests exist in tests/test_auth.py covering registration, login, protected routes, token refresh, and admin endpoints.

Resolved by PR #35 ("test(auth): add comprehensive JWT authentication test suite"). Closing.

This issue has already been resolved. Comprehensive JWT auth flow tests exist in `tests/test_auth.py` covering registration, login, protected routes, token refresh, and admin endpoints. Resolved by PR #35 ("test(auth): add comprehensive JWT authentication test suite"). Closing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#122