add python getter in capa system
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from lms.djangoapps.dashboard.git_import import DEFAULT_PYTHON_LIB_FILENAME
|
||||
|
||||
|
||||
def can_execute_unsafe_code(course_id):
|
||||
"""
|
||||
Determine if this course is allowed to run unsafe code.
|
||||
|
||||
For use from the ModuleStore. Checks the `course_id` against a list of whitelisted
|
||||
regexes.
|
||||
|
||||
Returns a boolean, true if the course can run outside the sandbox.
|
||||
|
||||
"""
|
||||
# To decide if we can run unsafe code, we check the course id against
|
||||
# a list of regexes configured on the server.
|
||||
# If this is not defined in the environment variables then default to the most restrictive, which
|
||||
# is 'no unsafe courses'
|
||||
# TODO: This should be a database configuration, where we can mark individual courses as being
|
||||
# safe/unsafe. Someone in the future should switch us over to that rather than using regexes
|
||||
# in a settings file
|
||||
# To others using this: the code as-is is brittle and likely to be changed in the future,
|
||||
# as per the TODO, so please consider carefully before adding more values to COURSES_WITH_UNSAFE_CODE
|
||||
for regex in getattr(settings, 'COURSES_WITH_UNSAFE_CODE', []):
|
||||
if re.match(regex, unicode(course_id)):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_python_lib_zip(contentstore, course_id):
|
||||
"""Return the bytes of the course code library file, if it exists."""
|
||||
python_lib_filename = getattr(settings, 'PYTHON_LIB_FILENAME', DEFAULT_PYTHON_LIB_FILENAME)
|
||||
asset_key = course_id.make_asset_key("asset", python_lib_filename)
|
||||
zip_lib = contentstore().find(asset_key, throw_on_not_found=False)
|
||||
if zip_lib is not None:
|
||||
return zip_lib.data
|
||||
else:
|
||||
return None
|
||||
@@ -7,7 +7,7 @@ from django.test.utils import override_settings
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from opaque_keys.edx.locator import CourseLocator, LibraryLocator
|
||||
|
||||
from util.sandboxing import can_execute_unsafe_code
|
||||
from xmodule.util.sandboxing import can_execute_unsafe_code
|
||||
|
||||
|
||||
class SandboxingTest(TestCase):
|
||||
|
||||
Reference in New Issue
Block a user