-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-126483: disable warnings filters mutation in concurrent test_check… #132694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
6a0d82f
5b109a6
535baad
0a09052
148e41d
43e73cf
aa8c74a
2b69467
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Test the support for SSL and sockets | ||
|
||
o | ||
import sys | ||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import unittest | ||
import unittest.mock | ||
|
@@ -31,6 +31,7 @@ | |
import platform | ||
import sysconfig | ||
import functools | ||
from contextlib import nullcontext | ||
try: | ||
import ctypes | ||
except ImportError: | ||
|
@@ -2843,6 +2844,7 @@ def test_ssl_in_multiple_threads(self): | |
# See GH-124984: OpenSSL is not thread safe. | ||
threads = [] | ||
|
||
warnings_filters = sys.flags.context_aware_warnings | ||
global USE_SAME_TEST_CONTEXT | ||
USE_SAME_TEST_CONTEXT = True | ||
try: | ||
|
@@ -2851,7 +2853,10 @@ def test_ssl_in_multiple_threads(self): | |
self.test_alpn_protocols, | ||
self.test_getpeercert, | ||
self.test_crl_check, | ||
self.test_check_hostname_idn, | ||
partial( | ||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.test_check_hostname_idn, | ||
warnings_filters=warnings_filters, | ||
), | ||
self.test_wrong_cert_tls12, | ||
self.test_wrong_cert_tls13, | ||
): | ||
|
@@ -3097,7 +3102,7 @@ def test_dual_rsa_ecc(self): | |
cipher = s.cipher()[0].split('-') | ||
self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA')) | ||
|
||
def test_check_hostname_idn(self): | ||
def test_check_hostname_idn(self, warnings_filters=True): | ||
if support.verbose: | ||
sys.stdout.write("\n") | ||
|
||
|
@@ -3152,16 +3157,26 @@ def test_check_hostname_idn(self): | |
server_hostname="python.example.org") as s: | ||
with self.assertRaises(ssl.CertificateError): | ||
s.connect((HOST, server.port)) | ||
with ThreadedEchoServer(context=server_context, chatty=True) as server: | ||
with warnings_helper.check_no_resource_warning(self): | ||
with self.assertRaises(UnicodeError): | ||
context.wrap_socket(socket.socket(), | ||
server_hostname='.pythontest.net') | ||
with ThreadedEchoServer(context=server_context, chatty=True) as server: | ||
with warnings_helper.check_no_resource_warning(self): | ||
with self.assertRaises(UnicodeDecodeError): | ||
context.wrap_socket(socket.socket(), | ||
server_hostname=b'k\xf6nig.idn.pythontest.net') | ||
with ( | ||
ThreadedEchoServer(context=server_context, chatty=True) as server, | ||
warnings_helper.check_no_resource_warning(self) | ||
if warnings_filters | ||
else nullcontext(), | ||
self.assertRaises(UnicodeError), | ||
): | ||
context.wrap_socket(socket.socket(), server_hostname='.pythontest.net') | ||
|
||
with ( | ||
ThreadedEchoServer(context=server_context, chatty=True) as server, | ||
warnings_helper.check_no_resource_warning(self) | ||
if warnings_filters | ||
else nullcontext(), | ||
self.assertRaises(UnicodeDecodeError), | ||
): | ||
context.wrap_socket( | ||
socket.socket(), | ||
server_hostname=b'k\xf6nig.idn.pythontest.net', | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest the following: def get_warnings_filter_context(self, warnings_filter):
if warnings_filters:
return warnings_helper.check_no_resource_warning(self)
return nullcontext() so that it can be used as follows: with (
ThreadedEchoServer(context=server_context, chatty=True) as server,
self.get_warnings_filter_context(warnings_filters),
self.assertRaises(UnicodeError),
):
context.wrap_socket(socket.socket(), server_hostname='.pythontest.net')
with (
ThreadedEchoServer(context=server_context, chatty=True) as server,
self.get_warnings_filter_context(warnings_filters),
self.assertRaises(UnicodeDecodeError),
):
context.wrap_socket(
socket.socket(),
server_hostname=b'k\xf6nig.idn.pythontest.net',
) It took me a while to see the ternary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add some extra parenthesis, like ruff would |
||
|
||
def test_wrong_cert_tls12(self): | ||
"""Connecting when the server rejects the client's certificate | ||
|
Uh oh!
There was an error while loading. Please reload this page.