Skip to content

Commit ab48adf

Browse files
committed
Tolerate Authorization Server not granting all scopes
1 parent 775e8b5 commit ab48adf

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tests/test_e2e.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,18 @@ def assertCacheWorksForUser(self, result_from_wire, scope, username=None):
5252
accounts = self.app.get_accounts(username=username)
5353
self.assertNotEqual(0, len(accounts))
5454
account = accounts[0]
55-
# Going to test acquire_token_silent(...) to locate an AT from cache
56-
result_from_cache = self.app.acquire_token_silent(scope, account=account)
57-
self.assertIsNotNone(result_from_cache)
58-
self.assertEqual(
59-
result_from_wire['access_token'], result_from_cache['access_token'],
60-
"We should get a cached AT")
55+
if ("scope" not in result_from_wire # This is the usual case
56+
or # Authority server could reject some scopes
57+
set(scope) <= set(result_from_wire["scope"].split(" "))
58+
):
59+
# Going to test acquire_token_silent(...) to locate an AT from cache
60+
result_from_cache = self.app.acquire_token_silent(scope, account=account)
61+
self.assertIsNotNone(result_from_cache)
62+
self.assertIsNone(
63+
result_from_cache.get("refresh_token"), "A cache hit returns no RT")
64+
self.assertEqual(
65+
result_from_wire['access_token'], result_from_cache['access_token'],
66+
"We should get a cached AT")
6167

6268
# Going to test acquire_token_silent(...) to obtain an AT by a RT from cache
6369
self.app.token_cache._cache["AccessToken"] = {} # A hacky way to clear ATs

0 commit comments

Comments
 (0)