Commit 6bc11465 authored by George Papathanail's avatar George Papathanail
Browse files

fix: wire get_caller_context fakes into the conformance test harness

parent 14249bc5
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ from open_exposure_gateway.application.services.quality_on_demand_service import
    QualityOnDemandService,
)
from open_exposure_gateway.dependencies import (
    get_caller_context,
    get_edge_app_service,
    get_location_retrieval_service,
    get_publisher,
@@ -31,6 +32,7 @@ from open_exposure_gateway.domain.edge_application_management import (
    SRMZoneMetadata,
)
from tests.conformance.harness import app
from tests.unit.conftest import fake_caller_context
from tests.unit.fakes import (
    FakeAppDeploymentRepository,
    FakeAppInstanceRepository,
@@ -106,5 +108,10 @@ def service_overrides() -> Generator[None, None, None]:
        srm_client=srm
    )
    app.dependency_overrides[get_publisher] = lambda: bus
    # Bypasses get_token_verifier/JWT verification entirely (same fake the unit tests
    # use): a two-legged app-provider satisfies every operation's role/flow requirements
    # (core/authorization.py) except Location Retrieval, which overrides this again to a
    # three-legged context in its own conformance test module.
    app.dependency_overrides[get_caller_context] = fake_caller_context
    yield
    app.dependency_overrides.clear()
+23 −0
Original line number Diff line number Diff line
@@ -10,7 +10,11 @@ from typing import TYPE_CHECKING

import pytest
import schemathesis
from fastapi import Request

from open_exposure_gateway.api.error_handlers import x_correlator_header
from open_exposure_gateway.core.auth.tokens import TokenFlow
from open_exposure_gateway.dependencies import CallerContext, get_caller_context
from tests.conformance.harness import app

if TYPE_CHECKING:
@@ -18,6 +22,25 @@ if TYPE_CHECKING:

pytestmark = pytest.mark.conformance


def _three_legged_caller_context(request: Request) -> CallerContext:
    """Location Retrieval always requires a three-legged token (core/authorization.py),
    unlike the other CAMARA APIs conftest's package-wide fake_caller_context covers."""
    return CallerContext(
        x_correlator=x_correlator_header(request),
        tenant_id="test_tenant",
        app_provider_id="test_app_provider",
        roles=["app-provider"],
        flow=TokenFlow.THREE_LEGGED,
        subject_id="test_subject",
    )


@pytest.fixture(autouse=True)
def three_legged_caller() -> None:
    app.dependency_overrides[get_caller_context] = _three_legged_caller_context


SPEC = (
    Path(__file__).parents[2]
    / "src"
+24 −0
Original line number Diff line number Diff line
@@ -3,18 +3,42 @@
from typing import Any

import pytest
from fastapi import Request
from fastapi.testclient import TestClient

from open_exposure_gateway.api.camara.location_retrieval.v0_5_0.router import (
    BASE_PATH as LOCATION_BASE,
)
from open_exposure_gateway.api.error_handlers import x_correlator_header
from open_exposure_gateway.core.auth.tokens import TokenFlow
from open_exposure_gateway.core.exceptions import (
    ErrorCode,
    UnprocessableEntityException,
)
from open_exposure_gateway.dependencies import CallerContext, get_caller_context
from open_exposure_gateway.domain.location_retrieval import SRMLocationResult
from open_exposure_gateway.main import app
from tests.unit.fakes import FakeDataBus, FakeSRMClient


def _three_legged_caller_context(request: Request) -> CallerContext:
    """Location Retrieval always requires a three-legged token (core/authorization.py),
    unlike the other CAMARA APIs api_client's default fake_caller_context covers."""
    return CallerContext(
        x_correlator=x_correlator_header(request),
        tenant_id="test_tenant",
        app_provider_id="test_app_provider",
        roles=["app-provider"],
        flow=TokenFlow.THREE_LEGGED,
        subject_id="test_subject",
    )


@pytest.fixture(autouse=True)
def three_legged_caller(api_client: TestClient) -> None:
    app.dependency_overrides[get_caller_context] = _three_legged_caller_context


RETRIEVE = f"{LOCATION_BASE}/retrieve"
PHONE = "+123456789"