@@ -1134,9 +1134,15 @@ def test_get_raw_token_mi_system_assigned(self):
11341134 self .assertEqual (subscription_id , self .test_mi_subscription_id )
11351135 self .assertEqual (tenant_id , self .test_mi_tenant )
11361136
1137- # verify tenant shouldn't be specified for MSI account
1138- with self .assertRaisesRegex (CLIError , "Tenant shouldn't be specified" ):
1139- cred , subscription_id , _ = profile .get_raw_token (resource = 'http://test_resource' , tenant = self .tenant_id )
1137+ # Specifying the current tenant is allowed
1138+ cred , subscription_id , tenant_id = profile .get_raw_token (tenant = self .test_mi_tenant )
1139+ self .assertEqual (tenant_id , self .test_mi_tenant )
1140+
1141+ # Specifying a non-current tenant is disallowed
1142+ with self .assertRaisesRegex (CLIError ,
1143+ "For managed identity account, getting access token for non-current tenants is "
1144+ "not supported" ):
1145+ profile .get_raw_token (tenant = 'another-tenant' )
11401146
11411147 @mock .patch ('azure.cli.core.auth.util.now_timestamp' , new = now_timestamp_mock )
11421148 @mock .patch ('azure.cli.core.auth.msal_credentials.ManagedIdentityCredential' , ManagedIdentityCredentialStub )
@@ -1285,9 +1291,15 @@ def cloud_shell_credential_factory():
12851291 self .assertEqual (subscription_id , test_subscription_id )
12861292 self .assertEqual (tenant_id , test_tenant_id )
12871293
1288- # Verify tenant shouldn't be specified for Cloud Shell account
1289- with self .assertRaisesRegex (CLIError , 'Cloud Shell' ):
1290- profile .get_raw_token (resource = 'http://test_resource' , tenant = self .tenant_id )
1294+ # Specifying the current tenant is allowed
1295+ cred , subscription_id , tenant_id = profile .get_raw_token (tenant = test_tenant_id )
1296+ self .assertEqual (tenant_id , test_tenant_id )
1297+
1298+ # Specifying a non-current tenant is disallowed
1299+ with self .assertRaisesRegex (CLIError ,
1300+ "For Cloud Shell account, getting access token for non-current tenants is "
1301+ "not supported" ):
1302+ profile .get_raw_token (tenant = 'another-tenant' )
12911303
12921304 @mock .patch ('azure.cli.core.auth.identity.Identity.get_user_credential' )
12931305 def test_get_msal_token (self , get_user_credential_mock ):
0 commit comments