Merge remote-tracking branch 'edx/opaque-keys' into opaque-keys-merge-master
This commit is contained in:
@@ -16,7 +16,12 @@ def can_execute_unsafe_code(course_id):
|
||||
# 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, course_id):
|
||||
if re.match(regex, course_id.to_deprecated_string()):
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -5,6 +5,7 @@ Tests for sandboxing.py in util app
|
||||
from django.test import TestCase
|
||||
from util.sandboxing import can_execute_unsafe_code
|
||||
from django.test.utils import override_settings
|
||||
from xmodule.modulestore.locations import SlashSeparatedCourseKey
|
||||
|
||||
|
||||
class SandboxingTest(TestCase):
|
||||
@@ -16,19 +17,19 @@ class SandboxingTest(TestCase):
|
||||
"""
|
||||
Test to make sure that a non-match returns false
|
||||
"""
|
||||
self.assertFalse(can_execute_unsafe_code('edX/notful/empty'))
|
||||
self.assertFalse(can_execute_unsafe_code(SlashSeparatedCourseKey('edX', 'notful', 'empty')))
|
||||
|
||||
@override_settings(COURSES_WITH_UNSAFE_CODE=['edX/full/.*'])
|
||||
def test_sandbox_inclusion(self):
|
||||
"""
|
||||
Test to make sure that a match works across course runs
|
||||
"""
|
||||
self.assertTrue(can_execute_unsafe_code('edX/full/2012_Fall'))
|
||||
self.assertTrue(can_execute_unsafe_code('edX/full/2013_Spring'))
|
||||
self.assertTrue(can_execute_unsafe_code(SlashSeparatedCourseKey('edX', 'full', '2012_Fall')))
|
||||
self.assertTrue(can_execute_unsafe_code(SlashSeparatedCourseKey('edX', 'full', '2013_Spring')))
|
||||
|
||||
def test_courses_with_unsafe_code_default(self):
|
||||
"""
|
||||
Test that the default setting for COURSES_WITH_UNSAFE_CODE is an empty setting, e.g. we don't use @override_settings in these tests
|
||||
"""
|
||||
self.assertFalse(can_execute_unsafe_code('edX/full/2012_Fall'))
|
||||
self.assertFalse(can_execute_unsafe_code('edX/full/2013_Spring'))
|
||||
self.assertFalse(can_execute_unsafe_code(SlashSeparatedCourseKey('edX', 'full', '2012_Fall')))
|
||||
self.assertFalse(can_execute_unsafe_code(SlashSeparatedCourseKey('edX', 'full', '2013_Spring')))
|
||||
|
||||
@@ -44,7 +44,7 @@ class ControllerQueryService(GradingService):
|
||||
log.debug(self.combined_notifications_url)
|
||||
data = self.get(self.combined_notifications_url, params)
|
||||
|
||||
tags = [u'course_id:{}'.format(course_id), u'user_is_staff:{}'.format(user_is_staff)]
|
||||
tags = [u'course_id:{}'.format(course_id.to_deprecated_string()), u'user_is_staff:{}'.format(user_is_staff)]
|
||||
tags.extend(
|
||||
u'{}:{}'.format(key, value)
|
||||
for key, value in data.items()
|
||||
@@ -56,12 +56,12 @@ class ControllerQueryService(GradingService):
|
||||
def get_grading_status_list(self, course_id, student_id):
|
||||
params = {
|
||||
'student_id': student_id,
|
||||
'course_id': course_id,
|
||||
'course_id': course_id.to_deprecated_string(),
|
||||
}
|
||||
|
||||
data = self.get(self.grading_status_list_url, params)
|
||||
|
||||
tags = [u'course_id:{}'.format(course_id)]
|
||||
tags = [u'course_id:{}'.format(course_id.to_deprecated_string())]
|
||||
self._record_result('get_grading_status_list', data, tags)
|
||||
dog_stats_api.histogram(
|
||||
self._metric_name('get_grading_status_list.length'),
|
||||
@@ -72,12 +72,12 @@ class ControllerQueryService(GradingService):
|
||||
|
||||
def get_flagged_problem_list(self, course_id):
|
||||
params = {
|
||||
'course_id': course_id,
|
||||
'course_id': course_id.to_deprecated_string(),
|
||||
}
|
||||
|
||||
data = self.get(self.flagged_problem_list_url, params)
|
||||
|
||||
tags = [u'course_id:{}'.format(course_id)]
|
||||
tags = [u'course_id:{}'.format(course_id.to_deprecated_string())]
|
||||
self._record_result('get_flagged_problem_list', data, tags)
|
||||
dog_stats_api.histogram(
|
||||
self._metric_name('get_flagged_problem_list.length'),
|
||||
@@ -87,7 +87,7 @@ class ControllerQueryService(GradingService):
|
||||
|
||||
def take_action_on_flags(self, course_id, student_id, submission_id, action_type):
|
||||
params = {
|
||||
'course_id': course_id,
|
||||
'course_id': course_id.to_deprecated_string(),
|
||||
'student_id': student_id,
|
||||
'submission_id': submission_id,
|
||||
'action_type': action_type
|
||||
@@ -95,7 +95,7 @@ class ControllerQueryService(GradingService):
|
||||
|
||||
data = self.post(self.take_action_on_flags_url, params)
|
||||
|
||||
tags = [u'course_id:{}'.format(course_id), u'action_type:{}'.format(action_type)]
|
||||
tags = [u'course_id:{}'.format(course_id.to_deprecated_string()), u'action_type:{}'.format(action_type)]
|
||||
self._record_result('take_action_on_flags', data, tags)
|
||||
return data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user