From 5dff168a23b0d70464cabefedb64b82fdf6b1714 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Sun, 22 Jan 2023 20:07:00 +0100 Subject: tests: Make assert_signature() more reusable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny --- tests/test_openpgp.py | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py index 640e590..17ef8f2 100644 --- a/tests/test_openpgp.py +++ b/tests/test_openpgp.py @@ -426,27 +426,30 @@ MANIFEST_VARIANTS = [ def assert_signature(sig: OpenPGPSignatureList, manifest_var: str, + expect_both: bool = True, ) -> None: """Make assertions about the signature""" if manifest_var == "TWO_SIGNATURE_MANIFEST": - assert sorted(sig) == [ + no_key_sig = OpenPGPSignatureData( + sig_status=OpenPGPSignatureStatus.NO_PUBLIC_KEY) + assert sorted(sig) == sorted([ OpenPGPSignatureData( - fingerprint=SECOND_KEY_FINGERPRINT, - timestamp=datetime.datetime(2023, 1, 21, 17, 16, 24), - primary_key_fingerprint=SECOND_KEY_FINGERPRINT, + fingerprint=KEY_FINGERPRINT, + timestamp=datetime.datetime(2023, 1, 21, 17, 14, 44), + primary_key_fingerprint=KEY_FINGERPRINT, sig_status=OpenPGPSignatureStatus.GOOD, trusted_sig=True, valid_sig=True, ), OpenPGPSignatureData( - fingerprint=KEY_FINGERPRINT, - timestamp=datetime.datetime(2023, 1, 21, 17, 14, 44), - primary_key_fingerprint=KEY_FINGERPRINT, + fingerprint=SECOND_KEY_FINGERPRINT, + timestamp=datetime.datetime(2023, 1, 21, 17, 16, 24), + primary_key_fingerprint=SECOND_KEY_FINGERPRINT, sig_status=OpenPGPSignatureStatus.GOOD, trusted_sig=True, valid_sig=True, - ), - ] + ) if expect_both else no_key_sig, + ]) elif manifest_var == 'SUBKEY_SIGNED_MANIFEST': assert len(sig) == 1 assert sig.fingerprint == SUBKEY_FINGERPRINT @@ -498,25 +501,7 @@ def test_verify_one_out_of_two(): with io.StringIO(TWO_SIGNATURE_MANIFEST) as f: sig = openpgp_env.verify_file(f, require_all_good=False) - assert sig == [ - OpenPGPSignatureData( - fingerprint="81E12C16BD8DCD60BE180845136880E72A7B1384", - timestamp=datetime.datetime(2023, 1, 21, 17, 14, 44), - expire_timestamp=None, - primary_key_fingerprint="81E12C16BD8DCD60BE18" - "0845136880E72A7B1384", - sig_status=OpenPGPSignatureStatus.GOOD, - valid_sig=True, - trusted_sig=True), - OpenPGPSignatureData( - fingerprint="", - timestamp=None, - expire_timestamp=None, - primary_key_fingerprint="", - sig_status=OpenPGPSignatureStatus.NO_PUBLIC_KEY, - valid_sig=False, - trusted_sig=False), - ] + assert_signature(sig, "TWO_SIGNATURE_MANIFEST", expect_both=False) except OpenPGPNoImplementation as e: pytest.skip(str(e)) -- cgit v1.2.3