Skip to content

[v4.13] PYTHON-5414 Fix "module service_identity has no attribute SICertificateError" when using pyopenssl #2386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: v4.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Version 4.13.2 is a bug fix release.

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

Issues Resolved
...............
Expand Down
6 changes: 3 additions & 3 deletions pymongo/pyopenssl_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@ def wrap_socket(
pyopenssl.verify_ip_address(ssl_conn, server_hostname)
else:
pyopenssl.verify_hostname(ssl_conn, server_hostname)
except ( # type:ignore[misc]
service_identity.SICertificateError,
service_identity.SIVerificationError,
except (
service_identity.CertificateError,
service_identity.VerificationError,
) as exc:
raise _CertificateError(str(exc)) from None
return ssl_conn
4 changes: 3 additions & 1 deletion test/asynchronous/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ async def test_cert_ssl_validation_hostname_matching(self):

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

with self.assertRaises(ConnectionFailure):
with self.assertRaises(ConnectionFailure) as cm:
await connected(
self.simple_client(
"server",
Expand All @@ -335,6 +335,8 @@ async def test_cert_ssl_validation_hostname_matching(self):
**self.credentials, # type: ignore[arg-type]
)
)
# PYTHON-5414 Check for "module service_identity has no attribute SICertificateError"
self.assertNotIn("has no attribute", str(cm.exception))

await connected(
self.simple_client(
Expand Down
4 changes: 3 additions & 1 deletion test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def test_cert_ssl_validation_hostname_matching(self):

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

with self.assertRaises(ConnectionFailure):
with self.assertRaises(ConnectionFailure) as cm:
connected(
self.simple_client(
"server",
Expand All @@ -335,6 +335,8 @@ def test_cert_ssl_validation_hostname_matching(self):
**self.credentials, # type: ignore[arg-type]
)
)
# PYTHON-5414 Check for "module service_identity has no attribute SICertificateError"
self.assertNotIn("has no attribute", str(cm.exception))

connected(
self.simple_client(
Expand Down
Loading