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 :
@@ -2871,6 +2872,7 @@ def test_ssl_in_multiple_threads(self):
2871
2872
# See GH-124984: OpenSSL is not thread safe.
2872
2873
threads = []
2873
2874
2875
+ warnings_filters = sys .flags .context_aware_warnings
2874
2876
global USE_SAME_TEST_CONTEXT
2875
2877
USE_SAME_TEST_CONTEXT = True
2876
2878
try :
@@ -2879,7 +2881,10 @@ def test_ssl_in_multiple_threads(self):
2879
2881
self .test_alpn_protocols ,
2880
2882
self .test_getpeercert ,
2881
2883
self .test_crl_check ,
2882
- self .test_check_hostname_idn ,
2884
+ functools .partial (
2885
+ self .test_check_hostname_idn ,
2886
+ warnings_filters = warnings_filters ,
2887
+ ),
2883
2888
self .test_wrong_cert_tls12 ,
2884
2889
self .test_wrong_cert_tls13 ,
2885
2890
):
@@ -3125,7 +3130,7 @@ def test_dual_rsa_ecc(self):
3125
3130
cipher = s .cipher ()[0 ].split ('-' )
3126
3131
self .assertTrue (cipher [:2 ], ('ECDHE' , 'ECDSA' ))
3127
3132
3128
- def test_check_hostname_idn (self ):
3133
+ def test_check_hostname_idn (self , warnings_filters = True ):
3129
3134
if support .verbose :
3130
3135
sys .stdout .write ("\n " )
3131
3136
@@ -3180,16 +3185,30 @@ def test_check_hostname_idn(self):
3180
3185
server_hostname = "python.example.org" ) as s :
3181
3186
with self .assertRaises (ssl .CertificateError ):
3182
3187
s .connect ((HOST , server .port ))
3183
- with ThreadedEchoServer (context = server_context , chatty = True ) as server :
3184
- with warnings_helper .check_no_resource_warning (self ):
3185
- with self .assertRaises (UnicodeError ):
3186
- context .wrap_socket (socket .socket (),
3187
- server_hostname = '.pythontest.net' )
3188
- with ThreadedEchoServer (context = server_context , chatty = True ) as server :
3189
- with warnings_helper .check_no_resource_warning (self ):
3190
- with self .assertRaises (UnicodeDecodeError ):
3191
- context .wrap_socket (socket .socket (),
3192
- server_hostname = b'k\xf6 nig.idn.pythontest.net' )
3188
+ with (
3189
+ ThreadedEchoServer (context = server_context , chatty = True ) as server ,
3190
+ (
3191
+ warnings_helper .check_no_resource_warning (self )
3192
+ if warnings_filters
3193
+ else nullcontext ()
3194
+ ),
3195
+ self .assertRaises (UnicodeError ),
3196
+ ):
3197
+ context .wrap_socket (socket .socket (), server_hostname = '.pythontest.net' )
3198
+
3199
+ with (
3200
+ ThreadedEchoServer (context = server_context , chatty = True ) as server ,
3201
+ (
3202
+ warnings_helper .check_no_resource_warning (self )
3203
+ if warnings_filters
3204
+ else nullcontext ()
3205
+ ),
3206
+ self .assertRaises (UnicodeDecodeError ),
3207
+ ):
3208
+ context .wrap_socket (
3209
+ socket .socket (),
3210
+ server_hostname = b'k\xf6 nig.idn.pythontest.net' ,
3211
+ )
3193
3212
3194
3213
def test_wrong_cert_tls12 (self ):
3195
3214
"""Connecting when the server rejects the client's certificate
0 commit comments