@@ -3118,7 +3118,9 @@ async def test_ssl_with_invalid_cert(
31183118 async def test_ssl_connection (
31193119 self , create_client : Callable [..., Awaitable [RedisCluster ]]
31203120 ) -> None :
3121- async with await create_client (ssl = True , ssl_cert_reqs = "none" ) as rc :
3121+ async with await create_client (
3122+ ssl = True , ssl_check_hostname = False , ssl_cert_reqs = "none"
3123+ ) as rc :
31223124 assert await rc .ping ()
31233125
31243126 @pytest .mark .parametrize (
@@ -3134,6 +3136,7 @@ async def test_ssl_connection_tls12_custom_ciphers(
31343136 ) -> None :
31353137 async with await create_client (
31363138 ssl = True ,
3139+ ssl_check_hostname = False ,
31373140 ssl_cert_reqs = "none" ,
31383141 ssl_min_version = ssl .TLSVersion .TLSv1_2 ,
31393142 ssl_ciphers = ssl_ciphers ,
@@ -3145,6 +3148,7 @@ async def test_ssl_connection_tls12_custom_ciphers_invalid(
31453148 ) -> None :
31463149 async with await create_client (
31473150 ssl = True ,
3151+ ssl_check_hostname = False ,
31483152 ssl_cert_reqs = "none" ,
31493153 ssl_min_version = ssl .TLSVersion .TLSv1_2 ,
31503154 ssl_ciphers = "foo:bar" ,
@@ -3166,6 +3170,7 @@ async def test_ssl_connection_tls13_custom_ciphers(
31663170 # TLSv1.3 does not support changing the ciphers
31673171 async with await create_client (
31683172 ssl = True ,
3173+ ssl_check_hostname = False ,
31693174 ssl_cert_reqs = "none" ,
31703175 ssl_min_version = ssl .TLSVersion .TLSv1_2 ,
31713176 ssl_ciphers = ssl_ciphers ,
@@ -3177,12 +3182,20 @@ async def test_ssl_connection_tls13_custom_ciphers(
31773182 async def test_validating_self_signed_certificate (
31783183 self , create_client : Callable [..., Awaitable [RedisCluster ]]
31793184 ) -> None :
3185+ # ssl_check_hostname=False is used to avoid hostname verification
3186+ # in the test environment, where the server certificate is self-signed
3187+ # and does not match the hostname that is extracted for the cluster.
3188+ # Cert hostname is 'localhost' in the cluster initialization when using
3189+ # 'localhost' it gets transformed into 127.0.0.1
3190+ # In production code, ssl_check_hostname should be set to True
3191+ # to ensure proper hostname verification.
31803192 async with await create_client (
31813193 ssl = True ,
31823194 ssl_ca_certs = self .ca_cert ,
31833195 ssl_cert_reqs = "required" ,
31843196 ssl_certfile = self .client_cert ,
31853197 ssl_keyfile = self .client_key ,
3198+ ssl_check_hostname = False ,
31863199 ) as rc :
31873200 assert await rc .ping ()
31883201
@@ -3192,10 +3205,18 @@ async def test_validating_self_signed_string_certificate(
31923205 with open (self .ca_cert ) as f :
31933206 cert_data = f .read ()
31943207
3208+ # ssl_check_hostname=False is used to avoid hostname verification
3209+ # in the test environment, where the server certificate is self-signed
3210+ # and does not match the hostname that is extracted for the cluster.
3211+ # Cert hostname is 'localhost' in the cluster initialization when using
3212+ # 'localhost' it gets transformed into 127.0.0.1
3213+ # In production code, ssl_check_hostname should be set to True
3214+ # to ensure proper hostname verification.
31953215 async with await create_client (
31963216 ssl = True ,
31973217 ssl_ca_data = cert_data ,
31983218 ssl_cert_reqs = "required" ,
3219+ ssl_check_hostname = False ,
31993220 ssl_certfile = self .client_cert ,
32003221 ssl_keyfile = self .client_key ,
32013222 ) as rc :
0 commit comments