@@ -3139,7 +3139,9 @@ async def test_ssl_with_invalid_cert(
31393139 async def test_ssl_connection (
31403140 self , create_client : Callable [..., Awaitable [RedisCluster ]]
31413141 ) -> None :
3142- async with await create_client (ssl = True , ssl_cert_reqs = "none" ) as rc :
3142+ async with await create_client (
3143+ ssl = True , ssl_check_hostname = False , ssl_cert_reqs = "none"
3144+ ) as rc :
31433145 assert await rc .ping ()
31443146
31453147 @pytest .mark .parametrize (
@@ -3155,6 +3157,7 @@ async def test_ssl_connection_tls12_custom_ciphers(
31553157 ) -> None :
31563158 async with await create_client (
31573159 ssl = True ,
3160+ ssl_check_hostname = False ,
31583161 ssl_cert_reqs = "none" ,
31593162 ssl_min_version = ssl .TLSVersion .TLSv1_2 ,
31603163 ssl_ciphers = ssl_ciphers ,
@@ -3166,6 +3169,7 @@ async def test_ssl_connection_tls12_custom_ciphers_invalid(
31663169 ) -> None :
31673170 async with await create_client (
31683171 ssl = True ,
3172+ ssl_check_hostname = False ,
31693173 ssl_cert_reqs = "none" ,
31703174 ssl_min_version = ssl .TLSVersion .TLSv1_2 ,
31713175 ssl_ciphers = "foo:bar" ,
@@ -3187,6 +3191,7 @@ async def test_ssl_connection_tls13_custom_ciphers(
31873191 # TLSv1.3 does not support changing the ciphers
31883192 async with await create_client (
31893193 ssl = True ,
3194+ ssl_check_hostname = False ,
31903195 ssl_cert_reqs = "none" ,
31913196 ssl_min_version = ssl .TLSVersion .TLSv1_2 ,
31923197 ssl_ciphers = ssl_ciphers ,
@@ -3198,12 +3203,20 @@ async def test_ssl_connection_tls13_custom_ciphers(
31983203 async def test_validating_self_signed_certificate (
31993204 self , create_client : Callable [..., Awaitable [RedisCluster ]]
32003205 ) -> None :
3206+ # ssl_check_hostname=False is used to avoid hostname verification
3207+ # in the test environment, where the server certificate is self-signed
3208+ # and does not match the hostname that is extracted for the cluster.
3209+ # Cert hostname is 'localhost' in the cluster initialization when using
3210+ # 'localhost' it gets transformed into 127.0.0.1
3211+ # In production code, ssl_check_hostname should be set to True
3212+ # to ensure proper hostname verification.
32013213 async with await create_client (
32023214 ssl = True ,
32033215 ssl_ca_certs = self .ca_cert ,
32043216 ssl_cert_reqs = "required" ,
32053217 ssl_certfile = self .client_cert ,
32063218 ssl_keyfile = self .client_key ,
3219+ ssl_check_hostname = False ,
32073220 ) as rc :
32083221 assert await rc .ping ()
32093222
@@ -3213,10 +3226,18 @@ async def test_validating_self_signed_string_certificate(
32133226 with open (self .ca_cert ) as f :
32143227 cert_data = f .read ()
32153228
3229+ # ssl_check_hostname=False is used to avoid hostname verification
3230+ # in the test environment, where the server certificate is self-signed
3231+ # and does not match the hostname that is extracted for the cluster.
3232+ # Cert hostname is 'localhost' in the cluster initialization when using
3233+ # 'localhost' it gets transformed into 127.0.0.1
3234+ # In production code, ssl_check_hostname should be set to True
3235+ # to ensure proper hostname verification.
32163236 async with await create_client (
32173237 ssl = True ,
32183238 ssl_ca_data = cert_data ,
32193239 ssl_cert_reqs = "required" ,
3240+ ssl_check_hostname = False ,
32203241 ssl_certfile = self .client_cert ,
32213242 ssl_keyfile = self .client_key ,
32223243 ) as rc :
0 commit comments