Skip to content

Commit

Permalink
fix: Custom parameters validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kuipumu committed Nov 17, 2023
1 parent 07a8c26 commit 94d7d8a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 1 addition & 4 deletions lti_consumer/lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@
'instructor': 'Instructor',
}
CUSTOM_PARAMETER_SEPARATOR = '='
# Allow a key-pair key and value to contain any character except "=".
CUSTOM_PARAMETER_REGEX = re.compile(
rf'^([^{CUSTOM_PARAMETER_SEPARATOR}]+{CUSTOM_PARAMETER_SEPARATOR}[^{CUSTOM_PARAMETER_SEPARATOR}]+)$',
)
CUSTOM_PARAMETER_REGEX = re.compile(rf'^(.+{CUSTOM_PARAMETER_SEPARATOR}.+)$')
# Catch a value enclosed by ${}, the value enclosed can contain any charater except "=".
CUSTOM_PARAMETER_TEMPLATE_REGEX = re.compile(r'^(\${[^%s]+})$' % CUSTOM_PARAMETER_SEPARATOR)

Expand Down
6 changes: 3 additions & 3 deletions lti_consumer/tests/unit/test_lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def test_context_id(self):
self.assertEqual(self.xblock.context_id, str(self.xblock.scope_ids.usage_id.context_key))

@ddt.data(
['x=y'], [' x x = y y '], ['x= '], [' =y'], [' = '],
['x=y', ' x x = y y ', 'x= ', ' =y', ' = '],
['x=y'], [' x x = y y '], ['x= '], [' =y'], [' = '], [' x = = y = z '],
['x=y', ' x x = y y ', 'x= ', ' =y', ' = ', ' x = = y = z '],
)
def test_validate_with_valid_custom_parameters(self, custom_parameters):
"""
Expand All @@ -167,7 +167,7 @@ def test_validate_with_empty_custom_parameters(self, add_mock, mock_validation_m
mock_validation_message('error', 'Custom Parameters must be a list'),
)

@ddt.data(['x'], ['x='], ['=y'], ['x==y'], ['x', 'x=', '=y', 'x==y'])
@ddt.data(['x'], ['x='], ['=y'], ['x', 'x=', '=y'])
@patch('lti_consumer.lti_xblock.ValidationMessage')
@patch.object(Validation, 'add')
def test_validate_with_invalid_custom_parameters(self, custom_parameters, add_mock, mock_validation_message):
Expand Down

0 comments on commit 94d7d8a

Please sign in to comment.