Skip to content

Commit

Permalink
Test Fix for FNS Account
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj Modi committed Apr 30, 2024
1 parent 7c9d5b4 commit 5db5372
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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));
}
}

Expand Down

0 comments on commit 5db5372

Please sign in to comment.