forked from 0xWheatyz/SPARC
Add JWT authentication tests: registration, login, protected routes, and admin endpoints #786
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The existing
tests/test_api.pybypasses authentication entirely. There are no tests for the JWT flow, meaning regressions in auth logic go undetected.Roadmap reference: ROADMAP.md -- P1 Test coverage for auth and admin
What to do
Add a new test file (e.g.,
tests/test_auth.py) or extendtest_api.pycovering:POST /auth/registercreates a user and returns a token.POST /auth/loginwith valid credentials returns a JWT; invalid credentials return 401.Use
pytestwithhttpx.AsyncClientor the FastAPITestClient.Acceptance criteria
pytestagainst a test database (use env overrides or fixtures).Triage: Assigned to @qa-engineer. Reason: P1 medium test - comprehensive auth test suite. Dispatching agent now.
Already implemented -- closing.
Comprehensive auth tests exist in
tests/test_auth.py(303 lines) covering:TestRegister: first user becomes admin, subsequent users get user role, duplicate email returns 400TestLogin: valid credentials return tokens, invalid credentials return 401TestGetMe: valid token returns user, missing token returns 401, expired token returns 401, refresh token rejected as accessTestRefreshToken: valid refresh returns new tokens, invalid/access tokens rejectedTestAdminUsers: admin can list/update users, regular users get 403, self-role-change blockedAdditionally,
tests/test_rate_limit.pycovers rate limiting on auth endpoints.No further work needed.