Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bff/bff_app/routes/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ def login_cb():

session.pop("cv", None)
session.pop("state", None)
current_app.logger.info(
"OAuth callback succeeded; returning response with status=%s location=%s",
response.status_code,
response.headers.get("Location"),
)
return response


Expand Down
10 changes: 8 additions & 2 deletions bff/tests/test_auth_callback.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from unittest.mock import MagicMock

from bff_app.routes import auth as auth_routes
Expand All @@ -18,7 +19,7 @@ def _fake_oauth_session(state="state-123", token=None):
return fake


def test_login_callback_exchanges_code_and_redirects(client, monkeypatch):
def test_login_callback_exchanges_code_and_redirects(client, monkeypatch, app, caplog):
# Mock the token exchange so we don't call the real auth server.
fake_oauth = _fake_oauth_session(
token={
Expand All @@ -35,10 +36,15 @@ def test_login_callback_exchanges_code_and_redirects(client, monkeypatch):
sess["state"] = "state-123"
sess["cv"] = "cv-hex"

res = client.get("/proxy/api/auth/callback?state=state-123&code=abc")
with caplog.at_level(logging.INFO, logger=app.logger.name):
res = client.get("/proxy/api/auth/callback?state=state-123&code=abc")

assert res.status_code == 302
assert res.headers["Location"] == "http://frontend.test"
assert (
"OAuth callback succeeded; returning response with status=302 "
"location=http://frontend.test"
) in caplog.text
set_cookie_headers = res.headers.getlist("Set-Cookie")
assert any(header.startswith("test-session_at=") for header in set_cookie_headers)
assert any(header.startswith("test-session_rt=") for header in set_cookie_headers)
Expand Down
Loading