Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions src/azure-cli-core/azure/cli/core/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,47 +501,6 @@ def test_login_in_cloud_shell(self, cloud_shell_credential_mock, create_subscrip
self.assertEqual(s['name'], self.display_name1)
self.assertEqual(s['id'], self.id1.split('/')[-1])

@mock.patch('azure.cli.core.auth.adal_authentication.MSIAuthenticationWrapper', autospec=True)
@mock.patch('azure.cli.core._profile.SubscriptionFinder._create_subscription_client', autospec=True)
@mock.patch.dict('os.environ', {'AZURE_CORE_USE_MSAL_MANAGED_IDENTITY': 'false'})
def test_login_with_mi_user_assigned_object_id(self, create_subscription_client_mock,
mock_msi_auth):
Comment on lines -507 to -508
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was overlooked in #31577.

mock_subscription_client = mock.MagicMock()
mock_subscription_client.subscriptions.list.return_value = [deepcopy(self.subscription1_raw)]
create_subscription_client_mock.return_value = mock_subscription_client

from azure.cli.core.azclierror import AzureResponseError
class AuthStub:
def __init__(self, **kwargs):
self.token = None
self.client_id = kwargs.get('client_id')
self.object_id = kwargs.get('object_id')
# since msrestazure 0.4.34, set_token in init
self.set_token()

def set_token(self):
# here we will reject the 1st sniffing of trying with client_id and then acccept the 2nd
if self.object_id:
self.token = {
'token_type': 'Bearer',
'access_token': TestProfile.test_mi_access_token
}
else:
raise AzureResponseError('Failed to connect to MSI. Please make sure MSI is configured correctly.\n'
'Get Token request returned http error: 400, reason: Bad Request')

profile = Profile(cli_ctx=DummyCli(), storage={'subscriptions': None})

mock_msi_auth.side_effect = AuthStub
test_object_id = '54826b22-38d6-4fb2-bad9-b7b93a3e9999'

subscriptions = profile.login_with_managed_identity(object_id=test_object_id)

s = subscriptions[0]
self.assertEqual(s['user']['name'], 'userAssignedIdentity')
self.assertEqual(s['user']['type'], 'servicePrincipal')
self.assertEqual(s['user']['assignedIdentityInfo'], 'MSIObject-{}'.format(test_object_id))

@mock.patch('azure.cli.core._profile.SubscriptionFinder._create_subscription_client', autospec=True)
@mock.patch('azure.cli.core.auth.msal_credentials.ManagedIdentityCredential', ManagedIdentityCredentialStub)
def test_login_with_mi_system_assigned(self, create_subscription_client_mock):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ def validate_bootstrap_container_registry_resource_id(namespace):
container_registry_resource_id = namespace.bootstrap_container_registry_resource_id
if container_registry_resource_id is None or container_registry_resource_id == '':
return
from msrestazure.tools import is_valid_resource_id
from azure.mgmt.core.tools import is_valid_resource_id
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call is added by #31095 after #29856 is merged.

if not is_valid_resource_id(container_registry_resource_id):
raise InvalidArgumentValueError("--bootstrap-container-registry-resource-id is not a valid Azure resource ID.")

Expand Down