@@ -3118,7 +3118,9 @@ async def test_ssl_with_invalid_cert(
3118
3118
async def test_ssl_connection (
3119
3119
self , create_client : Callable [..., Awaitable [RedisCluster ]]
3120
3120
) -> 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 :
3122
3124
assert await rc .ping ()
3123
3125
3124
3126
@pytest .mark .parametrize (
@@ -3134,6 +3136,7 @@ async def test_ssl_connection_tls12_custom_ciphers(
3134
3136
) -> None :
3135
3137
async with await create_client (
3136
3138
ssl = True ,
3139
+ ssl_check_hostname = False ,
3137
3140
ssl_cert_reqs = "none" ,
3138
3141
ssl_min_version = ssl .TLSVersion .TLSv1_2 ,
3139
3142
ssl_ciphers = ssl_ciphers ,
@@ -3145,6 +3148,7 @@ async def test_ssl_connection_tls12_custom_ciphers_invalid(
3145
3148
) -> None :
3146
3149
async with await create_client (
3147
3150
ssl = True ,
3151
+ ssl_check_hostname = False ,
3148
3152
ssl_cert_reqs = "none" ,
3149
3153
ssl_min_version = ssl .TLSVersion .TLSv1_2 ,
3150
3154
ssl_ciphers = "foo:bar" ,
@@ -3166,6 +3170,7 @@ async def test_ssl_connection_tls13_custom_ciphers(
3166
3170
# TLSv1.3 does not support changing the ciphers
3167
3171
async with await create_client (
3168
3172
ssl = True ,
3173
+ ssl_check_hostname = False ,
3169
3174
ssl_cert_reqs = "none" ,
3170
3175
ssl_min_version = ssl .TLSVersion .TLSv1_2 ,
3171
3176
ssl_ciphers = ssl_ciphers ,
@@ -3177,12 +3182,20 @@ async def test_ssl_connection_tls13_custom_ciphers(
3177
3182
async def test_validating_self_signed_certificate (
3178
3183
self , create_client : Callable [..., Awaitable [RedisCluster ]]
3179
3184
) -> 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.
3180
3192
async with await create_client (
3181
3193
ssl = True ,
3182
3194
ssl_ca_certs = self .ca_cert ,
3183
3195
ssl_cert_reqs = "required" ,
3184
3196
ssl_certfile = self .client_cert ,
3185
3197
ssl_keyfile = self .client_key ,
3198
+ ssl_check_hostname = False ,
3186
3199
) as rc :
3187
3200
assert await rc .ping ()
3188
3201
@@ -3192,10 +3205,18 @@ async def test_validating_self_signed_string_certificate(
3192
3205
with open (self .ca_cert ) as f :
3193
3206
cert_data = f .read ()
3194
3207
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.
3195
3215
async with await create_client (
3196
3216
ssl = True ,
3197
3217
ssl_ca_data = cert_data ,
3198
3218
ssl_cert_reqs = "required" ,
3219
+ ssl_check_hostname = False ,
3199
3220
ssl_certfile = self .client_cert ,
3200
3221
ssl_keyfile = self .client_key ,
3201
3222
) as rc :
0 commit comments