Skip to content

Commit d38c8b4

Browse files
committed
expand tests for complete coverage
1 parent f2b58cd commit d38c8b4

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

tests/test_openapi.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
)
1010

1111

12-
def test_no_edit_openapi_spec(source_api_server):
12+
def test_no_openapi_spec_endpoint(source_api_server):
1313
"""When no OpenAPI spec endpoint is set, the proxied OpenAPI spec is unaltered."""
1414
app = app_factory(
1515
upstream_url=source_api_server,
@@ -25,6 +25,24 @@ def test_no_edit_openapi_spec(source_api_server):
2525
assert "oidcAuth" not in openapi.get("components", {}).get("securitySchemes", {})
2626

2727

28+
def test_no_private_endpoints(source_api_server):
29+
"""When no endpoints are private, the proxied OpenAPI spec is unaltered."""
30+
app = app_factory(
31+
upstream_url=source_api_server,
32+
openapi_spec_endpoint="/api",
33+
private_endpoints={},
34+
default_public=True,
35+
)
36+
client = TestClient(app)
37+
response = client.get("/api")
38+
assert response.status_code == 200
39+
openapi = response.json()
40+
assert "info" in openapi
41+
assert "openapi" in openapi
42+
assert "paths" in openapi
43+
assert "oidcAuth" not in openapi.get("components", {}).get("securitySchemes", {})
44+
45+
2846
def test_oidc_in_openapi_spec(source_api: FastAPI, source_api_server: str):
2947
"""When OpenAPI spec endpoint is set, the proxied OpenAPI spec is augmented with oidc details."""
3048
app = app_factory(
@@ -45,7 +63,6 @@ def test_oidc_in_openapi_spec_private_endpoints(
4563
source_api: FastAPI, source_api_server: str
4664
):
4765
"""When OpenAPI spec endpoint is set & endpoints are marked private, those endpoints are marked private in the spec."""
48-
4966
private_endpoints = {
5067
# https://github.com/stac-api-extensions/collection-transaction/blob/v1.0.0-beta.1/README.md#methods
5168
"/collections": ["POST"],
@@ -65,9 +82,14 @@ def test_oidc_in_openapi_spec_private_endpoints(
6582
openapi = client.get(source_api.openapi_url).raise_for_status().json()
6683
for path, methods in private_endpoints.items():
6784
for method in methods:
68-
assert "oidcAuth" in (
69-
openapi.get("paths", {})
70-
.get(path, {})
71-
.get(method, {})
72-
.get("security", [])
73-
)
85+
openapi_path = openapi["paths"].get(path)
86+
assert openapi_path, f"Path {path} not found in OpenAPI spec"
87+
openapi_path_method = openapi_path.get(method.lower())
88+
assert (
89+
openapi_path_method
90+
), f"Method {method.lower()!r} not found for path {path!r} in OpenAPI spec for path {path}"
91+
security = openapi_path_method.get("security")
92+
assert security, f"Security not found for {path!r} {method.lower()!r}"
93+
assert any(
94+
"oidcAuth" in s for s in security
95+
), f'No "oidcAuth" in security for {path!r} {method.lower()!r}'

0 commit comments

Comments
 (0)