Skip to content

Commit

Permalink
Merge pull request #546 from lukpueh/fix-unexpected-rsa-err
Browse files Browse the repository at this point in the history
tests: quickfix flaky error message assertion
  • Loading branch information
jku authored Mar 22, 2023
2 parents 5c4f934 + ef69cfb commit c79b29b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,6 @@ def test_rsa(self): # pylint: disable=too-many-locals,too-many-statements
CryptoError,
"Password was not given but private key is encrypted",
),
# Error on encrypted but bad pw passed
(
[fn_encrypted],
{"password": "bad pw"},
CryptoError,
"Bad decrypt. Incorrect password?",
),
# Error on pw and prompt
(
[fn_default],
Expand All @@ -307,6 +300,18 @@ def test_rsa(self): # pylint: disable=too-many-locals,too-many-statements
),
)

# Error on encrypted but bad pw passed
# NOTE: for some key+pw combos the error differs, see pyca/cryptography#8563
with self.assertRaises(CryptoError) as ctx:
import_rsa_privatekey_from_file(fn_encrypted, password="bad pw")

error = str(ctx.exception)
self.assertTrue(
"Bad decrypt. Incorrect password?" in error
or "Could not deserialize key data" in error,
f"unexpected: {error}",
)

# Error on encrypted but bad pw prompted
err_msg = "Password was not given but private key is encrypted"
with self.assertRaises(CryptoError) as ctx, mock.patch(
Expand Down

0 comments on commit c79b29b

Please sign in to comment.