Skip to content

Commit 4d0dc7a

Browse files
authored
fix a variety of deprecation warnings (#1218)
1 parent 2d94946 commit 4d0dc7a

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

setup.cfg

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[tool:pytest]
2-
minversion = 3.0.1
3-
strict = true
2+
addopts = "-r s --strict-markers"
43
testpaths = tests
54

65
[metadata]

tests/test_crypto.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"""
77
import base64
88
import sys
9+
import warnings
910
from datetime import datetime, timedelta
1011
from subprocess import PIPE, Popen
11-
from warnings import simplefilter
1212

1313
from cryptography import x509
1414
from cryptography.hazmat.primitives import serialization
@@ -50,14 +50,15 @@
5050
load_certificate,
5151
load_certificate_request,
5252
load_crl,
53-
load_pkcs12,
54-
load_pkcs7_data,
5553
load_privatekey,
5654
load_publickey,
5755
sign,
5856
verify,
5957
)
6058

59+
with pytest.warns(DeprecationWarning):
60+
from OpenSSL.crypto import load_pkcs12, load_pkcs7_data
61+
6162
from .util import (
6263
EqualityTestsMixin,
6364
NON_ASCII,
@@ -2604,7 +2605,7 @@ def test_load_pkcs12_text_passphrase(self):
26042605
b"pass:" + passwd,
26052606
)
26062607
with pytest.warns(DeprecationWarning) as w:
2607-
simplefilter("always")
2608+
warnings.simplefilter("always")
26082609
p12 = load_pkcs12(p12_str, passphrase=b"whatever".decode("ascii"))
26092610
msg = "{0} for passphrase is no longer accepted, use bytes".format(
26102611
WARNING_TYPE_EXPECTED
@@ -2823,7 +2824,7 @@ def test_export_without_bytes(self):
28232824
p12 = self.gen_pkcs12(server_cert_pem, server_key_pem, root_cert_pem)
28242825

28252826
with pytest.warns(DeprecationWarning) as w:
2826-
simplefilter("always")
2827+
warnings.simplefilter("always")
28272828
dumped_p12 = p12.export(passphrase=b"randomtext".decode("ascii"))
28282829
msg = "{0} for passphrase is no longer accepted, use bytes".format(
28292830
WARNING_TYPE_EXPECTED
@@ -3678,8 +3679,8 @@ def test_export_md5_digest(self):
36783679
not emit a deprecation warning.
36793680
"""
36803681
crl = self._get_crl()
3681-
with pytest.warns(None) as catcher:
3682-
simplefilter("always")
3682+
with warnings.catch_warnings(record=True) as catcher:
3683+
warnings.simplefilter("always")
36833684
assert 0 == len(catcher)
36843685
dumped_crl = crl.export(self.cert, self.pkey, digest=b"md5")
36853686
text = _runopenssl(dumped_crl, b"crl", b"-noout", b"-text")
@@ -4368,14 +4369,14 @@ def test_sign_verify_with_text(self):
43684369
cert = load_certificate(FILETYPE_PEM, root_cert_pem)
43694370
for digest in ["md5", "sha1", "sha256"]:
43704371
with pytest.warns(DeprecationWarning) as w:
4371-
simplefilter("always")
4372+
warnings.simplefilter("always")
43724373
sig = sign(priv_key, content, digest)
43734374
assert "{0} for data is no longer accepted, use bytes".format(
43744375
WARNING_TYPE_EXPECTED
43754376
) == str(w[-1].message)
43764377

43774378
with pytest.warns(DeprecationWarning) as w:
4378-
simplefilter("always")
4379+
warnings.simplefilter("always")
43794380
verify(cert, sig, content, digest)
43804381
assert "{0} for data is no longer accepted, use bytes".format(
43814382
WARNING_TYPE_EXPECTED

tests/test_ssl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,7 @@ def test_client_set_session(self):
27692769
ctx = Context(TLSv1_2_METHOD)
27702770
ctx.use_privatekey(key)
27712771
ctx.use_certificate(cert)
2772-
ctx.set_session_id("unity-test")
2772+
ctx.set_session_id(b"unity-test")
27732773

27742774
def makeServer(socket):
27752775
server = Connection(ctx, socket)

0 commit comments

Comments
 (0)