aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Pipfile1
-rw-r--r--scripts/ci.sh5
-rw-r--r--tests/test_snekbox.py25
3 files changed, 26 insertions, 5 deletions
diff --git a/Pipfile b/Pipfile
index f03888d..9d8abf7 100644
--- a/Pipfile
+++ b/Pipfile
@@ -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())