|
@@ -781,26 +781,27 @@ public class TestOzoneManagerHA {
|
|
|
.setVolumeName(ozoneBucket.getVolumeName())
|
|
|
.setBucketName(ozoneBucket.getName()).build();
|
|
|
|
|
|
- boolean addAcl = objectStore.addAcl(ozoneObj, defaultUserAcl);
|
|
|
- Assert.assertTrue(addAcl);
|
|
|
-
|
|
|
- List<OzoneAcl> acls = objectStore.getAcl(ozoneObj);
|
|
|
+ testAddAcl(remoteUserName, ozoneObj, defaultUserAcl);
|
|
|
+ }
|
|
|
+ @Test
|
|
|
+ public void testRemoveBucketAcl() throws Exception {
|
|
|
+ OzoneBucket ozoneBucket = setupBucket();
|
|
|
+ String remoteUserName = "remoteUser";
|
|
|
+ OzoneAcl defaultUserAcl = new OzoneAcl(USER, remoteUserName,
|
|
|
+ READ, DEFAULT);
|
|
|
|
|
|
- Assert.assertTrue(containsAcl(defaultUserAcl, acls));
|
|
|
+ OzoneObj ozoneObj = OzoneObjInfo.Builder.newBuilder()
|
|
|
+ .setResType(OzoneObj.ResourceType.BUCKET)
|
|
|
+ .setStoreType(OzoneObj.StoreType.OZONE)
|
|
|
+ .setVolumeName(ozoneBucket.getVolumeName())
|
|
|
+ .setBucketName(ozoneBucket.getName()).build();
|
|
|
|
|
|
- // Add an already existing acl.
|
|
|
- addAcl = objectStore.addAcl(ozoneObj, defaultUserAcl);
|
|
|
- Assert.assertFalse(addAcl);
|
|
|
+ testRemoveAcl(remoteUserName, ozoneObj, defaultUserAcl);
|
|
|
|
|
|
- // Add an acl by changing acl type with same type, name and scope.
|
|
|
- defaultUserAcl = new OzoneAcl(USER, remoteUserName,
|
|
|
- WRITE, DEFAULT);
|
|
|
- addAcl = objectStore.addAcl(ozoneObj, defaultUserAcl);
|
|
|
- Assert.assertTrue(addAcl);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testRemoveBucketAcl() throws Exception {
|
|
|
+ public void testSetBucketAcl() throws Exception {
|
|
|
OzoneBucket ozoneBucket = setupBucket();
|
|
|
String remoteUserName = "remoteUser";
|
|
|
OzoneAcl defaultUserAcl = new OzoneAcl(USER, remoteUserName,
|
|
@@ -812,50 +813,96 @@ public class TestOzoneManagerHA {
|
|
|
.setVolumeName(ozoneBucket.getVolumeName())
|
|
|
.setBucketName(ozoneBucket.getName()).build();
|
|
|
|
|
|
- // As by default create bucket we add some default acls in RpcClient.
|
|
|
- List<OzoneAcl> acls = objectStore.getAcl(ozoneObj);
|
|
|
+ testSetAcl(remoteUserName, ozoneObj, defaultUserAcl);
|
|
|
+ }
|
|
|
|
|
|
- Assert.assertTrue(acls.size() > 0);
|
|
|
+ private boolean containsAcl(OzoneAcl ozoneAcl, List<OzoneAcl> ozoneAcls) {
|
|
|
+ for (OzoneAcl acl : ozoneAcls) {
|
|
|
+ boolean result = compareAcls(ozoneAcl, acl);
|
|
|
+ if (result) {
|
|
|
+ // We found a match, return.
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // Remove an existing acl.
|
|
|
- boolean removeAcl = objectStore.removeAcl(ozoneObj, acls.get(0));
|
|
|
- Assert.assertTrue(removeAcl);
|
|
|
+ private boolean compareAcls(OzoneAcl givenAcl, OzoneAcl existingAcl) {
|
|
|
+ if (givenAcl.getType().equals(existingAcl.getType())
|
|
|
+ && givenAcl.getName().equals(existingAcl.getName())
|
|
|
+ && givenAcl.getAclScope().equals(existingAcl.getAclScope())) {
|
|
|
+ BitSet bitSet = (BitSet) givenAcl.getAclBitSet().clone();
|
|
|
+ bitSet.and(existingAcl.getAclBitSet());
|
|
|
+ if (bitSet.equals(existingAcl.getAclBitSet())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // Trying to remove an already removed acl.
|
|
|
- removeAcl = objectStore.removeAcl(ozoneObj, acls.get(0));
|
|
|
- Assert.assertFalse(removeAcl);
|
|
|
+ @Test
|
|
|
+ public void testAddKeyAcl() throws Exception {
|
|
|
+ OzoneBucket ozoneBucket = setupBucket();
|
|
|
+ String remoteUserName = "remoteUser";
|
|
|
+ OzoneAcl userAcl = new OzoneAcl(USER, remoteUserName,
|
|
|
+ READ, DEFAULT);
|
|
|
|
|
|
- boolean addAcl = objectStore.addAcl(ozoneObj, defaultUserAcl);
|
|
|
- Assert.assertTrue(addAcl);
|
|
|
+ String key = createKey(ozoneBucket);
|
|
|
|
|
|
- // Just changed acl type here to write, rest all is same as defaultUserAcl.
|
|
|
- OzoneAcl modifiedUserAcl = new OzoneAcl(USER, remoteUserName,
|
|
|
- WRITE, DEFAULT);
|
|
|
- addAcl = objectStore.addAcl(ozoneObj, modifiedUserAcl);
|
|
|
- Assert.assertTrue(addAcl);
|
|
|
+ OzoneObj ozoneObj = OzoneObjInfo.Builder.newBuilder()
|
|
|
+ .setResType(OzoneObj.ResourceType.KEY)
|
|
|
+ .setStoreType(OzoneObj.StoreType.OZONE)
|
|
|
+ .setVolumeName(ozoneBucket.getVolumeName())
|
|
|
+ .setBucketName(ozoneBucket.getName())
|
|
|
+ .setKeyName(key).build();
|
|
|
|
|
|
- removeAcl = objectStore.removeAcl(ozoneObj, modifiedUserAcl);
|
|
|
- Assert.assertTrue(removeAcl);
|
|
|
+ testAddAcl(remoteUserName, ozoneObj, userAcl);
|
|
|
+ }
|
|
|
|
|
|
- removeAcl = objectStore.removeAcl(ozoneObj, defaultUserAcl);
|
|
|
- Assert.assertTrue(removeAcl);
|
|
|
+ @Test
|
|
|
+ public void testRemoveKeyAcl() throws Exception {
|
|
|
+ OzoneBucket ozoneBucket = setupBucket();
|
|
|
+ String remoteUserName = "remoteUser";
|
|
|
+ OzoneAcl userAcl = new OzoneAcl(USER, remoteUserName,
|
|
|
+ READ, DEFAULT);
|
|
|
+
|
|
|
+ String key = createKey(ozoneBucket);
|
|
|
+
|
|
|
+ OzoneObj ozoneObj = OzoneObjInfo.Builder.newBuilder()
|
|
|
+ .setResType(OzoneObj.ResourceType.KEY)
|
|
|
+ .setStoreType(OzoneObj.StoreType.OZONE)
|
|
|
+ .setVolumeName(ozoneBucket.getVolumeName())
|
|
|
+ .setBucketName(ozoneBucket.getName())
|
|
|
+ .setKeyName(key).build();
|
|
|
+
|
|
|
+ testRemoveAcl(remoteUserName, ozoneObj, userAcl);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testSetBucketAcl() throws Exception {
|
|
|
+ public void testSetKeyAcl() throws Exception {
|
|
|
OzoneBucket ozoneBucket = setupBucket();
|
|
|
String remoteUserName = "remoteUser";
|
|
|
- OzoneAcl defaultUserAcl = new OzoneAcl(USER, remoteUserName,
|
|
|
+ OzoneAcl userAcl = new OzoneAcl(USER, remoteUserName,
|
|
|
READ, DEFAULT);
|
|
|
|
|
|
+ String key = createKey(ozoneBucket);
|
|
|
+
|
|
|
OzoneObj ozoneObj = OzoneObjInfo.Builder.newBuilder()
|
|
|
- .setResType(OzoneObj.ResourceType.BUCKET)
|
|
|
+ .setResType(OzoneObj.ResourceType.KEY)
|
|
|
.setStoreType(OzoneObj.StoreType.OZONE)
|
|
|
.setVolumeName(ozoneBucket.getVolumeName())
|
|
|
- .setBucketName(ozoneBucket.getName()).build();
|
|
|
+ .setBucketName(ozoneBucket.getName())
|
|
|
+ .setKeyName(key).build();
|
|
|
+
|
|
|
+ testSetAcl(remoteUserName, ozoneObj, userAcl);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- // As by default create bucket we add some default acls in RpcClient.
|
|
|
+ private void testSetAcl(String remoteUserName, OzoneObj ozoneObj,
|
|
|
+ OzoneAcl userAcl) throws Exception {
|
|
|
+ // As by default create will add some default acls in RpcClient.
|
|
|
List<OzoneAcl> acls = objectStore.getAcl(ozoneObj);
|
|
|
|
|
|
Assert.assertTrue(acls.size() > 0);
|
|
@@ -875,32 +922,63 @@ public class TestOzoneManagerHA {
|
|
|
for (OzoneAcl ozoneAcl : newAcls) {
|
|
|
Assert.assertTrue(compareAcls(getAcls.get(i++), ozoneAcl));
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- private boolean containsAcl(OzoneAcl ozoneAcl, List<OzoneAcl> ozoneAcls) {
|
|
|
- for (OzoneAcl acl : ozoneAcls) {
|
|
|
- boolean result = compareAcls(ozoneAcl, acl);
|
|
|
- if (result) {
|
|
|
- // We found a match, return.
|
|
|
- return result;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
+ private void testAddAcl(String remoteUserName, OzoneObj ozoneObj,
|
|
|
+ OzoneAcl userAcl) throws Exception {
|
|
|
+ boolean addAcl = objectStore.addAcl(ozoneObj, userAcl);
|
|
|
+ Assert.assertTrue(addAcl);
|
|
|
+
|
|
|
+ List<OzoneAcl> acls = objectStore.getAcl(ozoneObj);
|
|
|
+
|
|
|
+ Assert.assertTrue(containsAcl(userAcl, acls));
|
|
|
+
|
|
|
+ // Add an already existing acl.
|
|
|
+ addAcl = objectStore.addAcl(ozoneObj, userAcl);
|
|
|
+ Assert.assertFalse(addAcl);
|
|
|
+
|
|
|
+ // Add an acl by changing acl type with same type, name and scope.
|
|
|
+ userAcl = new OzoneAcl(USER, remoteUserName,
|
|
|
+ WRITE, DEFAULT);
|
|
|
+ addAcl = objectStore.addAcl(ozoneObj, userAcl);
|
|
|
+ Assert.assertTrue(addAcl);
|
|
|
}
|
|
|
|
|
|
- private boolean compareAcls(OzoneAcl givenAcl, OzoneAcl existingAcl) {
|
|
|
- if (givenAcl.getType().equals(existingAcl.getType())
|
|
|
- && givenAcl.getName().equals(existingAcl.getName())
|
|
|
- && givenAcl.getAclScope().equals(existingAcl.getAclScope())) {
|
|
|
- BitSet bitSet = (BitSet) givenAcl.getAclBitSet().clone();
|
|
|
- bitSet.and(existingAcl.getAclBitSet());
|
|
|
- if (bitSet.equals(existingAcl.getAclBitSet())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
+ private void testRemoveAcl(String remoteUserName, OzoneObj ozoneObj,
|
|
|
+ OzoneAcl userAcl)
|
|
|
+ throws Exception{
|
|
|
+ // As by default create will add some default acls in RpcClient.
|
|
|
+ List<OzoneAcl> acls = objectStore.getAcl(ozoneObj);
|
|
|
+
|
|
|
+ Assert.assertTrue(acls.size() > 0);
|
|
|
+
|
|
|
+ // Remove an existing acl.
|
|
|
+ boolean removeAcl = objectStore.removeAcl(ozoneObj, acls.get(0));
|
|
|
+ Assert.assertTrue(removeAcl);
|
|
|
+
|
|
|
+ // Trying to remove an already removed acl.
|
|
|
+ removeAcl = objectStore.removeAcl(ozoneObj, acls.get(0));
|
|
|
+ Assert.assertFalse(removeAcl);
|
|
|
+
|
|
|
+ boolean addAcl = objectStore.addAcl(ozoneObj, userAcl);
|
|
|
+ Assert.assertTrue(addAcl);
|
|
|
+
|
|
|
+ // Just changed acl type here to write, rest all is same as defaultUserAcl.
|
|
|
+ OzoneAcl modifiedUserAcl = new OzoneAcl(USER, remoteUserName,
|
|
|
+ WRITE, DEFAULT);
|
|
|
+ addAcl = objectStore.addAcl(ozoneObj, modifiedUserAcl);
|
|
|
+ Assert.assertTrue(addAcl);
|
|
|
+
|
|
|
+ removeAcl = objectStore.removeAcl(ozoneObj, modifiedUserAcl);
|
|
|
+ Assert.assertTrue(removeAcl);
|
|
|
+
|
|
|
+ removeAcl = objectStore.removeAcl(ozoneObj, userAcl);
|
|
|
+ Assert.assertTrue(removeAcl);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Test
|
|
|
public void testOMRatisSnapshot() throws Exception {
|
|
|
String userName = "user" + RandomStringUtils.randomNumeric(5);
|