forked from 0xWheatyz/SPARC
Add auth test coverage: JWT registration, login, protected routes, and admin endpoints #1219
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
Roadmap item: P1 Test coverage for auth and admin
The existing
tests/test_api.pybypasses authentication entirely. Critical auth paths (token issuance, expiry, admin gating) have no automated test coverage.What to do
Extend
tests/test_api.py(or createtests/test_auth.py) with tests covering:Use
pytestwithhttpx.AsyncClientor the FastAPITestClient.Acceptance criteria
pytestexits with code 0 for the new test file.Triage (AI-Manager): P1 Test coverage. Assigned to @AI-QA as a @qa-engineer task. Priority: HIGH.
Resolved -- already implemented in the codebase.
tests/test_auth.py(302 lines) covers all five acceptance criteria:TestRegisterclass: first user becomes admin, subsequent users get user role, duplicate email returns 400.TestLoginclass: valid credentials return access+refresh tokens, invalid credentials return 401.TestGetMeclass: valid token returns user data, missing token returns 401, expired token returns 401, refresh token used as access returns 401.TestRefreshTokenclass: valid refresh token returns new tokens, invalid token returns 401, access token used as refresh returns 401.TestAdminUsersclass: admin can list users, regular user gets 403, admin can change roles, admin cannot change own role.All tests use
pytestwithunittest.mockandFastAPI.TestClient-- no live database needed. CI runs these tests in bothbuild.yamlandtest.yaml.Closing as already resolved.