use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.
the class ZMSImplTest method testSetupPolicyListWithAssertionsActiveOnly.
@Test
public void testSetupPolicyListWithAssertionsActiveOnly() {
final String domainName = "setup-policy-with-assert-active-only";
Policy policy1 = zmsTestInitializer.createPolicyObject(domainName, "policy1").setActive(true);
Policy policy2 = zmsTestInitializer.createPolicyObject(domainName, "policy2").setActive(false);
List<Policy> policyList = new ArrayList<>();
policyList.add(policy1);
policyList.add(policy2);
AthenzDomain domain = new AthenzDomain(domainName);
domain.setPolicies(policyList);
List<Policy> policies = zmsTestInitializer.getZms().setupPolicyList(domain, Boolean.TRUE, Boolean.FALSE);
assertEquals(1, policies.size());
assertEquals(policies.get(0).getName(), "setup-policy-with-assert-active-only:policy.policy1");
}
use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.
the class ZMSImplTest method testSetupServiceListWithKeysOnly.
@Test
public void testSetupServiceListWithKeysOnly() {
final String domainName = "setup-service-keys-only";
TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
ServiceIdentity service1 = zmsTestInitializer.createServiceObject(domainName, "service1", "http://localhost", "/usr/bin/java", "root", "users", "host1");
zmsTestInitializer.getZms().putServiceIdentity(zmsTestInitializer.getMockDomRsrcCtx(), domainName, "service1", zmsTestInitializer.getAuditRef(), service1);
ServiceIdentity service2 = zmsTestInitializer.createServiceObject(domainName, "service2", "http://localhost", "/usr/bin/java", "yahoo", "users", "host2");
zmsTestInitializer.getZms().putServiceIdentity(zmsTestInitializer.getMockDomRsrcCtx(), domainName, "service2", zmsTestInitializer.getAuditRef(), service2);
AthenzDomain domain = zmsTestInitializer.getZms().getAthenzDomain(domainName, false);
List<ServiceIdentity> services = zmsTestInitializer.getZms().setupServiceIdentityList(domain, Boolean.TRUE, Boolean.FALSE);
assertEquals(2, services.size());
boolean service1Check = false;
boolean service2Check = false;
for (ServiceIdentity service : services) {
switch(service.getName()) {
case "setup-service-keys-only.service1":
assertEquals(service.getExecutable(), "/usr/bin/java");
assertEquals(service.getUser(), "root");
assertEquals(service.getPublicKeys().size(), 2);
assertNull(service.getHosts());
service1Check = true;
break;
case "setup-service-keys-only.service2":
assertEquals(service.getExecutable(), "/usr/bin/java");
assertEquals(service.getUser(), "yahoo");
assertEquals(service.getPublicKeys().size(), 2);
assertNull(service.getHosts());
service2Check = true;
break;
}
}
assertTrue(service1Check);
assertTrue(service2Check);
zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName, zmsTestInitializer.getAuditRef());
}
use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.
the class ZMSImplTest method testHasAccessValidMember.
@Test
public void testHasAccessValidMember() {
TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("HasAccessDom1", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
Role role1 = zmsTestInitializer.createRoleObject("HasAccessDom1", "Role1", null, "user.user1", "user.user3");
zmsTestInitializer.getZms().putRole(zmsTestInitializer.getMockDomRsrcCtx(), "HasAccessDom1", "Role1", zmsTestInitializer.getAuditRef(), role1);
Policy policy1 = zmsTestInitializer.createPolicyObject("HasAccessDom1", "Policy1", "Role1", "UPDATE", "HasAccessDom1:resource1", AssertionEffect.ALLOW);
zmsTestInitializer.getZms().putPolicy(zmsTestInitializer.getMockDomRsrcCtx(), "HasAccessDom1", "Policy1", zmsTestInitializer.getAuditRef(), policy1);
// user1 and user3 have access to UPDATE/resource1
Principal principal1 = SimplePrincipal.create("user", "user1", "v=U1;d=user;n=user1;s=signature");
AthenzDomain domain = zmsTestInitializer.getZms().retrieveAccessDomain("hasaccessdom1", principal1);
assertEquals(zmsTestInitializer.getZms().hasAccess(domain, "update", "hasaccessdom1:resource1", principal1, null), AccessStatus.ALLOWED);
Principal principal3 = SimplePrincipal.create("user", "user3", "v=U1;d=user;n=user3;s=signature");
assertEquals(zmsTestInitializer.getZms().hasAccess(domain, "update", "hasaccessdom1:resource1", principal3, null), AccessStatus.ALLOWED);
zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "HasAccessDom1", zmsTestInitializer.getAuditRef());
}
use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.
the class ZMSImplTest method testRetrieveAccessDomainValid.
@Test
public void testRetrieveAccessDomainValid() {
TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("AccessDomain", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
Authority principalAuthority = new com.yahoo.athenz.common.server.debug.DebugPrincipalAuthority();
Principal pJane = principalAuthority.authenticate("v=U1;d=user;n=jane;s=signature", "10.11.12.13", "GET", null);
AthenzDomain athenzDomain = zmsTestInitializer.getZms().retrieveAccessDomain("accessdomain", pJane);
assertNotNull(athenzDomain);
zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "AccessDomain", zmsTestInitializer.getAuditRef());
}
use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.
the class ZMSImplTest method testGetAthenzDomainWithEntities.
@Test
public void testGetAthenzDomainWithEntities() {
final String domainName = "athenz-domain-with-entities";
TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
Entity entity1 = zmsTestInitializer.createEntityObject(domainName, "test-entity1");
zmsTestInitializer.getZms().putEntity(zmsTestInitializer.getMockDomRsrcCtx(), domainName, "test-entity1", zmsTestInitializer.getAuditRef(), entity1);
Entity entity2 = zmsTestInitializer.createEntityObject(domainName, "test-entity2");
zmsTestInitializer.getZms().putEntity(zmsTestInitializer.getMockDomRsrcCtx(), domainName, "test-entity2", zmsTestInitializer.getAuditRef(), entity2);
AthenzDomain domain = zmsTestInitializer.getZms().getAthenzDomain(domainName, false);
List<Entity> entities = domain.getEntities();
assertNotNull(entities);
assertEquals(entities.size(), 2);
boolean entity1Check = false;
boolean entity2Check = false;
for (Entity entity : entities) {
switch(entity.getName()) {
case "athenz-domain-with-entities:entity.test-entity1":
entity1Check = true;
break;
case "athenz-domain-with-entities:entity.test-entity2":
entity2Check = true;
break;
}
}
assertTrue(entity1Check);
assertTrue(entity2Check);
zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), domainName, zmsTestInitializer.getAuditRef());
}
Aggregations