@@ -53,6 +53,7 @@ public class ITestAzureBlobFileSystemChooseSAS extends AbstractAbfsIntegrationTe
53
53
54
54
private String accountSAS = null ;
55
55
private String containerSAS = null ;
56
+ private String accountAgnosticSAS = null ;
56
57
private static final String TEST_PATH = "testPath" ;
57
58
private static final String readPermission = "read" ;
58
59
@@ -73,6 +74,7 @@ public void setup() throws Exception {
73
74
super .setup ();
74
75
createFilesystemWithTestFileForSASTests (new Path (TEST_PATH ));
75
76
generateAccountSAS ();
77
+ generateAccountAgnosticSAS ();
76
78
generateContainerSAS ();
77
79
}
78
80
@@ -90,6 +92,21 @@ private void generateAccountSAS() throws AzureBlobFileSystemException {
90
92
accountSAS = configAccountSASGenerator .getAccountSAS (getAccountName ());
91
93
}
92
94
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
+
93
110
/**
94
111
* Generates a Container SAS Token using the Account Shared Key to be used as a fixed SAS Token.
95
112
* Container SAS used here will have only read permissions to resources.
@@ -163,7 +180,7 @@ private String getFixedSASToken(AbfsConfiguration config) throws Exception {
163
180
* @throws IOException
164
181
*/
165
182
@ Test
166
- public void testFixedTokenPreference () throws Exception {
183
+ public void testFixedSASTokenProviderPreference () throws Exception {
167
184
AbfsConfiguration testAbfsConfig = new AbfsConfiguration (
168
185
getRawConfiguration (), this .getAccountName (), this .getFileSystemName (),
169
186
getAbfsServiceType ());
@@ -176,28 +193,27 @@ public void testFixedTokenPreference() throws Exception {
176
193
testAbfsConfig .set (
177
194
accountProperty (FS_AZURE_SAS_FIXED_TOKEN , this .getAccountName ()),
178
195
accountSAS );
179
- testAbfsConfig .set (FS_AZURE_SAS_FIXED_TOKEN , accountSAS );
196
+ testAbfsConfig .set (FS_AZURE_SAS_FIXED_TOKEN , accountAgnosticSAS );
180
197
181
198
// Assert that Container Specific Fixed SAS is used
182
199
Assertions .assertThat (getFixedSASToken (testAbfsConfig ))
183
200
.describedAs ("Container-specific fixed SAS should've been used." )
184
- .contains ( "sr=c" );
201
+ .isEqualTo ( containerSAS );
185
202
186
203
// Assert that Account Specific Fixed SAS is used if container SAS isn't set
187
204
testAbfsConfig .unset (
188
205
containerProperty (FS_AZURE_SAS_FIXED_TOKEN , this .getFileSystemName (),
189
206
this .getAccountName ()));
190
207
Assertions .assertThat (getFixedSASToken (testAbfsConfig ))
191
208
.describedAs ("Account-specific fixed SAS should've been used." )
192
- .contains ( "ss=bf" );
209
+ .isEqualTo ( accountSAS );
193
210
194
211
//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.
196
212
testAbfsConfig .unset (
197
213
accountProperty (FS_AZURE_SAS_FIXED_TOKEN , this .getAccountName ()));
198
214
Assertions .assertThat (getFixedSASToken (testAbfsConfig ))
199
215
.describedAs ("Account-agnostic fixed SAS should've been used." )
200
- .contains ( "ss=bf" );
216
+ .isEqualTo ( accountAgnosticSAS );
201
217
}
202
218
203
219
/**
0 commit comments