diff options
author | 2018-05-31 14:44:38 +0200 | |
---|---|---|
committer | 2018-05-31 14:44:38 +0200 | |
commit | 4416893415e4ebe332e161a0b9571216b9c71760 (patch) | |
tree | d08725bce2bcbe7d3b71de80fab57783273957fe | |
parent | try again (diff) |
more tests
-rw-r--r-- | Pipfile | 1 | ||||
-rw-r--r-- | scripts/ci.sh | 5 | ||||
-rw-r--r-- | tests/test_snekbox.py | 25 |
3 files changed, 26 insertions, 5 deletions
@@ -24,6 +24,7 @@ python_version = "3.6" [scripts] lint = "flake8" test = "py.test tests --cov . --cov-report term-missing -v" +report = "py.test tests --cov . --cov-report=html" snekbox = "python snekbox.py" snekweb = "gunicorn -w 2 -b 0.0.0.0:5000 --log-level debug -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker snekweb:app" buildbox = "docker build -t pythondiscord/snekbox:latest -f docker/Dockerfile ." diff --git a/scripts/ci.sh b/scripts/ci.sh index 170d553..edf5295 100644 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -1,7 +1,2 @@ #!/bin/bash -echo $path chmod +x binaries/nsjail2.6-ubuntu-x86_64 -sudo updatedb -sudo locate libprotobuf -echo $(pwd)/binaries/nsjail2.6-ubuntu-x86_64 -Mo --rlimit_as 700 --chroot / -E LANG=en_US.UTF-8 -R/usr -R/lib -R/lib64 --user nobody --group nogroup --time_limit 2 --disable_proc --iface_no_lo --quiet -- $PYTHONEXECUTABLE -ISq -c 'print("test")' -$(pwd)/binaries/nsjail2.6-ubuntu-x86_64 -Mo --rlimit_as 700 --chroot / -E LANG=en_US.UTF-8 -R/usr -R/lib -R/lib64 --user nobody --group nogroup --time_limit 2 --disable_proc --iface_no_lo --quiet -- $PYTHONEXECUTABLE -ISq -c 'print("test")' diff --git a/tests/test_snekbox.py b/tests/test_snekbox.py index 8ebd0c0..ab45bdf 100644 --- a/tests/test_snekbox.py +++ b/tests/test_snekbox.py @@ -11,3 +11,28 @@ class SnekTests(unittest.TestCase): def test_nsjail(self): result = snek.python3('print("test")') self.assertEquals(result.strip(), 'test') + + def test_memory_error(self): + code = ('x = "*"\n' + 'while True:\n' + ' x = x * 99\n') + + result = snek.python3(code) + self.assertEquals(result.strip(), 'MemoryError') + + def test_timeout(self): + code = ('x = "*"\n' + 'while True:\n' + ' try:\n' + ' x = x * 99\n' + ' except:\n' + ' continue\n') + + result = snek.python3(code) + self.assertEquals(result.strip(), 'timed out or memory limit exceeded') + + def test_kill(self): + code = ('import subprocess\n' + 'print(subprocess.check_output("kill -9 6", shell=True).decode())') + result = snek.python3(code) + self.assertIn('returned non-zero exit status 1.', result.strip()) |