Skip to content

Commit 301e29a

Browse files
authored
Don't test that invalid RSA keys can be imported (#1139)
* Don't test that invalid RSA keys can be imported test_check_pr_897 asserts that an invalid key is correctly detected as invalid. However, in doing so, it also asserts that the invalid key is considered *valid* at parse time. Ideally, the underlying cryptography library would just call RSA_check_key during parsing, but it would then fail this test. Make the test more tolerant by allow either parsing or checking to throw an error. * Review comments, and also update the other test
1 parent 38f9b4e commit 301e29a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tests/test_crypto.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,10 +1206,11 @@ def test_regeneration(self):
12061206

12071207
def test_inconsistent_key(self):
12081208
"""
1209-
`PKey.check` returns `Error` if the key is not consistent.
1209+
Either `load_privatekey` or `PKey.check` returns `Error` if the key is
1210+
not consistent.
12101211
"""
1211-
key = load_privatekey(FILETYPE_PEM, inconsistentPrivateKeyPEM)
12121212
with pytest.raises(Error):
1213+
key = load_privatekey(FILETYPE_PEM, inconsistentPrivateKeyPEM)
12131214
key.check()
12141215

12151216
def test_check_public_key(self):
@@ -1228,10 +1229,11 @@ def test_check_public_key(self):
12281229

12291230
def test_check_pr_897(self):
12301231
"""
1231-
`PKey.check` raises `OpenSSL.crypto.Error` if provided with broken key
1232+
Either `load_privatekey` or `PKey.check` raises `OpenSSL.crypto.Error`
1233+
if provided with broken key
12321234
"""
1233-
pkey = load_privatekey(FILETYPE_PEM, rsa_p_not_prime_pem)
12341235
with pytest.raises(Error):
1236+
pkey = load_privatekey(FILETYPE_PEM, rsa_p_not_prime_pem)
12351237
pkey.check()
12361238

12371239

0 commit comments

Comments
 (0)