Skip to content
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
2 changes: 2 additions & 0 deletions pymongo/asynchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,8 @@ def option_repr(option: str, value: Any) -> str:
return "document_class=dict"
else:
return f"document_class={value.__module__}.{value.__name__}"
if option in {"tlscertificatekeyfilepassword"}:
return f"{option}='<redacted>'"
if option in common.TIMEOUT_OPTIONS and value is not None:
return f"{option}={int(value * 1000)}"

Expand Down
2 changes: 2 additions & 0 deletions pymongo/synchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,8 @@ def option_repr(option: str, value: Any) -> str:
return "document_class=dict"
else:
return f"document_class={value.__module__}.{value.__name__}"
if option in {"tlscertificatekeyfilepassword"}:
return f"{option}='<redacted>'"
if option in common.TIMEOUT_OPTIONS and value is not None:
return f"{option}={int(value * 1000)}"

Expand Down
10 changes: 10 additions & 0 deletions test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ async def test_keyword_arg_defaults(self):
self.assertEqual(ReadPreference.PRIMARY, client.read_preference)
self.assertAlmostEqual(12, client.options.server_selection_timeout)

def test_repr_redacts_tls_certificate_keyfile_password(self):
client = AsyncMongoClient(
"mongodb://localhost:27017/?tls=true&tlsCertificateKeyFilePassword=passphrase",
connect=False,
)
the_repr = repr(client)

self.assertIn("tlscertificatekeyfilepassword='<redacted>'", the_repr)
self.assertNotIn("passphrase", the_repr)

async def test_connect_timeout(self):
client = self.simple_client(connect=False, connectTimeoutMS=None, socketTimeoutMS=None)
pool_opts = client.options.pool_options
Expand Down
10 changes: 10 additions & 0 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ def test_keyword_arg_defaults(self):
self.assertEqual(ReadPreference.PRIMARY, client.read_preference)
self.assertAlmostEqual(12, client.options.server_selection_timeout)

def test_repr_redacts_tls_certificate_keyfile_password(self):
client = MongoClient(
"mongodb://localhost:27017/?tls=true&tlsCertificateKeyFilePassword=passphrase",
connect=False,
)
the_repr = repr(client)

self.assertIn("tlscertificatekeyfilepassword='<redacted>'", the_repr)
self.assertNotIn("passphrase", the_repr)

def test_connect_timeout(self):
client = self.simple_client(connect=False, connectTimeoutMS=None, socketTimeoutMS=None)
pool_opts = client.options.pool_options
Expand Down