Mercurial > p > roundup > code
diff test/test_templating.py @ 5211:f4b6a2a3e605
Fix expiration dates and expire csrf tokens properly
In client.py: add explicit expiration of csrf tokens to
handle_csrf. There is a clean_up() that runs on every client
connection before handle)csrf is invoked, but it only cleans every
hour. With short lived tokens this is insufficient. Also remove
debugging.
In templating.py fix values for seconds/week and minutes per week. The
original values were shifted/transposed and an order of magnitude off.
In test_templating.py again fix seconds/week constant.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 19 Mar 2017 17:10:13 -0400 |
| parents | a9ace22e0a2f |
| children | 578e86e015f9 |
line wrap: on
line diff
--- a/test/test_templating.py Sun Mar 19 15:32:14 2017 -0400 +++ b/test/test_templating.py Sun Mar 19 17:10:13 2017 -0400 @@ -143,8 +143,13 @@ ''' # the value below is number of seconds in a week. - week_seconds = 648000 + week_seconds = 604800 + + otks=self.client.db.getOTKManager() + for test in [ 'module', 'template', 'default_time' ]: + print "Testing:", test + if test == 'module': # test the module function nonce1 = anti_csrf_nonce(self, self.client, lifetime=1) @@ -162,7 +167,6 @@ greater_than = week_seconds - 10 * 60 self.assertEqual(len(nonce1), 64) - otks=self.client.db.getOTKManager() uid = otks.get(nonce1, 'uid', default=None) sid = otks.get(nonce1, 'sid', default=None) @@ -171,7 +175,11 @@ self.assertEqual(uid, 10) self.assertEqual(sid, self.client.session_api._sid) - ts = time.time() + now = time.time() + + print "now, timestamp, greater, difference", \ + now, timestamp, greater_than, now - timestamp + # lower bound of the difference is above. Upper bound # of difference is run time between time.time() in @@ -179,9 +187,7 @@ # that assigns ts above. I declare that difference # to be less than 1 second for this to pass. self.assertEqual(True, - greater_than < ts - timestamp < (greater_than + 1) ) - - print "completed", test + greater_than <= now - timestamp < (greater_than + 1) ) def test_string_url_quote(self): ''' test that urlquote quotes the string '''
