From 17cb140b2a3b4acd2d9b62c66ca2d96757677cd0 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Wed, 14 Jun 2023 17:33:17 -0400 Subject: [PATCH] Avoid looking for encrypted messages with "Plaintext" encoding This reduces the number of SKIPPED and XFAIL messages from the test suite. Given where the cleanup is happening, also make the remaining XFAIL messages a little clearer. --- tests/test_05_actions.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_05_actions.py b/tests/test_05_actions.py index 8a801c9c..55b088cc 100644 --- a/tests/test_05_actions.py +++ b/tests/test_05_actions.py @@ -621,6 +621,7 @@ def targette_sec(): seckeys = [ PGPKey.from_file(f)[0] for f in sorted(glob.glob('tests/testdata/keys/*.sec.asc')) ] pubkeys = [ PGPKey.from_file(f)[0] for f in sorted(glob.glob('tests/testdata/keys/*.pub.asc')) ] +symalgos = sorted(filter(lambda x: x is not SymmetricKeyAlgorithm.Plaintext, sorted(SymmetricKeyAlgorithm))) class TestPGPKey_Actions(object): sigs = {} @@ -906,14 +907,14 @@ def test_gpg_import_abe(self, abe): self.gpg_verify(abe) @pytest.mark.parametrize('pub,cipher', - itertools.product(pubkeys, sorted(SymmetricKeyAlgorithm)), - ids=['{}:{}-{}'.format(pk.key_algorithm.name, pk.key_size, c.name) for pk, c in itertools.product(pubkeys, sorted(SymmetricKeyAlgorithm))]) + itertools.product(pubkeys, symalgos), + ids=['{}:{}-{}'.format(pk.key_algorithm.name, pk.key_size, c.name) for pk, c in itertools.product(pubkeys, symalgos)]) def test_encrypt_message(self, pub, cipher): if pub.key_algorithm in {PubKeyAlgorithm.DSA}: pytest.skip('Asymmetric encryption only implemented for RSA/ECDH currently') - if cipher in {SymmetricKeyAlgorithm.Plaintext, SymmetricKeyAlgorithm.Twofish256, SymmetricKeyAlgorithm.IDEA}: - pytest.xfail('Symmetric cipher {} not supported for encryption'.format(cipher)) + if cipher in {SymmetricKeyAlgorithm.Twofish256, SymmetricKeyAlgorithm.IDEA}: + pytest.xfail(f'{cipher!r} not supported for encryption') # test encrypting a message mtxt = "This message will have been encrypted" @@ -925,7 +926,7 @@ def test_encrypt_message(self, pub, cipher): @pytest.mark.order(after='test_encrypt_message') @pytest.mark.parametrize('sf,cipher', - itertools.product(sorted(glob.glob('tests/testdata/keys/*.sec.asc')), sorted(SymmetricKeyAlgorithm))) + itertools.product(sorted(glob.glob('tests/testdata/keys/*.sec.asc')), symalgos)) def test_decrypt_message(self, sf, cipher): # test decrypting a message sec, _ = PGPKey.from_file(sf) @@ -949,7 +950,7 @@ def test_decrypt_message(self, sf, cipher): @pytest.mark.order(after='test_encrypt_message') @pytest.mark.parametrize('sf,cipher', - itertools.product(sorted(glob.glob('tests/testdata/keys/*.sec.asc')), sorted(SymmetricKeyAlgorithm))) + itertools.product(sorted(glob.glob('tests/testdata/keys/*.sec.asc')), symalgos)) def test_sign_encrypted_message(self, sf, cipher): # test decrypting a message sec, _ = PGPKey.from_file(sf)