From 871ad7d69483099c96bc7d4e9105cb1287d31853 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 10 Sep 2013 14:21:56 -0400 Subject: [PATCH] Pass hostname to LTI XModule Necessary for RFC compliance with oauthlib --- common/lib/capa/capa/tests/__init__.py | 1 + common/lib/xmodule/xmodule/lti_module.py | 9 ++++++--- common/lib/xmodule/xmodule/tests/__init__.py | 1 + common/lib/xmodule/xmodule/x_module.py | 3 ++- lms/djangoapps/courseware/module_render.py | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common/lib/capa/capa/tests/__init__.py b/common/lib/capa/capa/tests/__init__.py index ac81ff66c4..a1f75b0e92 100644 --- a/common/lib/capa/capa/tests/__init__.py +++ b/common/lib/capa/capa/tests/__init__.py @@ -36,6 +36,7 @@ def test_system(): user=Mock(), filestore=fs.osfs.OSFS(os.path.join(TEST_DIR, "test_files")), debug=True, + hostname="edx.org", xqueue={'interface': xqueue_interface, 'construct_callback': calledback_url, 'default_queuename': 'testqueue', 'waittime': 10}, node_path=os.environ.get("NODE_PATH", "/usr/local/lib/node_modules"), anonymous_student_id='student', diff --git a/common/lib/xmodule/xmodule/lti_module.py b/common/lib/xmodule/xmodule/lti_module.py index 6a9adba929..939190840a 100644 --- a/common/lib/xmodule/xmodule/lti_module.py +++ b/common/lib/xmodule/xmodule/lti_module.py @@ -6,7 +6,7 @@ http://www.imsglobal.org/LTI/v1p1p1/ltiIMGv1p1p1.html """ import logging -import oauthlib +import oauthlib.oauth1 import urllib from xmodule.editing_module import MetadataOnlyEditingDescriptor @@ -212,8 +212,11 @@ class LTIModule(LTIFields, XModule): # appending custom parameter for signing body.update(custom_parameters) - # This is needed for body encoding: - headers = {'Content-Type': 'application/x-www-form-urlencoded'} + headers = { + 'Host': self.system.HOSTNAME, + # This is needed for body encoding: + 'Content-Type': 'application/x-www-form-urlencoded', + } __, headers, __ = client.sign( unicode(self.launch_url), diff --git a/common/lib/xmodule/xmodule/tests/__init__.py b/common/lib/xmodule/xmodule/tests/__init__.py index b7e5ea8435..7f838aa242 100644 --- a/common/lib/xmodule/xmodule/tests/__init__.py +++ b/common/lib/xmodule/xmodule/tests/__init__.py @@ -62,6 +62,7 @@ def get_test_system(course_id=''): user=Mock(is_staff=False), filestore=Mock(), debug=True, + hostname="edx.org", xqueue={'interface': None, 'callback_url': '/', 'default_queuename': 'testqueue', 'waittime': 10, 'construct_callback' : Mock(side_effect="/")}, node_path=os.environ.get("NODE_PATH", "/usr/local/lib/node_modules"), xblock_field_data=lambda descriptor: descriptor._field_data, diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index 02feebea1b..edb9e7f640 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -833,7 +833,7 @@ class ModuleSystem(Runtime): def __init__( self, ajax_url, track_function, get_module, render_template, replace_urls, xblock_field_data, user=None, filestore=None, - debug=False, xqueue=None, publish=None, node_path="", + debug=False, hostname="", xqueue=None, publish=None, node_path="", anonymous_student_id='', course_id=None, open_ended_grading_interface=None, s3_interface=None, cache=None, can_execute_unsafe_code=None, replace_course_urls=None, @@ -897,6 +897,7 @@ class ModuleSystem(Runtime): self.get_module = get_module self.render_template = render_template self.DEBUG = self.debug = debug + self.HOSTNAME = self.hostname = hostname self.seed = user.id if user is not None else 0 self.replace_urls = replace_urls self.node_path = node_path diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 53f9c57f38..b6d22fbf57 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -347,6 +347,8 @@ def get_module_for_descriptor_internal(user, descriptor, field_data_cache, cours filestore=descriptor.system.resources_fs, get_module=inner_get_module, user=user, + debug=settings.DEBUG, + hostname=settings.SITE_NAME, # TODO (cpennington): This should be removed when all html from # a module is coming through get_html and is therefore covered # by the replace_static_urls code below @@ -380,7 +382,6 @@ def get_module_for_descriptor_internal(user, descriptor, field_data_cache, cours # pass position specified in URL to module through ModuleSystem system.set('position', position) - system.set('DEBUG', settings.DEBUG) if settings.MITX_FEATURES.get('ENABLE_PSYCHOMETRICS'): system.set( 'psychometrics_handler', # set callback for updating PsychometricsData