test: no empty tx for invalid JWT
This commit is contained in:
committed by
Steve Chavez
parent
df49f482dc
commit
2905753194
@@ -971,6 +971,28 @@ def test_no_pool_connection_required_on_bad_http_logic(defaultenv):
|
|||||||
response = postgrest.session.patch("/rpc/hello")
|
response = postgrest.session.patch("/rpc/hello")
|
||||||
assert response.status_code == 405
|
assert response.status_code == 405
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_pool_connection_required_on_bad_jwt_claim(defaultenv):
|
||||||
|
"no pool connection should be consumed for failing on invalid jwt"
|
||||||
|
|
||||||
|
env = {**defaultenv, "PGRST_DB_POOL": "1", "PGRST_JWT_SECRET": SECRET}
|
||||||
|
|
||||||
|
with run(env=env) as postgrest:
|
||||||
|
# First we retain the only pool connection available
|
||||||
|
# The try/except is a hack for not waiting for the response, taken from https://stackoverflow.com/a/45601591/4692662
|
||||||
|
try:
|
||||||
|
postgrest.session.get("/rpc/sleep?seconds=50", timeout=0.1)
|
||||||
|
except requests.exceptions.ReadTimeout:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Then the following requests should succeed rapidly
|
||||||
|
|
||||||
|
# A JWT with an invalid signature shouldn't open a connection
|
||||||
|
headers = jwtauthheader({"role": "postgrest_test_author"}, "Wrong Secret")
|
||||||
|
response = postgrest.session.get("/projects", headers=headers)
|
||||||
|
assert response.status_code == 401
|
||||||
|
|
||||||
|
|
||||||
# TODO: This test fails now because of https://github.com/PostgREST/postgrest/pull/2122
|
# TODO: This test fails now because of https://github.com/PostgREST/postgrest/pull/2122
|
||||||
# The stack size of 1K(-with-rtsopts=-K1K) is not enough and this fails with "stack overflow"
|
# The stack size of 1K(-with-rtsopts=-K1K) is not enough and this fails with "stack overflow"
|
||||||
# A stack size of 200K seems to be enough for succeess
|
# A stack size of 200K seems to be enough for succeess
|
||||||
|
|||||||
Reference in New Issue
Block a user