feat: Consolidate OAuth2 endpoints into auth module and remove redundant oauth file

This commit is contained in:
JSC
2025-07-26 15:15:17 +02:00
parent 51423779a8
commit 98e36b067d
6 changed files with 255 additions and 274 deletions

View File

@@ -35,7 +35,7 @@ class TestOAuthService:
assert isinstance(state, str)
assert len(state) > 10 # Should be a reasonable length
# Generate another to ensure they're different
state2 = oauth_service.generate_state()
assert state != state2
@@ -60,7 +60,7 @@ class TestOAuthService:
with pytest.raises(Exception) as exc_info:
oauth_service.get_provider("invalid")
assert "Unsupported OAuth provider" in str(exc_info.value)
@pytest.mark.asyncio
@@ -101,7 +101,7 @@ class TestGoogleOAuthProvider:
state = "test_state"
auth_url = provider.get_authorization_url(state)
assert "accounts.google.com" in auth_url
assert "client_id=test_client_id" in auth_url
assert f"state={state}" in auth_url
@@ -111,7 +111,7 @@ class TestGoogleOAuthProvider:
async def test_get_user_info_success(self) -> None:
"""Test successful user info retrieval."""
provider = GoogleOAuthProvider("test_client_id", "test_secret")
mock_response_data = {
"id": "google_user_123",
"email": "test@gmail.com",
@@ -151,14 +151,14 @@ class TestGitHubOAuthProvider:
async def test_get_user_info_success(self) -> None:
"""Test successful user info retrieval."""
provider = GitHubOAuthProvider("test_client_id", "test_secret")
mock_user_data = {
"id": 123456,
"login": "testuser",
"name": "Test User",
"avatar_url": "https://github.com/avatar.jpg",
}
mock_emails_data = [
{"email": "test@example.com", "primary": True, "verified": True},
{"email": "secondary@example.com", "primary": False, "verified": True},
@@ -170,7 +170,7 @@ class TestGitHubOAuthProvider:
mock_user_response.status_code = 200
mock_user_response.json.return_value = mock_user_data
# Mock emails response
# Mock emails response
mock_emails_response = Mock()
mock_emails_response.status_code = 200
mock_emails_response.json.return_value = mock_emails_data
@@ -189,4 +189,4 @@ class TestGitHubOAuthProvider:
assert user_info.provider_user_id == "123456"
assert user_info.email == "test@example.com"
assert user_info.name == "Test User"
assert user_info.picture == "https://github.com/avatar.jpg"
assert user_info.picture == "https://github.com/avatar.jpg"