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

Commit

Permalink
fix: Set the course id in auth_state with the normalized value (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
netoisc authored Sep 10, 2020
1 parent d3db4b7 commit 858e0f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/illumidesk/authenticators/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ async def authenticate( # noqa: C901

if validator.validate_launch_request(jwt_decoded):
course_id = jwt_decoded['https://purl.imsglobal.org/spec/lti/claim/context']['label']
course_id = lti_utils.normalize_string(course_id)
self.log.debug('Normalized course label is %s' % course_id)
username = ''
if 'email' in jwt_decoded and jwt_decoded['email']:
Expand Down
22 changes: 22 additions & 0 deletions src/tests/illumidesk/authenticators/test_lti13_authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ async def test_authenticator_returns_course_id_in_auth_state_with_valid_resource
assert result['auth_state']['course_id'] == 'intro101'


@pytest.mark.asyncio
async def test_authenticator_returns_auth_state_with_course_id_normalized(
auth_state_dict,
make_lti13_resource_link_request,
build_lti13_jwt_id_token,
make_mock_request_handler,
mock_nbhelper,
):
"""
Do we get a valid course_id when receiving a valid resource link request?
"""
authenticator = LTI13Authenticator()
request_handler = make_mock_request_handler(RequestHandler, authenticator=authenticator)
# change the context label to uppercase
link_request = make_lti13_resource_link_request
link_request['https://purl.imsglobal.org/spec/lti/claim/context']['label'] = 'CourseID-WITH_LARGE NAME'
with patch.object(RequestHandler, 'get_argument', return_value=build_lti13_jwt_id_token(link_request)):
with patch.object(LTI13LaunchValidator, 'validate_launch_request', return_value=True):
result = await authenticator.authenticate(request_handler, None)
assert result['auth_state']['course_id'] == 'courseid-with_largen'


@pytest.mark.asyncio
async def test_authenticator_returns_auth_state_name_from_lti13_email_claim(
make_lti13_resource_link_request, build_lti13_jwt_id_token, make_mock_request_handler, mock_nbhelper
Expand Down

0 comments on commit 858e0f3

Please sign in to comment.