Skip to content

Commit

Permalink
Fixing extra colons in LTI key (#70)
Browse files Browse the repository at this point in the history
Co-authored-by: Sankar Raj <[email protected]>
  • Loading branch information
sksankarraj and Sankar Raj authored Sep 15, 2020
1 parent 956630c commit bbd55a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lti_consumer/lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,13 @@ def lti_provider_key_secret(self):
"""
for lti_passport in self.course.lti_passports:
try:
lti_id, key, secret = [i.strip() for i in lti_passport.split(':')]
# NOTE While unpacking the lti_passport by using ":" as delimiter, first item will be lti_id,
# last item will be client_secret and the rest are considered as client_key.
# So you can have more than one colon for client_key.
lti_id, *key, secret = [i.strip() for i in lti_passport.split(':')]
if not key:
raise ValueError
key = ':'.join(key)
except ValueError:
msg = 'Could not parse LTI passport: {lti_passport!r}. Should be "id:key:secret" string.'
msg = self.ugettext(msg).format(lti_passport=lti_passport)
Expand Down
15 changes: 15 additions & 0 deletions lti_consumer/tests/unit/test_lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ def test_lti_provider_key_secret(self, mock_course):
self.assertEqual(lti_provider_key, key)
self.assertEqual(lti_provider_secret, secret)

@patch('lti_consumer.lti_xblock.LtiConsumerXBlock.course')
def test_lti_provider_key_with_extra_colons(self, mock_course):
"""
Test `lti_provider_key` returns correct key and secret, even if key has more colons.
"""
provider = 'lti_provider'
key = '1:10:test'
secret = 'secret'
self.xblock.lti_id = provider
type(mock_course).lti_passports = PropertyMock(return_value=["{}:{}:{}".format(provider, key, secret)])
lti_provider_key, lti_provider_secret = self.xblock.lti_provider_key_secret

self.assertEqual(lti_provider_key, key)
self.assertEqual(lti_provider_secret, secret)

@patch('lti_consumer.lti_xblock.LtiConsumerXBlock.course')
def test_lti_provider_key_secret_not_found(self, mock_course):
"""
Expand Down

0 comments on commit bbd55a4

Please sign in to comment.