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+
2846def 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 (
@@ -39,3 +57,39 @@ def test_oidc_in_openapi_spec(source_api: FastAPI, source_api_server: str):
3957 assert "openapi" in openapi
4058 assert "paths" in openapi
4159 assert "oidcAuth" in openapi .get ("components" , {}).get ("securitySchemes" , {})
60+
61+
62+ def test_oidc_in_openapi_spec_private_endpoints (
63+ source_api : FastAPI , source_api_server : str
64+ ):
65+ """When OpenAPI spec endpoint is set & endpoints are marked private, those endpoints are marked private in the spec."""
66+ private_endpoints = {
67+ # https://github.com/stac-api-extensions/collection-transaction/blob/v1.0.0-beta.1/README.md#methods
68+ "/collections" : ["POST" ],
69+ "/collections/{collection_id}" : ["PUT" , "PATCH" , "DELETE" ],
70+ # https://github.com/stac-api-extensions/transaction/blob/v1.0.0-rc.3/README.md#methods
71+ "/collections/{collection_id}/items" : ["POST" ],
72+ "/collections/{collection_id}/items/{item_id}" : ["PUT" , "PATCH" , "DELETE" ],
73+ # https://stac-utils.github.io/stac-fastapi/api/stac_fastapi/extensions/third_party/bulk_transactions/#bulktransactionextension
74+ "/collections/{collection_id}/bulk_items" : ["POST" ],
75+ }
76+ app = app_factory (
77+ upstream_url = source_api_server ,
78+ openapi_spec_endpoint = source_api .openapi_url ,
79+ private_endpoints = private_endpoints ,
80+ )
81+ client = TestClient (app )
82+ openapi = client .get (source_api .openapi_url ).raise_for_status ().json ()
83+ for path , methods in private_endpoints .items ():
84+ for method in methods :
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