Skip to content

Commit 754627b

Browse files
committed
Use token source during e2e tests
1 parent 23250c2 commit 754627b

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

tests/test_e2e.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,36 +122,31 @@ def assertCacheWorksForUser(
122122
set(scope) <= set(result_from_wire["scope"].split(" "))
123123
):
124124
# Going to test acquire_token_silent(...) to locate an AT from cache
125-
result_from_cache = self.app.acquire_token_silent(
125+
silent_result = self.app.acquire_token_silent(
126126
scope, account=account, data=data or {}, auth_scheme=auth_scheme)
127-
self.assertIsNotNone(result_from_cache)
127+
self.assertIsNotNone(silent_result)
128128
self.assertIsNone(
129-
result_from_cache.get("refresh_token"), "A cache hit returns no RT")
130-
# TODO: Assert POP AT shall not come from cache
129+
silent_result.get("refresh_token"), "acquire_token_silent() should return no RT")
131130
self.assertEqual(
132-
result_from_wire['access_token'], result_from_cache['access_token'],
133-
"We should get a cached AT")
131+
self.app._TOKEN_SOURCE_BROKER if auth_scheme else self.app._TOKEN_SOURCE_CACHE,
132+
silent_result[self.app._TOKEN_SOURCE])
134133

135134
if "refresh_token" in result_from_wire:
135+
assert auth_scheme is None
136136
# Going to test acquire_token_silent(...) to obtain an AT by a RT from cache
137137
self.app.token_cache._cache["AccessToken"] = {} # A hacky way to clear ATs
138-
result_from_cache = self.app.acquire_token_silent(
139-
scope, account=account, data=data or {})
140-
if "refresh_token" not in result_from_wire:
141-
self.assertEqual(
142-
result_from_cache["access_token"], result_from_wire["access_token"],
143-
"The previously cached AT should be returned")
144-
self.assertIsNotNone(result_from_cache,
138+
silent_result = self.app.acquire_token_silent(
139+
scope, account=account, data=data or {})
140+
self.assertIsNotNone(silent_result,
145141
"We should get a result from acquire_token_silent(...) call")
146-
self.assertIsNotNone(
147-
# We used to assert it this way:
148-
# result_from_wire['access_token'] != result_from_cache['access_token']
149-
# but ROPC in B2C tends to return the same AT we obtained seconds ago.
150-
# Now looking back, "refresh_token grant would return a brand new AT"
151-
# was just an empirical observation but never a commitment in specs,
152-
# so we adjust our way to assert here.
153-
(result_from_cache or {}).get("access_token"),
154-
"We should get an AT from acquire_token_silent(...) call")
142+
self.assertEqual(
143+
# We used to assert it this way:
144+
# result_from_wire['access_token'] != silent_result['access_token']
145+
# but ROPC in B2C tends to return the same AT we obtained seconds ago.
146+
# Now looking back, "refresh_token grant would return a brand new AT"
147+
# was just an empirical observation but never a commitment in specs,
148+
# so we adjust our way to assert here.
149+
self.app._TOKEN_SOURCE_IDP, silent_result[self.app._TOKEN_SOURCE])
155150

156151
def assertCacheWorksForApp(self, result_from_wire, scope):
157152
logger.debug(
@@ -164,11 +159,9 @@ def assertCacheWorksForApp(self, result_from_wire, scope):
164159
self.app.acquire_token_silent(scope, account=None),
165160
"acquire_token_silent(..., account=None) shall always return None")
166161
# Going to test acquire_token_for_client(...) to locate an AT from cache
167-
result_from_cache = self.app.acquire_token_for_client(scope)
168-
self.assertIsNotNone(result_from_cache)
169-
self.assertEqual(
170-
result_from_wire['access_token'], result_from_cache['access_token'],
171-
"We should get a cached AT")
162+
silent_result = self.app.acquire_token_for_client(scope)
163+
self.assertIsNotNone(silent_result)
164+
self.assertEqual(self.app._TOKEN_SOURCE_CACHE, silent_result[self.app._TOKEN_SOURCE])
172165

173166
@classmethod
174167
def _build_app(cls,

0 commit comments

Comments
 (0)