From 4d0dc7ae316bf5cf61af6bd675b532cfe22542ca Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Wed, 31 May 2023 11:13:19 +0800 Subject: [PATCH] fix a variety of deprecation warnings (#1218) --- setup.cfg | 3 +-- tests/test_crypto.py | 19 ++++++++++--------- tests/test_ssl.py | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/setup.cfg b/setup.cfg index 40a93c1db..c33dc2e3a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,5 @@ [tool:pytest] -minversion = 3.0.1 -strict = true +addopts = "-r s --strict-markers" testpaths = tests [metadata] diff --git a/tests/test_crypto.py b/tests/test_crypto.py index 0f67d207c..34292318d 100644 --- a/tests/test_crypto.py +++ b/tests/test_crypto.py @@ -6,9 +6,9 @@ """ import base64 import sys +import warnings from datetime import datetime, timedelta from subprocess import PIPE, Popen -from warnings import simplefilter from cryptography import x509 from cryptography.hazmat.primitives import serialization @@ -50,14 +50,15 @@ load_certificate, load_certificate_request, load_crl, - load_pkcs12, - load_pkcs7_data, load_privatekey, load_publickey, sign, verify, ) +with pytest.warns(DeprecationWarning): + from OpenSSL.crypto import load_pkcs12, load_pkcs7_data + from .util import ( EqualityTestsMixin, NON_ASCII, @@ -2604,7 +2605,7 @@ def test_load_pkcs12_text_passphrase(self): b"pass:" + passwd, ) with pytest.warns(DeprecationWarning) as w: - simplefilter("always") + warnings.simplefilter("always") p12 = load_pkcs12(p12_str, passphrase=b"whatever".decode("ascii")) msg = "{0} for passphrase is no longer accepted, use bytes".format( WARNING_TYPE_EXPECTED @@ -2823,7 +2824,7 @@ def test_export_without_bytes(self): p12 = self.gen_pkcs12(server_cert_pem, server_key_pem, root_cert_pem) with pytest.warns(DeprecationWarning) as w: - simplefilter("always") + warnings.simplefilter("always") dumped_p12 = p12.export(passphrase=b"randomtext".decode("ascii")) msg = "{0} for passphrase is no longer accepted, use bytes".format( WARNING_TYPE_EXPECTED @@ -3678,8 +3679,8 @@ def test_export_md5_digest(self): not emit a deprecation warning. """ crl = self._get_crl() - with pytest.warns(None) as catcher: - simplefilter("always") + with warnings.catch_warnings(record=True) as catcher: + warnings.simplefilter("always") assert 0 == len(catcher) dumped_crl = crl.export(self.cert, self.pkey, digest=b"md5") text = _runopenssl(dumped_crl, b"crl", b"-noout", b"-text") @@ -4368,14 +4369,14 @@ def test_sign_verify_with_text(self): cert = load_certificate(FILETYPE_PEM, root_cert_pem) for digest in ["md5", "sha1", "sha256"]: with pytest.warns(DeprecationWarning) as w: - simplefilter("always") + warnings.simplefilter("always") sig = sign(priv_key, content, digest) assert "{0} for data is no longer accepted, use bytes".format( WARNING_TYPE_EXPECTED ) == str(w[-1].message) with pytest.warns(DeprecationWarning) as w: - simplefilter("always") + warnings.simplefilter("always") verify(cert, sig, content, digest) assert "{0} for data is no longer accepted, use bytes".format( WARNING_TYPE_EXPECTED diff --git a/tests/test_ssl.py b/tests/test_ssl.py index 024436f06..804288e33 100644 --- a/tests/test_ssl.py +++ b/tests/test_ssl.py @@ -2769,7 +2769,7 @@ def test_client_set_session(self): ctx = Context(TLSv1_2_METHOD) ctx.use_privatekey(key) ctx.use_certificate(cert) - ctx.set_session_id("unity-test") + ctx.set_session_id(b"unity-test") def makeServer(socket): server = Connection(ctx, socket)