def test_bad_digest(self):
     """
     Test the verify function with a bad digest
     """
     hasher = DrupalPasswordHasher()
     password = "******"
     encoded = hasher.encode(password, hasher.salt())
     temp = encoded.split("$", 1)[1]
     temp = temp[2:]
     encoded = "drupal$$F" + temp
     with self.assertRaises(DrupalPasswordHasherInvalidHashException):
         hasher.verify(password, encoded)
 def test_verify(self):
     """
     Test the verify function
     """
     hasher = DrupalPasswordHasher()
     password = "******"
     encoded = hasher.encode(password, hasher.salt())
     self.assertTrue(hasher.verify(password, encoded))
 def test_verify_old(self):
     """
     Test the verify function when the password comes 
     from an old (emulated) drupal version
     """
     hasher = DrupalPasswordHasher()
     password = "******"
     digest = "$P$"
     salt = hasher.salt()
     settings = {"count": 1 << hasher._DRUPAL_HASH_COUNT, "salt": salt}
     encoded_hash = hasher._apply_hash(password, hasher._digests[digest], settings)
     encoded = "drupal$U$P$" + hasher._itoa64[hasher._DRUPAL_HASH_COUNT] + salt + encoded_hash
     self.assertFalse(hasher.verify(password, encoded))