Skip to content

Commit

Permalink
tests: quickfix flaky error message assertion
Browse files Browse the repository at this point in the history
Every now and then this test fails, because pyca/cryptography
raises an unexpected error message (see pyca/cryptography#8563)

Regardless of whether it is a good idea to assert error messages of
3rd party libraries, this patch provides a quick fix by asserting
that is one of both known error messages.

closes secure-systems-lab#463

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
  • Loading branch information
lukpueh committed Mar 22, 2023
1 parent 5c4f934 commit ef69cfb
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 ef69cfb

Please sign in to comment.