use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class ZTSImplTest method testGetPolicyList.
@Test
public void testGetPolicyList() {
List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy();
com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource("coretech:tenant.weather.*");
assertion.setAction("read");
assertion.setRole("coretech:role.readers");
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName("coretech:policy.reader");
policies.add(policy);
policy = new com.yahoo.athenz.zms.Policy();
assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource("coretech:tenant.weather.*");
assertion.setAction("write");
assertion.setRole("coretech:role.writers");
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName("coretech:policy.writer");
policies.add(policy);
com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
domainPolicies.setDomain("coretech");
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("coretech");
domain.setPolicies(signedPolicies);
domain.setModified(Timestamp.fromCurrentTime());
List<com.yahoo.athenz.zts.Policy> policyList = zts.getPolicyList(domain);
assertEquals(policyList.size(), 2);
assertEquals(policyList.get(0).getName(), "coretech:policy.reader");
assertEquals(policyList.get(1).getName(), "coretech:policy.writer");
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class InstanceProviderManagerTest method createSignedDomain.
private SignedDomain createSignedDomain(String domainName, String serviceName, boolean includeService, boolean includeEndPoint, String endPoint) {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
Role role = new Role();
role.setName(domainName + ":role.admin");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.adminuser"));
role.setRoleMembers(members);
roles.add(role);
List<ServiceIdentity> services = new ArrayList<>();
ServiceIdentity service = new ServiceIdentity();
service.setName(domainName + "." + serviceName);
if (includeEndPoint) {
service.setProviderEndpoint(endPoint);
}
services.add(service);
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 assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource(domainName + ":instance");
assertion.setAction("read");
assertion.setRole(domainName + ":role.admin");
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(domainName + ":policy.test");
policies.add(policy);
com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
domainPolicies.setDomain(domainName);
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(domainName);
domain.setRoles(roles);
if (includeService) {
domain.setServices(services);
}
domain.setPolicies(signedPolicies);
domain.setModified(Timestamp.fromCurrentTime());
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheRemovedHosts.
@Test
public void testAddDomainToCacheRemovedHosts() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = new DataCache();
ServiceIdentity service = new ServiceIdentity();
service.setName("coretech.storage");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
hosts.add("host2");
hosts.add("host3");
service.setHosts(hosts);
List<ServiceIdentity> services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
DomainData domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
/* removed hosts */
dataCache = new DataCache();
service = new ServiceIdentity();
service.setName("coretech.storage");
hosts = new ArrayList<>();
hosts.add("host1");
service.setHosts(hosts);
services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
HostServices hostServices = store.getHostServices("host1");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 1);
assertTrue(hosts.contains("coretech.storage"));
hostServices = store.getHostServices("host2");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 0);
hostServices = store.getHostServices("host3");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 0);
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testProcessDomainRolesNullRoles.
@Test
public void testProcessDomainRolesNullRoles() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DomainData domainData = new DomainData();
domainData.setName("coretech");
DataCache dataCache = new DataCache();
dataCache.setDomainData(domainData);
store.processDomainRoles(domainData, dataCache);
assertEquals(dataCache.getMemberCount(), 0);
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testProcessDomainRoles.
@Test
public void testProcessDomainRoles() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
List<Role> roles = new ArrayList<>();
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);
roles.add(role);
role = new Role();
role.setName("coretech:role.readers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user"));
role.setRoleMembers(members);
roles.add(role);
DomainData domainData = new DomainData();
domainData.setName("coretech");
domainData.setRoles(roles);
DataCache dataCache = new DataCache();
dataCache.setDomainData(domainData);
store.processDomainRoles(domainData, dataCache);
assertEquals(dataCache.getMemberRoleSet("user_domain.user").size(), 2);
assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.admin", 0)));
assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.readers", 0)));
}
Aggregations