@@ -498,7 +498,7 @@ def test_login_in_cloud_shell(self, cloud_shell_credential_mock, create_subscrip
498498
499499 @mock .patch ('requests.get' , autospec = True )
500500 @mock .patch ('azure.cli.core._profile.SubscriptionFinder._create_subscription_client' , autospec = True )
501- def test_find_subscriptions_in_vm_with_mi_system_assigned (self , create_subscription_client_mock , mock_get ):
501+ def test_login_with_mi_system_assigned (self , create_subscription_client_mock , mock_get ):
502502 mock_subscription_client = mock .MagicMock ()
503503 mock_subscription_client .subscriptions .list .return_value = [deepcopy (self .subscription1_raw )]
504504 create_subscription_client_mock .return_value = mock_subscription_client
@@ -531,7 +531,7 @@ def test_find_subscriptions_in_vm_with_mi_system_assigned(self, create_subscript
531531
532532 @mock .patch ('requests.get' , autospec = True )
533533 @mock .patch ('azure.cli.core._profile.SubscriptionFinder._create_subscription_client' , autospec = True )
534- def test_find_subscriptions_in_vm_with_mi_no_subscriptions (self , create_subscription_client_mock , mock_get ):
534+ def test_login_with_mi_no_subscriptions (self , create_subscription_client_mock , mock_get ):
535535 mock_subscription_client = mock .MagicMock ()
536536 mock_subscription_client .subscriptions .list .return_value = []
537537 create_subscription_client_mock .return_value = mock_subscription_client
@@ -566,8 +566,7 @@ def test_find_subscriptions_in_vm_with_mi_no_subscriptions(self, create_subscrip
566566
567567 @mock .patch ('requests.get' , autospec = True )
568568 @mock .patch ('azure.cli.core._profile.SubscriptionFinder._create_subscription_client' , autospec = True )
569- def test_find_subscriptions_in_vm_with_mi_user_assigned_with_client_id (self , create_subscription_client_mock ,
570- mock_get ):
569+ def test_login_with_mi_user_assigned_client_id (self , create_subscription_client_mock , mock_get ):
571570 mock_subscription_client = mock .MagicMock ()
572571 mock_subscription_client .subscriptions .list .return_value = [deepcopy (self .subscription1_raw )]
573572 create_subscription_client_mock .return_value = mock_subscription_client
@@ -587,6 +586,19 @@ def test_find_subscriptions_in_vm_with_mi_user_assigned_with_client_id(self, cre
587586 good_response .content = encoded_test_token
588587 mock_get .return_value = good_response
589588
589+ subscriptions = profile .login_with_managed_identity (client_id = test_client_id )
590+
591+ self .assertEqual (len (subscriptions ), 1 )
592+ s = subscriptions [0 ]
593+ self .assertEqual (s ['name' ], self .display_name1 )
594+ self .assertEqual (s ['id' ], self .id1 .split ('/' )[- 1 ])
595+ self .assertEqual (s ['tenantId' ], self .test_mi_tenant )
596+
597+ self .assertEqual (s ['user' ]['name' ], 'userAssignedIdentity' )
598+ self .assertEqual (s ['user' ]['type' ], 'servicePrincipal' )
599+ self .assertEqual (s ['user' ]['assignedIdentityInfo' ], 'MSIClient-{}' .format (test_client_id ))
600+
601+ # Old way of using identity_id
590602 subscriptions = profile .login_with_managed_identity (identity_id = test_client_id )
591603
592604 self .assertEqual (len (subscriptions ), 1 )
@@ -601,7 +613,7 @@ def test_find_subscriptions_in_vm_with_mi_user_assigned_with_client_id(self, cre
601613
602614 @mock .patch ('azure.cli.core.auth.adal_authentication.MSIAuthenticationWrapper' , autospec = True )
603615 @mock .patch ('azure.cli.core._profile.SubscriptionFinder._create_subscription_client' , autospec = True )
604- def test_find_subscriptions_in_vm_with_mi_user_assigned_with_object_id (self , create_subscription_client_mock ,
616+ def test_login_with_mi_user_assigned_object_id (self , create_subscription_client_mock ,
605617 mock_msi_auth ):
606618 mock_subscription_client = mock .MagicMock ()
607619 mock_subscription_client .subscriptions .list .return_value = [deepcopy (self .subscription1_raw )]
@@ -632,6 +644,14 @@ def set_token(self):
632644 mock_msi_auth .side_effect = AuthStub
633645 test_object_id = '54826b22-38d6-4fb2-bad9-b7b93a3e9999'
634646
647+ subscriptions = profile .login_with_managed_identity (object_id = test_object_id )
648+
649+ s = subscriptions [0 ]
650+ self .assertEqual (s ['user' ]['name' ], 'userAssignedIdentity' )
651+ self .assertEqual (s ['user' ]['type' ], 'servicePrincipal' )
652+ self .assertEqual (s ['user' ]['assignedIdentityInfo' ], 'MSIObject-{}' .format (test_object_id ))
653+
654+ # Old way of using identity_id
635655 subscriptions = profile .login_with_managed_identity (identity_id = test_object_id )
636656
637657 s = subscriptions [0 ]
@@ -641,7 +661,7 @@ def set_token(self):
641661
642662 @mock .patch ('requests.get' , autospec = True )
643663 @mock .patch ('azure.cli.core._profile.SubscriptionFinder._create_subscription_client' , autospec = True )
644- def test_find_subscriptions_in_vm_with_mi_user_assigned_with_res_id (self , create_subscription_client_mock ,
664+ def test_login_with_mi_user_assigned_resource_id (self , create_subscription_client_mock ,
645665 mock_get ):
646666
647667 mock_subscription_client = mock .MagicMock ()
@@ -665,6 +685,14 @@ def test_find_subscriptions_in_vm_with_mi_user_assigned_with_res_id(self, create
665685 good_response .content = encoded_test_token
666686 mock_get .return_value = good_response
667687
688+ subscriptions = profile .login_with_managed_identity (resource_id = test_res_id )
689+
690+ s = subscriptions [0 ]
691+ self .assertEqual (s ['user' ]['name' ], 'userAssignedIdentity' )
692+ self .assertEqual (s ['user' ]['type' ], 'servicePrincipal' )
693+ self .assertEqual (subscriptions [0 ]['user' ]['assignedIdentityInfo' ], 'MSIResource-{}' .format (test_res_id ))
694+
695+ # Old way of using identity_id
668696 subscriptions = profile .login_with_managed_identity (identity_id = test_res_id )
669697
670698 s = subscriptions [0 ]
0 commit comments