Skip to content

Commit 22851b7

Browse files
committed
separate account-agnostic sas token
1 parent c51e382 commit 22851b7

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class ITestAzureBlobFileSystemChooseSAS extends AbstractAbfsIntegrationTe
5353

5454
private String accountSAS = null;
5555
private String containerSAS = null;
56+
private String accountAgnosticSAS = null;
5657
private static final String TEST_PATH = "testPath";
5758
private static final String readPermission = "read";
5859

@@ -73,6 +74,7 @@ public void setup() throws Exception {
7374
super.setup();
7475
createFilesystemWithTestFileForSASTests(new Path(TEST_PATH));
7576
generateAccountSAS();
77+
generateAccountAgnosticSAS();
7678
generateContainerSAS();
7779
}
7880

@@ -90,6 +92,21 @@ private void generateAccountSAS() throws AzureBlobFileSystemException {
9092
accountSAS = configAccountSASGenerator.getAccountSAS(getAccountName());
9193
}
9294

95+
/**
96+
* Generates an Account SAS Token (for account-agnostic config) using the Account Shared Key to
97+
* be used as a fixed SAS Token.
98+
* Account SAS used here will only have write permissions to resources.
99+
* This will be used by individual tests to set in the configurations.
100+
* @throws AzureBlobFileSystemException
101+
*/
102+
private void generateAccountAgnosticSAS() throws AzureBlobFileSystemException {
103+
final String accountKey = getConfiguration().getStorageAccountKey();
104+
AccountSASGenerator configAccountSASGenerator = new AccountSASGenerator(Base64.decode(accountKey));
105+
// Setting only write permissions.
106+
configAccountSASGenerator.setPermissions("w");
107+
accountAgnosticSAS = configAccountSASGenerator.getAccountSAS(getAccountName());
108+
}
109+
93110
/**
94111
* Generates a Container SAS Token using the Account Shared Key to be used as a fixed SAS Token.
95112
* Container SAS used here will have only read permissions to resources.
@@ -163,7 +180,7 @@ private String getFixedSASToken(AbfsConfiguration config) throws Exception {
163180
* @throws IOException
164181
*/
165182
@Test
166-
public void testFixedTokenPreference() throws Exception {
183+
public void testFixedSASTokenProviderPreference() throws Exception {
167184
AbfsConfiguration testAbfsConfig = new AbfsConfiguration(
168185
getRawConfiguration(), this.getAccountName(), this.getFileSystemName(),
169186
getAbfsServiceType());
@@ -176,28 +193,27 @@ public void testFixedTokenPreference() throws Exception {
176193
testAbfsConfig.set(
177194
accountProperty(FS_AZURE_SAS_FIXED_TOKEN, this.getAccountName()),
178195
accountSAS);
179-
testAbfsConfig.set(FS_AZURE_SAS_FIXED_TOKEN, accountSAS);
196+
testAbfsConfig.set(FS_AZURE_SAS_FIXED_TOKEN, accountAgnosticSAS);
180197

181198
// Assert that Container Specific Fixed SAS is used
182199
Assertions.assertThat(getFixedSASToken(testAbfsConfig))
183200
.describedAs("Container-specific fixed SAS should've been used.")
184-
.contains("sr=c");
201+
.isEqualTo(containerSAS);
185202

186203
// Assert that Account Specific Fixed SAS is used if container SAS isn't set
187204
testAbfsConfig.unset(
188205
containerProperty(FS_AZURE_SAS_FIXED_TOKEN, this.getFileSystemName(),
189206
this.getAccountName()));
190207
Assertions.assertThat(getFixedSASToken(testAbfsConfig))
191208
.describedAs("Account-specific fixed SAS should've been used.")
192-
.contains("ss=bf");
209+
.isEqualTo(accountSAS);
193210

194211
//Assert that Account-Agnostic fixed SAS is used if no other fixed SAS configs are set.
195-
// The token is the same as the Account Specific Fixed SAS.
196212
testAbfsConfig.unset(
197213
accountProperty(FS_AZURE_SAS_FIXED_TOKEN, this.getAccountName()));
198214
Assertions.assertThat(getFixedSASToken(testAbfsConfig))
199215
.describedAs("Account-agnostic fixed SAS should've been used.")
200-
.contains("ss=bf");
216+
.isEqualTo(accountAgnosticSAS);
201217
}
202218

203219
/**

0 commit comments

Comments
 (0)