@@ -501,47 +501,6 @@ def test_login_in_cloud_shell(self, cloud_shell_credential_mock, create_subscrip
501501 self .assertEqual (s ['name' ], self .display_name1 )
502502 self .assertEqual (s ['id' ], self .id1 .split ('/' )[- 1 ])
503503
504- @mock .patch ('azure.cli.core.auth.adal_authentication.MSIAuthenticationWrapper' , autospec = True )
505- @mock .patch ('azure.cli.core._profile.SubscriptionFinder._create_subscription_client' , autospec = True )
506- @mock .patch .dict ('os.environ' , {'AZURE_CORE_USE_MSAL_MANAGED_IDENTITY' : 'false' })
507- def test_login_with_mi_user_assigned_object_id (self , create_subscription_client_mock ,
508- mock_msi_auth ):
509- mock_subscription_client = mock .MagicMock ()
510- mock_subscription_client .subscriptions .list .return_value = [deepcopy (self .subscription1_raw )]
511- create_subscription_client_mock .return_value = mock_subscription_client
512-
513- from azure .cli .core .azclierror import AzureResponseError
514- class AuthStub :
515- def __init__ (self , ** kwargs ):
516- self .token = None
517- self .client_id = kwargs .get ('client_id' )
518- self .object_id = kwargs .get ('object_id' )
519- # since msrestazure 0.4.34, set_token in init
520- self .set_token ()
521-
522- def set_token (self ):
523- # here we will reject the 1st sniffing of trying with client_id and then acccept the 2nd
524- if self .object_id :
525- self .token = {
526- 'token_type' : 'Bearer' ,
527- 'access_token' : TestProfile .test_mi_access_token
528- }
529- else :
530- raise AzureResponseError ('Failed to connect to MSI. Please make sure MSI is configured correctly.\n '
531- 'Get Token request returned http error: 400, reason: Bad Request' )
532-
533- profile = Profile (cli_ctx = DummyCli (), storage = {'subscriptions' : None })
534-
535- mock_msi_auth .side_effect = AuthStub
536- test_object_id = '54826b22-38d6-4fb2-bad9-b7b93a3e9999'
537-
538- subscriptions = profile .login_with_managed_identity (object_id = test_object_id )
539-
540- s = subscriptions [0 ]
541- self .assertEqual (s ['user' ]['name' ], 'userAssignedIdentity' )
542- self .assertEqual (s ['user' ]['type' ], 'servicePrincipal' )
543- self .assertEqual (s ['user' ]['assignedIdentityInfo' ], 'MSIObject-{}' .format (test_object_id ))
544-
545504 @mock .patch ('azure.cli.core._profile.SubscriptionFinder._create_subscription_client' , autospec = True )
546505 @mock .patch ('azure.cli.core.auth.msal_credentials.ManagedIdentityCredential' , ManagedIdentityCredentialStub )
547506 def test_login_with_mi_system_assigned (self , create_subscription_client_mock ):
0 commit comments