def test___import_pgp_key_gpg_import_fail(self, gpg_mock):
        gpg_mock.side_effect = sh.ErrorReturnCode('gpg', b'mock stdout',
                                                  b'mock error')

        pgp_private_key = TestStepImplementerSignContainerImagePodman.TEST_FAKE_PRIVATE_KEY

        with self.assertRaisesRegex(
                StepRunnerException,
                re.compile(
                    r"Error importing pgp private key:"
                    r".*RAN: gpg"
                    r".*STDOUT:"
                    r".*mock stdout"
                    r".*STDERR:"
                    r".*mock error", re.DOTALL)):
            PodmanSign._PodmanSign__import_pgp_key(
                pgp_private_key=pgp_private_key)

        gpg_mock.assert_called_once_with('--import',
                                         '--fingerprint',
                                         '--with-colons',
                                         '--import-options=import-show',
                                         _in=pgp_private_key,
                                         _out=Any(IOBase),
                                         _err_to_out=True,
                                         _tee='out')
Beispiel #2
0
    def test___import_pgp_key_fail_get_fingerprint(self, gpg_mock):
        pgp_private_key=TestStepImplementerSignContainerImagePodman.TEST_FAKE_PRIVATE_KEY

        with self.assertRaisesRegex(
            StepRunnerException,
            re.compile(
                r"Error getting PGP fingerprint for PGP key"
                r" to sign container image\(s\) with. See stdout and stderr for more info.",
                re.DOTALL
            )
        ):
            PodmanSign._PodmanSign__import_pgp_key(
                pgp_private_key=pgp_private_key
            )

        gpg_mock.assert_called_once_with(
            '--import',
            '--fingerprint',
            '--with-colons',
            '--import-options=import-show',
            _in=pgp_private_key,
            _out=Any(IOBase),
            _err_to_out=True,
            _tee='out'
        )
    def test___import_pgp_key_success(self, gpg_mock):
        gpg_mock.side_effect = TestStepImplementerSignContainerImagePodman.gpg_side_effect

        pgp_private_key = TestStepImplementerSignContainerImagePodman.TEST_FAKE_PRIVATE_KEY
        PodmanSign._PodmanSign__import_pgp_key(pgp_private_key=pgp_private_key)
        gpg_mock.assert_called_once_with('--import',
                                         '--fingerprint',
                                         '--with-colons',
                                         '--import-options=import-show',
                                         _in=pgp_private_key,
                                         _out=Any(IOBase),
                                         _err_to_out=True,
                                         _tee='out')