use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetSignedDomainInternal.
@Test
public void testGetSignedDomainInternal() throws IOException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore(null);
InputStream is = new FileInputStream("src/test/resources/iaas.json");
MockS3ObjectInputStream s3Is = new MockS3ObjectInputStream(is, null);
S3Object object = mock(S3Object.class);
when(object.getObjectContent()).thenReturn(s3Is);
when(store.awsS3Client.getObject("athenz-domain-sys.auth", "iaas")).thenReturn(object);
SignedDomain signedDomain = store.getSignedDomain(store.awsS3Client, "iaas");
assertNotNull(signedDomain);
DomainData domainData = signedDomain.getDomain();
assertNotNull(domainData);
assertEquals(domainData.getName(), "iaas");
is.close();
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testProcessDomainPolicies.
@Test
public void testProcessDomainPolicies() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
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("sports:role.readers");
assertion.setAction("assume_role");
assertion.setRole("coretech:role.readers");
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policies.add(policy);
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);
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), pkey));
signedPolicies.setKeyId("0");
DomainData domainData = new DomainData();
domainData.setName("coretech");
domainData.setPolicies(signedPolicies);
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)));
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testDeleteDomainFromCacheHosts.
@Test
public void testDeleteDomainFromCacheHosts() {
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");
service.setHosts(hosts);
List<ServiceIdentity> services = new ArrayList<>();
dataCache.processServiceIdentity(service);
services.add(service);
DomainData domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
store.deleteDomainFromCache("coretech");
HostServices hostServices = store.getHostServices("host1");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 0);
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method createDataCacheWildCard.
private DataCache createDataCacheWildCard(String domainName) {
DataCache dataCache = new DataCache();
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.user*"));
role.setRoleMembers(members);
roles.add(role);
dataCache.processRole(role);
role = new Role();
role.setName(domainName + ":role.readers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user1"));
members.add(new RoleMember().setMemberName("user_domain.joe"));
role.setRoleMembers(members);
roles.add(role);
dataCache.processRole(role);
role = new Role();
role.setName(domainName + ":role.editors");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("*"));
role.setRoleMembers(members);
roles.add(role);
dataCache.processRole(role);
role = new Role();
role.setName(domainName + ":role.writers");
role.setTrust(domainName + "Trust");
roles.add(role);
dataCache.processRole(role);
DomainData domainData = new DomainData();
domainData.setName(domainName);
domainData.setRoles(roles);
dataCache.setDomainData(domainData);
return dataCache;
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheSameHosts.
@Test
public void testAddDomainToCacheSameHosts() {
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");
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);
/* same hosts - no changes */
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"));
}
Aggregations