Skip to content

Commit 87f0c45

Browse files
committed
Added tests.
1 parent e644037 commit 87f0c45

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

charts/eoapi/profiles/experimental.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ stac-auth-proxy:
371371
# For testing this will be set dynamically; for production, point to your OIDC server
372372
# env:
373373
# OIDC_DISCOVERY_URL: "http://eoapi-mock-oidc-server.eoapi.svc.cluster.local:8080/.well-known/openid-configuration"
374+
authorization:
375+
record:
376+
mode: "custom"
377+
custom:
378+
filtersFile: "data/stac-auth-proxy/custom_filters.py"
374379

375380
######################
376381
# MOCK OIDC SERVER

tests/integration/test_stac_auth.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,119 @@ def test_stac_read_operations_work(stac_endpoint: str) -> None:
106106

107107
resp = client.get(f"{stac_endpoint}/collections")
108108
assert resp.status_code == 200
109+
110+
111+
def test_stac_auth_custom_filters_mounted() -> None:
112+
"""Test that custom filters ConfigMap, env vars, and file mount work correctly."""
113+
import subprocess
114+
115+
namespace = os.getenv("NAMESPACE", "eoapi")
116+
release = os.getenv("RELEASE_NAME", "eoapi")
117+
118+
# Check ConfigMap exists
119+
result = subprocess.run(
120+
[
121+
"kubectl",
122+
"get",
123+
"configmap",
124+
"-n",
125+
namespace,
126+
f"{release}-stac-auth-proxy-filters",
127+
"-o",
128+
"jsonpath={.data.custom_filters\\.py}",
129+
],
130+
capture_output=True,
131+
text=True,
132+
check=False,
133+
)
134+
if result.returncode != 0:
135+
pytest.skip("Custom filters ConfigMap not found (feature may be disabled)")
136+
137+
# Verify ConfigMap contains filter classes
138+
assert "class CollectionsFilter" in result.stdout
139+
assert "class ItemsFilter" in result.stdout
140+
141+
# Get stac-auth-proxy pod name
142+
result = subprocess.run(
143+
[
144+
"kubectl",
145+
"get",
146+
"pod",
147+
"-n",
148+
namespace,
149+
"-l",
150+
f"app.kubernetes.io/name=stac-auth-proxy,app.kubernetes.io/instance={release}",
151+
"-o",
152+
"jsonpath={.items[0].metadata.name}",
153+
],
154+
capture_output=True,
155+
text=True,
156+
check=True,
157+
)
158+
pod_name = result.stdout.strip()
159+
160+
if not pod_name:
161+
pytest.skip("stac-auth-proxy pod not found")
162+
163+
# Check env vars are set
164+
result = subprocess.run(
165+
[
166+
"kubectl",
167+
"exec",
168+
"-n",
169+
namespace,
170+
pod_name,
171+
"--",
172+
"printenv",
173+
"COLLECTIONS_FILTER_CLS",
174+
],
175+
capture_output=True,
176+
text=True,
177+
check=False,
178+
)
179+
assert result.returncode == 0, "COLLECTIONS_FILTER_CLS env var not set"
180+
assert (
181+
"stac_auth_proxy.custom_filters:CollectionsFilter" in result.stdout
182+
), f"Unexpected COLLECTIONS_FILTER_CLS value: {result.stdout}"
183+
184+
result = subprocess.run(
185+
[
186+
"kubectl",
187+
"exec",
188+
"-n",
189+
namespace,
190+
pod_name,
191+
"--",
192+
"printenv",
193+
"ITEMS_FILTER_CLS",
194+
],
195+
capture_output=True,
196+
text=True,
197+
check=False,
198+
)
199+
assert result.returncode == 0, "ITEMS_FILTER_CLS env var not set"
200+
assert (
201+
"stac_auth_proxy.custom_filters:ItemsFilter" in result.stdout
202+
), f"Unexpected ITEMS_FILTER_CLS value: {result.stdout}"
203+
204+
# Check if custom_filters.py is mounted at correct path
205+
result = subprocess.run(
206+
[
207+
"kubectl",
208+
"exec",
209+
"-n",
210+
namespace,
211+
pod_name,
212+
"--",
213+
"cat",
214+
"/app/src/stac_auth_proxy/custom_filters.py",
215+
],
216+
capture_output=True,
217+
text=True,
218+
check=True,
219+
)
220+
221+
# Verify mounted file contains expected filter classes
222+
assert "class CollectionsFilter" in result.stdout
223+
assert "class ItemsFilter" in result.stdout
224+
assert 'return "1=1"' in result.stdout

0 commit comments

Comments
 (0)