Skip to content

Commit 5db5372

Browse files
author
Anuj Modi
committed
Test Fix for FNS Account
1 parent 7c9d5b4 commit 5db5372

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/AbstractAbfsIntegrationTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,30 @@ public void loadConfiguredFileSystem() throws Exception {
284284
useConfiguredFileSystem = true;
285285
}
286286

287+
/**
288+
* Create a filesystem for SAS tests using the SharedKey authentication.
289+
* We do not allow filesystem creation with SAS because certain type of SAS do not have
290+
* required permissions, and it is not known what type of SAS is configured by user.
291+
* @throws Exception
292+
*/
287293
protected void createFilesystemForSASTests() throws Exception {
288-
// The SAS tests do not have permission to create a filesystem
289-
// so first create temporary instance of the filesystem using SharedKey
290-
// then re-use the filesystem it creates with SAS auth instead of SharedKey.
294+
createFilesystemWithTestFileForSASTests(null);
295+
}
296+
297+
/**
298+
* Create a filesystem for SAS tests along with a test file using SharedKey authentication.
299+
* We do not allow filesystem creation with SAS because certain type of SAS do not have
300+
* required permissions, and it is not known what type of SAS is configured by user.
301+
* @param testPath path of the test file.
302+
* @throws Exception
303+
*/
304+
protected void createFilesystemWithTestFileForSASTests(Path testPath) throws Exception {
291305
try (AzureBlobFileSystem tempFs = (AzureBlobFileSystem) FileSystem.newInstance(rawConfig)){
292306
ContractTestUtils.assertPathExists(tempFs, "This path should exist",
293307
new Path("/"));
308+
if (testPath != null) {
309+
tempFs.create(testPath).close();
310+
}
294311
abfsConfig.set(FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME, AuthType.SAS.name());
295312
usingFilesystemForSASTests = true;
296313
}

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemChooseSAS.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.apache.hadoop.fs.azurebfs.utils.AccountSASGenerator;
3535
import org.apache.hadoop.fs.azurebfs.utils.Base64;
3636

37-
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.ROOT_PATH;
3837
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_SAS_FIXED_TOKEN;
3938
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_SAS_TOKEN_PROVIDER_TYPE;
4039
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.accountProperty;
@@ -47,6 +46,7 @@
4746
public class ITestAzureBlobFileSystemChooseSAS extends AbstractAbfsIntegrationTest{
4847

4948
private String accountSAS = null;
49+
private final String TEST_PATH = "testPath";
5050

5151
/**
5252
* To differentiate which SASTokenProvider was used we will use different type of SAS Tokens.
@@ -62,9 +62,10 @@ public ITestAzureBlobFileSystemChooseSAS() throws Exception {
6262

6363
@Override
6464
public void setup() throws Exception {
65-
createFilesystemForSASTests();
65+
createFilesystemWithTestFileForSASTests(new Path(TEST_PATH));
6666
super.setup();
67-
generateAccountSAS(); }
67+
generateAccountSAS();
68+
}
6869

6970
/**
7071
* 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
143144

144145
// Asserting that FixedSASTokenProvider is used.
145146
Assertions.assertThat(testAbfsConfig.getSASTokenProvider())
146-
.describedAs("Custom SASTokenProvider Class must be used")
147+
.describedAs("FixedSASTokenProvider Class must be used")
147148
.isInstanceOf(FixedSASTokenProvider.class);
148149

149150
// Assert that Account SAS is used and only read operations are permitted.
@@ -152,7 +153,7 @@ private void testOnlyFixedTokenConfiguredInternal(AbfsConfiguration testAbfsConf
152153
newTestFs.create(testPath);
153154
});
154155
// Read Operation is permitted
155-
newTestFs.getFileStatus(new Path(ROOT_PATH));
156+
newTestFs.getFileStatus(new Path(TEST_PATH));
156157
}
157158
}
158159

0 commit comments

Comments
 (0)