Ejemplo n.º 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")))
Ejemplo n.º 2
0
 def create_manifest(self, package_dir, manifest_file):
     cli_command = CliCommand("summain",
                              self.commands.get_command_template("summain"))
     command = cli_command.get_command(
         dict(manifest_file=manifest_file, package_dir=package_dir))
     print(command)
     out = check_output(command)
     return out
Ejemplo n.º 3
0
 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])
Ejemplo n.º 4
0
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
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
Ejemplo n.º 6
0
 def test_get_cli_command(self):
     cli_command = CliCommand("echo", ['echo', string.Template('$input')])
     command = cli_command.get_command({'input': 'foo'})
     cli_execution = CliExecution(command)
     process_output = cli_execution.execute()
     print(process_output)
Ejemplo n.º 7
0
def gpg_encrypt_file_passphrase(file, passphrase):
    return CliCommand.get_command("gpg_passphrase_encrypt_file", {'file': file, 'passphrase': passphrase})