fix(api): Implement missing OIDC callback endpoint
This commit is contained in:
@@ -74,6 +74,21 @@ def test_oidc_login_redirect():
|
||||
assert response.status_code == 200
|
||||
assert response.json()["url"] == "https://oidc-provider.com/auth"
|
||||
|
||||
def test_oidc_callback_success():
|
||||
"""Test successful OIDC callback and JWT issuance."""
|
||||
with patch("ea_chatbot.api.routers.auth.oidc_client") as mock_oidc, \
|
||||
patch("ea_chatbot.api.routers.auth.history_manager") as mock_hm:
|
||||
|
||||
mock_oidc.exchange_code_for_token.return_value = {"access_token": "oidc-token"}
|
||||
mock_oidc.get_user_info.return_value = {"email": "sso@example.com", "name": "SSO User"}
|
||||
mock_hm.sync_user_from_oidc.return_value = User(id="sso-123", username="sso@example.com", display_name="SSO User")
|
||||
|
||||
response = client.get("/auth/oidc/callback?code=some-code")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "access_token" in response.json()
|
||||
assert response.json()["token_type"] == "bearer"
|
||||
|
||||
def test_get_me_success():
|
||||
"""Test getting current user with a valid token."""
|
||||
from ea_chatbot.api.utils import create_access_token
|
||||
@@ -76,9 +76,9 @@ def test_get_plot_success(auth_header, mock_user):
|
||||
mock_hm.get_session.return_value.__enter__.return_value = mock_session
|
||||
|
||||
# Mocking the models and their relationships
|
||||
mock_plot = Plot(id="p1", image_data=b"fake-image-data", message_id="m1")
|
||||
mock_msg = Message(id="m1", conversation_id="c1")
|
||||
mock_conv = Conversation(id="c1", user_id=mock_user.id)
|
||||
mock_conv = Conversation(id="c1", user_id=mock_user.id, user=mock_user)
|
||||
mock_msg = Message(id="m1", conversation_id="c1", conversation=mock_conv)
|
||||
mock_plot = Plot(id="p1", image_data=b"fake-image-data", message_id="m1", message=mock_msg)
|
||||
|
||||
def mock_get(model, id):
|
||||
if model == Plot: return mock_plot
|
||||
Reference in New Issue
Block a user