From d8a71bf5499e7438c15a9e7c1e15b3735ad91245 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Thu, 2 Jul 2020 15:05:18 +0800 Subject: [PATCH 01/23] resolve ketError for Cloud Shell --- src/azure-cli-core/azure/cli/core/adal_authentication.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/adal_authentication.py b/src/azure-cli-core/azure/cli/core/adal_authentication.py index 9b9d0db6db9..f82893d7a7f 100644 --- a/src/azure-cli-core/azure/cli/core/adal_authentication.py +++ b/src/azure-cli-core/azure/cli/core/adal_authentication.py @@ -60,8 +60,10 @@ def _get_token(self): # This method is exposed for Azure Core. def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument _, token, full_token, _ = self._get_token() - - return AccessToken(token, int(full_token['expiresIn'] + time.time())) + try: + return AccessToken(token, int(full_token['expiresIn'] + time.time())) + except KeyError: + return AccessToken(token, full_token['expires_on']) # This method is exposed for msrest. def signed_session(self, session=None): # pylint: disable=arguments-differ From 7acdefa5d9490a3350bfe6d9afd5632937105060 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 2 Jul 2020 08:11:56 +0000 Subject: [PATCH 02/23] fix cloud shell --- .vscode/launch.json | 11 ++++++++--- src/azure-cli-core/azure/cli/core/_profile.py | 7 +++++++ .../azure/cli/core/adal_authentication.py | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a3bb8f78c2a..4a98376ebfb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,15 +1,20 @@ { "version": "0.2.0", - "configurations": [ + "configurations": [ { "name": "Azure CLI Debug (Integrated Console)", "type": "python", "request": "launch", - "pythonPath": "${config:python.pythonPath}", + "pythonPath": "${command:python.interpreterPath}", "program": "${workspaceRoot}/src/azure-cli/azure/cli/__main__.py", "cwd": "${workspaceRoot}", "args": [ - "--help" + "storage", + "account", + "show", + "-n", + "zuhdefault", + "--debug" ], "console": "integratedTerminal", "debugOptions": [ diff --git a/src/azure-cli-core/azure/cli/core/_profile.py b/src/azure-cli-core/azure/cli/core/_profile.py index 42bcda1e6f0..aba9a7789e3 100644 --- a/src/azure-cli-core/azure/cli/core/_profile.py +++ b/src/azure-cli-core/azure/cli/core/_profile.py @@ -588,6 +588,13 @@ def _retrieve_tokens_from_external_tenants(): if self._msi_creds is None: self._msi_creds = MsiAccountTypes.msi_auth_factory(identity_type, identity_id, resource) auth_object = self._msi_creds + token = auth_object.token + import time + from datetime import datetime + a = int(int(token['expires_in']) + time.time()) + b = int(token['expires_on']) + print(datetime.fromtimestamp(a)) + print(datetime.fromtimestamp(b)) return (auth_object, str(account[_SUBSCRIPTION_ID]), diff --git a/src/azure-cli-core/azure/cli/core/adal_authentication.py b/src/azure-cli-core/azure/cli/core/adal_authentication.py index f82893d7a7f..5e025b10db7 100644 --- a/src/azure-cli-core/azure/cli/core/adal_authentication.py +++ b/src/azure-cli-core/azure/cli/core/adal_authentication.py @@ -63,7 +63,7 @@ def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument try: return AccessToken(token, int(full_token['expiresIn'] + time.time())) except KeyError: - return AccessToken(token, full_token['expires_on']) + return AccessToken(token, int(full_token['expires_on'])) # This method is exposed for msrest. def signed_session(self, session=None): # pylint: disable=arguments-differ From e9afbbf1426081202811c0142b8870e3935a6223 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 2 Jul 2020 10:10:54 +0000 Subject: [PATCH 03/23] add get_token for msi --- .vscode/launch.json | 6 ++--- src/azure-cli-core/azure/cli/core/_profile.py | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4a98376ebfb..a85de854efc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,9 +11,9 @@ "args": [ "storage", "account", - "show", - "-n", - "zuhdefault", + "list", + "-g", + "zuh", "--debug" ], "console": "integratedTerminal", diff --git a/src/azure-cli-core/azure/cli/core/_profile.py b/src/azure-cli-core/azure/cli/core/_profile.py index aba9a7789e3..1ebb1be5221 100644 --- a/src/azure-cli-core/azure/cli/core/_profile.py +++ b/src/azure-cli-core/azure/cli/core/_profile.py @@ -21,6 +21,8 @@ from azure.cli.core.util import get_file_json, in_cloud_console, open_page_in_browser, can_launch_browser,\ is_windows, is_wsl from azure.cli.core.cloud import get_active_cloud, set_cloud_subscription +from azure.core.credentials import AccessToken +from msrestazure.azure_active_directory import MSIAuthentication from knack.log import get_logger from knack.util import CLIError @@ -588,13 +590,6 @@ def _retrieve_tokens_from_external_tenants(): if self._msi_creds is None: self._msi_creds = MsiAccountTypes.msi_auth_factory(identity_type, identity_id, resource) auth_object = self._msi_creds - token = auth_object.token - import time - from datetime import datetime - a = int(int(token['expires_in']) + time.time()) - b = int(token['expires_on']) - print(datetime.fromtimestamp(a)) - print(datetime.fromtimestamp(b)) return (auth_object, str(account[_SUBSCRIPTION_ID]), @@ -767,6 +762,13 @@ def get_installation_id(self): return installation_id +class MsiAuthentication(MSIAuthentication): + # This method is exposed for Azure Core. + def get_token(self, resource): + token_entry = self._vm_msi.get_token(self.resource) + return AccessToken(token_entry['access_token'], token_entry['expires_on']) + + class MsiAccountTypes(object): # pylint: disable=no-method-argument,no-self-argument system_assigned = 'MSI' @@ -781,15 +783,14 @@ def valid_msi_account_types(): @staticmethod def msi_auth_factory(cli_account_name, identity, resource): - from msrestazure.azure_active_directory import MSIAuthentication if cli_account_name == MsiAccountTypes.system_assigned: - return MSIAuthentication(resource=resource) + return MsiAuthentication(resource=resource) if cli_account_name == MsiAccountTypes.user_assigned_client_id: - return MSIAuthentication(resource=resource, client_id=identity) + return MsiAuthentication(resource=resource, client_id=identity) if cli_account_name == MsiAccountTypes.user_assigned_object_id: - return MSIAuthentication(resource=resource, object_id=identity) + return MsiAuthentication(resource=resource, object_id=identity) if cli_account_name == MsiAccountTypes.user_assigned_resource_id: - return MSIAuthentication(resource=resource, msi_res_id=identity) + return MsiAuthentication(resource=resource, msi_res_id=identity) raise ValueError("unrecognized msi account name '{}'".format(cli_account_name)) From 9f2be7a6b500733603cee2e1c0fd610b17d22c6a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 2 Jul 2020 10:14:50 +0000 Subject: [PATCH 04/23] add more to ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1c235329480..87270754a64 100644 --- a/.gitignore +++ b/.gitignore @@ -66,6 +66,7 @@ src/build /doc/sphinx/_build /.vs/config/applicationhost.config .vscode/settings.json +.vscode/launch.json .vscode/.ropeproject/ .vscode/tags .vscode/cSpell.json From 87aa5992bf0b3a2daf844f272baffd0a517c7360 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 2 Jul 2020 10:18:48 +0000 Subject: [PATCH 05/23] reset --- .gitignore | 1 - .vscode/launch.json | 11 +++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 87270754a64..1c235329480 100644 --- a/.gitignore +++ b/.gitignore @@ -66,7 +66,6 @@ src/build /doc/sphinx/_build /.vs/config/applicationhost.config .vscode/settings.json -.vscode/launch.json .vscode/.ropeproject/ .vscode/tags .vscode/cSpell.json diff --git a/.vscode/launch.json b/.vscode/launch.json index a85de854efc..a3bb8f78c2a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,20 +1,15 @@ { "version": "0.2.0", - "configurations": [ + "configurations": [ { "name": "Azure CLI Debug (Integrated Console)", "type": "python", "request": "launch", - "pythonPath": "${command:python.interpreterPath}", + "pythonPath": "${config:python.pythonPath}", "program": "${workspaceRoot}/src/azure-cli/azure/cli/__main__.py", "cwd": "${workspaceRoot}", "args": [ - "storage", - "account", - "list", - "-g", - "zuh", - "--debug" + "--help" ], "console": "integratedTerminal", "debugOptions": [ From 83c1654b36ecac1f7c7944be16ca0c22e8ddd869 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 2 Jul 2020 10:19:34 +0000 Subject: [PATCH 06/23] ignore launch.json --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1c235329480..b474a2c374c 100644 --- a/.gitignore +++ b/.gitignore @@ -65,6 +65,7 @@ src/build /doc/_build /doc/sphinx/_build /.vs/config/applicationhost.config +.vscode/launch.json .vscode/settings.json .vscode/.ropeproject/ .vscode/tags From 141f00d3d14b7f51c1c3210e935caeaf4afedf09 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 2 Jul 2020 11:01:57 +0000 Subject: [PATCH 07/23] rename class --- src/azure-cli-core/azure/cli/core/_profile.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_profile.py b/src/azure-cli-core/azure/cli/core/_profile.py index 1ebb1be5221..597aad22cd5 100644 --- a/src/azure-cli-core/azure/cli/core/_profile.py +++ b/src/azure-cli-core/azure/cli/core/_profile.py @@ -762,7 +762,7 @@ def get_installation_id(self): return installation_id -class MsiAuthentication(MSIAuthentication): +class MSIAuthenticationWrapper(MSIAuthentication): # This method is exposed for Azure Core. def get_token(self, resource): token_entry = self._vm_msi.get_token(self.resource) @@ -784,13 +784,13 @@ def valid_msi_account_types(): @staticmethod def msi_auth_factory(cli_account_name, identity, resource): if cli_account_name == MsiAccountTypes.system_assigned: - return MsiAuthentication(resource=resource) + return MSIAuthenticationWrapper(resource=resource) if cli_account_name == MsiAccountTypes.user_assigned_client_id: - return MsiAuthentication(resource=resource, client_id=identity) + return MSIAuthenticationWrapper(resource=resource, client_id=identity) if cli_account_name == MsiAccountTypes.user_assigned_object_id: - return MsiAuthentication(resource=resource, object_id=identity) + return MSIAuthenticationWrapper(resource=resource, object_id=identity) if cli_account_name == MsiAccountTypes.user_assigned_resource_id: - return MsiAuthentication(resource=resource, msi_res_id=identity) + return MSIAuthenticationWrapper(resource=resource, msi_res_id=identity) raise ValueError("unrecognized msi account name '{}'".format(cli_account_name)) From 6c41d3c6e265d97c93f76ed2b3afca5e1463494b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 2 Jul 2020 11:42:45 +0000 Subject: [PATCH 08/23] fix style --- .vscode/launch.json | 4 ++-- src/azure-cli-core/azure/cli/core/_profile.py | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index a3bb8f78c2a..732d1156472 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,11 +5,11 @@ "name": "Azure CLI Debug (Integrated Console)", "type": "python", "request": "launch", - "pythonPath": "${config:python.pythonPath}", + "pythonPath": "${command:python.interpreterPath}", "program": "${workspaceRoot}/src/azure-cli/azure/cli/__main__.py", "cwd": "${workspaceRoot}", "args": [ - "--help" + "storage", "blob", "show", "-n", "a.txt", "-c", "test", "--account-name", "zuhdefault", "--auth-mode", "login" ], "console": "integratedTerminal", "debugOptions": [ diff --git a/src/azure-cli-core/azure/cli/core/_profile.py b/src/azure-cli-core/azure/cli/core/_profile.py index 597aad22cd5..1e420ff1940 100644 --- a/src/azure-cli-core/azure/cli/core/_profile.py +++ b/src/azure-cli-core/azure/cli/core/_profile.py @@ -309,7 +309,6 @@ def find_subscriptions_in_vm_with_msi(self, identity_id=None, allow_no_subscript import jwt from requests import HTTPError - from msrestazure.azure_active_directory import MSIAuthentication from msrestazure.tools import is_valid_resource_id resource = self.cli_ctx.cloud.endpoints.active_directory_resource_id @@ -390,7 +389,6 @@ def find_subscriptions_in_cloud_console(self): return deepcopy(consolidated) def _get_token_from_cloud_shell(self, resource): # pylint: disable=no-self-use - from msrestazure.azure_active_directory import MSIAuthentication auth = MSIAuthentication(resource=resource) auth.set_token() token_entry = auth.token @@ -764,9 +762,9 @@ def get_installation_id(self): class MSIAuthenticationWrapper(MSIAuthentication): # This method is exposed for Azure Core. - def get_token(self, resource): - token_entry = self._vm_msi.get_token(self.resource) - return AccessToken(token_entry['access_token'], token_entry['expires_on']) + def get_token(self): + self.set_token() + return AccessToken(self.token['access_token'], int(self.token['expires_on'])) class MsiAccountTypes(object): From b93e2444f9524c9f7a0932f5a680e92b1c78cd87 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 11:29:58 +0800 Subject: [PATCH 09/23] pass test_get_login_credentials_msi_system_assigned --- src/azure-cli-core/azure/cli/core/tests/test_profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile.py b/src/azure-cli-core/azure/cli/core/tests/test_profile.py index 080be1e0996..6eebbfe18fa 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile.py @@ -645,7 +645,7 @@ def test_get_login_credentials_aux_tenants(self, mock_get_token, mock_read_cred_ aux_tenants=[test_tenant_id2]) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_system_assigned(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] From 0f54593624c60d4febde811945e0976026a6614a Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 11:31:15 +0800 Subject: [PATCH 10/23] pass test_get_login_credentials_msi_system_assigned --- .../azure/cli/core/tests/test_profile_v2016_06_01.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py index e9c16209562..aeeaee0a17e 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py @@ -571,7 +571,7 @@ def test_get_login_credentials_aux_subscriptions(self, mock_get_token, mock_read self.assertEqual(mock_get_token.call_count, 2) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_system_assigned(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] From f95b978d7ee6a923cd05f1b0a2ddfe77fc0ffc78 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 11:32:49 +0800 Subject: [PATCH 11/23] =?UTF-8?q?=E2=9D=AF=20azdev=20test=20test=5Fget=5Fl?= =?UTF-8?q?ogin=5Fcredentials=5Fmsi=5Fuser=5Fassigned=5Fwith=5Fclient=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../azure/cli/core/tests/test_profile_v2016_06_01.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py index aeeaee0a17e..e37c489c865 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py @@ -602,7 +602,7 @@ def test_get_login_credentials_msi_system_assigned(self, mock_msi_auth, mock_rea self.assertTrue(cred.token_read_count) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_client_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] From d872b657089635e03ed73d2de357d94348bf4a18 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 11:35:47 +0800 Subject: [PATCH 12/23] test_get_login_credentials_msi_user_assigned_with_object_id --- .../azure/cli/core/tests/test_profile_v2016_06_01.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py index e37c489c865..18280336f37 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py @@ -633,7 +633,7 @@ def test_get_login_credentials_msi_user_assigned_with_client_id(self, mock_msi_a self.assertTrue(cred.client_id, test_client_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_object_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] From 936ab6d23e6e091f871fffad89b74968df4907a0 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 11:36:35 +0800 Subject: [PATCH 13/23] test_get_login_credentials_msi_user_assigned_with_res_id --- .../azure/cli/core/tests/test_profile_v2016_06_01.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py index 18280336f37..02c1657692c 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py @@ -664,7 +664,7 @@ def test_get_login_credentials_msi_user_assigned_with_object_id(self, mock_msi_a self.assertTrue(cred.object_id, test_object_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_res_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] From e9f54418b2e4f7bae7d8875f6fdf2303715d9e8b Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 11:42:27 +0800 Subject: [PATCH 14/23] test pass get_raaw_token --- src/azure-cli-core/azure/cli/core/tests/test_profile.py | 8 ++++---- .../azure/cli/core/tests/test_profile_v2016_06_01.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile.py b/src/azure-cli-core/azure/cli/core/tests/test_profile.py index 6eebbfe18fa..b989d99d1b6 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile.py @@ -676,7 +676,7 @@ def test_get_login_credentials_msi_system_assigned(self, mock_msi_auth, mock_rea self.assertTrue(cred.token_read_count) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_client_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -707,7 +707,7 @@ def test_get_login_credentials_msi_user_assigned_with_client_id(self, mock_msi_a self.assertTrue(cred.client_id, test_client_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_object_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -738,7 +738,7 @@ def test_get_login_credentials_msi_user_assigned_with_object_id(self, mock_msi_a self.assertTrue(cred.object_id, test_object_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_res_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -849,7 +849,7 @@ def test_get_raw_token_for_sp(self, mock_get_token, mock_read_cred_file): self.assertEqual(tenant, self.tenant_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_raw_token_msi_system_assigned(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py index 02c1657692c..76f2a70b055 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py @@ -753,7 +753,7 @@ def test_get_raw_token_for_sp(self, mock_get_token, mock_read_cred_file): self.assertEqual(tenant, self.tenant_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_raw_token_msi_system_assigned(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] From e751ece853e3a1bdec4670520741ddccf51bdb96 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 12:56:04 +0800 Subject: [PATCH 15/23] test_get_raw_token_in_cloud_console --- src/azure-cli-core/azure/cli/core/_profile.py | 2 +- src/azure-cli-core/azure/cli/core/tests/test_profile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_profile.py b/src/azure-cli-core/azure/cli/core/_profile.py index 1e420ff1940..13b98e9034b 100644 --- a/src/azure-cli-core/azure/cli/core/_profile.py +++ b/src/azure-cli-core/azure/cli/core/_profile.py @@ -389,7 +389,7 @@ def find_subscriptions_in_cloud_console(self): return deepcopy(consolidated) def _get_token_from_cloud_shell(self, resource): # pylint: disable=no-self-use - auth = MSIAuthentication(resource=resource) + auth = MSIAuthenticationWrapper(resource=resource) auth.set_token() token_entry = auth.token return (token_entry['token_type'], token_entry['access_token'], token_entry) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile.py b/src/azure-cli-core/azure/cli/core/tests/test_profile.py index b989d99d1b6..905a181c8f0 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile.py @@ -884,7 +884,7 @@ def test_get_raw_token_msi_system_assigned(self, mock_msi_auth, mock_read_cred_f @mock.patch('azure.cli.core._profile.in_cloud_console', autospec=True) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_raw_token_in_cloud_console(self, mock_msi_auth, mock_read_cred_file, mock_in_cloud_console): mock_read_cred_file.return_value = [] mock_in_cloud_console.return_value = True From 55b350ad515e105c27162c4dbf7cab97798cbb63 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 13:13:08 +0800 Subject: [PATCH 16/23] fix test --- src/azure-cli-core/azure/cli/core/_profile.py | 8 ++++---- src/azure-cli-core/azure/cli/core/tests/test_profile.py | 2 +- .../azure/cli/core/tests/test_profile_v2016_06_01.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_profile.py b/src/azure-cli-core/azure/cli/core/_profile.py index 13b98e9034b..2bd0b55cfbe 100644 --- a/src/azure-cli-core/azure/cli/core/_profile.py +++ b/src/azure-cli-core/azure/cli/core/_profile.py @@ -314,12 +314,12 @@ def find_subscriptions_in_vm_with_msi(self, identity_id=None, allow_no_subscript if identity_id: if is_valid_resource_id(identity_id): - msi_creds = MSIAuthentication(resource=resource, msi_res_id=identity_id) + msi_creds = MSIAuthenticationWrapper(resource=resource, msi_res_id=identity_id) identity_type = MsiAccountTypes.user_assigned_resource_id else: authenticated = False try: - msi_creds = MSIAuthentication(resource=resource, client_id=identity_id) + msi_creds = MSIAuthenticationWrapper(resource=resource, client_id=identity_id) identity_type = MsiAccountTypes.user_assigned_client_id authenticated = True except HTTPError as ex: @@ -331,7 +331,7 @@ def find_subscriptions_in_vm_with_msi(self, identity_id=None, allow_no_subscript if not authenticated: try: identity_type = MsiAccountTypes.user_assigned_object_id - msi_creds = MSIAuthentication(resource=resource, object_id=identity_id) + msi_creds = MSIAuthenticationWrapper(resource=resource, object_id=identity_id) authenticated = True except HTTPError as ex: if ex.response.reason == 'Bad Request' and ex.response.status == 400: @@ -344,7 +344,7 @@ def find_subscriptions_in_vm_with_msi(self, identity_id=None, allow_no_subscript else: identity_type = MsiAccountTypes.system_assigned - msi_creds = MSIAuthentication(resource=resource) + msi_creds = MSIAuthenticationWrapper(resource=resource) token_entry = msi_creds.token token = token_entry['access_token'] diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile.py b/src/azure-cli-core/azure/cli/core/tests/test_profile.py index 905a181c8f0..aec2a92b7db 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile.py @@ -1037,7 +1037,7 @@ def test_find_subscriptions_thru_username_non_password(self, mock_auth_context): # assert self.assertEqual([], subs) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) @mock.patch('azure.cli.core.profiles._shared.get_client_class', autospec=True) @mock.patch('azure.cli.core._profile._get_cloud_console_token_endpoint', autospec=True) @mock.patch('azure.cli.core._profile.SubscriptionFinder', autospec=True) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py index 76f2a70b055..0ca3e2d0591 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py @@ -899,7 +899,7 @@ def test_find_subscriptions_thru_username_non_password(self, mock_auth_context): # assert self.assertEqual([], subs) - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) @mock.patch('azure.cli.core.profiles._shared.get_client_class', autospec=True) @mock.patch('azure.cli.core._profile._get_cloud_console_token_endpoint', autospec=True) @mock.patch('azure.cli.core._profile.SubscriptionFinder', autospec=True) From 41b2ae10871ecff85e7e073f5cdee37612050939 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 13:40:41 +0800 Subject: [PATCH 17/23] test pass --- src/azure-cli-core/azure/cli/core/tests/test_profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile.py b/src/azure-cli-core/azure/cli/core/tests/test_profile.py index aec2a92b7db..2909a05e870 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile.py @@ -1186,7 +1186,7 @@ def __init__(self, *args, **kwargs): self.assertEqual(s['id'], self.id1.split('/')[-1]) self.assertEqual(s['tenantId'], '54826b22-38d6-4fb2-bad9-b7b93a3e9c5a') - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) @mock.patch('azure.cli.core.profiles._shared.get_client_class', autospec=True) @mock.patch('azure.cli.core._profile.SubscriptionFinder', autospec=True) def test_find_subscriptions_in_vm_with_msi_user_assigned_with_object_id(self, mock_subscription_finder, mock_get_client_class, From 4cf1fcb3506d6154df4b72ababeb1942349a49cd Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 13:48:43 +0800 Subject: [PATCH 18/23] test pass --- .../azure/cli/core/tests/test_profile_v2016_06_01.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py index 0ca3e2d0591..5f84985d241 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile_v2016_06_01.py @@ -1048,7 +1048,7 @@ def __init__(self, *args, **kwargs): self.assertEqual(s['id'], self.id1.split('/')[-1]) self.assertEqual(s['tenantId'], '54826b22-38d6-4fb2-bad9-b7b93a3e9c5a') - @mock.patch('msrestazure.azure_active_directory.MSIAuthentication', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) @mock.patch('azure.cli.core.profiles._shared.get_client_class', autospec=True) @mock.patch('azure.cli.core._profile.SubscriptionFinder', autospec=True) def test_find_subscriptions_in_vm_with_msi_user_assigned_with_object_id(self, mock_subscription_finder, mock_get_client_class, From 5bdfe741bf30e59e9a30727a08386a2735eb4402 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 14:16:05 +0800 Subject: [PATCH 19/23] revert launch.json --- .gitignore | 2 +- .vscode/launch.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index b474a2c374c..1e0022cad6c 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,7 @@ src/build /doc/_build /doc/sphinx/_build /.vs/config/applicationhost.config -.vscode/launch.json + .vscode/settings.json .vscode/.ropeproject/ .vscode/tags diff --git a/.vscode/launch.json b/.vscode/launch.json index 732d1156472..a3bb8f78c2a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,11 +5,11 @@ "name": "Azure CLI Debug (Integrated Console)", "type": "python", "request": "launch", - "pythonPath": "${command:python.interpreterPath}", + "pythonPath": "${config:python.pythonPath}", "program": "${workspaceRoot}/src/azure-cli/azure/cli/__main__.py", "cwd": "${workspaceRoot}", "args": [ - "storage", "blob", "show", "-n", "a.txt", "-c", "test", "--account-name", "zuhdefault", "--auth-mode", "login" + "--help" ], "console": "integratedTerminal", "debugOptions": [ From 8a5985e32a44b918e39de082d071fab5c86c3d9b Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 14:16:29 +0800 Subject: [PATCH 20/23] change gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1e0022cad6c..b474a2c374c 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,7 @@ src/build /doc/_build /doc/sphinx/_build /.vs/config/applicationhost.config - +.vscode/launch.json .vscode/settings.json .vscode/.ropeproject/ .vscode/tags From 2ab696b79b6c8c7dc875d5955b9d0b92e1bc091a Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Fri, 3 Jul 2020 16:02:45 +0800 Subject: [PATCH 21/23] import as required --- src/azure-cli-core/azure/cli/core/_profile.py | 11 ++--------- .../azure/cli/core/adal_authentication.py | 8 ++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/_profile.py b/src/azure-cli-core/azure/cli/core/_profile.py index 2bd0b55cfbe..23a4ad0b35e 100644 --- a/src/azure-cli-core/azure/cli/core/_profile.py +++ b/src/azure-cli-core/azure/cli/core/_profile.py @@ -21,8 +21,8 @@ from azure.cli.core.util import get_file_json, in_cloud_console, open_page_in_browser, can_launch_browser,\ is_windows, is_wsl from azure.cli.core.cloud import get_active_cloud, set_cloud_subscription -from azure.core.credentials import AccessToken -from msrestazure.azure_active_directory import MSIAuthentication + +from .adal_authentication import MSIAuthenticationWrapper from knack.log import get_logger from knack.util import CLIError @@ -760,13 +760,6 @@ def get_installation_id(self): return installation_id -class MSIAuthenticationWrapper(MSIAuthentication): - # This method is exposed for Azure Core. - def get_token(self): - self.set_token() - return AccessToken(self.token['access_token'], int(self.token['expires_on'])) - - class MsiAccountTypes(object): # pylint: disable=no-method-argument,no-self-argument system_assigned = 'MSI' diff --git a/src/azure-cli-core/azure/cli/core/adal_authentication.py b/src/azure-cli-core/azure/cli/core/adal_authentication.py index 5e025b10db7..275b09e419a 100644 --- a/src/azure-cli-core/azure/cli/core/adal_authentication.py +++ b/src/azure-cli-core/azure/cli/core/adal_authentication.py @@ -8,6 +8,7 @@ import adal from msrest.authentication import Authentication +from msrestazure.azure_active_directory import MSIAuthentication from azure.core.credentials import AccessToken from azure.cli.core.util import in_cloud_console @@ -85,3 +86,10 @@ def _log_hostname(): logger = get_logger(__name__) logger.warning("A Cloud Shell credential problem occurred. When you report the issue with the error " "below, please mention the hostname '%s'", socket.gethostname()) + + +class MSIAuthenticationWrapper(MSIAuthentication): + # This method is exposed for Azure Core. + def get_token(self): + self.set_token() + return AccessToken(self.token['access_token'], int(self.token['expires_on'])) From 00e01aa31b6798cd11ead782709863ce04d67459 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Thu, 9 Jul 2020 16:53:04 +0800 Subject: [PATCH 22/23] resolve comments --- .gitignore | 1 - .../azure/cli/core/adal_authentication.py | 2 +- .../azure/cli/core/tests/test_profile.py | 16 ++++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b474a2c374c..1c235329480 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,6 @@ src/build /doc/_build /doc/sphinx/_build /.vs/config/applicationhost.config -.vscode/launch.json .vscode/settings.json .vscode/.ropeproject/ .vscode/tags diff --git a/src/azure-cli-core/azure/cli/core/adal_authentication.py b/src/azure-cli-core/azure/cli/core/adal_authentication.py index 275b09e419a..19cfd10b56c 100644 --- a/src/azure-cli-core/azure/cli/core/adal_authentication.py +++ b/src/azure-cli-core/azure/cli/core/adal_authentication.py @@ -63,7 +63,7 @@ def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument _, token, full_token, _ = self._get_token() try: return AccessToken(token, int(full_token['expiresIn'] + time.time())) - except KeyError: + except KeyError: # needed to deal with differing unserialized MSI token payload return AccessToken(token, int(full_token['expires_on'])) # This method is exposed for msrest. diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile.py b/src/azure-cli-core/azure/cli/core/tests/test_profile.py index 2909a05e870..7022fca706d 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile.py @@ -645,7 +645,7 @@ def test_get_login_credentials_aux_tenants(self, mock_get_token, mock_read_cred_ aux_tenants=[test_tenant_id2]) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_system_assigned(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -676,7 +676,7 @@ def test_get_login_credentials_msi_system_assigned(self, mock_msi_auth, mock_rea self.assertTrue(cred.token_read_count) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_client_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -707,7 +707,7 @@ def test_get_login_credentials_msi_user_assigned_with_client_id(self, mock_msi_a self.assertTrue(cred.client_id, test_client_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_object_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -738,7 +738,7 @@ def test_get_login_credentials_msi_user_assigned_with_object_id(self, mock_msi_a self.assertTrue(cred.object_id, test_object_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_res_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -849,7 +849,7 @@ def test_get_raw_token_for_sp(self, mock_get_token, mock_read_cred_file): self.assertEqual(tenant, self.tenant_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) def test_get_raw_token_msi_system_assigned(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -884,7 +884,7 @@ def test_get_raw_token_msi_system_assigned(self, mock_msi_auth, mock_read_cred_f @mock.patch('azure.cli.core._profile.in_cloud_console', autospec=True) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) def test_get_raw_token_in_cloud_console(self, mock_msi_auth, mock_read_cred_file, mock_in_cloud_console): mock_read_cred_file.return_value = [] mock_in_cloud_console.return_value = True @@ -1037,7 +1037,7 @@ def test_find_subscriptions_thru_username_non_password(self, mock_auth_context): # assert self.assertEqual([], subs) - @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) @mock.patch('azure.cli.core.profiles._shared.get_client_class', autospec=True) @mock.patch('azure.cli.core._profile._get_cloud_console_token_endpoint', autospec=True) @mock.patch('azure.cli.core._profile.SubscriptionFinder', autospec=True) @@ -1186,7 +1186,7 @@ def __init__(self, *args, **kwargs): self.assertEqual(s['id'], self.id1.split('/')[-1]) self.assertEqual(s['tenantId'], '54826b22-38d6-4fb2-bad9-b7b93a3e9c5a') - @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) @mock.patch('azure.cli.core.profiles._shared.get_client_class', autospec=True) @mock.patch('azure.cli.core._profile.SubscriptionFinder', autospec=True) def test_find_subscriptions_in_vm_with_msi_user_assigned_with_object_id(self, mock_subscription_finder, mock_get_client_class, From 6085e2a53d31897f2ff4b708f0c0fc8d6a8c2b20 Mon Sep 17 00:00:00 2001 From: Zunli Hu Date: Thu, 9 Jul 2020 17:30:53 +0800 Subject: [PATCH 23/23] mock test --- .../azure/cli/core/tests/test_profile.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_profile.py b/src/azure-cli-core/azure/cli/core/tests/test_profile.py index 7022fca706d..2909a05e870 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_profile.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_profile.py @@ -645,7 +645,7 @@ def test_get_login_credentials_aux_tenants(self, mock_get_token, mock_read_cred_ aux_tenants=[test_tenant_id2]) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_system_assigned(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -676,7 +676,7 @@ def test_get_login_credentials_msi_system_assigned(self, mock_msi_auth, mock_rea self.assertTrue(cred.token_read_count) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_client_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -707,7 +707,7 @@ def test_get_login_credentials_msi_user_assigned_with_client_id(self, mock_msi_a self.assertTrue(cred.client_id, test_client_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_object_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -738,7 +738,7 @@ def test_get_login_credentials_msi_user_assigned_with_object_id(self, mock_msi_a self.assertTrue(cred.object_id, test_object_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_login_credentials_msi_user_assigned_with_res_id(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -849,7 +849,7 @@ def test_get_raw_token_for_sp(self, mock_get_token, mock_read_cred_file): self.assertEqual(tenant, self.tenant_id) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_raw_token_msi_system_assigned(self, mock_msi_auth, mock_read_cred_file): mock_read_cred_file.return_value = [] @@ -884,7 +884,7 @@ def test_get_raw_token_msi_system_assigned(self, mock_msi_auth, mock_read_cred_f @mock.patch('azure.cli.core._profile.in_cloud_console', autospec=True) @mock.patch('azure.cli.core._profile._load_tokens_from_file', autospec=True) - @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) def test_get_raw_token_in_cloud_console(self, mock_msi_auth, mock_read_cred_file, mock_in_cloud_console): mock_read_cred_file.return_value = [] mock_in_cloud_console.return_value = True @@ -1037,7 +1037,7 @@ def test_find_subscriptions_thru_username_non_password(self, mock_auth_context): # assert self.assertEqual([], subs) - @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) @mock.patch('azure.cli.core.profiles._shared.get_client_class', autospec=True) @mock.patch('azure.cli.core._profile._get_cloud_console_token_endpoint', autospec=True) @mock.patch('azure.cli.core._profile.SubscriptionFinder', autospec=True) @@ -1186,7 +1186,7 @@ def __init__(self, *args, **kwargs): self.assertEqual(s['id'], self.id1.split('/')[-1]) self.assertEqual(s['tenantId'], '54826b22-38d6-4fb2-bad9-b7b93a3e9c5a') - @mock.patch('azure.cli.core.adal_authentication.MSIAuthenticationWrapper', autospec=True) + @mock.patch('azure.cli.core._profile.MSIAuthenticationWrapper', autospec=True) @mock.patch('azure.cli.core.profiles._shared.get_client_class', autospec=True) @mock.patch('azure.cli.core._profile.SubscriptionFinder', autospec=True) def test_find_subscriptions_in_vm_with_msi_user_assigned_with_object_id(self, mock_subscription_finder, mock_get_client_class,