|
1 | 1 | """Basic test cases for the proxy app.""" |
2 | 2 |
|
3 | 3 | import pytest |
4 | | -from fastapi import FastAPI |
5 | 4 | from fastapi.testclient import TestClient |
| 5 | +from utils import AppFactory |
6 | 6 |
|
7 | | -from stac_auth_proxy import Settings, create_app |
8 | | - |
9 | | - |
10 | | -@pytest.fixture(scope="module") |
11 | | -def test_app(source_api_server: str) -> FastAPI: |
12 | | - """Fixture for the proxy app, pointing to the source API.""" |
13 | | - return create_app( |
14 | | - Settings.model_validate( |
15 | | - { |
16 | | - "upstream_url": source_api_server, |
17 | | - "oidc_discovery_url": "https://samples.auth0.com/.well-known/openid-configuration", |
18 | | - "default_public": False, |
19 | | - }, |
20 | | - ) |
21 | | - ) |
| 7 | +app_factory = AppFactory( |
| 8 | + oidc_discovery_url="https://samples.auth0.com/.well-known/openid-configuration" |
| 9 | +) |
22 | 10 |
|
23 | 11 |
|
24 | 12 | @pytest.mark.parametrize( |
@@ -49,14 +37,17 @@ def test_default_public_true(source_api_server, path, method, expected_status): |
49 | 37 | When default_public=true and private_endpoints aren't set, all endpoints should be |
50 | 38 | public except for transaction endpoints. |
51 | 39 | """ |
52 | | - test_app = create_app( |
53 | | - Settings.model_validate( |
54 | | - { |
55 | | - "upstream_url": source_api_server, |
56 | | - "oidc_discovery_url": "https://samples.auth0.com/.well-known/openid-configuration", |
57 | | - "default_public": True, |
58 | | - }, |
59 | | - ) |
| 40 | + test_app = app_factory( |
| 41 | + upstream_url=source_api_server, |
| 42 | + public_endpoints={}, |
| 43 | + private_endpoints={ |
| 44 | + "/collections": ["POST"], |
| 45 | + "/collections/{collection_id}": ["PUT", "PATCH", "DELETE"], |
| 46 | + "/collections/{collection_id}/items": ["POST"], |
| 47 | + "/collections/{collection_id}/items/{item_id}": ["PUT", "PATCH", "DELETE"], |
| 48 | + "/collections/{collection_id}/bulk_items": ["POST"], |
| 49 | + }, |
| 50 | + default_public=True, |
60 | 51 | ) |
61 | 52 | client = TestClient(test_app) |
62 | 53 | response = client.request(method=method, url=path) |
@@ -91,14 +82,11 @@ def test_default_public_false(source_api_server, path, method, expected_status): |
91 | 82 | When default_public=false and private_endpoints aren't set, all endpoints should be |
92 | 83 | public except for transaction endpoints. |
93 | 84 | """ |
94 | | - test_app = create_app( |
95 | | - Settings.model_validate( |
96 | | - { |
97 | | - "upstream_url": source_api_server, |
98 | | - "oidc_discovery_url": "https://samples.auth0.com/.well-known/openid-configuration", |
99 | | - "default_public": False, |
100 | | - }, |
101 | | - ) |
| 85 | + test_app = app_factory( |
| 86 | + upstream_url=source_api_server, |
| 87 | + public_endpoints={"/api.html": ["GET"], "/api": ["GET"]}, |
| 88 | + private_endpoints={}, |
| 89 | + default_public=False, |
102 | 90 | ) |
103 | 91 | client = TestClient(test_app) |
104 | 92 | response = client.request(method=method, url=path) |
|
0 commit comments