def init_trust(self): # Create a temporary directory and save a test key-pair to it: temp_dir = tempfile.TemporaryDirectory() temp_path = temp_dir.name private_key, public_key = TrustBasics.generateNewKeyPair() private_path = os.path.join(temp_path, "test_private_key.pem") public_path = os.path.join(temp_path, "test_public_key.pem") TrustBasics.saveKeyPair(private_key, private_path, public_path, _passphrase) # Create random files: all_paths = [ os.path.abspath(os.path.join(temp_path, x, y, z)) for x in _folder_names for y in _subfolder_names for z in _file_names ] for path in all_paths: folder_path = os.path.dirname(path) if not os.path.exists(folder_path): os.makedirs(folder_path) with open(path, "w") as file: file.write("".join( random.choice(['a', 'b', 'c', '0', '1', '2', '\n']) for _ in range(1024))) # Instantiate a trust object with the public key that was just generated: violation_callback = MagicMock() trust = Trust( public_path) # No '.getInstance', since key & handler provided. trust._violation_handler = violation_callback yield temp_path, private_path, trust, violation_callback temp_dir.cleanup()
def init_trust(self): # Create a temporary directory and save a test key-pair to it: temp_dir = tempfile.TemporaryDirectory() temp_path = temp_dir.name private_key, public_key = TrustBasics.generateNewKeyPair() private_path = os.path.join(temp_path, "test_private_key.pem") public_path = os.path.join(temp_path, "test_public_key.pem") TrustBasics.saveKeyPair(private_key, private_path, public_path, _passphrase) # Create random files: all_paths = [ os.path.abspath(os.path.join(temp_path, x, y, z)) for x in _folder_names for y in _subfolder_names for z in _file_names ] for path in all_paths: folder_path = os.path.dirname(path) if not os.path.exists(folder_path): os.makedirs(folder_path) with open(path, "w") as file: file.write("".join( random.choice(['a', 'b', 'c', '0', '1', '2', '\n']) for _ in range(1024))) # Set up mocked Central File Storage & plugin file (don't move the files yet, though): CentralFileStorage.setIsEnterprise(True) central_storage_dir = tempfile.TemporaryDirectory() central_storage_path = central_storage_dir.name large_plugin_path = os.path.join(temp_path, _folder_names[2]) store_folder = os.path.join(large_plugin_path, _subfolder_names[0]) store_file = os.path.join(large_plugin_path, _file_names[2]) central_storage_dict = [[ f"{_subfolder_names[0]}", f"{_subfolder_names[0]}", "1.0.0", CentralFileStorage._hashItem(store_folder) ], [ f"{_file_names[2]}", f"{_file_names[2]}", "1.0.0", CentralFileStorage._hashItem(store_file) ]] central_storage_file_path = os.path.join( large_plugin_path, TrustBasics.getCentralStorageFilename()) with open(central_storage_file_path, "w") as file: json.dump(central_storage_dict, file, indent=2) # Instantiate a trust object with the public key that was just generated: violation_callback = MagicMock() trust = Trust( public_path) # No '.getInstance', since key & handler provided. trust._violation_handler = violation_callback yield temp_path, private_path, trust, violation_callback, central_storage_path temp_dir.cleanup() central_storage_dir.cleanup() CentralFileStorage.setIsEnterprise(False)