2727APPCONFIG_AUTH_TOKEN_AUDIENCE = "https://appconfig.azure.com"
2828
2929TEST_MI_SUBSCRIPTION = {
30- "id" : "00000000-0000-0000-0000-000000000000" ,
31- "name" : "MSI subscription" ,
32- "isDefault" : True ,
33- "state" : "Enabled" ,
34- "user" : {
35- "name" : "systemAssignedIdentity"
36- },
37- "tenantId" : "00000000-0000-0000-0000-000000000000" ,
38- "environmentName" : "AzureCloud" ,
39- "homeTenantId" : "00000000-0000-0000-0000-000000000000" ,
40- "managedByTenants" : []
41- }
30+ "id" : "00000000-0000-0000-0000-000000000000" ,
31+ "name" : "MSI subscription" ,
32+ "isDefault" : True ,
33+ "state" : "Enabled" ,
34+ "user" : {
35+ "name" : "systemAssignedIdentity"
36+ },
37+ "tenantId" : "00000000-0000-0000-0000-000000000000" ,
38+ "environmentName" : "AzureCloud" ,
39+ "homeTenantId" : "00000000-0000-0000-0000-000000000000" ,
40+ "managedByTenants" : []
41+ }
42+
43+ TEST_USER_SUBSCRIPTION = {
44+ "id" : "00000000-0000-0000-0000-000000000000" ,
45+ "name" : "Service Principal Subscription" ,
46+ "state" : "Enabled" ,
47+ "isDefault" : True ,
48+ "user" : {
49+ 50+ "type" : "user"
51+ },
52+ "tenantId" : "00000000-0000-0000-0000-000000000000" ,
53+ "environmentName" : "AzureCloud" ,
54+ "homeTenantId" : "00000000-0000-0000-0000-000000000000" ,
55+ "managedByTenants" : []
56+ }
4257
4358def mock_get_active_cloud (cli_ctx = None ):
4459 cloud = get_active_cloud (cli_ctx )
@@ -213,9 +228,7 @@ def test_azconfig_aad_auth(self, resource_group, location):
213228 @mock .patch ('azure.cli.core.auth.adal_authentication.MSIAuthenticationWrapper.get_token' )
214229 @mock .patch ('azure.cli.core._profile.Profile.get_subscription' )
215230 def test_azconfig_mi_token_override (self , get_subscriptions_mock , msi_get_token_mock , msi_set_token_mock ):
216- # Mock the subscription list
217231 get_subscriptions_mock .return_value = TEST_MI_SUBSCRIPTION
218-
219232 msi_get_token_mock .return_value = { "token" : "mocked_token" , "expires_on" : 1234567890 }
220233
221234 mock_cmd = mock .MagicMock ()
@@ -234,9 +247,11 @@ def test_azconfig_mi_token_override(self, get_subscriptions_mock, msi_get_token_
234247 appconfig_credential ._impl .get_token .assert_called_once_with (f"{ APPCONFIG_AUTH_TOKEN_AUDIENCE } /.default" )
235248
236249
250+ @mock .patch ('azure.cli.core.auth.msal_credentials.UserCredential' )
237251 @mock .patch ('azure.cli.core.auth.credential_adaptor.CredentialAdaptor.get_token' )
238- def test_azconfig_credential_adaptor_token_override (self , get_token_mock ):
239- # Mock the subscription list
252+ @mock .patch ('azure.cli.core._profile.Profile.get_subscription' )
253+ def test_azconfig_credential_adaptor_token_override (self , get_subscription_mock , get_token_mock , user_cred_mock ):
254+ get_subscription_mock .return_value = TEST_USER_SUBSCRIPTION
240255 get_token_mock .return_value = { "token" : "mocked_token" , "expires_on" : 1234567890 }
241256
242257 profile = Profile (cli_ctx = DummyCli ())
0 commit comments