@@ -109,6 +109,7 @@ def tester(url, **kwargs):
109109 self .scopes , self .account , post = tester )
110110 self .assertEqual ("" , result .get ("classification" ))
111111
112+
112113class TestClientApplicationAcquireTokenSilentFociBehaviors (unittest .TestCase ):
113114
114115 def setUp (self ):
@@ -263,6 +264,7 @@ def test_get_accounts_should_find_accounts_under_different_alias(self):
263264 def test_acquire_token_silent_should_find_at_under_different_alias (self ):
264265 result = self .app .acquire_token_silent (self .scopes , self .account )
265266 self .assertNotEqual (None , result )
267+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_CACHE )
266268 self .assertEqual (self .access_token , result .get ('access_token' ))
267269
268270 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):
360362 post = lambda url , * args , ** kwargs : # Utilize the undocumented test feature
361363 self .fail ("I/O shouldn't happen in cache hit AT scenario" )
362364 )
365+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_CACHE )
363366 self .assertEqual (access_token , result .get ("access_token" ))
364367 self .assertNotIn ("refresh_in" , result , "Customers need not know refresh_in" )
365368
@@ -374,6 +377,7 @@ def mock_post(url, headers=None, *args, **kwargs):
374377 "refresh_in" : 123 ,
375378 }))
376379 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 )
377381 self .assertEqual (new_access_token , result .get ("access_token" ))
378382 self .assertNotIn ("refresh_in" , result , "Customers need not know refresh_in" )
379383
@@ -385,6 +389,7 @@ def mock_post(url, headers=None, *args, **kwargs):
385389 self .assertEqual ("4|84,4|" , (headers or {}).get (CLIENT_CURRENT_TELEMETRY ))
386390 return MinimalResponse (status_code = 400 , text = json .dumps ({"error" : "foo" }))
387391 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 )
388393 self .assertEqual (old_at , result .get ("access_token" ))
389394
390395 def test_expired_token_and_unavailable_aad_should_return_error (self ):
@@ -409,6 +414,7 @@ def mock_post(url, headers=None, *args, **kwargs):
409414 "refresh_in" : 123 ,
410415 }))
411416 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 )
412418 self .assertEqual (new_access_token , result .get ("access_token" ))
413419 self .assertNotIn ("refresh_in" , result , "Customers need not know refresh_in" )
414420
@@ -444,6 +450,7 @@ def test_maintaining_offline_state_and_sending_them(self):
444450 post = lambda url , * args , ** kwargs : # Utilize the undocumented test feature
445451 self .fail ("I/O shouldn't happen in cache hit AT scenario" )
446452 )
453+ self .assertEqual (result [app ._TOKEN_SOURCE ], app ._TOKEN_SOURCE_CACHE )
447454 self .assertEqual (cached_access_token , result .get ("access_token" ))
448455
449456 error1 = "error_1"
@@ -477,6 +484,7 @@ def mock_post(url, headers=None, *args, **kwargs):
477484 "The previous error should result in same success counter plus latest error info" )
478485 return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
479486 result = app .acquire_token_by_device_flow ({"device_code" : "123" }, post = mock_post )
487+ self .assertEqual (result [app ._TOKEN_SOURCE ], app ._TOKEN_SOURCE_IDP )
480488 self .assertEqual (at , result .get ("access_token" ))
481489
482490 def mock_post (url , headers = None , * args , ** kwargs ):
@@ -485,6 +493,7 @@ def mock_post(url, headers=None, *args, **kwargs):
485493 "The previous success should reset all offline telemetry counters" )
486494 return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
487495 result = app .acquire_token_by_device_flow ({"device_code" : "123" }, post = mock_post )
496+ self .assertEqual (result [app ._TOKEN_SOURCE ], app ._TOKEN_SOURCE_IDP )
488497 self .assertEqual (at , result .get ("access_token" ))
489498
490499
@@ -503,6 +512,7 @@ def mock_post(url, headers=None, *args, **kwargs):
503512 result = self .app .acquire_token_by_auth_code_flow (
504513 {"state" : state , "code_verifier" : "bar" }, {"state" : state , "code" : "012" },
505514 post = mock_post )
515+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
506516 self .assertEqual (at , result .get ("access_token" ))
507517
508518 def test_acquire_token_by_refresh_token (self ):
@@ -511,6 +521,7 @@ def mock_post(url, headers=None, *args, **kwargs):
511521 self .assertEqual ("4|85,1|" , (headers or {}).get (CLIENT_CURRENT_TELEMETRY ))
512522 return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
513523 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 )
514525 self .assertEqual (at , result .get ("access_token" ))
515526
516527
@@ -529,6 +540,7 @@ def mock_post(url, headers=None, *args, **kwargs):
529540 return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
530541 result = self .app .acquire_token_by_device_flow (
531542 {"device_code" : "123" }, post = mock_post )
543+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
532544 self .assertEqual (at , result .get ("access_token" ))
533545
534546 def test_acquire_token_by_username_password (self ):
@@ -538,6 +550,7 @@ def mock_post(url, headers=None, *args, **kwargs):
538550 return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
539551 result = self .app .acquire_token_by_username_password (
540552 "username" , "password" , ["scope" ], post = mock_post )
553+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
541554 self .assertEqual (at , result .get ("access_token" ))
542555
543556
@@ -556,6 +569,7 @@ def mock_post(url, headers=None, *args, **kwargs):
556569 "expires_in" : 0 ,
557570 }))
558571 result = self .app .acquire_token_for_client (["scope" ], post = mock_post )
572+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
559573 self .assertEqual ("AT 1" , result .get ("access_token" ), "Shall get a new token" )
560574
561575 def mock_post (url , headers = None , * args , ** kwargs ):
@@ -566,13 +580,15 @@ def mock_post(url, headers=None, *args, **kwargs):
566580 "refresh_in" : - 100 , # A hack to make sure it will attempt refresh
567581 }))
568582 result = self .app .acquire_token_for_client (["scope" ], post = mock_post )
583+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_IDP )
569584 self .assertEqual ("AT 2" , result .get ("access_token" ), "Shall get a new token" )
570585
571586 def mock_post (url , headers = None , * args , ** kwargs ):
572587 # 1/0 # TODO: Make sure this was called
573588 self .assertEqual ("4|730,4|" , (headers or {}).get (CLIENT_CURRENT_TELEMETRY ))
574589 return MinimalResponse (status_code = 400 , text = json .dumps ({"error" : "foo" }))
575590 result = self .app .acquire_token_for_client (["scope" ], post = mock_post )
591+ self .assertEqual (result [self .app ._TOKEN_SOURCE ], self .app ._TOKEN_SOURCE_CACHE )
576592 self .assertEqual ("AT 2" , result .get ("access_token" ), "Shall get aging token" )
577593
578594 def test_acquire_token_on_behalf_of (self ):
@@ -581,6 +597,7 @@ def mock_post(url, headers=None, *args, **kwargs):
581597 self .assertEqual ("4|523,0|" , (headers or {}).get (CLIENT_CURRENT_TELEMETRY ))
582598 return MinimalResponse (status_code = 200 , text = json .dumps ({"access_token" : at }))
583599 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 )
584601 self .assertEqual (at , result .get ("access_token" ))
585602
586603
0 commit comments