3535import org .apache .hadoop .fs .azurebfs .utils .ServiceSASGenerator ;
3636import org .apache .hadoop .fs .azurebfs .utils .Base64 ;
3737
38+ import static org .apache .hadoop .fs .azurebfs .constants .AbfsHttpConstants .EMPTY_STRING ;
3839import static org .apache .hadoop .fs .azurebfs .constants .ConfigurationKeys .FS_AZURE_SAS_FIXED_TOKEN ;
3940import static org .apache .hadoop .fs .azurebfs .constants .ConfigurationKeys .FS_AZURE_SAS_TOKEN_PROVIDER_TYPE ;
4041import static org .apache .hadoop .fs .azurebfs .constants .ConfigurationKeys .accountProperty ;
@@ -53,8 +54,8 @@ public class ITestAzureBlobFileSystemChooseSAS extends AbstractAbfsIntegrationTe
5354
5455 private String accountSAS = null ;
5556 private String containerSAS = null ;
57+ private String accountAgnosticSAS = null ;
5658 private static final String TEST_PATH = "testPath" ;
57- private static final String readPermission = "read" ;
5859
5960 /**
6061 * To differentiate which SASTokenProvider was used we will use different type of SAS Tokens.
@@ -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.
@@ -154,7 +171,7 @@ private String getFixedSASToken(AbfsConfiguration config) throws Exception {
154171 return config .getSASTokenProvider ()
155172 .getSASToken (this .getAccountName (), this .getFileSystemName (),
156173 getMethodName (),
157- readPermission );
174+ EMPTY_STRING );
158175 }
159176
160177 /**
@@ -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