@@ -122,36 +122,31 @@ def assertCacheWorksForUser(
122
122
set (scope ) <= set (result_from_wire ["scope" ].split (" " ))
123
123
):
124
124
# 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 (
126
126
scope , account = account , data = data or {}, auth_scheme = auth_scheme )
127
- self .assertIsNotNone (result_from_cache )
127
+ self .assertIsNotNone (silent_result )
128
128
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" )
131
130
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 ] )
134
133
135
134
if "refresh_token" in result_from_wire :
135
+ assert auth_scheme is None
136
136
# Going to test acquire_token_silent(...) to obtain an AT by a RT from cache
137
137
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 ,
145
141
"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 ])
155
150
156
151
def assertCacheWorksForApp (self , result_from_wire , scope ):
157
152
logger .debug (
@@ -164,11 +159,9 @@ def assertCacheWorksForApp(self, result_from_wire, scope):
164
159
self .app .acquire_token_silent (scope , account = None ),
165
160
"acquire_token_silent(..., account=None) shall always return None" )
166
161
# 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 ])
172
165
173
166
@classmethod
174
167
def _build_app (cls ,
0 commit comments