Skip to content

Commit ad34174

Browse files
ShaneHarveympsijm
andauthored
[v4.13] PYTHON-5414 Fix "module service_identity has no attribute SICertificateError" when using pyopenssl (#2386)
Co-authored-by: Maarten Sijm <[email protected]>
1 parent b127460 commit ad34174

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

doc/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Version 4.13.2 is a bug fix release.
88

99
- Fixed a bug where ``AsyncMongoClient`` would block the event loop while creating new connections,
1010
potentially significantly increasing latency for ongoing operations.
11+
- Fixed a bug that resulted in confusing error messages after hostname verification errors when using PyOpenSSL.
1112

1213
Issues Resolved
1314
...............

pymongo/pyopenssl_context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ def wrap_socket(
420420
pyopenssl.verify_ip_address(ssl_conn, server_hostname)
421421
else:
422422
pyopenssl.verify_hostname(ssl_conn, server_hostname)
423-
except ( # type:ignore[misc]
424-
service_identity.SICertificateError,
425-
service_identity.SIVerificationError,
423+
except (
424+
service_identity.CertificateError,
425+
service_identity.VerificationError,
426426
) as exc:
427427
raise _CertificateError(str(exc)) from None
428428
return ssl_conn

test/asynchronous/test_ssl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ async def test_cert_ssl_validation_hostname_matching(self):
323323

324324
response = await self.client.admin.command(HelloCompat.LEGACY_CMD)
325325

326-
with self.assertRaises(ConnectionFailure):
326+
with self.assertRaises(ConnectionFailure) as cm:
327327
await connected(
328328
self.simple_client(
329329
"server",
@@ -335,6 +335,8 @@ async def test_cert_ssl_validation_hostname_matching(self):
335335
**self.credentials, # type: ignore[arg-type]
336336
)
337337
)
338+
# PYTHON-5414 Check for "module service_identity has no attribute SICertificateError"
339+
self.assertNotIn("has no attribute", str(cm.exception))
338340

339341
await connected(
340342
self.simple_client(

test/test_ssl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def test_cert_ssl_validation_hostname_matching(self):
323323

324324
response = self.client.admin.command(HelloCompat.LEGACY_CMD)
325325

326-
with self.assertRaises(ConnectionFailure):
326+
with self.assertRaises(ConnectionFailure) as cm:
327327
connected(
328328
self.simple_client(
329329
"server",
@@ -335,6 +335,8 @@ def test_cert_ssl_validation_hostname_matching(self):
335335
**self.credentials, # type: ignore[arg-type]
336336
)
337337
)
338+
# PYTHON-5414 Check for "module service_identity has no attribute SICertificateError"
339+
self.assertNotIn("has no attribute", str(cm.exception))
338340

339341
connected(
340342
self.simple_client(

0 commit comments

Comments
 (0)