2727import org .apache .hadoop .fs .azurebfs .contracts .exceptions .ConfigurationPropertyNotFoundException ;
2828import org .apache .hadoop .fs .azurebfs .contracts .exceptions .InvalidConfigurationValueException ;
2929import org .apache .hadoop .fs .azurebfs .contracts .exceptions .TokenAccessProviderException ;
30+ import org .apache .hadoop .fs .azurebfs .oauth2 .AccessTokenProvider ;
3031import org .apache .hadoop .fs .azurebfs .oauth2 .ClientCredsTokenProvider ;
3132import org .apache .hadoop .fs .azurebfs .oauth2 .CustomTokenProviderAdapter ;
3233import org .apache .hadoop .fs .azurebfs .oauth2 .MsiTokenProvider ;
6667 */
6768public class TestAccountConfiguration {
6869 private static final String TEST_OAUTH_PROVIDER_CLASS_CONFIG = "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider" ;
70+ private static final String TEST_OAUTH_MSI_TOKEN_PROVIDER_CLASS_CONFIG = "org.apache.hadoop.fs.azurebfs.oauth2.MsiTokenProvider" ;
6971 private static final String TEST_CUSTOM_PROVIDER_CLASS_CONFIG = "org.apache.hadoop.fs.azurebfs.oauth2.RetryTestTokenProvider" ;
7072 private static final String TEST_SAS_PROVIDER_CLASS_CONFIG_1 = "org.apache.hadoop.fs.azurebfs.extensions.MockErrorSASTokenProvider" ;
7173 private static final String TEST_SAS_PROVIDER_CLASS_CONFIG_2 = "org.apache.hadoop.fs.azurebfs.extensions.MockSASTokenProvider" ;
@@ -90,11 +92,6 @@ public class TestAccountConfiguration {
9092 FS_AZURE_ACCOUNT_OAUTH_USER_NAME ,
9193 FS_AZURE_ACCOUNT_OAUTH_USER_PASSWORD ));
9294
93- private static final List <String > MSI_TOKEN_OAUTH_CONFIG_KEYS =
94- Collections .unmodifiableList (Arrays .asList (
95- FS_AZURE_ACCOUNT_OAUTH_MSI_TENANT ,
96- FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID ));
97-
9895 private static final List <String > REFRESH_TOKEN_OAUTH_CONFIG_KEYS =
9996 Collections .unmodifiableList (Arrays .asList (
10097 FS_AZURE_ACCOUNT_OAUTH_REFRESH_TOKEN ,
@@ -410,10 +407,8 @@ public void testAccessTokenProviderPrecedence()
410407 public void testOAuthConfigPropNotFound () throws Throwable {
411408 testConfigPropNotFound (CLIENT_CREDENTIAL_OAUTH_CONFIG_KEYS , ClientCredsTokenProvider .class .getName ());
412409 testConfigPropNotFound (USER_PASSWORD_OAUTH_CONFIG_KEYS , UserPasswordTokenProvider .class .getName ());
413- testConfigPropNotFound (MSI_TOKEN_OAUTH_CONFIG_KEYS , MsiTokenProvider .class .getName ());
414410 testConfigPropNotFound (REFRESH_TOKEN_OAUTH_CONFIG_KEYS , RefreshTokenBasedTokenProvider .class .getName ());
415411 testConfigPropNotFound (WORKLOAD_IDENTITY_OAUTH_CONFIG_KEYS , WorkloadIdentityTokenProvider .class .getName ());
416-
417412 }
418413
419414 private void testConfigPropNotFound (List <String > configKeys ,
@@ -444,6 +439,30 @@ private static void testMissingConfigKey(final AbfsConfiguration abfsConf,
444439 () -> abfsConf .getTokenProvider ().getClass ().getTypeName ())));
445440 }
446441
442+ @ Test
443+ public void testClientAndTenantIdOptionalWhenUsingMsiTokenProvider () throws Throwable {
444+ final String accountName = "account" ;
445+ final Configuration conf = new Configuration ();
446+ final AbfsConfiguration abfsConf = new AbfsConfiguration (conf , accountName );
447+
448+ final String accountNameSuffix = "." + abfsConf .getAccountName ();
449+ String authKey = FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME + accountNameSuffix ;
450+ String providerClassKey = "" ;
451+ String providerClassValue = "" ;
452+
453+ providerClassKey = FS_AZURE_ACCOUNT_TOKEN_PROVIDER_TYPE_PROPERTY_NAME + accountNameSuffix ;
454+ providerClassValue = TEST_OAUTH_MSI_TOKEN_PROVIDER_CLASS_CONFIG ;
455+
456+ abfsConf .set (authKey , AuthType .OAuth .toString ());
457+ abfsConf .set (providerClassKey , providerClassValue );
458+
459+ AccessTokenProvider tokenProviderTypeName = abfsConf .getTokenProvider ();
460+ // Test that we managed to instantiate an MsiTokenProvider without having to define the tenant and client ID.
461+ // Those 2 fields are optional as they can automatically be determined by the Azure Metadata service when
462+ // running on an Azure VM.
463+ Assertions .assertThat (tokenProviderTypeName ).describedAs ("Token Provider Should be MsiTokenProvider" ).isInstanceOf (MsiTokenProvider .class );
464+ }
465+
447466 public void testGlobalAndAccountOAuthPrecedence (AbfsConfiguration abfsConf ,
448467 AuthType globalAuthType ,
449468 AuthType accountSpecificAuthType )
0 commit comments