comparison test/test_templating.py @ 6826:28b906a237d8

Fix anti_csrf_nonce test Make the MockDatabase inherit from roundup.backends.sessions_common SessionCommon. This provides the getUniqueKey method. Also the encoding as base64 changed the length, so had to adjust the assert.
author John Rouillard <rouilj@ieee.org>
date Sun, 07 Aug 2022 04:18:20 -0400
parents 38b73f7495f8
children 234fefd7568a
comparison
equal deleted inserted replaced
6825:b04e44db7d8d 6826:28b906a237d8
40 skip_markdown = mark_class(pytest.mark.skip( 40 skip_markdown = mark_class(pytest.mark.skip(
41 reason='markdown not available')) 41 reason='markdown not available'))
42 42
43 from roundup.anypy.strings import u2s, s2u 43 from roundup.anypy.strings import u2s, s2u
44 44
45 class MockDatabase(MockNull): 45 from roundup.backends.sessions_common import SessionCommon
46
47 class MockDatabase(MockNull, SessionCommon):
46 def getclass(self, name): 48 def getclass(self, name):
47 # limit class names 49 # limit class names
48 if name not in [ 'issue', 'user', 'status' ]: 50 if name not in [ 'issue', 'user', 'status' ]:
49 raise KeyError('There is no class called "%s"' % name) 51 raise KeyError('There is no class called "%s"' % name)
50 # Class returned must have hasnode(id) method that returns true 52 # Class returned must have hasnode(id) method that returns true
242 244
243 def test_anti_csrf_nonce(self): 245 def test_anti_csrf_nonce(self):
244 '''call the csrf creation function and do basic length test 246 '''call the csrf creation function and do basic length test
245 247
246 Store the data in a mock db with the same api as the otk 248 Store the data in a mock db with the same api as the otk
247 db. Make sure nonce is 64 chars long. Lookup the nonce in 249 db. Make sure nonce is 54 chars long. Lookup the nonce in
248 db and retrieve data. Verify that the nonce lifetime is 250 db and retrieve data. Verify that the nonce lifetime is
249 correct (within 1 second of 1 week - lifetime), the uid is 251 correct (within 1 second of 1 week - lifetime), the uid is
250 correct (1), the dummy sid is correct. 252 correct (1), the dummy sid is correct.
251 253
252 Consider three cases: 254 Consider three cases:
278 # use the module function but with no lifetime 280 # use the module function but with no lifetime
279 nonce1 = anti_csrf_nonce(self.client) 281 nonce1 = anti_csrf_nonce(self.client)
280 # see above for web nonce lifetime. 282 # see above for web nonce lifetime.
281 greater_than = week_seconds - 10 * 60 283 greater_than = week_seconds - 10 * 60
282 284
283 self.assertEqual(len(nonce1), 64) 285 self.assertEqual(len(nonce1), 54)
284 286
285 uid = otks.get(nonce1, 'uid', default=None) 287 uid = otks.get(nonce1, 'uid', default=None)
286 sid = otks.get(nonce1, 'sid', default=None) 288 sid = otks.get(nonce1, 'sid', default=None)
287 timestamp = otks.get(nonce1, '__timestamp', default=None) 289 timestamp = otks.get(nonce1, '__timestamp', default=None)
288 290

Roundup Issue Tracker: http://roundup-tracker.org/