feat: add fixed questions and improve authentication
This commit is contained in:
1 parent
8af4fed89d
commit
4c9f75f31e
42 files changed
+4008
-200
No files matched your search
@@ -2,12 +2,15 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.gateway import auth_middleware
|
||||
from app.gateway.app import app as gateway_app
|
||||
from app.gateway.auth.token_source import get_explicit_or_session_token
|
||||
from app.gateway.auth_middleware import PUBLIC_HEALTH_PATHS, AuthMiddleware
|
||||
|
||||
|
||||
@@ -98,3 +101,28 @@ def test_non_health_route_still_requires_auth(monkeypatch: pytest.MonkeyPatch) -
|
||||
response = client.get("/private")
|
||||
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
def _auth_request(*, authorization: str = "", cookie: str = "") -> SimpleNamespace:
|
||||
headers = {"authorization": authorization} if authorization else {}
|
||||
cookies = {"access_token": cookie} if cookie else {}
|
||||
return SimpleNamespace(headers=headers, cookies=cookies)
|
||||
|
||||
|
||||
def test_explicit_bearer_token_wins_over_shared_cookie() -> None:
|
||||
"""Another tab's cookie must not override this tab's explicit token."""
|
||||
request = _auth_request(authorization="Bearer current-tab", cookie="other-tab")
|
||||
|
||||
assert get_explicit_or_session_token(request) == "current-tab"
|
||||
|
||||
|
||||
def test_cookie_remains_the_fallback_for_cookie_only_clients() -> None:
|
||||
request = _auth_request(cookie="browser-session")
|
||||
|
||||
assert get_explicit_or_session_token(request) == "browser-session"
|
||||
|
||||
|
||||
def test_malformed_authorization_header_does_not_hide_valid_cookie() -> None:
|
||||
request = _auth_request(authorization="Basic abc", cookie="browser-session")
|
||||
|
||||
assert get_explicit_or_session_token(request) == "browser-session"
|
||||
Reference in new issue
Block a user