use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class DataCacheTest method testMultipleHostsSkipDuplicate.
@Test
public void testMultipleHostsSkipDuplicate() {
Domain domain = new Domain();
domain.setName("testDomain");
ServiceIdentity service = new ServiceIdentity();
service.setName("testDomain.storage");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
hosts.add("host2");
hosts.add("host1");
service.setHosts(hosts);
DataCache cache = new DataCache();
cache.processServiceIdentity(service);
Map<String, Set<String>> hostMap = cache.getHostMap();
assertEquals(hostMap.size(), 2);
assertTrue(hostMap.containsKey("host1"));
Set<String> set = hostMap.get("host1");
assertEquals(set.size(), 1);
assertTrue(set.contains("testDomain.storage"));
assertTrue(hostMap.containsKey("host2"));
set = hostMap.get("host2");
assertEquals(set.size(), 1);
assertTrue(set.contains("testDomain.storage"));
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class DataCacheTest method testMultipleHostsSingleService.
@Test
public void testMultipleHostsSingleService() {
Domain domain = new Domain();
domain.setName("testDomain");
ServiceIdentity service = new ServiceIdentity();
service.setName("testDomain.storage");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
hosts.add("host2");
service.setHosts(hosts);
DataCache cache = new DataCache();
cache.processServiceIdentity(service);
Map<String, Set<String>> hostMap = cache.getHostMap();
assertEquals(hostMap.size(), 2);
assertTrue(hostMap.containsKey("host1"));
Set<String> set = hostMap.get("host1");
assertEquals(set.size(), 1);
assertTrue(set.contains("testDomain.storage"));
assertTrue(hostMap.containsKey("host2"));
set = hostMap.get("host2");
assertEquals(set.size(), 1);
assertTrue(set.contains("testDomain.storage"));
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class ZTSImplTest method createTenantSignedDomain.
private SignedDomain createTenantSignedDomain(String domainName, String providerDomain, String providerService) {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
Role role = new Role();
role.setName(generateRoleName(domainName, "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(generateRoleName(domainName, "tenancy." + providerDomain + "." + providerService + ".admin"));
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user100"));
members.add(new RoleMember().setMemberName("user_domain.user101"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, "readers"));
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user100"));
members.add(new RoleMember().setMemberName("user_domain.user101"));
role.setRoleMembers(members);
roles.add(role);
ServiceIdentity service = new ServiceIdentity();
service.setName(domainName + ".storage");
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
List<String> hosts = new ArrayList<>();
hosts.add("host1");
hosts.add("host2");
service.setHosts(hosts);
List<ServiceIdentity> services = new ArrayList<>();
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(generateRoleName(providerDomain, "tenant.readers"));
assertion.setAction("assume_role");
assertion.setRole(generateRoleName(domainName, "readers"));
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(generatePolicyName(domainName, "tenancy.readers"));
policies.add(policy);
policy = new com.yahoo.athenz.zms.Policy();
assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource(generateRoleName(providerDomain, providerService + ".tenant." + domainName + ".admin"));
assertion.setAction("assume_role");
assertion.setRole(generateRoleName(domainName, "tenancy." + providerDomain + "." + providerService + ".admin"));
assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(generatePolicyName(domainName, "tenancy." + providerDomain + "." + providerService + ".admin"));
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);
domain.setServices(services);
domain.setPolicies(signedPolicies);
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.ServiceIdentity 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.ServiceIdentity in project athenz by yahoo.
the class FileConnectionTest method testUpdateServiceIdentity.
@Test
public void testUpdateServiceIdentity() {
File fileDir = new File("/home/athenz/zms_store");
File quotaDir = new File("/home/athenz/zms_quota");
try (FileConnection fileconnection = new FileConnection(fileDir, quotaDir)) {
ServiceIdentity service1 = new ServiceIdentity();
try {
fileconnection.updateServiceIdentity("Domain1", service1);
} catch (Exception ex) {
assertTrue(true);
}
}
}
Aggregations