@@ -194,3 +194,66 @@ def test_unpadded_urlsafe_b64encode():
194194
195195 for case , expected in cases :
196196 assert _helpers .unpadded_urlsafe_b64encode (case ) == expected
197+
198+ def test_hash_sensitive_info_basic ():
199+ test_data = {
200+ "expires_in" : 3599 ,
201+ "access_token" : "access-123" ,
202+ "scope" : "https://www.googleapis.com/auth/test-api" ,
203+ "token_type" : "Bearer" ,
204+ }
205+ hashed_data = _helpers .hash_sensitive_info (test_data )
206+ assert hashed_data ["expires_in" ] == 3599
207+ assert hashed_data ["scope" ] == "https://www.googleapis.com/auth/test-api"
208+ assert hashed_data ["access_token" ].startswith ("hashed_access_token-" )
209+ assert hashed_data ["token_type" ] == "Bearer"
210+
211+ def test_hash_sensitive_info_multiple_sensitive ():
212+ test_data = {
213+ "access_token" : "some_long_token" ,
214+ "id_token" : "1234-5678-9012-3456" ,
215+ "expires_in" : 3599 ,
216+ "token_type" : "Bearer" ,
217+ }
218+ hashed_data = _helpers .hash_sensitive_info (test_data )
219+ assert hashed_data ["expires_in" ] == 3599
220+ assert hashed_data ["token_type" ] == "Bearer"
221+ assert hashed_data ["access_token" ].startswith ("hashed_access_token-" )
222+ assert hashed_data ["id_token" ].startswith ("hashed_id_token-" )
223+
224+
225+ def test_hash_sensitive_info_none_value ():
226+ test_data = {"username" : "user3" , "secret" : None , "normal_data" : "abc" }
227+ hashed_data = _helpers .hash_sensitive_info (test_data )
228+ assert hashed_data ["secret" ] is None
229+ assert hashed_data ["normal_data" ] == "abc"
230+
231+
232+ def test_hash_sensitive_info_non_string_value ():
233+ test_data = {"username" : "user4" , "access_token" : 12345 , "normal_data" : "def" }
234+ hashed_data = _helpers .hash_sensitive_info (test_data )
235+ assert hashed_data ["access_token" ].startswith ("hashed_access_token-" )
236+ assert hashed_data ["normal_data" ] == "def"
237+
238+ def test_hash_sensitive_info_empty_dict ():
239+ test_data = {}
240+ hashed_data = _helpers .hash_sensitive_info (test_data )
241+ assert hashed_data == {}
242+
243+ def test_hash_value_consistent_hashing ():
244+ value = "test_value"
245+ field_name = "test_field"
246+ hash1 = _helpers ._hash_value (value , field_name )
247+ hash2 = _helpers ._hash_value (value , field_name )
248+ assert hash1 == hash2
249+
250+ def test_hash_value_different_hashing ():
251+ value1 = "test_value1"
252+ value2 = "test_value2"
253+ field_name = "test_field"
254+ hash1 = _helpers ._hash_value (value1 , field_name )
255+ hash2 = _helpers ._hash_value (value2 , field_name )
256+ assert hash1 != hash2
257+
258+ def test_hash_value_none ():
259+ assert _helpers ._hash_value (None , "test" ) is None
0 commit comments