From 61c3f0a91582ad337bbaeea06472f23816478ce8 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Sat, 5 Sep 2020 17:36:58 +0200 Subject: Add gpg-wrap command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: https://github.com/mgorny/gemato/issues/18 Signed-off-by: Michał Górny --- tests/test_openpgp.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests') diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py index dbb71e5..69f0aad 100644 --- a/tests/test_openpgp.py +++ b/tests/test_openpgp.py @@ -6,6 +6,8 @@ import datetime import io import os +import shlex +import signal import tempfile import pytest @@ -841,3 +843,39 @@ def test_refresh_wkd_fallback_to_hkp(openpgp_env_with_refresh, ]) def test_get_wkd_url(email, expected): assert OpenPGPEnvironment.get_wkd_url(email) == expected + + +@pytest.mark.parametrize( + 'command,expected,match', + [('true', 0, None), + ('false', 1, None), + ('gpg --verify {tmp_path}/Manifest', 0, None), + ('gpg --verify {tmp_path}/Manifest.subkey', 2, None), + ('sh -c "kill $$"', -signal.SIGTERM, + f'Child process terminated due to signal: ' + f'{signal.strsignal(signal.SIGTERM)}'), + ('sh -c "kill -USR1 $$"', -signal.SIGUSR1, + f'Child process terminated due to signal: ' + f'{signal.strsignal(signal.SIGUSR1)}'), + ]) +def test_cli_gpg_wrap(tmp_path, caplog, command, expected, match): + with open(tmp_path / '.key.bin', 'wb') as f: + f.write(VALID_PUBLIC_KEY) + with open(tmp_path / 'Manifest', 'w') as f: + f.write(SIGNED_MANIFEST) + with open(tmp_path / 'Manifest.subkey', 'w') as f: + f.write(SUBKEY_SIGNED_MANIFEST) + + command = [x.replace('{tmp_path}', str(tmp_path)) + for x in shlex.split(command)] + retval = gemato.cli.main(['gemato', 'gpg-wrap', + '--openpgp-key', + str(tmp_path / '.key.bin'), + '--no-refresh-keys', + '--'] + command) + if str(OpenPGPNoImplementation('')) in caplog.text: + pytest.skip('OpenPGP implementation missing') + + assert retval == expected + if match is not None: + assert match in caplog.text -- cgit v1.2.3