@@ -206,6 +206,38 @@ def testAddByAdfs(self):
206
206
"appmetadata-fs.msidlab8.com-my_client_id" )
207
207
)
208
208
209
+ def assertFoundAccessToken (self , * , scopes , query , data = None ):
210
+ cached_at = None
211
+ for cached_at in self .cache .search (
212
+ TokenCache .CredentialType .ACCESS_TOKEN , target = scopes , query = query ):
213
+ for k , v in (data or {}).items (): # The extra data, if any
214
+ self .assertEqual (cached_at .get (k ), v , f"AT should contain { k } ={ v } " )
215
+ self .assertTrue (cached_at , "AT should be cached and searchable" )
216
+ return cached_at
217
+
218
+ def _test_data_should_be_saved_and_searchable_in_access_token (self , data ):
219
+ scopes = ["s2" , "s1" , "s3" ] # Not in particular order
220
+ self .cache .add ({
221
+ "data" : data ,
222
+ "client_id" : "my_client_id" ,
223
+ "scope" : scopes ,
224
+ "token_endpoint" : "https://login.example.com/contoso/v2/token" ,
225
+ "response" : build_response (
226
+ uid = "uid" , utid = "utid" , # client_info
227
+ expires_in = 3600 , access_token = "an access token" ,
228
+ refresh_token = "a refresh token" ),
229
+ }, now = 1000 )
230
+ self .assertFoundAccessToken (scopes = scopes , data = data , query = dict (
231
+ data , # Also use the extra data as a query criteria
232
+ client_id = "my_client_id" ,
233
+ environment = "login.example.com" ,
234
+ realm = "contoso" ,
235
+ home_account_id = "uid.utid" ,
236
+ ))
237
+
238
+ def test_extra_data_should_also_be_recorded_and_searchable_in_access_token (self ):
239
+ self ._test_data_should_be_saved_and_searchable_in_access_token ({"key_id" : "1" })
240
+
209
241
def test_key_id_is_also_recorded (self ):
210
242
my_key_id = "some_key_id_123"
211
243
self .cache .add ({
@@ -258,7 +290,7 @@ def test_old_rt_data_with_wrong_key_should_still_be_salvaged_into_new_rt(self):
258
290
)
259
291
260
292
261
- class SerializableTokenCacheTestCase (TokenCacheTestCase ):
293
+ class SerializableTokenCacheTestCase (unittest . TestCase ):
262
294
# Run all inherited test methods, and have extra check in tearDown()
263
295
264
296
def setUp (self ):
0 commit comments