Skip to content

Commit

Permalink
[QOLSVC-3186] fix equality assertions for compiled patterns
Browse files Browse the repository at this point in the history
- Py2 doesn't necessarily give the same object when compiling the same pattern twice,
so we need to compare the raw patterns instead of the compiled ones
  • Loading branch information
ThrawnCA committed Oct 12, 2023
1 parent d4f194d commit 7582747
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ckanext/csrf_filter/test_anti_csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,16 @@ def test_exempt_rules(self):
config = {'ckanext.csrf_filter.secret_key': 'secret_key'}
config['ckanext.csrf_filter.exempt_rules'] = '["^/datatables/ajax/.*", "/datatables/filtered-download/.*"]'
expected = [
re.compile('^/+api/.*'),
re.compile('^/datatables/ajax/.*'),
re.compile('/datatables/filtered-download/.*')
'^/+api/.*',
'^/datatables/ajax/.*',
'/datatables/filtered-download/.*'
]
anti_csrf.configure(config)
six.assertCountEqual(self, anti_csrf.exempt_rules, expected)
# Use custom matching since equivalent patterns won't necessarily
# compile to equal objects under all Python versions
self.assertEqual(len(anti_csrf.exempt_rules), len(expected))
for index in range(len(anti_csrf.exempt_rules)):
self.assertEquals(anti_csrf.exempt_rules[index].pattern, expected[index])

# test bad JSON string
config['ckanext.csrf_filter.exempt_rules'] = '^/datatables/ajax/.*", "/datatables/filtered-download/.*'
Expand Down

0 comments on commit 7582747

Please sign in to comment.