Skip to content

Commit 9c1404f

Browse files
committed
Update OIDC augmentation to ensure options requests don't require auth
1 parent 07b51cc commit 9c1404f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/stac_auth_proxy/middleware/UpdateOpenApiMiddleware.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def transform_json(self, data: dict[str, Any], request: Request) -> dict[str, An
6262
# Add security to private endpoints
6363
for path, method_config in data["paths"].items():
6464
for method, config in method_config.items():
65+
# if method == "options":
66+
# # OPTIONS requests are not authenticated, https://fetch.spec.whatwg.org/#cors-protocol-and-credentials
67+
# continue
6568
match = find_match(
6669
path,
6770
method,

tests/test_openapi.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,23 @@ def test_oidc_in_openapi_spec_public_endpoints(
140140

141141
openapi = client.get(source_api.openapi_url).raise_for_status().json()
142142

143-
expected_auth = {"/queryables": ["GET"]}
143+
expected_required_auth = {"/queryables": ["GET"]}
144144
for path, method_config in openapi["paths"].items():
145145
for method, config in method_config.items():
146146
security = config.get("security")
147-
if security:
148-
assert path not in expected_auth
147+
if method == "options":
148+
assert not security, "OPTIONS requests should not be authenticated"
149+
elif security:
150+
assert (
151+
path not in expected_required_auth
152+
), f"Path {path} should not require authentication"
149153
else:
150-
assert path in expected_auth
154+
assert (
155+
path in expected_required_auth
156+
), f"Path {path} should require authentication"
151157
assert any(
152-
method.casefold() == m.casefold() for m in expected_auth[path]
158+
method.casefold() == m.casefold()
159+
for m in expected_required_auth[path]
153160
)
154161

155162

0 commit comments

Comments
 (0)