@@ -212,7 +212,7 @@ def test_hash_sensitive_info_basic():
212212 "scope" : "https://www.googleapis.com/auth/test-api" ,
213213 "token_type" : "Bearer" ,
214214 }
215- hashed_data = _helpers .hash_sensitive_info (test_data )
215+ hashed_data = _helpers ._hash_sensitive_info (test_data )
216216 assert hashed_data ["expires_in" ] == 3599
217217 assert hashed_data ["scope" ] == "https://www.googleapis.com/auth/test-api"
218218 assert hashed_data ["access_token" ].startswith ("hashed_access_token-" )
@@ -226,7 +226,7 @@ def test_hash_sensitive_info_multiple_sensitive():
226226 "expires_in" : 3599 ,
227227 "token_type" : "Bearer" ,
228228 }
229- hashed_data = _helpers .hash_sensitive_info (test_data )
229+ hashed_data = _helpers ._hash_sensitive_info (test_data )
230230 assert hashed_data ["expires_in" ] == 3599
231231 assert hashed_data ["token_type" ] == "Bearer"
232232 assert hashed_data ["access_token" ].startswith ("hashed_access_token-" )
@@ -235,21 +235,57 @@ def test_hash_sensitive_info_multiple_sensitive():
235235
236236def test_hash_sensitive_info_none_value ():
237237 test_data = {"username" : "user3" , "secret" : None , "normal_data" : "abc" }
238- hashed_data = _helpers .hash_sensitive_info (test_data )
238+ hashed_data = _helpers ._hash_sensitive_info (test_data )
239239 assert hashed_data ["secret" ] is None
240240 assert hashed_data ["normal_data" ] == "abc"
241241
242242
243243def test_hash_sensitive_info_non_string_value ():
244244 test_data = {"username" : "user4" , "access_token" : 12345 , "normal_data" : "def" }
245- hashed_data = _helpers .hash_sensitive_info (test_data )
245+ hashed_data = _helpers ._hash_sensitive_info (test_data )
246246 assert hashed_data ["access_token" ].startswith ("hashed_access_token-" )
247247 assert hashed_data ["normal_data" ] == "def"
248248
249249
250+ def test_hash_sensitive_info_list_value ():
251+ test_data = [
252+ {"name" : "Alice" , "access_token" : "12345" },
253+ {"name" : "Bob" , "client_id" : "1141" },
254+ ]
255+ hashed_data = _helpers ._hash_sensitive_info (test_data )
256+ assert hashed_data [0 ]["access_token" ].startswith ("hashed_access_token-" )
257+ assert hashed_data [1 ]["client_id" ].startswith ("hashed_client_id-" )
258+
259+
260+ def test_hash_sensitive_info_nested_list_value ():
261+ test_data = [{"names" : ["Alice" , "Bob" ], "tokens" : [{"access_token" : "1234" }]}]
262+ hashed_data = _helpers ._hash_sensitive_info (test_data )
263+ assert hashed_data [0 ]["tokens" ][0 ]["access_token" ].startswith (
264+ "hashed_access_token-"
265+ )
266+
267+
268+ def test_hash_sensitive_info_int_value ():
269+ test_data = 123
270+ hashed_data = _helpers ._hash_sensitive_info (test_data )
271+ assert hashed_data == "<class 'int'>"
272+
273+
274+ def test_hash_sensitive_info_bool_value ():
275+ test_data = True
276+ hashed_data = _helpers ._hash_sensitive_info (test_data )
277+ assert hashed_data == "<class 'bool'>"
278+
279+
280+ def test_hash_sensitive_info_byte_value ():
281+ test_data = b"1243"
282+ hashed_data = _helpers ._hash_sensitive_info (test_data )
283+ assert hashed_data == "<class 'bytes'>"
284+
285+
250286def test_hash_sensitive_info_empty_dict ():
251287 test_data = {}
252- hashed_data = _helpers .hash_sensitive_info (test_data )
288+ hashed_data = _helpers ._hash_sensitive_info (test_data )
253289 assert hashed_data == {}
254290
255291
@@ -321,6 +357,27 @@ def test_request_log_debug_enabled(logger, caplog):
321357 }
322358
323359
360+ def test_request_log_plain_text_debug_enabled (logger , caplog ):
361+ logger .setLevel (logging .DEBUG )
362+ with mock .patch ("google.auth._helpers.CLIENT_LOGGING_SUPPORTED" , True ):
363+ _helpers .request_log (
364+ logger ,
365+ "GET" ,
366+ "http://example.com" ,
367+ b"This is plain text." ,
368+ {"Authorization" : "Bearer token" , "Content-Type" : "text/plain" },
369+ )
370+ assert len (caplog .records ) == 1
371+ record = caplog .records [0 ]
372+ assert record .message == "Making request..."
373+ assert record .httpRequest == {
374+ "method" : "GET" ,
375+ "url" : "http://example.com" ,
376+ "body" : "<class 'str'>" ,
377+ "headers" : {"Authorization" : "Bearer token" , "Content-Type" : "text/plain" },
378+ }
379+
380+
324381def test_request_log_debug_disabled (logger , caplog ):
325382 logger .setLevel (logging .INFO )
326383 with mock .patch ("google.auth._helpers.CLIENT_LOGGING_SUPPORTED" , True ):
@@ -365,7 +422,7 @@ def json(self):
365422 assert len (caplog .records ) == 1
366423 record = caplog .records [0 ]
367424 assert record .message == "Response received..."
368- assert record .httpResponse == ["item1 " , "item2 " , "item3 " ]
425+ assert record .httpResponse == ["<class 'str'> " , "<class 'str'> " , "<class 'str'> " ]
369426
370427
371428def test_parse_request_body_bytes_valid ():
0 commit comments