Skip to content

Commit 65d33e7

Browse files
committed
fix: three types of auth
1 parent 0c3a7a1 commit 65d33e7

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

.github/workflows/run-checks.yaml

+20-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ jobs:
2525
run_daemon: true
2626
id: ipfs_setup
2727

28-
2928
- name: Install and configure Nginx
3029
run: |
3130
# Install Nginx
@@ -38,10 +37,28 @@ jobs:
3837
listen 5002;
3938
server_name localhost;
4039
40+
# Default deny unless authenticated
41+
set \$auth_valid 0;
42+
4143
location /api/v0/ {
4244
# Enforce X-API-Key for API key auth
43-
if (\$http_x_api_key != "test") {
44-
return 401 "Unauthorized: Invalid or missing X-API-Key";
45+
if (\$http_x_api_key = "test") {
46+
set \$auth_valid 1;
47+
}
48+
49+
# Check Bearer token
50+
if (\$http_authorization = "Bearer test") {
51+
set \$auth_valid 1;
52+
}
53+
54+
# Check Basic Auth (test:test = dGVzdDp0ZXN0)
55+
if (\$http_authorization = "Basic dGVzdDp0ZXN0") {
56+
set \$auth_valid 1;
57+
}
58+
59+
# Deny if no valid auth method
60+
if (\$auth_valid = 0) {
61+
return 401 "Unauthorized: Invalid or missing authentication";
4562
}
4663
4764
# Proxy to IPFS RPC API

tests/test_zarr_ipfs.py

+30-19
Original file line numberDiff line numberDiff line change
@@ -169,33 +169,44 @@ def test_authenticated_gateway(random_zarr_dataset: tuple[str, xr.Dataset]):
169169
xr.testing.assert_identical(loaded_ds, expected_ds)
170170

171171
# # Test with just bearer_token key
172-
# hamt = HAMT(
173-
# store=IPFSStore(
174-
# # api_key="test",
175-
# # basic_auth=("test", "test"),
176-
# bearer_token="test",
177-
# ),
178-
# transformer_encode=encrypt,
179-
# transformer_decode=decrypt,
180-
# )
181-
# test_ds.to_zarr(store=hamt, mode="w")
182-
183-
# hamt.make_read_only()
184-
# loaded_ds = xr.open_zarr(store=hamt)
185-
# xr.testing.assert_identical(loaded_ds, expected_ds)
172+
hamt = HAMT(
173+
store=IPFSStore(
174+
bearer_token="test",
175+
),
176+
transformer_encode=encrypt,
177+
transformer_decode=decrypt,
178+
)
179+
test_ds.to_zarr(store=hamt, mode="w")
186180

181+
hamt.make_read_only()
182+
loaded_ds = xr.open_zarr(store=hamt)
183+
xr.testing.assert_identical(loaded_ds, expected_ds)
187184

188-
# Test with wrong API Key
185+
# # Test with just basic auth
189186
hamt = HAMT(
190-
store=IPFSStore(
191-
rpc_uri_stem = "http://127.0.0.1:5002",
192-
api_key="badKey",
187+
store=IPFSStore(
188+
basic_auth=("test", "test"),
193189
),
194190
transformer_encode=encrypt,
195191
transformer_decode=decrypt,
196192
)
193+
test_ds.to_zarr(store=hamt, mode="w")
194+
195+
hamt.make_read_only()
196+
loaded_ds = xr.open_zarr(store=hamt)
197+
xr.testing.assert_identical(loaded_ds, expected_ds)
198+
199+
200+
# Test with wrong API Key
197201
with pytest.raises(Exception):
198-
test_ds.to_zarr(store=hamt, mode="w")
202+
hamt = HAMT(
203+
store=IPFSStore(
204+
rpc_uri_stem = "http://127.0.0.1:5002",
205+
api_key="badKey",
206+
),
207+
transformer_encode=encrypt,
208+
transformer_decode=decrypt,
209+
)
199210

200211
# Now trying to load without a decryptor, xarray should be able to read the metadata and still perform operations on the unencrypted variable
201212
print("Attempting to read and print metadata of partially encrypted zarr")

0 commit comments

Comments
 (0)