snvijaya commented on a change in pull request #1842: HADOOP-16730 : ABFS: Add 
Authorizer Interface
URL: https://github.com/apache/hadoop/pull/1842#discussion_r379627813
 
 

 ##########
 File path: 
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemAuthorization.java
 ##########
 @@ -36,331 +40,485 @@
 import static org.apache.hadoop.fs.permission.AclEntryScope.ACCESS;
 import static org.apache.hadoop.fs.permission.AclEntryType.GROUP;
 import static org.apache.hadoop.test.LambdaTestUtils.intercept;
-import static org.junit.Assume.assumeTrue;
 
 /**
  * Test Perform Authorization Check operation
  */
-public class ITestAzureBlobFileSystemAuthorization extends 
AbstractAbfsIntegrationTest {
-
-  private static final Path TEST_READ_ONLY_FILE_PATH_0 = new 
Path(TEST_READ_ONLY_FILE_0);
-  private static final Path TEST_READ_ONLY_FOLDER_PATH = new 
Path(TEST_READ_ONLY_FOLDER);
-  private static final Path TEST_WRITE_ONLY_FILE_PATH_0 = new 
Path(TEST_WRITE_ONLY_FILE_0);
-  private static final Path TEST_WRITE_ONLY_FILE_PATH_1 = new 
Path(TEST_WRITE_ONLY_FILE_1);
-  private static final Path TEST_READ_WRITE_FILE_PATH_0 = new 
Path(TEST_READ_WRITE_FILE_0);
-  private static final Path TEST_READ_WRITE_FILE_PATH_1 = new 
Path(TEST_READ_WRITE_FILE_1);
-  private static final Path TEST_WRITE_ONLY_FOLDER_PATH = new 
Path(TEST_WRITE_ONLY_FOLDER);
-  private static final Path TEST_WRITE_THEN_READ_ONLY_PATH = new 
Path(TEST_WRITE_THEN_READ_ONLY);
-  private static final String TEST_AUTHZ_CLASS = 
"org.apache.hadoop.fs.azurebfs.extensions.MockAbfsAuthorizer";
+public class ITestAzureBlobFileSystemAuthorization
+    extends AbstractAbfsIntegrationTest {
+
+  private static final String TEST_READ_ONLY_FILE_PATH_PREFIX_0 =
+      TEST_READ_ONLY_FILE_0;
+  private static final String TEST_READ_ONLY_FILE_PATH_PREFIX_1 =
+      TEST_READ_ONLY_FILE_1;
+  private static final String TEST_READ_ONLY_FOLDER_PATH_PREFIX =
+      TEST_READ_ONLY_FOLDER;
+  private static final String TEST_WRITE_ONLY_FILE_PATH_PREFIX_0 =
+      TEST_WRITE_ONLY_FILE_0;
+  private static final String TEST_WRITE_ONLY_FILE_PATH_PREFIX_1 =
+      TEST_WRITE_ONLY_FILE_1;
+  private static final String TEST_READ_WRITE_FILE_PATH_PREFIX_0 =
+      TEST_READ_WRITE_FILE_0;
+  private static final String TEST_READ_WRITE_FILE_PATH_PREFIX_1 =
+      TEST_READ_WRITE_FILE_1;
+  private static final String TEST_WRITE_ONLY_FOLDER_PATH_PREFIX =
+      TEST_WRITE_ONLY_FOLDER;
+  private static final String TEST_WRITE_THEN_READ_ONLY_PATH_PREFIX =
+      TEST_WRITE_THEN_READ_ONLY;
+  private static final String TEST_AUTHZ_CLASS =
+      "org.apache.hadoop.fs" + ".azurebfs.extensions.MockAbfsAuthorizer";
   private static final String TEST_USER = UUID.randomUUID().toString();
   private static final String TEST_GROUP = UUID.randomUUID().toString();
   private static final String BAR = UUID.randomUUID().toString();
+  @Rule
+  public TestName name = new TestName();
 
   public ITestAzureBlobFileSystemAuthorization() throws Exception {
   }
 
   @Override
   public void setup() throws Exception {
-    
this.getConfiguration().set(ConfigurationKeys.ABFS_EXTERNAL_AUTHORIZATION_CLASS,
 TEST_AUTHZ_CLASS);
+    boolean isHNSEnabled = this.getConfiguration().getBoolean(
+        TestConfigurationKeys.FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT, false);
+    Assume.assumeTrue(isHNSEnabled == true);
+    this.getConfiguration().setAbfsAuthorizerClass(TEST_AUTHZ_CLASS);
+    loadAuthorizer();
     super.setup();
   }
 
   @Test
   public void testOpenFileWithInvalidPath() throws Exception {
     final AzureBlobFileSystem fs = this.getFileSystem();
-    intercept(IllegalArgumentException.class,
-        ()-> {
-          fs.open(new Path("")).close();
+    intercept(IllegalArgumentException.class, () -> {
+      fs.open(new Path("")).close();
     });
   }
 
   @Test
   public void testOpenFileAuthorized() throws Exception {
     final AzureBlobFileSystem fs = this.getFileSystem();
-    fs.create(TEST_WRITE_THEN_READ_ONLY_PATH).close();
-    fs.open(TEST_WRITE_THEN_READ_ONLY_PATH).close();
+    Path testFilePath = new Path(
+        TEST_WRITE_THEN_READ_ONLY_PATH_PREFIX + name.getMethodName());
+    ((MockAbfsAuthorizer) fs.getAbfsStore().getAuthorizer())
+        .setwriteThenReadOnly(testFilePath.getName(), 
WriteReadMode.WRITE_MODE);
+    fs.create(testFilePath).close();
+    ((MockAbfsAuthorizer) fs.getAbfsStore().getAuthorizer())
+        .setwriteThenReadOnly(testFilePath.getName(), WriteReadMode.READ_MODE);
+    fs.open(testFilePath).close();
   }
 
   @Test
   public void testOpenFileUnauthorized() throws Exception {
     final AzureBlobFileSystem fs = this.getFileSystem();
-    fs.create(TEST_WRITE_ONLY_FILE_PATH_0).close();
-    intercept(AbfsAuthorizationException.class,
-        ()-> {
-          fs.open(TEST_WRITE_ONLY_FILE_PATH_0).close();
+    Path testFilePath = new Path(
 
 Review comment:
   Refactored

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to