Skip to content

Commit

Permalink
remove duplicate ResourceOwnership class form zms server (#2859)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Avetisyan <[email protected]>
  • Loading branch information
havetisyan authored Jan 22, 2025
1 parent 0717450 commit fa30018
Show file tree
Hide file tree
Showing 5 changed files with 393 additions and 885 deletions.
2 changes: 1 addition & 1 deletion libs/java/server_common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<packaging>jar</packaging>

<properties>
<code.coverage.min>0.9063</code.coverage.min>
<code.coverage.min>0.9159</code.coverage.min>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.yahoo.athenz.zms.utils;
package com.yahoo.athenz.common.server.util;

import com.yahoo.athenz.common.server.ServerResourceException;
import com.yahoo.athenz.common.server.util.config.dynamic.DynamicConfigBoolean;
import com.yahoo.athenz.zms.*;
import org.testng.Assert;
import org.testng.annotations.Test;

import static org.testng.Assert.*;
Expand Down Expand Up @@ -141,14 +143,17 @@ public void testGetResourcePolicyOwnership() {

ResourcePolicyOwnership resourceOwnership =
ResourceOwnership.getResourcePolicyOwnership("object:object-owner,assertions:assertions-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertEquals(resourceOwnership.getAssertionsOwner(), "assertions-owner");

resourceOwnership = ResourceOwnership.getResourcePolicyOwnership("object:object-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertNull(resourceOwnership.getAssertionsOwner());

resourceOwnership = ResourceOwnership.getResourcePolicyOwnership("object:object-owner,unknown:test");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertNull(resourceOwnership.getAssertionsOwner());
}
Expand All @@ -160,16 +165,19 @@ public void testGetResourceRoleOwnership() {

ResourceRoleOwnership resourceOwnership =
ResourceOwnership.getResourceRoleOwnership("object:object-owner,meta:meta-owner,members:members-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertEquals(resourceOwnership.getMetaOwner(), "meta-owner");
assertEquals(resourceOwnership.getMembersOwner(), "members-owner");

resourceOwnership = ResourceOwnership.getResourceRoleOwnership("object:object-owner,meta:meta-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertEquals(resourceOwnership.getMetaOwner(), "meta-owner");
assertNull(resourceOwnership.getMembersOwner());

resourceOwnership = ResourceOwnership.getResourceRoleOwnership("object:object-owner,meta:meta-owner,unknown:test");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertEquals(resourceOwnership.getMetaOwner(), "meta-owner");
assertNull(resourceOwnership.getMembersOwner());
Expand All @@ -182,16 +190,19 @@ public void testGetResourceGroupOwnership() {

ResourceGroupOwnership resourceOwnership =
ResourceOwnership.getResourceGroupOwnership("object:object-owner,meta:meta-owner,members:members-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertEquals(resourceOwnership.getMetaOwner(), "meta-owner");
assertEquals(resourceOwnership.getMembersOwner(), "members-owner");

resourceOwnership = ResourceOwnership.getResourceGroupOwnership("object:object-owner,meta:meta-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertEquals(resourceOwnership.getMetaOwner(), "meta-owner");
assertNull(resourceOwnership.getMembersOwner());

resourceOwnership = ResourceOwnership.getResourceGroupOwnership("object:object-owner,meta:meta-owner,unknown:test");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertEquals(resourceOwnership.getMetaOwner(), "meta-owner");
assertNull(resourceOwnership.getMembersOwner());
Expand All @@ -204,14 +215,17 @@ public void testGetResourceServiceIdentityOwnership() {

ResourceServiceIdentityOwnership resourceOwnership =
ResourceOwnership.getResourceServiceOwnership("object:object-owner,publickeys:publickeys-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertEquals(resourceOwnership.getPublicKeysOwner(), "publickeys-owner");

resourceOwnership = ResourceOwnership.getResourceServiceOwnership("object:object-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertNull(resourceOwnership.getPublicKeysOwner());

resourceOwnership = ResourceOwnership.getResourceServiceOwnership("object:object-owner,unknown:test");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertNull(resourceOwnership.getPublicKeysOwner());
}
Expand All @@ -223,14 +237,17 @@ public void testGetResourceDomainOwnership() {

ResourceDomainOwnership resourceOwnership =
ResourceOwnership.getResourceDomainOwnership("object:object-owner,meta:meta-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertEquals(resourceOwnership.getMetaOwner(), "meta-owner");

resourceOwnership = ResourceOwnership.getResourceDomainOwnership("object:object-owner");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertNull(resourceOwnership.getMetaOwner());

resourceOwnership = ResourceOwnership.getResourceDomainOwnership("object:object-owner,unknown:test");
assertNotNull(resourceOwnership);
assertEquals(resourceOwnership.getObjectOwner(), "object-owner");
assertNull(resourceOwnership.getMetaOwner());
}
Expand All @@ -248,7 +265,7 @@ public void testOwnershipCheckFailure() {
}

@Test
public void testVerifyDeleteResourceObjectOwnership() {
public void testVerifyDeleteResourceObjectOwnership() throws ServerResourceException {

// for all objects verify that if the object doesn't have
// resource ownership or no object owner then we return right
Expand Down Expand Up @@ -287,7 +304,7 @@ public void testSkipEnforceResourceOwnership() {
}

@Test
public void testVerifyRoleMembersDeleteResourceOwnership() {
public void testVerifyRoleMembersDeleteResourceOwnership() throws ServerResourceException {

ResourceOwnership.verifyRoleMembersDeleteResourceOwnership(new Role(), "resourceOwner", "unit-test");
ResourceOwnership.verifyRoleMembersDeleteResourceOwnership(new Role()
Expand All @@ -297,20 +314,20 @@ public void testVerifyRoleMembersDeleteResourceOwnership() {
try {
ResourceOwnership.verifyRoleMembersDeleteResourceOwnership(memberOwnerRole, "resourceOwner", "unit-test");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 409);
} catch (ServerResourceException ex) {
Assert.assertEquals(ex.getCode(), 409);
}

Role objectOwnerRole = new Role().setResourceOwnership(new ResourceRoleOwnership().setObjectOwner("object-owner"));
try {
ResourceOwnership.verifyRoleMembersDeleteResourceOwnership(objectOwnerRole, "resourceOwner", "unit-test");
} catch (ResourceException ex) {
} catch (ServerResourceException ex) {
fail();
}
}

@Test
public void testVerifyGroupMembersDeleteResourceOwnership() {
public void testVerifyGroupMembersDeleteResourceOwnership() throws ServerResourceException {

ResourceOwnership.verifyGroupMembersDeleteResourceOwnership(new Group(), "resourceOwner", "unit-test");
ResourceOwnership.verifyGroupMembersDeleteResourceOwnership(new Group()
Expand All @@ -320,20 +337,20 @@ public void testVerifyGroupMembersDeleteResourceOwnership() {
try {
ResourceOwnership.verifyGroupMembersDeleteResourceOwnership(memberOwnerGroup, "resourceOwner", "unit-test");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 409);
} catch (ServerResourceException ex) {
Assert.assertEquals(ex.getCode(), 409);
}

Group objectOwnerGroup = new Group().setResourceOwnership(new ResourceGroupOwnership().setObjectOwner("object-owner"));
try {
ResourceOwnership.verifyGroupMembersDeleteResourceOwnership(objectOwnerGroup, "resourceOwner", "unit-test");
} catch (ResourceException ex) {
} catch (ServerResourceException ex) {
fail();
}
}

@Test
public void testVerifyPolicyAssertionsDeleteResourceOwnership() {
public void testVerifyPolicyAssertionsDeleteResourceOwnership() throws ServerResourceException {

ResourceOwnership.verifyPolicyAssertionsDeleteResourceOwnership(new Policy(), "resourceOwner", "unit-test");
ResourceOwnership.verifyPolicyAssertionsDeleteResourceOwnership(new Policy()
Expand All @@ -343,14 +360,14 @@ public void testVerifyPolicyAssertionsDeleteResourceOwnership() {
try {
ResourceOwnership.verifyPolicyAssertionsDeleteResourceOwnership(assertionsOwnerPolicy, "resourceOwner", "unit-test");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 409);
} catch (ServerResourceException ex) {
Assert.assertEquals(ex.getCode(), 409);
}

Policy objectOwnerPolicy = new Policy().setResourceOwnership(new ResourcePolicyOwnership().setObjectOwner("object-owner"));
try {
ResourceOwnership.verifyPolicyAssertionsDeleteResourceOwnership(objectOwnerPolicy, "resourceOwner", "unit-test");
} catch (ResourceException ex) {
} catch (ServerResourceException ex) {
fail();
}
}
Expand Down
Loading

0 comments on commit fa30018

Please sign in to comment.