def get_key_details(self): """Get details of all stored API keys.""" details = set() for q in self.quotas.keys(): details.add( ApiKeyDto(UnhashedKey.from_string(q), self.quotas[q], date.today())) return details
def testMatching(self): bytes_to_hash = "totallysecret".encode("utf-8") bytes_hashed = bcrypt.hashpw(bytes_to_hash, bcrypt.gensalt()) key_from_hashed = HashedKey.from_bytes(bytes_hashed) key_from_unhashed = UnhashedKey.from_bytes(bytes_to_hash) self.assertTrue(key_from_hashed.matches(key_from_unhashed)) self.assertTrue(key_from_unhashed.matches(key_from_hashed))
def _get_tuple(self, unhashed_key_string): quotas = self.dal.get_key_details() hashed_key = UnhashedKey.from_string(unhashed_key_string) quota_or_empty = [t for t in quotas if t.key.matches(hashed_key)] if len(quota_or_empty) < 1: return None return quota_or_empty[0]
def get_key_details(self): """Return details for all API keys as DTOs.""" details = set() for row in self.rows: details.add( ApiKeyDto( UnhashedKey.from_string(row[1]), row[3], row[2])) return details
def testUnhashedStringification(self): key = UnhashedKey.from_string("keyExample") stringified = "{}".format(key) self.assertTrue("Raw: keyExample" in stringified)