def test_store(self): key_name = "test_key-{}".format( str(binascii.hexlify(os.urandom(5)).decode())) key_pair = self._crypto.generate_keys() key_entry = KeyEntry(key_name, key_pair.private_key.raw_key, {}) key_storage = KeyStorage() key_storage.store(key_entry) file_path = self.__filename_for_clean(key_storage, key_name) try: self.assertTrue(os.path.exists(file_path)) finally: os.remove(file_path)
def test_load(self): key_name = "test_key-{}".format( str(binascii.hexlify(os.urandom(5)).decode())) additional_data = {"some_key": "some_value"} key_pair = self._crypto.generate_keys() key_entry = KeyEntry(key_name, key_pair.private_key.raw_key, additional_data) key_storage = KeyStorage() key_storage.store(key_entry) raw_loaded_key_entry = key_storage.load(key_name) try: self.assertEqual(raw_loaded_key_entry["name"], key_name) self.assertEqual(bytearray(key_pair.private_key.raw_key), bytearray(raw_loaded_key_entry["value"])) self.assertDictEqual(additional_data, raw_loaded_key_entry["meta"]) finally: os.remove(self.__filename_for_clean(key_storage, key_name))
def test_load_key_with_empty_name(self): key_storage = KeyStorage() self.assertRaises(ValueError, key_storage.load, None)
def test_load_unexisting_key(self): key_name = "test_key-{}".format( str(binascii.hexlify(os.urandom(10)).decode())) key_storage = KeyStorage() self.assertRaises(ValueError, key_storage.load, key_name)
def test_store_none(self): key_entry = None key_storage = KeyStorage() self.assertRaises(ValueError, key_storage.store, key_entry)
def test_delete_key_empty_name(self): key_storage = KeyStorage() self.assertRaises(ValueError, key_storage.delete, None)