-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
from tests import unittest | ||
import msal | ||
import logging | ||
import sys | ||
|
||
if not sys.platform.startswith("win"): | ||
raise unittest.SkipTest("Currently, our broker supports Windows") | ||
|
||
SCOPE_ARM = "https://management.azure.com/.default" | ||
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) | ||
enable_broker_on_windows=True, | ||
) | ||
|
||
|
||
class ForceRefreshTestCase(unittest.TestCase): | ||
def test_silent_with_force_refresh(self): | ||
print("Testing silent flow with force_refresh=True") | ||
result = pca.acquire_token_interactive(scopes=[SCOPE_ARM], prompt="select_account", parent_window_handle=pca.CONSOLE_WINDOW_HANDLE, enable_msa_passthrough=True) | ||
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] | ||
assert account, "The logged in account should have been established by interactive flow" | ||
oldToken = result.get("access_token") | ||
|
||
|
||
result = pca.acquire_token_silent( | ||
scopes=[SCOPE_ARM], | ||
account=account, | ||
force_refresh=False) | ||
|
||
# This token should have been recieved from cache | ||
assert result.get("access_token") == oldToken, "Token should not be refreshed" | ||
|
||
|
||
result = pca.acquire_token_silent( | ||
scopes=[SCOPE_ARM], | ||
account=account, | ||
force_refresh=True) | ||
|
||
# Token will be different proving it is not token from cache and was renewed | ||
assert result.get("access_token") != oldToken, "Token should be refreshed" | ||
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) | ||
|