Skip to content

Commit ae73105

Browse files
committed
Unit test to catch a potential future regression
1 parent cb1b500 commit ae73105

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

tests/test_application.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,21 +240,30 @@ def setUp(self):
240240
uid=uid, utid=utid,
241241
access_token=self.access_token, refresh_token="some refresh token"),
242242
}) # 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(
246244
self.client_id,
247245
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()
249249
self.assertNotEqual([], accounts)
250250
self.assertEqual(self.environment_in_cache, accounts[0].get("environment"),
251251
"We should be able to find an account under an authority alias")
252252

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)
260269

0 commit comments

Comments
 (0)