Skip to content

Commit

Permalink
fixup! Also clean up and test reporting of sandboxed exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
timmc-edx committed Jan 11, 2024
1 parent 448bb1f commit d1e0a74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion edx_arch_experiments/codejail_service/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_unsafely(self):
({}, 'code'),
)
def test_missing_params(self, params, missing):
"""code and globals_dict are required"""
"""Two code and globals_dict params are required."""
self._test_codejail_api(
params=params,
exp_status=400, exp_body={
Expand All @@ -114,6 +114,7 @@ def test_missing_params(self, params, missing):
)

def test_extra_files(self):
"""Check that we can include a course library."""
# "Course library" containing `course_library.triangular_number`.
#
# It's tempting to use zipfile to write to an io.BytesIO so
Expand All @@ -139,3 +140,10 @@ def test_extra_files(self):
files={'python_lib.zip': lib_zip},
exp_status=200, exp_body={'globals_dict': {'result': 21}},
)

def test_exception(self):
"""Report exceptions from jailed code."""
self._test_codejail_api(
params={'code': '1/0', 'globals_dict': {}},
exp_status=200, exp_body={'emsg': 'ZeroDivisionError: division by zero'},
)
4 changes: 2 additions & 2 deletions edx_arch_experiments/codejail_service/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def code_exec_view_v0(request):
slug=slug,
)
except SafeExecException as e:
log.debug("CodejailService execution failed for {slug=} with: {e!r}")
return Response({'emsg': f"Code jail execution failed: {e!r}"})
log.debug("CodejailService execution failed for {slug=} with: {e}")
return Response({'emsg': str(e)})

log.debug("CodejailService execution succeeded for {slug=}, with globals={output_globals_dict!r}")
return Response({'globals_dict': output_globals_dict})

0 comments on commit d1e0a74

Please sign in to comment.