summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2020-09-05 17:36:58 +0200
committerMichał Górny <mgorny@gentoo.org>2020-09-05 17:37:12 +0200
commit61c3f0a91582ad337bbaeea06472f23816478ce8 (patch)
tree99fb958798a713c00a3220069937121478f8cd1c /tests
parentd418c9e19970f62143b27b433c44215a249f1a9c (diff)
downloadgemato-61c3f0a91582ad337bbaeea06472f23816478ce8.tar.gz
Add gpg-wrap command
Closes: https://github.com/mgorny/gemato/issues/18 Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_openpgp.py38
1 files changed, 38 insertions, 0 deletions
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