From 270933c1a2afa0aa60409946bb7319d85fd60059 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Fri, 10 Nov 2017 23:19:05 -0500 Subject: Use a different warning class so users get warnings (#4014) * Use a different warning class so users get warnings * fixed tests * do our own warning class * typo * flake8 --- tests/hazmat/primitives/test_asym_utils.py | 7 +++++-- tests/hazmat/primitives/test_dsa.py | 9 +++++---- tests/hazmat/primitives/test_ec.py | 9 +++++---- tests/hazmat/primitives/test_rsa.py | 20 +++++++++----------- tests/x509/test_x509.py | 4 ++-- 5 files changed, 26 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_asym_utils.py b/tests/hazmat/primitives/test_asym_utils.py index 4835f091..fc9e9fd8 100644 --- a/tests/hazmat/primitives/test_asym_utils.py +++ b/tests/hazmat/primitives/test_asym_utils.py @@ -10,12 +10,15 @@ from cryptography.hazmat.primitives.asymmetric.utils import ( Prehashed, decode_dss_signature, decode_rfc6979_signature, encode_dss_signature, encode_rfc6979_signature, ) +from cryptography.utils import CryptographyDeprecationWarning def test_deprecated_rfc6979_signature(): - sig = pytest.deprecated_call(encode_rfc6979_signature, 1, 1) + with pytest.warns(CryptographyDeprecationWarning): + sig = encode_rfc6979_signature(1, 1) assert sig == b"0\x06\x02\x01\x01\x02\x01\x01" - decoded = pytest.deprecated_call(decode_rfc6979_signature, sig) + with pytest.warns(CryptographyDeprecationWarning): + decoded = decode_rfc6979_signature(sig) assert decoded == (1, 1) diff --git a/tests/hazmat/primitives/test_dsa.py b/tests/hazmat/primitives/test_dsa.py index 89303fed..f08de6a1 100644 --- a/tests/hazmat/primitives/test_dsa.py +++ b/tests/hazmat/primitives/test_dsa.py @@ -18,6 +18,7 @@ from cryptography.hazmat.primitives.asymmetric import dsa from cryptography.hazmat.primitives.asymmetric.utils import ( Prehashed, encode_dss_signature ) +from cryptography.utils import CryptographyDeprecationWarning from .fixtures_dsa import ( DSA_KEY_1024, DSA_KEY_2048, DSA_KEY_3072 @@ -574,9 +575,8 @@ class TestDSAVerification(object): y=vector['y'] ).public_key(backend) sig = encode_dss_signature(vector['r'], vector['s']) - verifier = pytest.deprecated_call( - public_key.verifier, sig, algorithm() - ) + with pytest.warns(CryptographyDeprecationWarning): + verifier = public_key.verifier(sig, algorithm()) verifier.update(vector['msg']) if vector['result'] == "F": @@ -687,7 +687,8 @@ class TestDSASignature(object): ), x=vector['x'] ).private_key(backend) - signer = pytest.deprecated_call(private_key.signer, algorithm()) + with pytest.warns(CryptographyDeprecationWarning): + signer = private_key.signer(algorithm()) signer.update(vector['msg']) signature = signer.finalize() assert signature diff --git a/tests/hazmat/primitives/test_ec.py b/tests/hazmat/primitives/test_ec.py index f493869d..4f08f184 100644 --- a/tests/hazmat/primitives/test_ec.py +++ b/tests/hazmat/primitives/test_ec.py @@ -20,6 +20,7 @@ from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.asymmetric.utils import ( Prehashed, encode_dss_signature ) +from cryptography.utils import CryptographyDeprecationWarning from .fixtures_ec import EC_KEY_SECP384R1 from ...doubles import DummyKeySerializationEncryption @@ -350,13 +351,13 @@ class TestECDSAVectors(object): pkey = key.public_key() assert pkey - signer = pytest.deprecated_call(key.signer, ec.ECDSA(hash_type())) + with pytest.warns(CryptographyDeprecationWarning): + signer = key.signer(ec.ECDSA(hash_type())) signer.update(b"YELLOW SUBMARINE") signature = signer.finalize() - verifier = pytest.deprecated_call( - pkey.verifier, signature, ec.ECDSA(hash_type()) - ) + with pytest.warns(CryptographyDeprecationWarning): + verifier = pkey.verifier(signature, ec.ECDSA(hash_type())) verifier.update(b"YELLOW SUBMARINE") verifier.verify() diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index fc956ecb..09820429 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -24,6 +24,7 @@ from cryptography.hazmat.primitives.asymmetric import ( from cryptography.hazmat.primitives.asymmetric.rsa import ( RSAPrivateNumbers, RSAPublicNumbers ) +from cryptography.utils import CryptographyDeprecationWarning from .fixtures_rsa import ( RSA_KEY_1024, RSA_KEY_1025, RSA_KEY_1026, RSA_KEY_1027, RSA_KEY_1028, @@ -383,11 +384,8 @@ class TestRSASignature(object): n=private["modulus"] ) ).private_key(backend) - signer = pytest.deprecated_call( - private_key.signer, - padding.PKCS1v15(), - hashes.SHA1() - ) + with pytest.warns(CryptographyDeprecationWarning): + signer = private_key.signer(padding.PKCS1v15(), hashes.SHA1()) signer.update(binascii.unhexlify(example["message"])) signature = signer.finalize() assert binascii.hexlify(signature) == example["signature"] @@ -714,12 +712,12 @@ class TestRSAVerification(object): e=public["public_exponent"], n=public["modulus"] ).public_key(backend) - verifier = pytest.deprecated_call( - public_key.verifier, - binascii.unhexlify(example["signature"]), - padding.PKCS1v15(), - hashes.SHA1() - ) + with pytest.warns(CryptographyDeprecationWarning): + verifier = public_key.verifier( + binascii.unhexlify(example["signature"]), + padding.PKCS1v15(), + hashes.SHA1() + ) verifier.update(binascii.unhexlify(example["message"])) verifier.verify() diff --git a/tests/x509/test_x509.py b/tests/x509/test_x509.py index 97b5a749..27e284a3 100644 --- a/tests/x509/test_x509.py +++ b/tests/x509/test_x509.py @@ -577,7 +577,7 @@ class TestRSACertificate(object): backend ) - with pytest.deprecated_call(): + with pytest.warns(utils.CryptographyDeprecationWarning): assert cert.serial == 2 assert cert.serial_number == 2 @@ -588,7 +588,7 @@ class TestRSACertificate(object): backend ) - with pytest.deprecated_call(): + with pytest.warns(utils.CryptographyDeprecationWarning): cert.serial def test_load_der_cert(self, backend): -- cgit v1.2.3