diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/AbstractAbfsIntegrationTest.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/AbstractAbfsIntegrationTest.java index 00d853175108d..2f0d52f056bd9 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/AbstractAbfsIntegrationTest.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/AbstractAbfsIntegrationTest.java @@ -284,13 +284,30 @@ public void loadConfiguredFileSystem() throws Exception { useConfiguredFileSystem = true; } + /** + * Create a filesystem for SAS tests using the SharedKey authentication. + * We do not allow filesystem creation with SAS because certain type of SAS do not have + * required permissions, and it is not known what type of SAS is configured by user. + * @throws Exception + */ protected void createFilesystemForSASTests() throws Exception { - // The SAS tests do not have permission to create a filesystem - // so first create temporary instance of the filesystem using SharedKey - // then re-use the filesystem it creates with SAS auth instead of SharedKey. + createFilesystemWithTestFileForSASTests(null); + } + + /** + * Create a filesystem for SAS tests along with a test file using SharedKey authentication. + * We do not allow filesystem creation with SAS because certain type of SAS do not have + * required permissions, and it is not known what type of SAS is configured by user. + * @param testPath path of the test file. + * @throws Exception + */ + protected void createFilesystemWithTestFileForSASTests(Path testPath) throws Exception { try (AzureBlobFileSystem tempFs = (AzureBlobFileSystem) FileSystem.newInstance(rawConfig)){ ContractTestUtils.assertPathExists(tempFs, "This path should exist", new Path("/")); + if (testPath != null) { + tempFs.create(testPath).close(); + } abfsConfig.set(FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME, AuthType.SAS.name()); usingFilesystemForSASTests = true; } diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemChooseSAS.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemChooseSAS.java index 4bfab1cbfaaa6..45f88f49a2c1e 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemChooseSAS.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemChooseSAS.java @@ -34,7 +34,6 @@ import org.apache.hadoop.fs.azurebfs.utils.AccountSASGenerator; import org.apache.hadoop.fs.azurebfs.utils.Base64; -import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.ROOT_PATH; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_SAS_FIXED_TOKEN; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_SAS_TOKEN_PROVIDER_TYPE; import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.accountProperty; @@ -47,6 +46,7 @@ public class ITestAzureBlobFileSystemChooseSAS extends AbstractAbfsIntegrationTest{ private String accountSAS = null; + private final String TEST_PATH = "testPath"; /** * To differentiate which SASTokenProvider was used we will use different type of SAS Tokens. @@ -62,9 +62,10 @@ public ITestAzureBlobFileSystemChooseSAS() throws Exception { @Override public void setup() throws Exception { - createFilesystemForSASTests(); + createFilesystemWithTestFileForSASTests(new Path(TEST_PATH)); super.setup(); - generateAccountSAS(); } + generateAccountSAS(); + } /** * Generates an Account SAS Token using the Account Shared Key to be used as a fixed SAS Token. @@ -143,7 +144,7 @@ private void testOnlyFixedTokenConfiguredInternal(AbfsConfiguration testAbfsConf // Asserting that FixedSASTokenProvider is used. Assertions.assertThat(testAbfsConfig.getSASTokenProvider()) - .describedAs("Custom SASTokenProvider Class must be used") + .describedAs("FixedSASTokenProvider Class must be used") .isInstanceOf(FixedSASTokenProvider.class); // Assert that Account SAS is used and only read operations are permitted. @@ -152,7 +153,7 @@ private void testOnlyFixedTokenConfiguredInternal(AbfsConfiguration testAbfsConf newTestFs.create(testPath); }); // Read Operation is permitted - newTestFs.getFileStatus(new Path(ROOT_PATH)); + newTestFs.getFileStatus(new Path(TEST_PATH)); } }