def get(cls, value):
     # DB does not contain key but the key_hash.
     value_hash = hash_utils.hash(value)
     for model_object in ApiKeyDB.objects(key_hash=value_hash):
         return model_object
     raise ApiKeyNotFoundError('ApiKey with key_hash=%s not found.' %
                               value_hash)
Beispiel #2
0
    def get(cls, value):
        # DB does not contain key but the key_hash.
        value_hash = hash_utils.hash(value)
        result = cls.query(key_hash=value_hash).first()

        if not result:
            raise ApiKeyNotFoundError('ApiKey with key_hash=%s not found.' % value_hash)

        return result
 def test_hash_uniqueness(self):
     count = 10000
     api_keys = [auth_utils.generate_api_key() for _ in range(count)]
     hashes = set([hash_utils.hash(api_key) for api_key in api_keys])
     self.assertEqual(len(hashes), count, 'Expected all unique hashes.')
 def test_hash_repeatability(self):
     api_key = auth_utils.generate_api_key()
     hash1 = hash_utils.hash(api_key)
     hash2 = hash_utils.hash(api_key)
     self.assertEqual(hash1, hash2, 'Expected a repeated hash.')
Beispiel #5
0
def generate_api_key_and_hash():
    api_key = generate_api_key()
    api_key_hash = hash_utils.hash(api_key)
    return api_key, api_key_hash
Beispiel #6
0
def generate_api_key_and_hash():
    api_key = generate_api_key()
    api_key_hash = hash_utils.hash(api_key)
    return api_key, api_key_hash
Beispiel #7
0
 def test_hash_uniqueness(self):
     count = 10000
     api_keys = [auth_utils.generate_api_key() for _ in range(count)]
     hashes = set([hash_utils.hash(api_key) for api_key in api_keys])
     self.assertEqual(len(hashes), count, 'Expected all unique hashes.')
Beispiel #8
0
 def test_hash_repeatability(self):
     api_key = auth_utils.generate_api_key()
     hash1 = hash_utils.hash(api_key)
     hash2 = hash_utils.hash(api_key)
     self.assertEqual(hash1, hash2, 'Expected a repeated hash.')
Beispiel #9
0
 def get(cls, value):
     # DB does not contain key but the key_hash.
     value_hash = hash_utils.hash(value)
     for model_object in ApiKeyDB.objects(key_hash=value_hash):
         return model_object
     raise ApiKeyNotFoundError('ApiKey with key_hash=%s not found.' % value_hash)