Skip to content

Commit 447fd0b

Browse files
authored
feat: Upgrade to codejail 4.0.0 (#36916)
This brings an important security improvement -- codejail won't default to running in unsafe mode, which can happen if certain configuration errors are present. Properly configured installations shouldn't be affected. We just need to adjust some unit tests to opt into unsafe mode. Changes: - Update `edx-codejail` dependency to [version 4.0.0](https://github.com/openedx/codejail/blob/master/CHANGELOG.rst#400---2025-06-13) - Define a `use_unsafe_codejail` decorator that allows running a unit test (or entire TestCase class) in unsafe mode - Use that decorator as needed, based on which tests started failing
1 parent 0c493b6 commit 447fd0b

13 files changed

Lines changed: 58 additions & 5 deletions

File tree

lms/djangoapps/courseware/tests/test_submitting_problems.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
OptionResponseXMLFactory,
2929
SchematicResponseXMLFactory
3030
)
31+
from xmodule.capa.tests.test_util import use_unsafe_codejail
3132
from xmodule.capa.xqueue_interface import XQueueInterface
3233
from common.djangoapps.course_modes.models import CourseMode
3334
from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule
@@ -810,6 +811,7 @@ def test_three_files(self, mock_xqueue_post):
810811
self.assertEqual(list(kwargs['files'].keys()), filenames.split())
811812

812813

814+
@use_unsafe_codejail()
813815
class TestPythonGradedResponse(TestSubmittingProblems):
814816
"""
815817
Check that we can submit a schematic and custom response, and it answers properly.

lms/djangoapps/instructor_task/tests/test_integration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from xmodule.capa.responsetypes import StudentInputError
2424
from xmodule.capa.tests.response_xml_factory import CodeResponseXMLFactory, CustomResponseXMLFactory
25+
from xmodule.capa.tests.test_util import use_unsafe_codejail
2526
from lms.djangoapps.courseware.model_data import StudentModule
2627
from lms.djangoapps.grades.api import CourseGradeFactory
2728
from lms.djangoapps.instructor_task.api import (
@@ -71,6 +72,7 @@ def _assert_task_failure(self, entry_id, task_type, problem_url_name, expected_m
7172

7273
@ddt.ddt
7374
@override_settings(RATELIMIT_ENABLE=False)
75+
@use_unsafe_codejail()
7476
class TestRescoringTask(TestIntegrationTask):
7577
"""
7678
Integration-style tests for rescoring problems in a background task.

requirements/edx/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ edx-celeryutils==1.4.0
421421
# -r requirements/edx/kernel.in
422422
# edx-name-affirmation
423423
# super-csv
424-
edx-codejail==3.5.2
424+
edx-codejail==4.0.0
425425
# via -r requirements/edx/kernel.in
426426
edx-completion==4.9
427427
# via -r requirements/edx/kernel.in

requirements/edx/development.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ edx-celeryutils==1.4.0
691691
# -r requirements/edx/testing.txt
692692
# edx-name-affirmation
693693
# super-csv
694-
edx-codejail==3.5.2
694+
edx-codejail==4.0.0
695695
# via
696696
# -r requirements/edx/doc.txt
697697
# -r requirements/edx/testing.txt

requirements/edx/doc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ edx-celeryutils==1.4.0
505505
# -r requirements/edx/base.txt
506506
# edx-name-affirmation
507507
# super-csv
508-
edx-codejail==3.5.2
508+
edx-codejail==4.0.0
509509
# via -r requirements/edx/base.txt
510510
edx-completion==4.9
511511
# via -r requirements/edx/base.txt

requirements/edx/kernel.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ edx-celeryutils
6666
edx-completion
6767
edx-django-release-util # Release utils for the edx release pipeline
6868
edx-django-sites-extensions
69-
edx-codejail
69+
# Codejail 4 brings important safety improvements (no unsafe mode by default)
70+
edx-codejail>=4.0.0
7071
# edx-django-utils 5.14.1 adds FrontendMonitoringMiddleware
7172
edx-django-utils>=5.14.1 # Utilities for cache, monitoring, and plugins
7273
edx-drf-extensions

requirements/edx/testing.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ edx-celeryutils==1.4.0
530530
# -r requirements/edx/base.txt
531531
# edx-name-affirmation
532532
# super-csv
533-
edx-codejail==3.5.2
533+
edx-codejail==4.0.0
534534
# via -r requirements/edx/base.txt
535535
edx-completion==4.9
536536
# via -r requirements/edx/base.txt

xmodule/capa/safe_exec/tests/test_safe_exec.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
from xmodule.capa.safe_exec import safe_exec, update_hash
2525
from xmodule.capa.safe_exec.remote_exec import is_codejail_in_darklaunch, is_codejail_rest_service_enabled
2626
from xmodule.capa.safe_exec.safe_exec import emsg_normalizers, normalize_error_message
27+
from xmodule.capa.tests.test_util import use_unsafe_codejail
2728

2829

30+
@use_unsafe_codejail()
2931
class TestSafeExec(unittest.TestCase): # lint-amnesty, pylint: disable=missing-class-docstring
3032
def test_set_values(self):
3133
g = {}
@@ -530,6 +532,7 @@ def set(self, key, value):
530532
self.cache[key] = value
531533

532534

535+
@use_unsafe_codejail()
533536
class TestSafeExecCaching(unittest.TestCase):
534537
"""Test that caching works on safe_exec."""
535538

@@ -654,6 +657,7 @@ def test_deep_ordering(self):
654657
assert h1 == h2
655658

656659

660+
@use_unsafe_codejail()
657661
class TestRealProblems(unittest.TestCase): # lint-amnesty, pylint: disable=missing-class-docstring
658662
def test_802x(self):
659663
code = textwrap.dedent("""\

xmodule/capa/tests/test_capa_problem.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from xmodule.capa.correctmap import CorrectMap
1616
from xmodule.capa.responsetypes import LoncapaProblemError
1717
from xmodule.capa.tests.helpers import new_loncapa_problem
18+
from xmodule.capa.tests.test_util import use_unsafe_codejail
1819
from openedx.core.djangolib.markup import HTML
1920

2021

@@ -23,6 +24,7 @@
2324

2425

2526
@ddt.ddt
27+
@use_unsafe_codejail()
2628
class CAPAProblemTest(unittest.TestCase):
2729
""" CAPA problem related tests"""
2830

@@ -424,6 +426,7 @@ def test_optionresponse_option_with_empty_text(self):
424426

425427

426428
@ddt.ddt
429+
@use_unsafe_codejail()
427430
class CAPAMultiInputProblemTest(unittest.TestCase):
428431
""" TestCase for CAPA problems with multiple inputtypes """
429432

xmodule/capa/tests/test_html_render.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
import ddt
1212
from lxml import etree
1313
from xmodule.capa.tests.helpers import new_loncapa_problem, mock_capa_system
14+
from xmodule.capa.tests.test_util import use_unsafe_codejail
1415
from openedx.core.djangolib.markup import HTML
1516

1617
from .response_xml_factory import CustomResponseXMLFactory, StringResponseXMLFactory
1718

1819

1920
@ddt.ddt
21+
@use_unsafe_codejail()
2022
class CapaHtmlRenderTest(unittest.TestCase):
2123
"""
2224
CAPA HTML rendering tests class.

0 commit comments

Comments
 (0)