|
27 | 27 | import org.apache.hadoop.fs.azurebfs.contracts.exceptions.ConfigurationPropertyNotFoundException; |
28 | 28 | import org.apache.hadoop.fs.azurebfs.contracts.exceptions.InvalidConfigurationValueException; |
29 | 29 | import org.apache.hadoop.fs.azurebfs.contracts.exceptions.TokenAccessProviderException; |
| 30 | +import org.apache.hadoop.fs.azurebfs.oauth2.AccessTokenProvider; |
30 | 31 | import org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider; |
31 | 32 | import org.apache.hadoop.fs.azurebfs.oauth2.CustomTokenProviderAdapter; |
| 33 | +import org.apache.hadoop.fs.azurebfs.oauth2.MsiTokenProvider; |
32 | 34 | import org.apache.hadoop.fs.azurebfs.services.AuthType; |
33 | 35 | import org.apache.hadoop.test.GenericTestUtils; |
34 | 36 | import org.apache.hadoop.test.LambdaTestUtils; |
|
57 | 59 | * that do allow default values (all others) follow another form. |
58 | 60 | */ |
59 | 61 | public class TestAccountConfiguration { |
60 | | - private static final String TEST_OAUTH_PROVIDER_CLASS_CONFIG = "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider"; |
| 62 | + private static final String TEST_OAUTH_CLIENT_CREDS_TOKEN_PROVIDER_CLASS_CONFIG = "org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider"; |
| 63 | + private static final String TEST_OAUTH_MSI_TOKEN_PROVIDER_CLASS_CONFIG = "org.apache.hadoop.fs.azurebfs.oauth2.MsiTokenProvider"; |
61 | 64 | private static final String TEST_CUSTOM_PROVIDER_CLASS_CONFIG = "org.apache.hadoop.fs.azurebfs.oauth2.RetryTestTokenProvider"; |
62 | 65 | private static final String TEST_SAS_PROVIDER_CLASS_CONFIG_1 = "org.apache.hadoop.fs.azurebfs.extensions.MockErrorSASTokenProvider"; |
63 | 66 | private static final String TEST_SAS_PROVIDER_CLASS_CONFIG_2 = "org.apache.hadoop.fs.azurebfs.extensions.MockSASTokenProvider"; |
@@ -400,6 +403,30 @@ private static void testMissingConfigKey(final AbfsConfiguration abfsConf, |
400 | 403 | () -> abfsConf.getTokenProvider().getClass().getTypeName()))); |
401 | 404 | } |
402 | 405 |
|
| 406 | + @Test |
| 407 | + public void testClientAndTenantIdOptionalWhenUsingMsiTokenProvider() throws Throwable { |
| 408 | + final String accountName = "account"; |
| 409 | + final Configuration conf = new Configuration(); |
| 410 | + final AbfsConfiguration abfsConf = new AbfsConfiguration(conf, accountName); |
| 411 | + |
| 412 | + final String accountNameSuffix = "." + abfsConf.getAccountName(); |
| 413 | + String authKey = FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME + accountNameSuffix; |
| 414 | + String providerClassKey = ""; |
| 415 | + String providerClassValue = ""; |
| 416 | + |
| 417 | + providerClassKey = FS_AZURE_ACCOUNT_TOKEN_PROVIDER_TYPE_PROPERTY_NAME + accountNameSuffix; |
| 418 | + providerClassValue = TEST_OAUTH_MSI_TOKEN_PROVIDER_CLASS_CONFIG; |
| 419 | + |
| 420 | + abfsConf.set(authKey, AuthType.OAuth.toString()); |
| 421 | + abfsConf.set(providerClassKey, providerClassValue); |
| 422 | + |
| 423 | + AccessTokenProvider tokenProviderTypeName = abfsConf.getTokenProvider(); |
| 424 | + // Test that we managed to instantiate an MsiTokenProvider without having to define the tenant and client ID. |
| 425 | + // Those 2 fields are optional as they can automatically be determined by the Azure Metadata service when |
| 426 | + // running on an Azure VM. |
| 427 | + Assertions.assertThat(tokenProviderTypeName).isInstanceOf(MsiTokenProvider.class); |
| 428 | + } |
| 429 | + |
403 | 430 | public void testGlobalAndAccountOAuthPrecedence(AbfsConfiguration abfsConf, |
404 | 431 | AuthType globalAuthType, |
405 | 432 | AuthType accountSpecificAuthType) |
@@ -455,7 +482,7 @@ public void setAuthConfig(AbfsConfiguration abfsConf, |
455 | 482 | case OAuth: |
456 | 483 | providerClassKey = FS_AZURE_ACCOUNT_TOKEN_PROVIDER_TYPE_PROPERTY_NAME |
457 | 484 | + (isAccountSetting ? accountNameSuffix : ""); |
458 | | - providerClassValue = TEST_OAUTH_PROVIDER_CLASS_CONFIG; |
| 485 | + providerClassValue = TEST_OAUTH_CLIENT_CREDS_TOKEN_PROVIDER_CLASS_CONFIG; |
459 | 486 |
|
460 | 487 | abfsConf.set(FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT |
461 | 488 | + ((isAccountSetting) ? accountNameSuffix : ""), |
|
0 commit comments