Skip to content

Commit c2a036c

Browse files
committed
test: add tests for apikey removal
1 parent 245f5f2 commit c2a036c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

testinfra/test_ami.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,53 @@ def test_postgrest_can_connect_to_db(host):
339339
},
340340
)
341341
assert res.ok
342+
343+
344+
# There would be an error if the `apikey` query parameter isn't removed,
345+
# since PostgREST treats query parameters as conditions.
346+
#
347+
# Worth testing since remove_apikey_query_parameter.lua uses regexp instead
348+
# of parsed query parameters.
349+
def test_postgrest_starting_apikey_query_parameter_is_removed(host):
350+
res = requests.get(
351+
f"http://{host.backend.get_hostname()}/rest/v1/buckets",
352+
headers={
353+
"accept-profile": "storage",
354+
},
355+
params={
356+
"apikey": service_role_key,
357+
"id": "eq.absent",
358+
"name": "eq.absent",
359+
},
360+
)
361+
assert res.ok
362+
363+
364+
def test_postgrest_middle_apikey_query_parameter_is_removed(host):
365+
res = requests.get(
366+
f"http://{host.backend.get_hostname()}/rest/v1/buckets",
367+
headers={
368+
"accept-profile": "storage",
369+
},
370+
params={
371+
"id": "eq.absent",
372+
"apikey": service_role_key,
373+
"name": "eq.absent",
374+
},
375+
)
376+
assert res.ok
377+
378+
379+
def test_postgrest_ending_apikey_query_parameter_is_removed(host):
380+
res = requests.get(
381+
f"http://{host.backend.get_hostname()}/rest/v1/buckets",
382+
headers={
383+
"accept-profile": "storage",
384+
},
385+
params={
386+
"id": "eq.absent",
387+
"name": "eq.absent",
388+
"apikey": service_role_key,
389+
},
390+
)
391+
assert res.ok

0 commit comments

Comments
 (0)