Skip to content

Commit

Permalink
Test other caps
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed Oct 16, 2023
1 parent e7718e6 commit 03b58de
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tests/js-custom-authorization/custom_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ def test_stack_size_limit(network, args):
r = c.post("/app/recursive", body={"depth": safe_depth})
assert r.status_code == http.HTTPStatus.OK, r

# Lower the cap until we likely run out of stack out of user code,
# and check that we don't crash and return an error message
cap = max_stack_bytes
while cap > 0:
cap //= 2
LOG.info(f"Max stack size: {cap}")
with temporary_js_limits(network, primary, max_stack_bytes=cap):
r = c.post("/app/recursive", body={"depth": 1})
if r.status_code == http.HTTPStatus.INTERNAL_SERVER_ERROR:
message = r.body.json()["error"]["message"]
assert message == "Exception thrown while executing.", message
break

# Cap is so low that we must run out before we enter user code
with temporary_js_limits(network, primary, max_stack_bytes=100):
r = c.post("/app/recursive", body={"depth": 1})
assert r.status_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
message = r.body.json()["error"]["message"]
assert message == "Exception thrown while executing.", message

return network


Expand Down Expand Up @@ -153,7 +173,7 @@ def test_heap_size_limit(network, args):

# Cap is so low that we must run out before we enter user code
with temporary_js_limits(network, primary, max_heap_bytes=100):
r = c.post("/app/alloc", body={"size": 5})
r = c.post("/app/alloc", body={"size": 1})
assert r.status_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
message = r.body.json()["error"]["message"]
assert message == "Exception thrown while executing.", message
Expand Down Expand Up @@ -186,6 +206,26 @@ def test_execution_time_limit(network, args):
message = r.body.json()["error"]["details"][0]["message"]
assert message == "InternalError: interrupted", message

# Lower the cap until we likely run out of heap out of user code,
# and check that we don't crash and return an error message
cap = safe_time
while cap > 0:
cap //= 2
LOG.info(f"Max exec time: {cap}")
with temporary_js_limits(network, primary, max_execution_time_ms=cap):
r = c.post("/app/sleep", body={"time": 10})
if r.status_code == http.HTTPStatus.INTERNAL_SERVER_ERROR:
message = r.body.json()["error"]["message"]
assert message == "Operation took too long to complete.", message
break

# Cap is so low that we must run out before we enter user code
with temporary_js_limits(network, primary, max_execution_time_ms=0):
r = c.post("/app/sleep", body={"time": 10})
assert r.status_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
message = r.body.json()["error"]["message"]
assert message == "Operation took too long to complete.", message

return network


Expand Down

0 comments on commit 03b58de

Please sign in to comment.