コード例 #1
0
 def test_gpg_encrypt_file_passphrase(self):
     """
     Test encrypt/decrypt with passphrase
     """
     cmd_encrypt = gpg_encrypt_file_passphrase(EncryptionTest.test_file,
                                               "12345")
     print(cmd_encrypt)
     self.assertEqual(7, len(cmd_encrypt))
     expected_cmd_list = [
         'gpg', '--yes', '--batch', '--passphrase', '12345', '-c',
         EncryptionTest.test_file
     ]
     self.assertTrue(cmd_encrypt == expected_cmd_list)
     out = subprocess.call(cmd_encrypt, cwd=EncryptionTest.tmp_dir)
     self.assertEqual(0, out)
     cli_commands = CliCommands()
     cli_command = CliCommand(
         "gpg_passphrase_decrypt_file",
         cli_commands.get_command_template("gpg_passphrase_decrypt_file"))
     cmd_decrypt = cli_command.get_command({
         'encrypted_file':
         "%s.gpg" % EncryptionTest.test_file,
         'decrypted_file':
         "test_decrypted.txt",
         'passphrase':
         "12345"
     })
     out = subprocess.call(cmd_decrypt, cwd=EncryptionTest.tmp_dir)
     self.assertEqual(0, out)
     self.assertEqual(
         "test",
         read_file_content(
             os.path.join(EncryptionTest.tmp_dir, "test_decrypted.txt")))
コード例 #2
0
ファイル: test_cli.py プロジェクト: MatteoRomiti/eatb
 def test_cli_commands(self):
     cli_commands = CliCommands()
     cli_command = CliCommand("echo",
                              cli_commands.get_command_template("echo"))
     command = cli_command.get_command({'input': "test"})
     self.assertIsNotNone(command)
     self.assertEqual(2, len(command))
     self.assertEqual('echo', command[0])
     self.assertEqual('test', command[1])
コード例 #3
0
ファイル: encryption.py プロジェクト: MatteoRomiti/eatb
def gpg_encrypt_file_passphrase(file, passphrase):
    """
    Encrypt file using passphrase
    :param file: file
    :param passphrase: passphrase
    :return: CLI command string
    """
    cli_commands = CliCommands()
    cli_command = CliCommand(
        "gpg_passphrase_encrypt_file",
        cli_commands.get_command_template("gpg_passphrase_encrypt_file"))
    command = cli_command.get_command({'file': file, 'passphrase': passphrase})
    return command
コード例 #4
0
def get_hashed_filelist(strip_path_part, directory, commands=CliCommands()):
    """
    e.g. get_hashed_filelist("/home/user/", "/home/user/test")
    :param commands:
    :param strip_path_part: part of the path to be removed for the key
    :param directory: directory for which the hashed file list is to be created
    :return: hashed file list
    """
    cli_command = CliCommand("summainstdout", commands.get_command_template("summainstdout"))
    command = cli_command.get_command(dict(package_dir=directory))
    summain_out = check_output(command)
    json_summain_out = json.loads(summain_out)
    result = {}
    for entry in json_summain_out:
        if "SHA256" in entry:
            key = entry['Name'].lstrip(strip_path_part)
            result[key] = {"hash": entry['SHA256'], "path": entry["Name"]}
    return result
コード例 #5
0
ファイル: manifest.py プロジェクト: E-ARK-Software/eatb
 def __init__(self, working_directory, commands=CliCommands()):
     self.working_directory = working_directory
     self.commands = commands
     if not os.path.exists(working_directory):
         os.makedirs(working_directory)