Beispiel #1
0
 def test1(self):
     # test a proper login
 
     creds = MemoryCredentialStore()
     creds.add("uid", "pwdhash")
     chals = MemoryChallengeStore()
     a = Auth(creds, chals)
     
     # client asks for challenge
     c = a.new_challenge()
     
     # client calculates response
     res = hashlib.sha1(c + "pwdhash").hexdigest()
     
     # check response
     v = a.validate(c, "uid", res)
     self.assertTrue(v)
Beispiel #2
0
 def test5(self):
     # test a faulty login, with invalid resopnse
 
     creds = MemoryCredentialStore()
     creds.add("uid", "pwdhash")
     chals = MemoryChallengeStore()
     a = Auth(creds, chals)
     
     # client asks for challenge
     c = a.new_challenge()
     
     # client calculates response
     res = hashlib.sha1(c + "pwdhash" + "this is wrong").hexdigest()
     
     # check response
     v = a.validate(c, "uid", res)
     self.assertFalse(v)
Beispiel #3
0
 def test3(self):
     # test a faulty login, with expired challenge
 
     creds = MemoryCredentialStore()
     creds.add("uid", "pwdhash")
     chals = MemoryChallengeStore()
     a = Auth(creds, chals, challenge_ttl=1)
     
     # client asks for challenge
     c = a.new_challenge()
     
     time.sleep(a.challenge_ttl.seconds)
     
     # client calculates response
     res = hashlib.sha1(c + "pwdhash").hexdigest()
     
     # check response
     v = a.validate(c, "uid", res)
     self.assertFalse(v)
Beispiel #4
0
 def test4(self):
     # test a faulty login, with unkown challenge
 
     creds = MemoryCredentialStore()
     creds.add("uid", "pwdhash")
     chals = MemoryChallengeStore()
     a = Auth(creds, chals)
     
     # client asks for challenge
     c = a.new_challenge()
     
     # now make challenge invalid
     c = "invalid challenge"
     
     # client calculates response
     res = hashlib.sha1(c + "pwdhash").hexdigest()
     
     # check response
     v = a.validate(c, "uid", res)
     self.assertFalse(v)
Beispiel #5
0
 def test6(self):
     # test a faulty login, re-using challenge
 
     creds = MemoryCredentialStore()
     creds.add("uid", "pwdhash")
     chals = MemoryChallengeStore()
     a = Auth(creds, chals)
     
     # client asks for challenge
     c = a.new_challenge()
     
     # client calculates response
     res = hashlib.sha1(c + "pwdhash").hexdigest()
     
     # check response
     v = a.validate(c, "uid", res)
     self.assertTrue(v)
     
     # try to use it again
     v = a.validate(c, "uid", res)
     self.assertFalse(v)