@@ -153,8 +153,8 @@ def tester(url, data=None, **kwargs):
153153 return MinimalResponse (status_code = 400 , text = error_response )
154154 app ._acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family (
155155 app .authority , self .scopes , self .account , post = tester )
156- self .assertNotEqual ([], app .token_cache .find (
157- msal .TokenCache .CredentialType .REFRESH_TOKEN , query = {"secret" : self .frt }),
156+ self .assertIsNotNone ( next ( app .token_cache .search (
157+ msal .TokenCache .CredentialType .REFRESH_TOKEN , query = {"secret" : self .frt }), None ),
158158 "The FRT should not be removed from the cache" )
159159
160160 def test_known_orphan_app_will_skip_frt_and_only_use_its_own_rt (self ):
@@ -187,11 +187,11 @@ def tester(url, data=None, **kwargs):
187187 app .authority , self .scopes , self .account , post = tester )
188188 logger .debug ("%s.cache = %s" , self .id (), self .cache .serialize ())
189189 self .assertEqual ("at" , at .get ("access_token" ), "New app should get a new AT" )
190- app_metadata = app .token_cache .find (
190+ app_metadata = next ( app .token_cache .search (
191191 msal .TokenCache .CredentialType .APP_METADATA ,
192- query = {"client_id" : app .client_id })
193- self .assertNotEqual ([], app_metadata , "Should record new app's metadata" )
194- self .assertEqual ("1" , app_metadata [ 0 ] .get ("family_id" ),
192+ query = {"client_id" : app .client_id }), None )
193+ self .assertIsNotNone ( app_metadata , "Should record new app's metadata" )
194+ self .assertEqual ("1" , app_metadata .get ("family_id" ),
195195 "The new family app should be recorded as in the same family" )
196196 # Known family app will simply use FRT, which is largely the same as this one
197197
@@ -218,25 +218,25 @@ def test_family_app_remove_account(self):
218218 account = app .get_accounts ()[0 ]
219219 mine = {"home_account_id" : account ["home_account_id" ]}
220220
221- self .assertNotEqual ([], self .cache .find (
222- self .cache .CredentialType .ACCESS_TOKEN , query = mine ))
223- self .assertNotEqual ([], self .cache .find (
224- self .cache .CredentialType .REFRESH_TOKEN , query = mine ))
225- self .assertNotEqual ([], self .cache .find (
226- self .cache .CredentialType .ID_TOKEN , query = mine ))
227- self .assertNotEqual ([], self .cache .find (
228- self .cache .CredentialType .ACCOUNT , query = mine ))
221+ self .assertIsNotNone ( next ( self .cache .search (
222+ self .cache .CredentialType .ACCESS_TOKEN , query = mine ), None ) )
223+ self .assertIsNotNone ( next ( self .cache .search (
224+ self .cache .CredentialType .REFRESH_TOKEN , query = mine ), None ) )
225+ self .assertIsNotNone ( next ( self .cache .search (
226+ self .cache .CredentialType .ID_TOKEN , query = mine ), None ) )
227+ self .assertIsNotNone ( next ( self .cache .search (
228+ self .cache .CredentialType .ACCOUNT , query = mine ), None ) )
229229
230230 app .remove_account (account )
231231
232- self .assertEqual ([], self .cache .find (
233- self .cache .CredentialType .ACCESS_TOKEN , query = mine ))
234- self .assertEqual ([], self .cache .find (
235- self .cache .CredentialType .REFRESH_TOKEN , query = mine ))
236- self .assertEqual ([], self .cache .find (
237- self .cache .CredentialType .ID_TOKEN , query = mine ))
238- self .assertEqual ([], self .cache .find (
239- self .cache .CredentialType .ACCOUNT , query = mine ))
232+ self .assertIsNone ( next ( self .cache .search (
233+ self .cache .CredentialType .ACCESS_TOKEN , query = mine ), None ) )
234+ self .assertIsNone ( next ( self .cache .search (
235+ self .cache .CredentialType .REFRESH_TOKEN , query = mine ), None ) )
236+ self .assertIsNone ( next ( self .cache .search (
237+ self .cache .CredentialType .ID_TOKEN , query = mine ), None ) )
238+ self .assertIsNone ( next ( self .cache .search (
239+ self .cache .CredentialType .ACCOUNT , query = mine ), None ) )
240240
241241
242242class TestClientApplicationForAuthorityMigration (unittest .TestCase ):
@@ -711,25 +711,26 @@ def test_remove_tokens_for_client_should_remove_client_tokens_only(self):
711711 cca = msal .ConfidentialClientApplication (
712712 "client_id" , client_credential = "secret" ,
713713 authority = "https://login.microsoftonline.com/microsoft.onmicrosoft.com" )
714- self .assertEqual (
715- 0 , len ( cca . token_cache . find ( msal .TokenCache .CredentialType .ACCESS_TOKEN )))
714+ self .assertIsNone ( next ( cca . token_cache . search (
715+ msal .TokenCache .CredentialType .ACCESS_TOKEN ), None ))
716716 cca .acquire_token_for_client (
717717 ["scope" ],
718718 post = lambda url , ** kwargs : MinimalResponse (
719719 status_code = 200 , text = json .dumps ({"access_token" : "AT for client" })))
720- self .assertEqual (
721- 1 , len ( cca . token_cache . find ( msal .TokenCache .CredentialType .ACCESS_TOKEN )))
720+ self .assertEqual (1 , len ( list ( cca . token_cache . search (
721+ msal .TokenCache .CredentialType .ACCESS_TOKEN ) )))
722722 cca .acquire_token_by_username_password (
723723 "johndoe" , "password" , ["scope" ],
724724 post = lambda url , ** kwargs : MinimalResponse (
725725 status_code = 200 , text = json .dumps (build_response (
726726 access_token = at_for_user , expires_in = 3600 ,
727727 uid = "uid" , utid = "utid" , # This populates home_account_id
728728 ))))
729- self .assertEqual (
730- 2 , len ( cca . token_cache . find ( msal .TokenCache .CredentialType .ACCESS_TOKEN )))
729+ self .assertEqual (2 , len ( list ( cca . token_cache . search (
730+ msal .TokenCache .CredentialType .ACCESS_TOKEN ) )))
731731 cca .remove_tokens_for_client ()
732- remaining_tokens = cca .token_cache .find (msal .TokenCache .CredentialType .ACCESS_TOKEN )
732+ remaining_tokens = list (cca .token_cache .search (
733+ msal .TokenCache .CredentialType .ACCESS_TOKEN ))
733734 self .assertEqual (1 , len (remaining_tokens ))
734735 self .assertEqual (at_for_user , remaining_tokens [0 ].get ("secret" ))
735736
0 commit comments