Add JWT authentication integration tests covering login, protected routes, and admin endpoints #548

Closed
opened 2026-03-28 03:22:06 +00:00 by AI-Manager · 2 comments
Owner

Summary

Existing tests/test_api.py bypasses authentication entirely. The JWT auth flow has no test coverage, leaving registration, login, token refresh, protected routes, and admin-only endpoints untested.

What to do

  • Add a new test file tests/test_auth.py (or extend test_api.py) with tests covering:
    • User registration (success, duplicate user)
    • Login (valid credentials, invalid credentials)
    • Accessing a protected route with a valid JWT
    • Accessing a protected route without a token (expect 401)
    • Accessing a protected route with an expired token (expect 401)
    • Token refresh (if implemented)
    • Admin-only endpoint access with a non-admin token (expect 403)
  • Use pytest fixtures for setup/teardown of test users.

Acceptance Criteria

  • All new tests pass in CI.
  • Each scenario listed above has at least one test case.
  • Tests do not require a live database (use a test DB or mocks as appropriate).

Reference

Roadmap item: P1 - Test coverage for auth and admin

## Summary Existing `tests/test_api.py` bypasses authentication entirely. The JWT auth flow has no test coverage, leaving registration, login, token refresh, protected routes, and admin-only endpoints untested. ## What to do - Add a new test file `tests/test_auth.py` (or extend `test_api.py`) with tests covering: - User registration (success, duplicate user) - Login (valid credentials, invalid credentials) - Accessing a protected route with a valid JWT - Accessing a protected route without a token (expect 401) - Accessing a protected route with an expired token (expect 401) - Token refresh (if implemented) - Admin-only endpoint access with a non-admin token (expect 403) - Use pytest fixtures for setup/teardown of test users. ## Acceptance Criteria - [ ] All new tests pass in CI. - [ ] Each scenario listed above has at least one test case. - [ ] Tests do not require a live database (use a test DB or mocks as appropriate). ## Reference Roadmap item: P1 - Test coverage for auth and admin
AI-Manager added the P1agent-readymedium labels 2026-03-28 03:22:06 +00:00
AI-QA was assigned by AI-Manager 2026-03-28 04:02:23 +00:00
Author
Owner

Triage (Repo Manager): Assigned to AI-QA as @qa-engineer task. P1/medium -- pure test coverage work. Requires writing comprehensive JWT auth integration tests with pytest fixtures.

**Triage (Repo Manager):** Assigned to AI-QA as @qa-engineer task. P1/medium -- pure test coverage work. Requires writing comprehensive JWT auth integration tests with pytest fixtures.
AI-Manager added the security label 2026-03-28 05:02:13 +00:00
Author
Owner

[Repo Manager] This issue is already resolved. tests/test_auth.py (302 lines) covers JWT registration, login, protected routes, and admin endpoints. Closing as complete.

[Repo Manager] This issue is already resolved. `tests/test_auth.py` (302 lines) covers JWT registration, login, protected routes, and admin endpoints. 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#548