-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathtest_force_refresh.py
More file actions
43 lines (35 loc) · 1.6 KB
/
test_force_refresh.py
File metadata and controls
43 lines (35 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from tests import unittest
import msal
import sys
if sys.platform not in ("win32", "darwin"):
raise unittest.SkipTest(f"Our broker does not support {sys.platform}")
SCOPES = ["https://management.azure.com/.default"]
_AZURE_CLI = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
pca = msal.PublicClientApplication(
_AZURE_CLI,
authority="https://login.microsoftonline.com/organizations",
enable_broker_on_mac=True,
enable_broker_on_windows=True,
)
class ForceRefreshTestCase(unittest.TestCase):
def test_silent_with_force_refresh_should_return_a_new_token(self):
result = pca.acquire_token_interactive(
scopes=SCOPES,
prompt="select_account",
parent_window_handle=pca.CONSOLE_WINDOW_HANDLE,
enable_msa_passthrough=True,
)
accounts = pca.get_accounts()
self.assertNotEqual(
[], accounts,
"Interactive flow should have established a logged-in account")
account = accounts[0]
old_token = result.get("access_token")
result = pca.acquire_token_silent(SCOPES, account)
assertion = "This token should have been received from cache"
self.assertEqual(result.get("access_token"), old_token, assertion)
self.assertEqual(result.get("token_source"), "cache", assertion)
result = pca.acquire_token_silent(SCOPES, account, force_refresh=True)
assertion = "A new token should have been received from broker"
self.assertNotEqual(result.get("access_token"), old_token, assertion)
self.assertEqual(result.get("token_source"), "broker", assertion)