Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
fix: Normalize course id when received with LTI 1.1 context_label (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgwerner authored Dec 14, 2020
1 parent 927705f commit 90cc2b1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/illumidesk/authenticators/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async def authenticate(self, handler: BaseHandler, data: Dict[str, str] = None)
# runs as a docker container we need to normalize the string so we can use it
# as a container name.
if 'context_label' in args and args['context_label']:
course_id = args['context_label']
course_id = lti_utils.normalize_string(args['context_label'])
self.log.debug('Course context_label normalized to: %s' % course_id)
else:
raise HTTPError(400, 'Course label not included in the LTI request')
Expand Down
27 changes: 27 additions & 0 deletions src/tests/illumidesk/authenticators/test_lti11_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,33 @@ async def test_authenticator_uses_lti_utils_normalize_string(
assert mock_normalize_string.called


@pytest.mark.asyncio
async def test_authenticator_uses_lti_utils_normalize_string_for_context_label(
make_lti11_success_authentication_request_args, gradesender_controlfile_mock, mock_nbhelper
):
"""
Ensure that we call the normalize string method with the LTI11Authenticator when the course id is
obtained from the context_label argument.
"""
with patch.object(LTI11LaunchValidator, 'validate_launch_request', return_value=True):
with patch.object(LTIUtils, 'normalize_string', return_value='foobar') as mock_normalize_string:
authenticator = LTI11Authenticator()
handler = Mock(spec=RequestHandler)
request = HTTPServerRequest(
method='POST',
connection=Mock(),
)
handler.request = request

handler.request.arguments = make_lti11_success_authentication_request_args('context_label')
handler.request.get_argument = lambda x, strip=True: make_lti11_success_authentication_request_args(
'context_label'
)[x][0].decode()

_ = await authenticator.authenticate(handler, None)
assert mock_normalize_string.called


@pytest.mark.asyncio
@patch('pathlib.Path.mkdir')
async def test_authenticator_uses_lti_grades_sender_control_file_with_student_role(
Expand Down
2 changes: 1 addition & 1 deletion src/tests/illumidesk/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def _make_lti11_basic_launch_args(
@pytest.fixture(scope='function')
def make_lti11_success_authentication_request_args():
def _make_lti11_success_authentication_request_args(
lms_vendor: str = 'canvas', role: str = 'Instructor'
lms_vendor: str = 'canvas', role: str = 'Instructor',
) -> Dict[str, str]:
"""
Return a valid request arguments make from LMS to our tool (when authentication steps were success)
Expand Down

0 comments on commit 90cc2b1

Please sign in to comment.