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
6 changes: 5 additions & 1 deletion backend/handler/auth/hybrid_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ async def authenticate(

# Check if Authorization header exists
if "Authorization" in conn.headers:
scheme, token = conn.headers["Authorization"].split()
auth_header_parts = conn.headers["Authorization"].split()
if len(auth_header_parts) != 2:
return None

scheme, token = auth_header_parts
Comment on lines 27 to +32

# Check if basic auth header is valid
if scheme.lower() == "basic":
Expand Down
9 changes: 9 additions & 0 deletions backend/tests/endpoints/test_heartbeat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import AsyncMock, MagicMock, patch

Check failure on line 1 in backend/tests/endpoints/test_heartbeat.py

View workflow job for this annotation

GitHub Actions / Trunk Check

black

Incorrect formatting, autoformat by running 'trunk fmt'

import pytest
from fastapi import status

from exceptions.fs_exceptions import PlatformAlreadyExistsException
Expand Down Expand Up @@ -51,6 +52,14 @@
assert isinstance(oidc["RP_INITIATED_LOGOUT"], bool)


@pytest.mark.parametrize("authorization_header", ["Bearer ", "Foo", "a b c"])
def test_heartbeat_with_malformed_authorization_header(client, authorization_header: str):
response = client.get(
"/api/heartbeat", headers={"Authorization": authorization_header}
)
assert response.status_code == status.HTTP_200_OK


def test_heartbeat_metadata(client):
response = client.get("/api/heartbeat/metadata/launchbox")
assert response.status_code == status.HTTP_200_OK
Expand Down
16 changes: 16 additions & 0 deletions backend/tests/handler/auth/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,22 @@ def __init__(self):
assert result is None


@pytest.mark.parametrize("authorization_header", ["Bearer ", "Foo", "a b c"])
async def test_hybrid_auth_backend_malformed_authorization_header(
authorization_header: str,
):
class MockConnection(HTTPConnection):
def __init__(self):
self.scope: dict[str, dict] = {"session": {}}
self._headers = {"Authorization": authorization_header}

backend = HybridAuthBackend()
conn = MockConnection()

result = await backend.authenticate(conn)
assert result is None


async def test_hybrid_auth_backend_with_refresh_token(editor_user: User):
refresh_token = oauth_handler.create_refresh_token(
data={
Expand Down
Loading