diff options
author | Tim Burke <tim.burke@gmail.com> | 2018-07-28 17:58:01 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2018-07-28 20:58:01 -0400 |
commit | 4b958d16569f87cc6499f03ce96a1b6cc9a0ea08 (patch) | |
tree | f02a1e5b2aad4e5ba61aece338334ad32835c683 /tests/hazmat/primitives/test_rsa.py | |
parent | e722e557e08171e265008711b824df44d4e9ec7d (diff) | |
download | cryptography-4b958d16569f87cc6499f03ce96a1b6cc9a0ea08.tar.gz cryptography-4b958d16569f87cc6499f03ce96a1b6cc9a0ea08.tar.bz2 cryptography-4b958d16569f87cc6499f03ce96a1b6cc9a0ea08.zip |
Test for expected CryptographyDeprecationWarnings (#4372)
The remaining calls to `signer()` and `verifier()` are exercising the
deprecated API intentionally. Let's test that the deprecation warnings
are being raised as expected.
Closes #4311; see also #4314.
Diffstat (limited to 'tests/hazmat/primitives/test_rsa.py')
-rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index ec08eade..4d56bcd4 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -541,7 +541,8 @@ class TestRSASignature(object): ) def test_use_after_finalize(self, backend): private_key = RSA_KEY_512.private_key(backend) - signer = private_key.signer(padding.PKCS1v15(), hashes.SHA1()) + with pytest.warns(CryptographyDeprecationWarning): + signer = private_key.signer(padding.PKCS1v15(), hashes.SHA1()) signer.update(b"sign me") signer.finalize() with pytest.raises(AlreadyFinalized): @@ -658,7 +659,8 @@ class TestRSASignature(object): ) def test_prehashed_unsupported_in_signer_ctx(self, backend): private_key = RSA_KEY_512.private_key(backend) - with pytest.raises(TypeError): + with pytest.raises(TypeError), \ + pytest.warns(CryptographyDeprecationWarning): private_key.signer( padding.PKCS1v15(), asym_utils.Prehashed(hashes.SHA1()) @@ -672,7 +674,8 @@ class TestRSASignature(object): ) def test_prehashed_unsupported_in_verifier_ctx(self, backend): public_key = RSA_KEY_512.private_key(backend).public_key() - with pytest.raises(TypeError): + with pytest.raises(TypeError), \ + pytest.warns(CryptographyDeprecationWarning): public_key.verifier( b"0" * 64, padding.PKCS1v15(), @@ -702,14 +705,12 @@ class TestRSAVerification(object): e=public["public_exponent"], n=public["modulus"] ).public_key(backend) - with pytest.warns(CryptographyDeprecationWarning): - verifier = public_key.verifier( - binascii.unhexlify(example["signature"]), - padding.PKCS1v15(), - hashes.SHA1() - ) - verifier.update(binascii.unhexlify(example["message"])) - verifier.verify() + public_key.verify( + binascii.unhexlify(example["signature"]), + binascii.unhexlify(example["message"]), + padding.PKCS1v15(), + hashes.SHA1() + ) @pytest.mark.supported( only_if=lambda backend: backend.rsa_padding_supported( @@ -932,11 +933,12 @@ class TestRSAVerification(object): b"sign me", padding.PKCS1v15(), hashes.SHA1() ) - verifier = public_key.verifier( - signature, - padding.PKCS1v15(), - hashes.SHA1() - ) + with pytest.warns(CryptographyDeprecationWarning): + verifier = public_key.verifier( + signature, + padding.PKCS1v15(), + hashes.SHA1() + ) verifier.update(b"sign me") verifier.verify() with pytest.raises(AlreadyFinalized): @@ -962,7 +964,8 @@ class TestRSAVerification(object): public_key = RSA_KEY_512.public_numbers.public_key(backend) signature = 1234 - with pytest.raises(TypeError): + with pytest.raises(TypeError), \ + pytest.warns(CryptographyDeprecationWarning): public_key.verifier( signature, padding.PKCS1v15(), |