Skip to content

Commit

Permalink
Fix test: ensure that deprecation warnings don't interfere with test …
Browse files Browse the repository at this point in the history
…suite

Once CAST5 is deprecated, a deprecation warning might arise in
addition to the warnings about already-protected secret keys might not
be the first warning.

Instead, we have the test look through the warnings and validate the
content of any matching warning.
  • Loading branch information
dkg committed Jun 28, 2023
1 parent ba04c11 commit fb885e6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/test_10_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ def test_protect_pubkey(self, rsa_pub, recwarn):
def test_protect_protected_key(self, rsa_enc, recwarn):
rsa_enc.protect('QwertyUiop', SymmetricKeyAlgorithm.CAST5, HashAlgorithm.SHA1)

w = recwarn.pop(UserWarning)
assert str(w.message) == "This key is already protected with a passphrase - " \
"please unlock it before attempting to specify a new passphrase"
assert w.filename == __file__
warning = "This key is already protected with a passphrase - please unlock it before attempting to specify a new passphrase"
msgs = list(filter(lambda x: str(x.message) == warning, recwarn))
assert len(msgs) == 1
assert msgs[0].filename == __file__

def test_unlock_wrong_passphrase(self, rsa_enc):
with pytest.raises(PGPDecryptionError):
Expand Down

0 comments on commit fb885e6

Please sign in to comment.