@@ -240,21 +240,30 @@ def setUp(self):
240
240
uid = uid , utid = utid ,
241
241
access_token = self .access_token , refresh_token = "some refresh token" ),
242
242
}) # The add(...) helper populates correct home_account_id for future searching
243
-
244
- def test_get_accounts (self ):
245
- app = ClientApplication (
243
+ self .app = ClientApplication (
246
244
self .client_id ,
247
245
authority = self .authority_url_in_app , token_cache = self .cache )
248
- accounts = app .get_accounts ()
246
+
247
+ def test_get_accounts_should_find_accounts_under_different_alias (self ):
248
+ accounts = self .app .get_accounts ()
249
249
self .assertNotEqual ([], accounts )
250
250
self .assertEqual (self .environment_in_cache , accounts [0 ].get ("environment" ),
251
251
"We should be able to find an account under an authority alias" )
252
252
253
- def test_acquire_token_silent (self ):
254
- app = ClientApplication (
255
- self .client_id ,
256
- authority = self .authority_url_in_app , token_cache = self .cache )
257
- at = app .acquire_token_silent (self .scopes , self .account )
258
- self .assertNotEqual (None , at )
259
- self .assertEqual (self .access_token , at .get ('access_token' ))
253
+ def test_acquire_token_silent_should_find_at_under_different_alias (self ):
254
+ result = self .app .acquire_token_silent (self .scopes , self .account )
255
+ self .assertNotEqual (None , result )
256
+ self .assertEqual (self .access_token , result .get ('access_token' ))
257
+
258
+ def test_acquire_token_silent_should_find_rt_under_different_alias (self ):
259
+ self .cache ._cache ["AccessToken" ] = {} # A hacky way to clear ATs
260
+ class ExpectedBehavior (Exception ):
261
+ pass
262
+ def helper (scopes , account , authority , * args , ** kwargs ):
263
+ if authority .instance == self .environment_in_cache :
264
+ raise ExpectedBehavior ("RT of different alias being attempted" )
265
+ self .app ._acquire_token_silent_from_cache_and_possibly_refresh_it = helper
266
+
267
+ with self .assertRaises (ExpectedBehavior ):
268
+ self .app .acquire_token_silent (["different scope" ], self .account )
260
269
0 commit comments