2828import java .util .List ;
2929import java .util .stream .Collectors ;
3030
31- import org .assertj .core .api .Assertions ;
3231import org .junit .jupiter .api .BeforeEach ;
3332import org .junit .jupiter .api .Test ;
3433import org .mockito .Mockito ;
5756import static org .apache .hadoop .fs .azurebfs .constants .TestConfigurationKeys .FS_AZURE_BLOB_FS_CHECKACCESS_TEST_CLIENT_SECRET ;
5857import static org .apache .hadoop .fs .azurebfs .constants .TestConfigurationKeys .FS_AZURE_BLOB_FS_CHECKACCESS_TEST_USER_GUID ;
5958import static org .apache .hadoop .fs .azurebfs .constants .TestConfigurationKeys .FS_AZURE_BLOB_FS_CLIENT_SERVICE_PRINCIPAL_OBJECT_ID ;
59+ import static org .apache .hadoop .fs .azurebfs .constants .TestConfigurationKeys .FS_AZURE_TEST_APP_SERVICE_PRINCIPAL_TENANT_ID ;
6060import static org .apache .hadoop .fs .azurebfs .constants .TestConfigurationKeys .FS_AZURE_TEST_END_USER_OBJECT_ID ;
61+ import static org .apache .hadoop .fs .azurebfs .constants .TestConfigurationKeys .FS_AZURE_TEST_END_USER_TENANT_ID ;
6162import static org .apache .hadoop .test .LambdaTestUtils .intercept ;
6263import static org .assertj .core .api .Assumptions .assumeThat ;
6364
6465/**
6566 * Integration tests for AzureBlobFileSystem using User-Bound SAS and OAuth.
6667 * Covers scenarios for token provider configuration, SAS token validity, and basic file operations.
6768 */
68- public class ITestAzureBlobFileSystemUserBoundSAS extends AbstractAbfsIntegrationTest {
69+ public class ITestAzureBlobFileSystemUserBoundSAS
70+ extends AbstractAbfsIntegrationTest {
6971
7072 private static Path testPath = new Path ("/test.txt" );
7173
@@ -115,6 +117,8 @@ public void setup() throws Exception {
115117 abfsConfig .get (FS_AZURE_BLOB_FS_CHECKACCESS_TEST_CLIENT_SECRET ));
116118 abfsConfig .set (FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET ,
117119 abfsConfig .get (FS_AZURE_BLOB_FS_CHECKACCESS_TEST_CLIENT_SECRET ));
120+ abfsConfig .set (FS_AZURE_TEST_END_USER_TENANT_ID ,
121+ abfsConfig .get (FS_AZURE_TEST_APP_SERVICE_PRINCIPAL_TENANT_ID ));
118122 abfsConfig .set (FS_AZURE_TEST_END_USER_OBJECT_ID ,
119123 abfsConfig .get (FS_AZURE_BLOB_FS_CHECKACCESS_TEST_USER_GUID ));
120124 abfsConfig .set (FS_AZURE_SAS_TOKEN_PROVIDER_TYPE ,
@@ -154,7 +158,8 @@ private void injectMockTokenProvider(AzureBlobFileSystem fs,
154158 */
155159 private AzureBlobFileSystem createTestFileSystem () throws RuntimeException {
156160 try {
157- return (AzureBlobFileSystem ) FileSystem .newInstance (getRawConfiguration ());
161+ return (AzureBlobFileSystem ) FileSystem .newInstance (
162+ getRawConfiguration ());
158163 } catch (IOException e ) {
159164 throw new RuntimeException (e );
160165 }
@@ -167,7 +172,8 @@ private AzureBlobFileSystem createTestFileSystem() throws RuntimeException {
167172 @ Test
168173 public void testShouldFailWhenSduoidMismatchesServicePrincipalId ()
169174 throws Exception {
170- this .getConfiguration ().set (FS_AZURE_TEST_END_USER_OBJECT_ID , TEST_OBJECT_ID );
175+ this .getConfiguration ()
176+ .set (FS_AZURE_TEST_END_USER_OBJECT_ID , TEST_OBJECT_ID );
171177 AzureBlobFileSystem testFs = createTestFileSystem ();
172178 intercept (AccessDeniedException .class ,
173179 () -> {
@@ -201,7 +207,8 @@ public void testOAuthTokenProviderAndSASTokenFlow() throws Exception {
201207
202208 // Verify AbfsConfiguration has an SASTokenProvider configured
203209 SASTokenProvider sasProvider
204- = abfsConfiguration .getUserBoundSASTokenProvider (AuthType .UserboundSASWithOAuth );
210+ = abfsConfiguration .getUserBoundSASTokenProvider (
211+ AuthType .UserboundSASWithOAuth );
205212 assertNotNull (sasProvider ,
206213 "SASTokenProvider for user-bound SAS must be configured" );
207214 assertInstanceOf (MockUserBoundSASTokenProvider .class , sasProvider ,
@@ -216,7 +223,7 @@ public void testOAuthTokenProviderAndSASTokenFlow() throws Exception {
216223 }
217224
218225 /*
219- * Tests listing and deleting files under an implicit directory
226+ * Tests listing and deleting files under an implicit directory
220227 */
221228 @ Test
222229 public void testOperationsForImplicitPaths () throws Exception {
@@ -245,7 +252,8 @@ public void testOperationsForImplicitPaths() throws Exception {
245252 listOp .getResult ().getListResultSchema ().paths ();
246253
247254 assertNotNull (listedEntries , "List result should not be null" );
248- assertEquals (2 , listedEntries .size (), "Expected exactly two files under implicit directory" );
255+ assertEquals (2 , listedEntries .size (),
256+ "Expected exactly two files under implicit directory" );
249257
250258 client .deletePath (
251259 implicitDir .toString (),
@@ -346,7 +354,8 @@ public void testOperationWithValidAndExpiredSASToken() throws Exception {
346354 // Get a real SAS token from the configured provider
347355 AbfsConfiguration abfsConfig = testFs .getAbfsStore ().getAbfsConfiguration ();
348356 SASTokenProvider realSasProvider
349- = abfsConfig .getUserBoundSASTokenProvider (AuthType .UserboundSASWithOAuth );
357+ = abfsConfig .getUserBoundSASTokenProvider (
358+ AuthType .UserboundSASWithOAuth );
350359 assertNotNull (realSasProvider ,
351360 "SASTokenProvider for user-bound SAS must be configured" );
352361 String validSasToken = realSasProvider .getSASToken (
@@ -388,20 +397,26 @@ public void testOperationWithValidAndExpiredSASToken() throws Exception {
388397 injectMockSASTokenProvider (testFs , mockSasProvider );
389398
390399 // Try a file operation and expect failure due to expired SAS token
391- intercept (AccessDeniedException .class , () -> {testFs .getFileStatus (testPath );});
400+ intercept (AccessDeniedException .class ,
401+ () -> {testFs .getFileStatus (testPath );});
392402 }
393403
394404 // Helper method to inject a mock SASTokenProvider into the AbfsClient
395- private void injectMockSASTokenProvider (AzureBlobFileSystem fs , SASTokenProvider provider ) throws Exception {
396- Field abfsStoreField = AzureBlobFileSystem .class .getDeclaredField ("abfsStore" );
405+ private void injectMockSASTokenProvider (AzureBlobFileSystem fs ,
406+ SASTokenProvider provider ) throws Exception {
407+ Field abfsStoreField = AzureBlobFileSystem .class .getDeclaredField (
408+ "abfsStore" );
397409 abfsStoreField .setAccessible (true );
398- AzureBlobFileSystemStore store = (AzureBlobFileSystemStore ) abfsStoreField .get (fs );
410+ AzureBlobFileSystemStore store
411+ = (AzureBlobFileSystemStore ) abfsStoreField .get (fs );
399412
400- Field abfsClientField = AzureBlobFileSystemStore .class .getDeclaredField ("client" );
413+ Field abfsClientField = AzureBlobFileSystemStore .class .getDeclaredField (
414+ "client" );
401415 abfsClientField .setAccessible (true );
402416 AbfsClient client = (AbfsClient ) abfsClientField .get (store );
403417
404- Field sasProviderField = AbfsClient .class .getDeclaredField ("sasTokenProvider" );
418+ Field sasProviderField = AbfsClient .class .getDeclaredField (
419+ "sasTokenProvider" );
405420 sasProviderField .setAccessible (true );
406421 sasProviderField .set (client , provider );
407422 }
0 commit comments