srdo commented on a change in pull request #2990: STORM-3372: Fix NPE when 
shutting down HFSSpout, fix storm-hdfs tests…
URL: https://github.com/apache/storm/pull/2990#discussion_r281024342
 
 

 ##########
 File path: 
external/storm-hdfs-blobstore/src/test/java/org/apache/storm/hdfs/blobstore/BlobStoreTest.java
 ##########
 @@ -289,133 +280,130 @@ public void testReplication(String path, BlobStore 
store)
         store.deleteBlob("test", getSubject(createSubject));
     }
 
-    public Subject getSubject(String name) {
+    public static Subject getSubject(String name) {
         Subject subject = new Subject();
         SingleUserPrincipal user = new SingleUserPrincipal(name);
         subject.getPrincipals().add(user);
         return subject;
     }
-
-    // Check for Blobstore with authentication
-    public void testWithAuthentication(BlobStore store)
-        throws Exception {
-        //Test for Nimbus Admin
-        Subject admin = getSubject("admin");
-        assertStoreHasExactly(store);
-        SettableBlobMeta metadata = new 
SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
-        try (AtomicOutputStream out = store.createBlob("test", metadata, 
admin)) {
-            assertStoreHasExactly(store, "test");
-            out.write(1);
+    
+    static enum AuthenticationTestSubject {
+        //Nimbus Admin
+        ADMIN(getSubject("admin")),
+        //Nimbus groups admin
+        ADMIN_GROUPS_USER(getSubject("adminGroupsUser")),
+        //Supervisor admin
+        SUPERVISOR(getSubject("supervisor")),
+        //Nimbus itself
+        NIMBUS(getNimbusSubject());
+        
+        private Subject subject;
+
+        private AuthenticationTestSubject(Subject subject) {
+            this.subject = subject;
         }
-        store.deleteBlob("test", admin);
-
-        //Test for Nimbus Groups Admin
-        Subject adminsGroupsUser = getSubject("adminsGroupsUser");
-        assertStoreHasExactly(store);
-        metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
-        try (AtomicOutputStream out = store.createBlob("test", metadata, 
adminsGroupsUser)) {
-            assertStoreHasExactly(store, "test");
-            out.write(1);
+    }
+    
+    @ParameterizedTest
+    @EnumSource(value = AuthenticationTestSubject.class)
+    void testWithAuthentication(AuthenticationTestSubject testSubject) throws 
Exception {
+        try (AutoCloseableBlobStoreContainer container = 
initHdfs("/storm/blobstore-auth-" + testSubject.name())) {
+            BlobStore store = container.blobStore;
+            assertStoreHasExactly(store);
+            SettableBlobMeta metadata = new 
SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
+            try (AtomicOutputStream out = store.createBlob("test", metadata, 
testSubject.subject)) {
+                assertStoreHasExactly(store, "test");
+                out.write(1);
+            }
+            store.deleteBlob("test", testSubject.subject);
         }
-        store.deleteBlob("test", adminsGroupsUser);
-
-        //Test for Supervisor Admin
-        Subject supervisor = getSubject("supervisor");
-        assertStoreHasExactly(store);
-        metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
-        try (AtomicOutputStream out = store.createBlob("test", metadata, 
supervisor)) {
+    }
+    
+    @ParameterizedTest
+    @ValueSource(booleans = {true, false})
+    void testWithAuthenticationDummy(boolean securityEnabled) throws Exception 
{
+        try (AutoCloseableBlobStoreContainer container = 
initHdfs("/storm/blobstore-auth-dummy-sec-" + securityEnabled)) {
+            BlobStore store = container.blobStore;
+            Subject who = getSubject("test_subject");
+            assertStoreHasExactly(store);
+
+            // Tests for case when subject != null (security turned on) and
+            // acls for the blob are set to WORLD_EVERYTHING
+            SettableBlobMeta metadata = new SettableBlobMeta(securityEnabled ? 
BlobStoreAclHandler.DEFAULT : BlobStoreAclHandler.WORLD_EVERYTHING);
+            try (AtomicOutputStream out = store.createBlob("test", metadata, 
who)) {
+                out.write(1);
+            }
             assertStoreHasExactly(store, "test");
-            out.write(1);
+            if (securityEnabled) {
+                // Testing whether acls are set to WORLD_EVERYTHING. Here the 
acl should not contain WORLD_EVERYTHING because
+                // the subject is neither null nor empty. The ACL should 
however contain USER_EVERYTHING as user needs to have
+                // complete access to the blob
+                assertTrue("ACL contains WORLD_EVERYTHING", 
!metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
+            } else {
+                // Testing whether acls are set to WORLD_EVERYTHING
+                assertTrue("ACL does not contain WORLD_EVERYTHING", 
metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
+            }
+            
+            readAssertEqualsWithAuth(store, who, "test", 1);
+
+            LOG.info("Deleting test");
+            store.deleteBlob("test", who);
+            assertStoreHasExactly(store);
         }
-        store.deleteBlob("test", supervisor);
-
-        //Test for Nimbus itself as a user
-        Subject nimbus = getNimbusSubject();
-        assertStoreHasExactly(store);
-        metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
-        try (AtomicOutputStream out = store.createBlob("test", metadata, 
nimbus)) {
+    }
+    
+    @Test
+    void testWithAuthenticationUpdate() throws Exception {
+        try (AutoCloseableBlobStoreContainer container = 
initHdfs("/storm/blobstore-auth-update")) {
+            BlobStore store = container.blobStore;
+            Subject who = getSubject("test_subject");
+            assertStoreHasExactly(store);
+
+            SettableBlobMeta metadata = new 
SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
+            try (AtomicOutputStream out = store.createBlob("test", metadata, 
who)) {
+                out.write(1);
+            }
             assertStoreHasExactly(store, "test");
-            out.write(1);
-        }
-        store.deleteBlob("test", nimbus);
-
-        // Test with a dummy test_subject for cases where subject !=null 
(security turned on)
-        Subject who = getSubject("test_subject");
-        assertStoreHasExactly(store);
-
-        // Tests for case when subject != null (security turned on) and
-        // acls for the blob are set to WORLD_EVERYTHING
-        metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
-        try (AtomicOutputStream out = store.createBlob("test", metadata, who)) 
{
-            out.write(1);
-        }
-        assertStoreHasExactly(store, "test");
-        // Testing whether acls are set to WORLD_EVERYTHING
-        assertTrue("ACL does not contain WORLD_EVERYTHING", 
metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
-        readAssertEqualsWithAuth(store, who, "test", 1);
-
-        LOG.info("Deleting test");
-        store.deleteBlob("test", who);
-        assertStoreHasExactly(store);
-
-        // Tests for case when subject != null (security turned on) and
-        // acls are not set for the blob (DEFAULT)
-        LOG.info("Creating test again");
-        metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
-        try (AtomicOutputStream out = store.createBlob("test", metadata, who)) 
{
-            out.write(2);
-        }
-        assertStoreHasExactly(store, "test");
-        // Testing whether acls are set to WORLD_EVERYTHING. Here the acl 
should not contain WORLD_EVERYTHING because
-        // the subject is neither null nor empty. The ACL should however 
contain USER_EVERYTHING as user needs to have
-        // complete access to the blob
-        assertTrue("ACL does not contain WORLD_EVERYTHING", 
!metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
-        readAssertEqualsWithAuth(store, who, "test", 2);
-
-        LOG.info("Updating test");
-        try (AtomicOutputStream out = store.updateBlob("test", who)) {
-            out.write(3);
-        }
-        assertStoreHasExactly(store, "test");
-        readAssertEqualsWithAuth(store, who, "test", 3);
-
-        LOG.info("Updating test again");
-        try (AtomicOutputStream out = store.updateBlob("test", who)) {
-            out.write(4);
-        }
-        LOG.info("SLEEPING");
-        Thread.sleep(2);
-        assertStoreHasExactly(store, "test");
-        readAssertEqualsWithAuth(store, who, "test", 3);
+            readAssertEqualsWithAuth(store, who, "test", 1);
+            
+            try (AtomicOutputStream out = store.updateBlob("test", who)) {
+                out.write(2);
+            }
+            assertStoreHasExactly(store, "test");
+            readAssertEqualsWithAuth(store, who, "test", 2);
+            
+            try (AtomicOutputStream out = store.updateBlob("test", who)) {
+                out.write(3);
+            }
+            assertStoreHasExactly(store, "test");
+            readAssertEqualsWithAuth(store, who, "test", 3);
 
-        //Test for subject with no principals and acls set to WORLD_EVERYTHING
-        who = new Subject();
-        metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
-        LOG.info("Creating test");
-        try (AtomicOutputStream out = 
store.createBlob("test-empty-subject-WE", metadata, who)) {
-            out.write(2);
+            LOG.info("Deleting test");
+            store.deleteBlob("test", who);
+            assertStoreHasExactly(store);
         }
-        assertStoreHasExactly(store, "test-empty-subject-WE", "test");
-        // Testing whether acls are set to WORLD_EVERYTHING
-        assertTrue("ACL does not contain WORLD_EVERYTHING", 
metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
-        readAssertEqualsWithAuth(store, who, "test-empty-subject-WE", 2);
-
-        //Test for subject with no principals and acls set to DEFAULT
-        who = new Subject();
-        metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT);
-        LOG.info("Creating other");
-        try (AtomicOutputStream out = 
store.createBlob("test-empty-subject-DEF", metadata, who)) {
-            out.write(2);
-        }
-        assertStoreHasExactly(store, "test-empty-subject-DEF", "test", 
"test-empty-subject-WE");
-        // Testing whether acls are set to WORLD_EVERYTHING
-        assertTrue("ACL does not contain WORLD_EVERYTHING", 
metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
-        readAssertEqualsWithAuth(store, who, "test-empty-subject-DEF", 2);
-
-        if (store instanceof HdfsBlobStore) {
-            ((HdfsBlobStore) store).fullCleanup(1);
-        } else {
-            fail("Error the blobstore is of unknowntype");
+    }
+    
+    @ParameterizedTest
+    @ValueSource(booleans = {true, false})
+    void testWithAuthenticationNoPrincipal(boolean securityEnabled) throws 
Exception {
+        try (AutoCloseableBlobStoreContainer container = 
initHdfs("/storm/blobstore-auth-no-principal-sec-" + securityEnabled)) {
 
 Review comment:
   This is 
https://github.com/apache/storm/pull/2990/files#diff-a48145dd5bbd83aced6dd85b1d85ec64L392
 and the remainder of the old test.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to