@@ -196,6 +196,41 @@ def test_types(self):
196196
197197 self .assertRaises (ConfigurationError , AsyncMongoClient , [])
198198
199+ async def test_repr_redacts_aws_session_token (self ):
200+ token = "SECRET_AWS_SESSION_TOKEN"
201+ client = AsyncMongoClient (
202+ "mongodb://AKIA:SECRET@localhost:27017/"
203+ f"?authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:{ token } " ,
204+ connect = False ,
205+ )
206+
207+ the_repr = repr (client )
208+
209+ self .assertNotIn (token , the_repr )
210+ self .assertIn ("'AWS_SESSION_TOKEN': '<redacted>'" , the_repr )
211+
212+ async def test_repr_redacts_secret_auth_mechanism_properties (self ):
213+ token = "SECRET_AWS_SESSION_TOKEN"
214+ api_key = "SECRET_API_KEY"
215+ client = AsyncMongoClient (
216+ "mongodb://AKIA:SECRET@localhost:27017/" ,
217+ authMechanism = "MONGODB-AWS" ,
218+ authMechanismProperties = {
219+ "aws_session_token" : token ,
220+ "CUSTOM_API_KEY" : api_key ,
221+ "TOKEN_RESOURCE" : "mongodb://cluster.example" ,
222+ },
223+ connect = False ,
224+ )
225+
226+ the_repr = repr (client )
227+
228+ self .assertNotIn (token , the_repr )
229+ self .assertNotIn (api_key , the_repr )
230+ self .assertIn ("'aws_session_token': '<redacted>'" , the_repr )
231+ self .assertIn ("'CUSTOM_API_KEY': '<redacted>'" , the_repr )
232+ self .assertIn ("'TOKEN_RESOURCE': 'mongodb://cluster.example'" , the_repr )
233+
199234 async def test_max_pool_size_zero (self ):
200235 self .simple_client (maxPoolSize = 0 )
201236
0 commit comments