use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheNewDomain.
@Test
public void testAddDomainToCacheNewDomain() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = new DataCache();
Role role = new Role();
role.setName("coretech:role.admin");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user"));
role.setRoleMembers(members);
List<Role> roles = new ArrayList<>();
roles.add(role);
DomainData domainData = new DomainData();
domainData.setRoles(roles);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
DomainData domain = store.getDomainData("coretech");
assertNotNull(domain);
assertEquals(domain.getRoles().size(), 1);
assertEquals(domain.getRoles().get(0).getName(), "coretech:role.admin");
assertEquals(domain.getRoles().get(0).getRoleMembers().size(), 1);
assertEquals(domain.getRoles().get(0).getRoleMembers().get(0).getMemberName(), "user_domain.user");
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testProcessDomainServiceIdentitiesNullPolicies.
@Test
public void testProcessDomainServiceIdentitiesNullPolicies() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = new DataCache();
DomainData domainData = new DomainData();
domainData.setName("coretech");
dataCache.setDomainData(domainData);
store.processDomainServiceIdentities(domainData, dataCache);
HostServices hostServices = store.getHostServices("host1");
List<String> hosts = hostServices.getNames();
assertNull(hosts);
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheUpdatedDomain.
@Test
public void testAddDomainToCacheUpdatedDomain() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = new DataCache();
Role role = new Role();
role.setName("coretech:role.admin");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user"));
role.setRoleMembers(members);
List<Role> roles = new ArrayList<>();
roles.add(role);
DomainData domainData = new DomainData();
domainData.setRoles(roles);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
/* update member list */
role = new Role();
role.setName("coretech:role.admin");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user1"));
members.add(new RoleMember().setMemberName("user_domain.user2"));
role.setRoleMembers(members);
roles = new ArrayList<>();
roles.add(role);
dataCache = new DataCache();
domainData = new DomainData();
domainData.setRoles(roles);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
DomainData domain = store.getDomainData("coretech");
assertNotNull(domain);
assertEquals(domain.getRoles().size(), 1);
assertEquals(domain.getRoles().get(0).getName(), "coretech:role.admin");
assertEquals(domain.getRoles().get(0).getRoleMembers().size(), 2);
boolean user1 = false;
boolean user2 = false;
for (RoleMember member : domain.getRoles().get(0).getRoleMembers()) {
switch(member.getMemberName()) {
case "user_domain.user1":
user1 = true;
break;
case "user_domain.user2":
user2 = true;
break;
}
}
assertTrue(user1);
assertTrue(user2);
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class ZTSImplTest method testAccess.
@Test
public void testAccess() {
DataCache domain = new DataCache();
DomainData domainData = new DomainData();
domainData.setName("coretechtrust");
domain.setDomainData(domainData);
domainData.setRoles(new ArrayList<Role>());
Role role1 = createRoleObject("coretechtrust", "role1", null, "user_domain.user1", null);
Role role2 = createRoleObject("coretechtrust", "role2", null, "user_domain.user2", null);
domainData.getRoles().add(role1);
domainData.getRoles().add(role2);
Policy policy = createPolicyObject("coretechtrust", "access", "coretechtrust:role.role1", false, "update", "coretechtrust:table1", AssertionEffect.ALLOW);
domainData.setPolicies(new com.yahoo.athenz.zms.SignedPolicies());
domainData.getPolicies().setContents(new com.yahoo.athenz.zms.DomainPolicies());
domainData.getPolicies().getContents().setPolicies(new ArrayList<Policy>());
domainData.getPolicies().getContents().getPolicies().add(policy);
store.getCacheStore().put("coretechtrust", domain);
Principal principal1 = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user1;s=signature", 0, null);
assertTrue(authorizer.access("update", "coretechtrust:table1", principal1, null));
assertFalse(authorizer.access("update", "coretechtrust:table2", principal1, null));
assertFalse(authorizer.access("delete", "coretechtrust:table1", principal1, null));
Principal principal2 = SimplePrincipal.create("user_domain", "user2", "v=U1;d=user_domain;n=user2;s=signature", 0, null);
assertFalse(authorizer.access("update", "coretechtrust:table1", principal2, null));
Principal principal3 = SimplePrincipal.create("user_domain", "user3", "v=U1;d=user_domain;n=user3;s=signature", 0, null);
assertFalse(authorizer.access("update", "coretechtrust:table1", principal3, null));
store.getCacheStore().invalidate("coretechtrust");
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class ZTSImplTest method signedAuthorizedProviderDomain.
private SignedDomain signedAuthorizedProviderDomain() {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
Role role = new Role();
role.setName(generateRoleName("sys.auth", "providers"));
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("athenz.provider"));
role.setRoleMembers(members);
roles.add(role);
List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy();
com.yahoo.athenz.zms.Assertion assertion1 = new com.yahoo.athenz.zms.Assertion();
assertion1.setResource("sys.auth:instance");
assertion1.setAction("launch");
assertion1.setRole("sys.auth:role.providers");
com.yahoo.athenz.zms.Assertion assertion2 = new com.yahoo.athenz.zms.Assertion();
assertion2.setResource("sys.auth:dns.ostk.athenz.cloud");
assertion2.setAction("launch");
assertion2.setRole("sys.auth:role.providers");
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion1);
assertions.add(assertion2);
policy.setAssertions(assertions);
policy.setName("sys.auth:policy.providers");
policies.add(policy);
com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
domainPolicies.setDomain("sys.auth");
domainPolicies.setPolicies(policies);
com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies();
signedPolicies.setContents(domainPolicies);
signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), privateKey));
signedPolicies.setKeyId("0");
DomainData domain = new DomainData();
domain.setName("sys.auth");
domain.setRoles(roles);
domain.setPolicies(signedPolicies);
domain.setModified(Timestamp.fromCurrentTime());
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
signedDomain.setKeyId("0");
return signedDomain;
}
Aggregations