@@ -109,6 +109,7 @@ def tester(url, **kwargs):
109
109
self .scopes , self .account , post = tester )
110
110
self .assertEqual ("" , result .get ("classification" ))
111
111
112
+
112
113
class TestClientApplicationAcquireTokenSilentFociBehaviors (unittest .TestCase ):
113
114
114
115
def setUp (self ):
@@ -263,6 +264,7 @@ def test_get_accounts_should_find_accounts_under_different_alias(self):
263
264
def test_acquire_token_silent_should_find_at_under_different_alias (self ):
264
265
result = self .app .acquire_token_silent (self .scopes , self .account )
265
266
self .assertNotEqual (None , result )
267
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_CACHE )
266
268
self .assertEqual (self .access_token , result .get ('access_token' ))
267
269
268
270
def test_acquire_token_silent_should_find_rt_under_different_alias (self ):
@@ -360,6 +362,7 @@ def test_fresh_token_should_be_returned_from_cache(self):
360
362
post = lambda url , * args , ** kwargs : # Utilize the undocumented test feature
361
363
self .fail ("I/O shouldn't happen in cache hit AT scenario" )
362
364
)
365
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_CACHE )
363
366
self .assertEqual (access_token , result .get ("access_token" ))
364
367
self .assertNotIn ("refresh_in" , result , "Customers need not know refresh_in" )
365
368
@@ -374,6 +377,7 @@ def mock_post(url, headers=None, *args, **kwargs):
374
377
"refresh_in" : 123 ,
375
378
}))
376
379
result = self .app .acquire_token_silent (['s1' ], self .account , post = mock_post )
380
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
377
381
self .assertEqual (new_access_token , result .get ("access_token" ))
378
382
self .assertNotIn ("refresh_in" , result , "Customers need not know refresh_in" )
379
383
@@ -385,6 +389,7 @@ def mock_post(url, headers=None, *args, **kwargs):
385
389
self .assertEqual ("4|84,4|" , (headers or {}).get (CLIENT_CURRENT_TELEMETRY ))
386
390
return MinimalResponse (status_code = 400 , text = json .dumps ({"error" : "foo" }))
387
391
result = self .app .acquire_token_silent (['s1' ], self .account , post = mock_post )
392
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_CACHE )
388
393
self .assertEqual (old_at , result .get ("access_token" ))
389
394
390
395
def test_expired_token_and_unavailable_aad_should_return_error (self ):
@@ -409,6 +414,7 @@ def mock_post(url, headers=None, *args, **kwargs):
409
414
"refresh_in" : 123 ,
410
415
}))
411
416
result = self .app .acquire_token_silent (['s1' ], self .account , post = mock_post )
417
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
412
418
self .assertEqual (new_access_token , result .get ("access_token" ))
413
419
self .assertNotIn ("refresh_in" , result , "Customers need not know refresh_in" )
414
420
@@ -444,6 +450,7 @@ def test_maintaining_offline_state_and_sending_them(self):
444
450
post = lambda url , * args , ** kwargs : # Utilize the undocumented test feature
445
451
self .fail ("I/O shouldn't happen in cache hit AT scenario" )
446
452
)
453
+ self .assertEqual (result [app ._TOKEN_SOURCE ], app ._TOKEN_SOURCE_CACHE )
447
454
self .assertEqual (cached_access_token , result .get ("access_token" ))
448
455
449
456
error1 = "error_1"
@@ -477,6 +484,7 @@ def mock_post(url, headers=None, *args, **kwargs):
477
484
"The previous error should result in same success counter plus latest error info" )
478
485
return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
479
486
result = app .acquire_token_by_device_flow ({"device_code" : "123" }, post = mock_post )
487
+ self .assertEqual (result [app ._TOKEN_SOURCE ], app ._TOKEN_SOURCE_IDP )
480
488
self .assertEqual (at , result .get ("access_token" ))
481
489
482
490
def mock_post (url , headers = None , * args , ** kwargs ):
@@ -485,6 +493,7 @@ def mock_post(url, headers=None, *args, **kwargs):
485
493
"The previous success should reset all offline telemetry counters" )
486
494
return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
487
495
result = app .acquire_token_by_device_flow ({"device_code" : "123" }, post = mock_post )
496
+ self .assertEqual (result [app ._TOKEN_SOURCE ], app ._TOKEN_SOURCE_IDP )
488
497
self .assertEqual (at , result .get ("access_token" ))
489
498
490
499
@@ -503,6 +512,7 @@ def mock_post(url, headers=None, *args, **kwargs):
503
512
result = self .app .acquire_token_by_auth_code_flow (
504
513
{"state" : state , "code_verifier" : "bar" }, {"state" : state , "code" : "012" },
505
514
post = mock_post )
515
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
506
516
self .assertEqual (at , result .get ("access_token" ))
507
517
508
518
def test_acquire_token_by_refresh_token (self ):
@@ -511,6 +521,7 @@ def mock_post(url, headers=None, *args, **kwargs):
511
521
self .assertEqual ("4|85,1|" , (headers or {}).get (CLIENT_CURRENT_TELEMETRY ))
512
522
return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
513
523
result = self .app .acquire_token_by_refresh_token ("rt" , ["s" ], post = mock_post )
524
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
514
525
self .assertEqual (at , result .get ("access_token" ))
515
526
516
527
@@ -529,6 +540,7 @@ def mock_post(url, headers=None, *args, **kwargs):
529
540
return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
530
541
result = self .app .acquire_token_by_device_flow (
531
542
{"device_code" : "123" }, post = mock_post )
543
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
532
544
self .assertEqual (at , result .get ("access_token" ))
533
545
534
546
def test_acquire_token_by_username_password (self ):
@@ -538,6 +550,7 @@ def mock_post(url, headers=None, *args, **kwargs):
538
550
return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
539
551
result = self .app .acquire_token_by_username_password (
540
552
"username" , "password" , ["scope" ], post = mock_post )
553
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
541
554
self .assertEqual (at , result .get ("access_token" ))
542
555
543
556
@@ -556,6 +569,7 @@ def mock_post(url, headers=None, *args, **kwargs):
556
569
"expires_in" : 0 ,
557
570
}))
558
571
result = self .app .acquire_token_for_client (["scope" ], post = mock_post )
572
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
559
573
self .assertEqual ("AT 1" , result .get ("access_token" ), "Shall get a new token" )
560
574
561
575
def mock_post (url , headers = None , * args , ** kwargs ):
@@ -566,13 +580,15 @@ def mock_post(url, headers=None, *args, **kwargs):
566
580
"refresh_in" : - 100 , # A hack to make sure it will attempt refresh
567
581
}))
568
582
result = self .app .acquire_token_for_client (["scope" ], post = mock_post )
583
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
569
584
self .assertEqual ("AT 2" , result .get ("access_token" ), "Shall get a new token" )
570
585
571
586
def mock_post (url , headers = None , * args , ** kwargs ):
572
587
# 1/0 # TODO: Make sure this was called
573
588
self .assertEqual ("4|730,4|" , (headers or {}).get (CLIENT_CURRENT_TELEMETRY ))
574
589
return MinimalResponse (status_code = 400 , text = json .dumps ({"error" : "foo" }))
575
590
result = self .app .acquire_token_for_client (["scope" ], post = mock_post )
591
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_CACHE )
576
592
self .assertEqual ("AT 2" , result .get ("access_token" ), "Shall get aging token" )
577
593
578
594
def test_acquire_token_on_behalf_of (self ):
@@ -581,6 +597,7 @@ def mock_post(url, headers=None, *args, **kwargs):
581
597
self .assertEqual ("4|523,0|" , (headers or {}).get (CLIENT_CURRENT_TELEMETRY ))
582
598
return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
583
599
result = self .app .acquire_token_on_behalf_of ("assertion" , ["s" ], post = mock_post )
600
+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
584
601
self .assertEqual (at , result .get ("access_token" ))
585
602
586
603
0 commit comments