Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ profile apparmor_profile /home/sandbox/codejail_sandbox-python3.8/bin/python {
/usr/lib/python3.8/lib-dynload/datetime.so mr,
/usr/lib/python3.8/lib-dynload/_elementtree.so mr,
/usr/lib/python3.8/lib-dynload/pyexpat.so mr,
/usr/lib/python3.8/lib-dynload/future_builtins.so mr,
#
# Allow access to selections from /proc
#
Expand Down
35 changes: 3 additions & 32 deletions codejail/tests/test_jail_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TestFeatures(JailCodeHelpersMixin, TestCase):

def test_hello_world(self):
res = jailpy(code="""
from __future__ import print_function; print('Hello, world!')
print('Hello, world!')
""")
self.assertResultOk(res)
self.assertEqual(res.stdout, b'Hello, world!\n')
Expand All @@ -76,7 +76,6 @@ def test_argv(self):
set_limit('REALTIME', 2)
res = jailpy(
code="""
from __future__ import print_function
import sys
print(':'.join(sys.argv[1:]))
""",
Expand All @@ -100,7 +99,6 @@ def test_ends_with_exception(self):
def test_stdin_is_provided(self):
res = jailpy(
code="""
from __future__ import print_function
import json, sys
print(sum(json.load(sys.stdin)))
""",
Expand All @@ -112,7 +110,6 @@ def test_stdin_is_provided(self):
def test_stdin_can_be_large_and_binary(self):
res = jailpy(
code="""
from __future__ import print_function
import sys
print(sum(ord(c) for c in sys.stdin.read()))
""",
Expand Down Expand Up @@ -152,7 +149,6 @@ def test_stderr_can_be_large_and_binary(self):
def test_files_are_copied(self):
res = jailpy(
code="""
from __future__ import print_function
print('Look:', open('hello.txt').read())
""",
files=[file_here("hello.txt")]
Expand All @@ -163,7 +159,6 @@ def test_files_are_copied(self):
def test_directories_are_copied(self):
res = jailpy(
code="""\
from __future__ import print_function
import os
res = []
for path, dirs, files in os.walk("."):
Expand Down Expand Up @@ -195,7 +190,6 @@ def test_executing_extra_files(self):
res = jailpy(
extra_files=[
("run.py", bytes(textwrap.dedent("""\
from __future__ import print_function
import os
print(sorted(os.listdir('.')))
print(open('also.txt', 'rb').read())
Expand All @@ -221,7 +215,6 @@ def test_we_can_remove_tmp_files(self):
set_limit('FSIZE', 1000)
res = jailpy(
code="""\
from __future__ import print_function
import os, shutil, tempfile
temp_dir = tempfile.mkdtemp()
with open("{}/myfile.txt".format(temp_dir), "w") as f:
Expand All @@ -246,7 +239,7 @@ def test_we_can_remove_tmp_files(self):
def test_slugs_get_logged(self, log_log):
jailpy(
code="""
from __future__ import print_function; print('Hello, world!')
print('Hello, world!')
""",
slug="HELLO"
)
Expand All @@ -271,7 +264,6 @@ def test_cant_use_too_much_memory(self):
set_limit('VMEM', 80000000)
res = jailpy(
code="""
from __future__ import print_function
print(len(bytearray(100000000)))
"""
)
Expand All @@ -284,7 +276,6 @@ def test_changing_vmem_limit(self):
set_limit('VMEM', 160000000)
res = jailpy(
code="""
from __future__ import print_function
print(len(bytearray(100000000)))
"""
)
Expand All @@ -297,7 +288,6 @@ def test_disabling_vmem_limit(self):
set_limit('VMEM', 0)
res = jailpy(
code="""
from __future__ import print_function
print(len(bytearray(50000000)))
"""
)
Expand All @@ -310,7 +300,6 @@ def test_cant_use_too_much_cpu(self):
set_limit('REALTIME', 10)
res = jailpy(
code="""
from __future__ import print_function
from six.moves import range
print(sum(range(2**31-1)))
"""
Expand All @@ -326,7 +315,6 @@ def test_cant_use_too_much_time(self, log_log):
set_limit('REALTIME', 1)
res = jailpy(
code="""
from __future__ import print_function
import time
time.sleep(1.5)
print('Done!')
Expand All @@ -344,7 +332,6 @@ def test_changing_realtime_limit(self):
set_limit('REALTIME', 2)
res = jailpy(
code="""
from __future__ import print_function
import time
time.sleep(1.5)
print('Done!')
Expand All @@ -358,7 +345,6 @@ def test_disabling_realtime_limit(self):
set_limit('REALTIME', 0)
res = jailpy(
code="""
from __future__ import print_function
import time
time.sleep(1.5)
print('Done!')
Expand All @@ -369,7 +355,6 @@ def test_disabling_realtime_limit(self):

def test_cant_write_files(self):
res = jailpy(code="""\
from __future__ import print_function
print("Trying")
with open("mydata.txt", "w") as f:
f.write("hello")
Expand All @@ -383,7 +368,6 @@ def test_cant_write_files(self):
def test_can_write_temp_files(self):
set_limit('FSIZE', 1000)
res = jailpy(code="""\
from __future__ import print_function
import os, tempfile
print("Trying mkstemp")
f, path = tempfile.mkstemp()
Expand All @@ -399,7 +383,6 @@ def test_can_write_temp_files(self):
def test_cant_write_large_temp_files(self):
set_limit('FSIZE', 1000)
res = jailpy(code="""\
from __future__ import print_function
import os, tempfile
from six.moves import range
print("Trying mkstemp")
Expand All @@ -424,7 +407,6 @@ def test_cant_write_many_small_temp_files(self):
# pylint: disable=unreachable
set_limit('FSIZE', 1000)
res = jailpy(code="""\
from __future__ import print_function
import os, tempfile
print("Trying mkstemp 250")
for i in range(250):
Expand All @@ -442,7 +424,6 @@ def test_cant_write_many_small_temp_files(self):

def test_cant_use_network(self):
res = jailpy(code="""\
from __future__ import print_function
try:
from urllib import urlopen
except ImportError:
Expand All @@ -458,7 +439,6 @@ def test_cant_use_network(self):

def test_cant_use_raw_network(self):
res = jailpy(code="""\
from __future__ import print_function
try:
from urllib import urlopen
except ImportError:
Expand All @@ -476,7 +456,6 @@ def test_cant_fork(self):
set_limit('NPROC', 1)
res = jailpy(
code="""\
from __future__ import print_function
import os
print("Forking")
child_ppid = os.fork()
Expand All @@ -492,7 +471,6 @@ def test_cant_see_environment_variables(self):
os.environ['HONEY_BOO_BOO'] = 'Look!'
res = jailpy(
code="""\
from __future__ import print_function
import os
for name, value in os.environ.items():
print("%s: %r" % (name, value))
Expand All @@ -505,7 +483,6 @@ def test_reading_dev_random(self):
# We can read 10 bytes just fine.
res = jailpy(
code="""
from __future__ import print_function
x = open('/dev/urandom', 'rb').read(10)
print(len(x))
"""
Expand All @@ -516,7 +493,6 @@ def test_reading_dev_random(self):
# If we try to read all of it, we'll be killed by the real-time limit.
res = jailpy(
code="""
from __future__ import print_function
x = open('/dev/urandom', 'rb').read()
print('Done!')
"""
Expand Down Expand Up @@ -556,7 +532,6 @@ def test_symlinks_in_directories_wont_copy_data(self):
# the symlink.
res = jailpy(
code="""\
from __future__ import print_function
print(open('copied/here.txt').read()) # can read
print(open('copied/herelink.txt').read()) # can read
print(open('copied/link.txt').read()) # can't read
Expand All @@ -570,7 +545,6 @@ def test_symlinks_wont_copy_data(self):
# Run some code in the sandbox, with a copied file which is a symlink.
res = jailpy(
code="""\
from __future__ import print_function
print(open('here.txt').read()) # can read
print(open('herelink.txt').read()) # can read
print(open('link.txt').read()) # can't read
Expand All @@ -593,7 +567,6 @@ def test_crash_cpython(self):
raise SkipTest('Not supported in Python 3 yet')
# pylint: disable=unreachable
res = jailpy(code="""\
from __future__ import print_function
import new, sys
bad_code = new.code(0,0,0,0,"KABOOM",(),(),(),"","",0,"")
crash_me = new.function(bad_code, {})
Expand All @@ -608,7 +581,6 @@ def test_crash_cpython(self):

def test_read_etc_passwd(self):
res = jailpy(code="""\
from __future__ import print_function
bytes = len(open('/etc/passwd').read())
print('Gotcha', bytes)
""")
Expand All @@ -618,7 +590,6 @@ def test_read_etc_passwd(self):

def test_find_other_sandboxes(self):
res = jailpy(code="""
from __future__ import print_function
import os
places = [
"..", "/tmp", "/", "/home", "/etc", "/var"
Expand Down Expand Up @@ -651,7 +622,7 @@ def setUp(self):
def run_ok(self):
"""Run some code to see that it works."""
num = int(time.time()*100000)
res = jailpy(code="from __future__ import print_function; print('Look: %d')" % num)
res = jailpy(code="print('Look: %d')" % num)
self.assertResultOk(res)
self.assertEqual(res.stdout, b'Look: %d\n' % num)

Expand Down
2 changes: 1 addition & 1 deletion codejail/tests/test_safe_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def g():

def test_printing_stuff_when_you_shouldnt(self):
globs = {}
self.safe_exec("from __future__ import print_function; a = 17; print('hi!')", globs)
self.safe_exec("a = 17; print('hi!')", globs)
self.assertEqual(globs['a'], 17)

def test_importing_lots_of_crap(self):
Expand Down
1 change: 0 additions & 1 deletion requirements/sandbox.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
# of sandboxes used for testing codejail

django
future
numpy
six
3 changes: 1 addition & 2 deletions requirements/sandbox.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#
# This file is autogenerated by pip-compile with python 3.8
# This file is autogenerated by pip-compile with Python 3.8
# To update, run:
#
# make upgrade
#
asgiref==3.5.2 # via django
django==3.2.17 # via -c requirements/common_constraints.txt, -c requirements/constraints.txt, -r requirements/sandbox.in
future==0.18.2 # via -r requirements/sandbox.in
numpy==1.22.4 # via -r requirements/sandbox.in
pytz==2022.1 # via django
six==1.16.0 # via -r requirements/sandbox.in
Expand Down