Skip to content

Commit

Permalink
Add additional tests to ensure invalid binary paths are not ran
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Jan 24, 2024
1 parent 2952eca commit 6dcf094
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ def test_multi_binary_support(self):
self.assertEqual(status, 200)
self.assertEqual(json.loads(response)["stdout"], expected)

def invalid_binary_paths(self):
"""Test that passing invalid binary paths result in no code execution."""
with run_gunicorn():
cases = [
("/bin/bash", "test files outside of /lang cannot be ran"),
(
"/lang/../bin/bash",
"test path traversal still stops files outside /lang from running",
),
("/foo/bar", "test non-existant files are not ran"),
]
for path, msg in cases:
with self.subTest(msg=msg, path=path):
body = {"args": ["-c", "echo", "hi"], "binary_path": path}
response, status = snekbox_request(body)
self.assertEqual(status, 400)
expected = {"title": "binary_path file is invalid"}
self.assertEqual(json.loads(response)["stdout"], expected)

def test_eval(self):
"""Test normal eval requests without files."""
with run_gunicorn():
Expand Down

0 comments on commit 6dcf094

Please sign in to comment.