Spaces:
Build error
Build error
File size: 1,825 Bytes
3e6248e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
"""
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]
|