Commit 038afdb9 authored by Dimitrios Gogos's avatar Dimitrios Gogos
Browse files

feat: add app_provider_id claim handling in get_caller_context and corresponding tests

parent 361f238f
Loading
Loading
Loading
Loading
Loading
+3 −1
Changes for src/open_exposure_gateway/dependencies.py: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -177,13 +177,15 @@ async def get_caller_context(

    # A user without an `organization` is a tenant of their own.
    tenant_id: str = claims.get("organization") or subject
    # An API client acts for the developer who created it; the portal puts them in this claim.
    app_provider_id: str = claims.get("app_provider_id") or subject

    return _remember_caller(
        request,
        CallerContext(
            x_correlator=x_correlator_header(request),
            tenant_id=tenant_id,
            app_provider_id=subject,
            app_provider_id=app_provider_id,
            roles=roles,
            scopes=claims.get("scope", "").split(),
            client_id=claims.get("azp"),
+1 −1
Changes for src/open_exposure_gateway/domain/edge_application_management.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ class SRMComputeIntent(BaseModel):
class SRMServiceSpecDescriptor(BaseModel):
    artifact_type: str | None = None
    source_api: str = "edge-application-management"
    # Submitted CAMARA `appProvider`; the spec's app_provider_id is the caller's `sub`.
    # Submitted CAMARA `appProvider`; the spec's app_provider_id is the caller's.
    app_provider: str | None = None


+11 −0
Changes for tests/unit/test_caller_context.py: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -90,6 +90,17 @@ class TestTenantId:
        assert caller.app_provider_id == "user-123"


class TestAppProviderId:
    async def test_app_provider_id_claim_is_the_app_provider(self) -> None:
        caller = await _caller(_claims(sub="service-account-1", app_provider_id="user-123"))
        assert caller.app_provider_id == "user-123"
        assert caller.tenant_id == "acme-labs"

    async def test_without_the_claim_the_subject_is_the_app_provider(self) -> None:
        caller = await _caller(_claims(sub="service-account-1"))
        assert caller.app_provider_id == "service-account-1"


class TestClientId:
    async def test_client_id_is_the_azp_claim(self) -> None:
        caller = await _caller(_claims(azp="acme-backend"))