|
@@ -18,16 +18,20 @@
|
|
|
|
|
|
package org.apache.hadoop.ozone;
|
|
|
|
|
|
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
|
|
|
+
|
|
|
import org.junit.Test;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Set;
|
|
|
|
|
|
+import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.*;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
|
/**
|
|
|
- * This class is to test acl stoarge and retreival in ozone store.
|
|
|
+ * This class is to test acl storage and retrieval in ozone store.
|
|
|
*/
|
|
|
public class TestOzoneAcls {
|
|
|
|
|
@@ -39,8 +43,8 @@ public class TestOzoneAcls {
|
|
|
testMatrix.put("user:bilbo:r", Boolean.TRUE);
|
|
|
testMatrix.put("user:bilbo:w", Boolean.TRUE);
|
|
|
testMatrix.put("user:bilbo:rw", Boolean.TRUE);
|
|
|
- testMatrix.put("user:bilbo:wr", Boolean.TRUE);
|
|
|
- testMatrix.put(" user:bilbo:wr ", Boolean.TRUE);
|
|
|
+ testMatrix.put("user:bilbo:a", Boolean.TRUE);
|
|
|
+ testMatrix.put(" user:bilbo:a ", Boolean.TRUE);
|
|
|
|
|
|
|
|
|
// ACLs makes no judgement on the quality of
|
|
@@ -53,7 +57,16 @@ public class TestOzoneAcls {
|
|
|
testMatrix.put("", Boolean.FALSE);
|
|
|
testMatrix.put(null, Boolean.FALSE);
|
|
|
testMatrix.put(" user:bilbo:", Boolean.FALSE);
|
|
|
- testMatrix.put(" user:bilbo:rx", Boolean.FALSE);
|
|
|
+ testMatrix.put(" user:bilbo:rx", Boolean.TRUE);
|
|
|
+ testMatrix.put(" user:bilbo:rwdlncxy", Boolean.TRUE);
|
|
|
+ testMatrix.put(" group:bilbo:rwdlncxy", Boolean.TRUE);
|
|
|
+ testMatrix.put(" world::rwdlncxy", Boolean.TRUE);
|
|
|
+ testMatrix.put(" user:bilbo:rncxy", Boolean.TRUE);
|
|
|
+ testMatrix.put(" group:bilbo:ncxy", Boolean.TRUE);
|
|
|
+ testMatrix.put(" world::ncxy", Boolean.TRUE);
|
|
|
+ testMatrix.put(" user:bilbo:rwcxy", Boolean.TRUE);
|
|
|
+ testMatrix.put(" group:bilbo:rwcxy", Boolean.TRUE);
|
|
|
+ testMatrix.put(" world::rwcxy", Boolean.TRUE);
|
|
|
testMatrix.put(" user:bilbo:mk", Boolean.FALSE);
|
|
|
testMatrix.put(" user::rw", Boolean.FALSE);
|
|
|
testMatrix.put("user11:bilbo:rw", Boolean.FALSE);
|
|
@@ -62,12 +75,12 @@ public class TestOzoneAcls {
|
|
|
testMatrix.put(" group:hobbit:r", Boolean.TRUE);
|
|
|
testMatrix.put(" group:hobbit:w", Boolean.TRUE);
|
|
|
testMatrix.put(" group:hobbit:rw", Boolean.TRUE);
|
|
|
- testMatrix.put(" group:hobbit:wr", Boolean.TRUE);
|
|
|
+ testMatrix.put(" group:hobbit:a", Boolean.TRUE);
|
|
|
testMatrix.put(" group:*:rw", Boolean.TRUE);
|
|
|
testMatrix.put(" group:~!:rw", Boolean.TRUE);
|
|
|
|
|
|
testMatrix.put(" group:hobbit:", Boolean.FALSE);
|
|
|
- testMatrix.put(" group:hobbit:rx", Boolean.FALSE);
|
|
|
+ testMatrix.put(" group:hobbit:rx", Boolean.TRUE);
|
|
|
testMatrix.put(" group:hobbit:mk", Boolean.FALSE);
|
|
|
testMatrix.put(" group::", Boolean.FALSE);
|
|
|
testMatrix.put(" group::rw", Boolean.FALSE);
|
|
@@ -77,14 +90,14 @@ public class TestOzoneAcls {
|
|
|
testMatrix.put("JUNK group:hobbit:r", Boolean.FALSE);
|
|
|
testMatrix.put("JUNK group:hobbit:w", Boolean.FALSE);
|
|
|
testMatrix.put("JUNK group:hobbit:rw", Boolean.FALSE);
|
|
|
- testMatrix.put("JUNK group:hobbit:wr", Boolean.FALSE);
|
|
|
+ testMatrix.put("JUNK group:hobbit:a", Boolean.FALSE);
|
|
|
testMatrix.put("JUNK group:*:rw", Boolean.FALSE);
|
|
|
testMatrix.put("JUNK group:~!:rw", Boolean.FALSE);
|
|
|
|
|
|
testMatrix.put(" world::r", Boolean.TRUE);
|
|
|
testMatrix.put(" world::w", Boolean.TRUE);
|
|
|
testMatrix.put(" world::rw", Boolean.TRUE);
|
|
|
- testMatrix.put(" world::wr", Boolean.TRUE);
|
|
|
+ testMatrix.put(" world::a", Boolean.TRUE);
|
|
|
|
|
|
testMatrix.put(" world:bilbo:w", Boolean.FALSE);
|
|
|
testMatrix.put(" world:bilbo:rw", Boolean.FALSE);
|
|
@@ -97,7 +110,7 @@ public class TestOzoneAcls {
|
|
|
try {
|
|
|
OzoneAcl.parseAcl(key);
|
|
|
// should never get here since parseAcl will throw
|
|
|
- fail("An exception was expected but did not happen.");
|
|
|
+ fail("An exception was expected but did not happen. Key: " + key);
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
// nothing to do
|
|
|
}
|
|
@@ -109,33 +122,51 @@ public class TestOzoneAcls {
|
|
|
public void testAclValues() {
|
|
|
OzoneAcl acl = OzoneAcl.parseAcl("user:bilbo:rw");
|
|
|
assertEquals(acl.getName(), "bilbo");
|
|
|
- assertEquals(OzoneAcl.OzoneACLRights.READ_WRITE, acl.getRights());
|
|
|
- assertEquals(OzoneAcl.OzoneACLType.USER, acl.getType());
|
|
|
+ assertEquals(Arrays.asList(READ, WRITE), acl.getRights());
|
|
|
+ assertEquals(ACLIdentityType.USER, acl.getType());
|
|
|
|
|
|
- acl = OzoneAcl.parseAcl("user:bilbo:wr");
|
|
|
+ acl = OzoneAcl.parseAcl("user:bilbo:a");
|
|
|
assertEquals("bilbo", acl.getName());
|
|
|
- assertEquals(OzoneAcl.OzoneACLRights.READ_WRITE, acl.getRights());
|
|
|
- assertEquals(OzoneAcl.OzoneACLType.USER, acl.getType());
|
|
|
+ assertEquals(Arrays.asList(ALL), acl.getRights());
|
|
|
+ assertEquals(ACLIdentityType.USER, acl.getType());
|
|
|
|
|
|
acl = OzoneAcl.parseAcl("user:bilbo:r");
|
|
|
assertEquals("bilbo", acl.getName());
|
|
|
- assertEquals(OzoneAcl.OzoneACLRights.READ, acl.getRights());
|
|
|
- assertEquals(OzoneAcl.OzoneACLType.USER, acl.getType());
|
|
|
+ assertEquals(Arrays.asList(READ), acl.getRights());
|
|
|
+ assertEquals(ACLIdentityType.USER, acl.getType());
|
|
|
|
|
|
acl = OzoneAcl.parseAcl("user:bilbo:w");
|
|
|
assertEquals("bilbo", acl.getName());
|
|
|
- assertEquals(OzoneAcl.OzoneACLRights.WRITE, acl.getRights());
|
|
|
- assertEquals(OzoneAcl.OzoneACLType.USER, acl.getType());
|
|
|
+ assertEquals(Arrays.asList(WRITE), acl.getRights());
|
|
|
+ assertEquals(ACLIdentityType.USER, acl.getType());
|
|
|
|
|
|
- acl = OzoneAcl.parseAcl("group:hobbit:wr");
|
|
|
+ acl = OzoneAcl.parseAcl("group:hobbit:a");
|
|
|
assertEquals(acl.getName(), "hobbit");
|
|
|
- assertEquals(OzoneAcl.OzoneACLRights.READ_WRITE, acl.getRights());
|
|
|
- assertEquals(OzoneAcl.OzoneACLType.GROUP, acl.getType());
|
|
|
+ assertEquals(Arrays.asList(ALL), acl.getRights());
|
|
|
+ assertEquals(ACLIdentityType.GROUP, acl.getType());
|
|
|
+
|
|
|
+ acl = OzoneAcl.parseAcl("world::a");
|
|
|
+ assertEquals(acl.getName(), "");
|
|
|
+ assertEquals(Arrays.asList(ALL), acl.getRights());
|
|
|
+ assertEquals(ACLIdentityType.WORLD, acl.getType());
|
|
|
+
|
|
|
+ acl = OzoneAcl.parseAcl("user:bilbo:rwdlncxy");
|
|
|
+ assertEquals(acl.getName(), "bilbo");
|
|
|
+ assertEquals(Arrays.asList(READ, WRITE, DELETE, LIST, NONE, CREATE,
|
|
|
+ READ_ACL, WRITE_ACL), acl.getRights());
|
|
|
+ assertEquals(ACLIdentityType.USER, acl.getType());
|
|
|
+
|
|
|
+ acl = OzoneAcl.parseAcl("group:hadoop:rwdlncxy");
|
|
|
+ assertEquals(acl.getName(), "hadoop");
|
|
|
+ assertEquals(Arrays.asList(READ, WRITE, DELETE, LIST, NONE, CREATE,
|
|
|
+ READ_ACL, WRITE_ACL), acl.getRights());
|
|
|
+ assertEquals(ACLIdentityType.GROUP, acl.getType());
|
|
|
|
|
|
- acl = OzoneAcl.parseAcl("world::wr");
|
|
|
+ acl = OzoneAcl.parseAcl("world::rwdlncxy");
|
|
|
assertEquals(acl.getName(), "");
|
|
|
- assertEquals(OzoneAcl.OzoneACLRights.READ_WRITE, acl.getRights());
|
|
|
- assertEquals(OzoneAcl.OzoneACLType.WORLD, acl.getType());
|
|
|
+ assertEquals(Arrays.asList(READ, WRITE, DELETE, LIST, NONE, CREATE,
|
|
|
+ READ_ACL, WRITE_ACL), acl.getRights());
|
|
|
+ assertEquals(ACLIdentityType.WORLD, acl.getType());
|
|
|
}
|
|
|
|
|
|
}
|