31
31
import platform
32
32
import sysconfig
33
33
import functools
34
+ from contextlib import nullcontext
34
35
try :
35
36
import ctypes
36
37
except ImportError :
@@ -2843,6 +2844,7 @@ def test_ssl_in_multiple_threads(self):
2843
2844
# See GH-124984: OpenSSL is not thread safe.
2844
2845
threads = []
2845
2846
2847
+ warnings_filters = sys .flags .context_aware_warnings
2846
2848
global USE_SAME_TEST_CONTEXT
2847
2849
USE_SAME_TEST_CONTEXT = True
2848
2850
try :
@@ -2851,7 +2853,10 @@ def test_ssl_in_multiple_threads(self):
2851
2853
self .test_alpn_protocols ,
2852
2854
self .test_getpeercert ,
2853
2855
self .test_crl_check ,
2854
- self .test_check_hostname_idn ,
2856
+ functools .partial (
2857
+ self .test_check_hostname_idn ,
2858
+ warnings_filters = warnings_filters ,
2859
+ ),
2855
2860
self .test_wrong_cert_tls12 ,
2856
2861
self .test_wrong_cert_tls13 ,
2857
2862
):
@@ -3097,7 +3102,7 @@ def test_dual_rsa_ecc(self):
3097
3102
cipher = s .cipher ()[0 ].split ('-' )
3098
3103
self .assertTrue (cipher [:2 ], ('ECDHE' , 'ECDSA' ))
3099
3104
3100
- def test_check_hostname_idn (self ):
3105
+ def test_check_hostname_idn (self , warnings_filters = True ):
3101
3106
if support .verbose :
3102
3107
sys .stdout .write ("\n " )
3103
3108
@@ -3152,16 +3157,30 @@ def test_check_hostname_idn(self):
3152
3157
server_hostname = "python.example.org" ) as s :
3153
3158
with self .assertRaises (ssl .CertificateError ):
3154
3159
s .connect ((HOST , server .port ))
3155
- with ThreadedEchoServer (context = server_context , chatty = True ) as server :
3156
- with warnings_helper .check_no_resource_warning (self ):
3157
- with self .assertRaises (UnicodeError ):
3158
- context .wrap_socket (socket .socket (),
3159
- server_hostname = '.pythontest.net' )
3160
- with ThreadedEchoServer (context = server_context , chatty = True ) as server :
3161
- with warnings_helper .check_no_resource_warning (self ):
3162
- with self .assertRaises (UnicodeDecodeError ):
3163
- context .wrap_socket (socket .socket (),
3164
- server_hostname = b'k\xf6 nig.idn.pythontest.net' )
3160
+ with (
3161
+ ThreadedEchoServer (context = server_context , chatty = True ) as server ,
3162
+ (
3163
+ warnings_helper .check_no_resource_warning (self )
3164
+ if warnings_filters
3165
+ else nullcontext ()
3166
+ ),
3167
+ self .assertRaises (UnicodeError ),
3168
+ ):
3169
+ context .wrap_socket (socket .socket (), server_hostname = '.pythontest.net' )
3170
+
3171
+ with (
3172
+ ThreadedEchoServer (context = server_context , chatty = True ) as server ,
3173
+ (
3174
+ warnings_helper .check_no_resource_warning (self )
3175
+ if warnings_filters
3176
+ else nullcontext ()
3177
+ ),
3178
+ self .assertRaises (UnicodeDecodeError ),
3179
+ ):
3180
+ context .wrap_socket (
3181
+ socket .socket (),
3182
+ server_hostname = b'k\xf6 nig.idn.pythontest.net' ,
3183
+ )
3165
3184
3166
3185
def test_wrong_cert_tls12 (self ):
3167
3186
"""Connecting when the server rejects the client's certificate
0 commit comments