Exemple #1
0
 def test_gpg_dearmor_args(self):
     """Verify correct command gets called to dearmor keys
     """
     with mock.patch.object(subp, 'subp', return_value=('', '')) as m_subp:
         gpg.dearmor('key')
         test_call = mock.call(
             ["gpg", "--dearmor"], data='key', decode=False)
         assert test_call == m_subp.call_args
Exemple #2
0
 def test_gpg_dearmor_args(self):
     """Verify correct command gets called to dearmor keys"""
     with mock.patch.object(subp, "subp",
                            return_value=SubpResult("", "")) as m_subp:
         gpg.dearmor("key")
         test_call = mock.call(["gpg", "--dearmor"],
                               data="key",
                               decode=False)
         assert test_call == m_subp.call_args
Exemple #3
0
 def test_dearmor_bad_value(self):
     """This exception is handled by the callee. Ensure it is not caught
     internally.
     """
     with mock.patch.object(subp,
                            "subp",
                            side_effect=subp.ProcessExecutionError):
         with pytest.raises(subp.ProcessExecutionError):
             gpg.dearmor("garbage key value")
Exemple #4
0
    def apt_key_add():
        """apt-key add <file>

        returns filepath to new keyring, or '/dev/null' when an error occurs
        """
        file_name = "/dev/null"
        if not output_file:
            util.logexc(
                LOG, 'Unknown filename, failed to add key: "{}"'.format(data))
        else:
            try:
                key_dir = (CLOUD_INIT_GPG_DIR
                           if hardened else APT_TRUSTED_GPG_DIR)
                stdout = gpg.dearmor(data)
                file_name = "{}{}.gpg".format(key_dir, output_file)
                util.write_file(file_name, stdout)
            except subp.ProcessExecutionError:
                util.logexc(LOG,
                            "Gpg error, failed to add key: {}".format(data))
            except UnicodeDecodeError:
                util.logexc(LOG,
                            "Decode error, failed to add key: {}".format(data))
        return file_name