Skip to content

Commit ef69cfb

Browse files
committed
tests: quickfix flaky error message assertion
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 #463 Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
1 parent 5c4f934 commit ef69cfb

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

tests/test_interface.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,6 @@ def test_rsa(self): # pylint: disable=too-many-locals,too-many-statements
276276
CryptoError,
277277
"Password was not given but private key is encrypted",
278278
),
279-
# Error on encrypted but bad pw passed
280-
(
281-
[fn_encrypted],
282-
{"password": "bad pw"},
283-
CryptoError,
284-
"Bad decrypt. Incorrect password?",
285-
),
286279
# Error on pw and prompt
287280
(
288281
[fn_default],
@@ -307,6 +300,18 @@ def test_rsa(self): # pylint: disable=too-many-locals,too-many-statements
307300
),
308301
)
309302

303+
# Error on encrypted but bad pw passed
304+
# NOTE: for some key+pw combos the error differs, see pyca/cryptography#8563
305+
with self.assertRaises(CryptoError) as ctx:
306+
import_rsa_privatekey_from_file(fn_encrypted, password="bad pw")
307+
308+
error = str(ctx.exception)
309+
self.assertTrue(
310+
"Bad decrypt. Incorrect password?" in error
311+
or "Could not deserialize key data" in error,
312+
f"unexpected: {error}",
313+
)
314+
310315
# Error on encrypted but bad pw prompted
311316
err_msg = "Password was not given but private key is encrypted"
312317
with self.assertRaises(CryptoError) as ctx, mock.patch(

0 commit comments

Comments
 (0)