Esempio n. 1
0
 def test_nonce_count_management(self):
     nm = SignedNonceManager(timeout=0.1)
     request = make_request()
     nonce1 = nm.generate_nonce(request)
     self.assertEquals(nm.get_nonce_count(nonce1), None)
     nm.set_nonce_count(nonce1, 1)
     self.assertEquals(nm.get_nonce_count(nonce1), 1)
     # purging won't remove it until it has expired.
     nm._purge_expired_nonces()
     self.assertEquals(nm.get_nonce_count(nonce1), 1)
     time.sleep(0.1)
     nm._purge_expired_nonces()
     self.assertEquals(nm.get_nonce_count(nonce1), None)
Esempio n. 2
0
 def test_auto_purging_of_expired_nonces(self):
     nm = SignedNonceManager(timeout=0.2)
     request = make_request()
     nonce1 = nm.generate_nonce(request)
     nm.set_nonce_count(nonce1, 1)
     time.sleep(0.1)
     # nonce1 hasn't expired, so adding a new one won't purge it
     nonce2 = nm.generate_nonce(request)
     nm.set_nonce_count(nonce2, 1)
     self.assertEquals(nm.get_nonce_count(nonce1), 1)
     time.sleep(0.1)
     # nonce1 has expired, it should be purged when adding another.
     # nonce2 hasn't expired so it should remain in memory.
     nonce3 = nm.generate_nonce(request)
     nm.set_nonce_count(nonce3, 1)
     self.assertEquals(nm.get_nonce_count(nonce1), None)
     self.assertEquals(nm.get_nonce_count(nonce2), 1)