@@ -30,6 +30,59 @@ def test_timeout_arg(self):
3030 timeout = call_args [0 ][1 ]
3131 assert timeout >= 0 , "socket timeout must be nonnegative"
3232
33+ def test_ssl_server_hostname (self ):
34+ from kazoo .handlers import utils
35+ from kazoo .handlers .utils import create_tcp_connection , socket , ssl
36+
37+ with patch .object (utils , "_set_default_tcpsock_options" ):
38+ with patch .object (ssl .SSLContext , "wrap_socket" ) as wrap_socket :
39+ create_tcp_connection (
40+ socket ,
41+ ("127.0.0.1" , 2181 ),
42+ timeout = 1.5 ,
43+ hostname = "fakehostname" ,
44+ use_ssl = True ,
45+ )
46+
47+ for call_args in wrap_socket .call_args_list :
48+ server_hostname = call_args [1 ]["server_hostname" ]
49+ assert server_hostname == "fakehostname"
50+
51+ def test_ssl_server_check_hostname (self ):
52+ from kazoo .handlers import utils
53+ from kazoo .handlers .utils import create_tcp_connection , socket , ssl
54+
55+ with patch .object (utils , "_set_default_tcpsock_options" ):
56+ with patch .object (
57+ ssl .SSLContext , "wrap_socket" , autospec = True
58+ ) as wrap_socket :
59+ create_tcp_connection (
60+ socket ,
61+ ("127.0.0.1" , 2181 ),
62+ timeout = 1.5 ,
63+ hostname = "fakehostname" ,
64+ use_ssl = True ,
65+ check_hostname = True ,
66+ )
67+
68+ for call_args in wrap_socket .call_args_list :
69+ ssl_context = call_args [0 ][0 ]
70+ assert ssl_context .check_hostname
71+
72+ def test_ssl_server_check_hostname_config_validation (self ):
73+ from kazoo .handlers .utils import create_tcp_connection , socket
74+
75+ with pytest .raises (ValueError ):
76+ create_tcp_connection (
77+ socket ,
78+ ("127.0.0.1" , 2181 ),
79+ timeout = 1.5 ,
80+ hostname = "fakehostname" ,
81+ use_ssl = True ,
82+ verify_certs = False ,
83+ check_hostname = True ,
84+ )
85+
3386 def test_timeout_arg_eventlet (self ):
3487 if not EVENTLET_HANDLER_AVAILABLE :
3588 pytest .skip ("eventlet handler not available." )
0 commit comments