Skip to content

Commit

Permalink
fix a variety of deprecation warnings (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
reaperhulk committed May 31, 2023
1 parent 2d94946 commit 4d0dc7a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[tool:pytest]
minversion = 3.0.1
strict = true
addopts = "-r s --strict-markers"
testpaths = tests

[metadata]
Expand Down
19 changes: 10 additions & 9 deletions tests/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4d0dc7a

Please sign in to comment.