コード例 #1
0
 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)
コード例 #2
0
 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))
コード例 #3
0
 def test_load_key_with_empty_name(self):
     key_storage = KeyStorage()
     self.assertRaises(ValueError, key_storage.load, None)
コード例 #4
0
 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)
コード例 #5
0
 def test_store_none(self):
     key_entry = None
     key_storage = KeyStorage()
     self.assertRaises(ValueError, key_storage.store, key_entry)
コード例 #6
0
 def test_delete_key_empty_name(self):
     key_storage = KeyStorage()
     self.assertRaises(ValueError, key_storage.delete, None)