Commit 2fb00308 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

Merge branch 'fix/partner-registry-problem-details' into 'develop'

fix(fm): answer the partner registry and identity routes with ProblemDetails

See merge request !29
parents 3c4fba54 341319f4
Loading
Loading
Loading
Loading
Loading
+7 −5
Changes for src/federation_manager/api/errors.py: 7 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -111,11 +111,13 @@ def problem(
    )


# The operator-facing federation lifecycle OEG proxies onto /internal (§L.3b). OEG relays only
# the statuses OPG.04 v1.4.0 declares for those operations (_PROBLEM_STATUSES) and turns
# anything else into its own 502, so on these routes FM maps its EWBI-side 403/502 onto that
# set; `type` still says which failure it was.
_PROXIED_PATH = re.compile(r"^/internal/partners/[^/]+/federations(/|$)")
# The /internal routes OEG relays for the portal: partner registry, our identity and the
# federation lifecycle. OEG relays only the statuses each route declares, as ProblemDetails,
# and turns anything else into its own 502, so on these routes FM maps its EWBI-side 403/502
# onto the OPG.04 v1.4.0 set (_PROBLEM_STATUSES); `type` still says which failure it was.
_PROXIED_PATH = re.compile(
    r"^/internal/(identity|partners(/[^/]+)?|partners/[^/]+/federations(/.*)?)$"
)

# Partner rejections that describe the operator's own request and are relayed as they are.
# Anything else the partner answers (its 401/403 is about our token, its 5xx about itself)
+15 −2
Changes for tests/test_partner_registry.py: 15 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -106,7 +106,13 @@ def test_partner_without_outbound_credentials_is_valid(client: TestClient) -> No
    ],
)
def test_invalid_registration_rejected(client: TestClient, overrides: dict[str, Any]) -> None:
    assert client.post(PARTNERS, json=_registration(**overrides)).status_code == 422
    response = client.post(PARTNERS, json=_registration(**overrides))

    # OEG relays this route, so a bad body is ProblemDetails like the rest of what it relays
    assert response.status_code == 400
    assert response.headers["content-type"] == "application/problem+json"
    assert response.json()["type"] == "urn:oop:ewbi:error:invalid-request"
    assert response.json()["invalidParams"]


def test_unknown_partner_is_404(client: TestClient) -> None:
@@ -116,6 +122,13 @@ def test_unknown_partner_is_404(client: TestClient) -> None:
    assert client.patch(f"{PARTNERS}/{uuid4()}", json={"name": "x"}).status_code == 404


def test_malformed_partner_id_is_problem_details(client: TestClient) -> None:
    response = client.get(f"{PARTNERS}/not-a-uuid")

    assert response.status_code == 400
    assert response.json()["invalidParams"][0]["param"] == "partner_op_id"


def test_patch_updates_only_given_fields(client: TestClient) -> None:
    partner = _register(client)

@@ -150,7 +163,7 @@ def test_patch_rejects_clearing_required_or_changing_identity(
) -> None:
    partner = _register(client)

    assert client.patch(f"{PARTNERS}/{partner['id']}", json=body).status_code == 422
    assert client.patch(f"{PARTNERS}/{partner['id']}", json=body).status_code == 400


def test_patch_to_a_client_id_held_by_another_partner_conflicts(client: TestClient) -> None: