Spaces:
Build error
Build error
| """ | |
| E2E Tests for Authentication Flow | |
| Tests real authentication with live server. | |
| Google OAuth is mocked via test endpoint. | |
| """ | |
| import pytest | |
| from unittest.mock import patch | |
| from google_auth_service import GoogleUserInfo | |
| class TestAuthE2E: | |
| """Test authentication flow with real server.""" | |
| def test_check_registration_not_found(self, api_client): | |
| """Check registration for non-existent user.""" | |
| response = api_client.post("/auth/check-registration", json={ | |
| "user_id": "nonexistent@example.com" | |
| }) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["is_registered"] is False | |
| def test_auth_me_without_token(self, api_client): | |
| """Access /auth/me without token returns 401.""" | |
| response = api_client.get("/auth/me") | |
| assert response.status_code == 401 | |
| def test_auth_me_with_invalid_token(self, api_client): | |
| """Access /auth/me with invalid token returns 401.""" | |
| response = api_client.get("/auth/me", headers={ | |
| "Authorization": "Bearer invalid.token.here" | |
| }) | |
| assert response.status_code == 401 | |
| class TestProtectedEndpointsAuthE2E: | |
| """Test that auth endpoints are protected correctly.""" | |
| def test_logout_without_auth(self, api_client): | |
| """Logout without auth should still work (clear cookies).""" | |
| response = api_client.post("/auth/logout") | |
| # Logout typically returns 200 even without auth (just clears cookie) | |
| assert response.status_code in [200, 401] | |
| def test_refresh_without_token(self, api_client): | |
| """Refresh without token returns 401.""" | |
| response = api_client.post("/auth/refresh") | |
| assert response.status_code in [401, 422] | |