@@ -15,32 +15,28 @@ def temp_location():
15
15
yield os .path .join (test_folder , 'token_cache.bin' )
16
16
shutil .rmtree (test_folder , ignore_errors = True )
17
17
18
-
19
- def _test_token_cache_roundtrip (cache ):
18
+ def _test_token_cache_roundtrip (persistence ):
20
19
client_id = os .getenv ('AZURE_CLIENT_ID' )
21
20
client_secret = os .getenv ('AZURE_CLIENT_SECRET' )
22
21
if not (client_id and client_secret ):
23
22
pytest .skip ('no credentials present to test TokenCache round-trip with.' )
24
23
25
- app = msal .ConfidentialClientApplication (
26
- client_id = client_id ,
27
- client_credential = client_secret ,
28
- token_cache = cache )
29
24
desired_scopes = ['https://graph.microsoft.com/.default' ]
30
- token1 = app .acquire_token_for_client (scopes = desired_scopes )
31
- os .utime ( # Mock having another process update the cache
32
- cache ._persistence .get_location (), None )
33
- token2 = app .acquire_token_silent (scopes = desired_scopes , account = None )
34
- assert token1 ['access_token' ] == token2 ['access_token' ]
35
-
36
- def test_file_token_cache_roundtrip (temp_location ):
37
- _test_token_cache_roundtrip (PersistedTokenCache (FilePersistence (temp_location )))
38
-
39
- def test_current_platform_cache_roundtrip_with_persistence_builder (temp_location ):
40
- _test_token_cache_roundtrip (PersistedTokenCache (build_encrypted_persistence (temp_location )))
41
-
42
- def test_persisted_token_cache (temp_location ):
43
- _test_token_cache_roundtrip (PersistedTokenCache (FilePersistence (temp_location )))
25
+ apps = [ # Multiple apps sharing same persistence
26
+ msal .ConfidentialClientApplication (
27
+ client_id , client_credential = client_secret ,
28
+ token_cache = PersistedTokenCache (persistence )) for i in range (2 )]
29
+ token1 = apps [0 ].acquire_token_for_client (scopes = desired_scopes )
30
+ assert token1 ["token_source" ] == "identity_provider" , "Initial token should come from IdP"
31
+ token2 = apps [1 ].acquire_token_for_client (scopes = desired_scopes ) # Hit token cache in MSAL 1.23+
32
+ assert token2 ["token_source" ] == "cache" , "App2 should hit cache written by app1"
33
+ assert token1 ['access_token' ] == token2 ['access_token' ], "Cache should hit"
34
+
35
+ def test_token_cache_roundtrip_with_persistence_biulder (temp_location ):
36
+ _test_token_cache_roundtrip (build_encrypted_persistence (temp_location ))
37
+
38
+ def test_token_cache_roundtrip_with_file_persistence (temp_location ):
39
+ _test_token_cache_roundtrip (FilePersistence (temp_location ))
44
40
45
41
def test_file_not_found_error_is_not_raised ():
46
42
persistence = FilePersistence ('non_existing_file' )
0 commit comments