|
6 | 6 | """
|
7 | 7 | import base64
|
8 | 8 | import sys
|
| 9 | +import warnings |
9 | 10 | from datetime import datetime, timedelta
|
10 | 11 | from subprocess import PIPE, Popen
|
11 |
| -from warnings import simplefilter |
12 | 12 |
|
13 | 13 | from cryptography import x509
|
14 | 14 | from cryptography.hazmat.primitives import serialization
|
|
50 | 50 | load_certificate,
|
51 | 51 | load_certificate_request,
|
52 | 52 | load_crl,
|
53 |
| - load_pkcs12, |
54 |
| - load_pkcs7_data, |
55 | 53 | load_privatekey,
|
56 | 54 | load_publickey,
|
57 | 55 | sign,
|
58 | 56 | verify,
|
59 | 57 | )
|
60 | 58 |
|
| 59 | +with pytest.warns(DeprecationWarning): |
| 60 | + from OpenSSL.crypto import load_pkcs12, load_pkcs7_data |
| 61 | + |
61 | 62 | from .util import (
|
62 | 63 | EqualityTestsMixin,
|
63 | 64 | NON_ASCII,
|
@@ -2604,7 +2605,7 @@ def test_load_pkcs12_text_passphrase(self):
|
2604 | 2605 | b"pass:" + passwd,
|
2605 | 2606 | )
|
2606 | 2607 | with pytest.warns(DeprecationWarning) as w:
|
2607 |
| - simplefilter("always") |
| 2608 | + warnings.simplefilter("always") |
2608 | 2609 | p12 = load_pkcs12(p12_str, passphrase=b"whatever".decode("ascii"))
|
2609 | 2610 | msg = "{0} for passphrase is no longer accepted, use bytes".format(
|
2610 | 2611 | WARNING_TYPE_EXPECTED
|
@@ -2823,7 +2824,7 @@ def test_export_without_bytes(self):
|
2823 | 2824 | p12 = self.gen_pkcs12(server_cert_pem, server_key_pem, root_cert_pem)
|
2824 | 2825 |
|
2825 | 2826 | with pytest.warns(DeprecationWarning) as w:
|
2826 |
| - simplefilter("always") |
| 2827 | + warnings.simplefilter("always") |
2827 | 2828 | dumped_p12 = p12.export(passphrase=b"randomtext".decode("ascii"))
|
2828 | 2829 | msg = "{0} for passphrase is no longer accepted, use bytes".format(
|
2829 | 2830 | WARNING_TYPE_EXPECTED
|
@@ -3678,8 +3679,8 @@ def test_export_md5_digest(self):
|
3678 | 3679 | not emit a deprecation warning.
|
3679 | 3680 | """
|
3680 | 3681 | 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") |
3683 | 3684 | assert 0 == len(catcher)
|
3684 | 3685 | dumped_crl = crl.export(self.cert, self.pkey, digest=b"md5")
|
3685 | 3686 | text = _runopenssl(dumped_crl, b"crl", b"-noout", b"-text")
|
@@ -4368,14 +4369,14 @@ def test_sign_verify_with_text(self):
|
4368 | 4369 | cert = load_certificate(FILETYPE_PEM, root_cert_pem)
|
4369 | 4370 | for digest in ["md5", "sha1", "sha256"]:
|
4370 | 4371 | with pytest.warns(DeprecationWarning) as w:
|
4371 |
| - simplefilter("always") |
| 4372 | + warnings.simplefilter("always") |
4372 | 4373 | sig = sign(priv_key, content, digest)
|
4373 | 4374 | assert "{0} for data is no longer accepted, use bytes".format(
|
4374 | 4375 | WARNING_TYPE_EXPECTED
|
4375 | 4376 | ) == str(w[-1].message)
|
4376 | 4377 |
|
4377 | 4378 | with pytest.warns(DeprecationWarning) as w:
|
4378 |
| - simplefilter("always") |
| 4379 | + warnings.simplefilter("always") |
4379 | 4380 | verify(cert, sig, content, digest)
|
4380 | 4381 | assert "{0} for data is no longer accepted, use bytes".format(
|
4381 | 4382 | WARNING_TYPE_EXPECTED
|
|
0 commit comments