use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetUpdatedSignedDomainsWithChange.
@Test
public void testGetUpdatedSignedDomainsWithChange() throws FileNotFoundException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore(null);
ArrayList<S3ObjectSummary> objectList = new ArrayList<>();
S3ObjectSummary objectSummary = new S3ObjectSummary();
objectSummary.setKey("iaas");
objectSummary.setLastModified(new Date(100));
objectList.add(objectSummary);
objectSummary = new S3ObjectSummary();
objectSummary.setKey("iaas.athenz");
objectSummary.setLastModified(new Date(200));
objectList.add(objectSummary);
ObjectListing objectListing = mock(ObjectListing.class);
when(objectListing.getObjectSummaries()).thenReturn(objectList);
when(objectListing.isTruncated()).thenReturn(false);
when(store.awsS3Client.listObjects(any(ListObjectsRequest.class))).thenReturn(objectListing);
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);
when(store.awsS3Client.getObject("athenz-domain-sys.auth", "iaas.athenz")).thenReturn(object);
// set the last modification time to return one of the domains
store.lastModTime = (new Date(150)).getTime();
StringBuilder lastModTimeBuffer = new StringBuilder(512);
SignedDomains signedDomains = store.getUpdatedSignedDomains(lastModTimeBuffer);
assertTrue(lastModTimeBuffer.length() > 0);
List<SignedDomain> domainList = signedDomains.getDomains();
assertEquals(domainList.size(), 1);
DomainData domainData = domainList.get(0).getDomain();
assertNotNull(domainData);
assertEquals(domainData.getName(), "iaas");
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method createTenantSignedDomain.
private SignedDomain createTenantSignedDomain(String domainName, String providerDomain) {
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.user"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(domainName + ":role.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);
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(providerDomain + ":role.tenant.readers");
assertion.setAction("assume_role");
assertion.setRole(domainName + ":role.readers");
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(domainName + ":policy.tenancy.readers");
policies.add(policy);
ServiceIdentity service = new ServiceIdentity();
service.setName(domainName + ".storage");
setServicePublicKey(service, "0", "abcdefgh");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
service.setHosts(hosts);
List<ServiceIdentity> services = new ArrayList<>();
services.add(service);
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), pkey));
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), pkey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheUpdatedPublicKeysVersions.
@Test
public void testAddDomainToCacheUpdatedPublicKeysVersions() {
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");
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
com.yahoo.athenz.zms.PublicKeyEntry publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT1);
publicKey.setId("1");
List<com.yahoo.athenz.zms.PublicKeyEntry> publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
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);
/* update multiple version public keys */
dataCache = new DataCache();
service = new ServiceIdentity();
service.setName("coretech.storage");
publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT0);
publicKey.setId("0");
publicKeys.add(publicKey);
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT3);
publicKey.setId("1");
publicKeys.add(publicKey);
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT2);
publicKey.setId("2");
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
assertEquals(store.getPublicKey("coretech", "storage", "0"), ZTS_PEM_CERT0);
assertEquals(store.getPublicKey("coretech", "storage", "1"), ZTS_PEM_CERT3);
assertEquals(store.getPublicKey("coretech", "storage", "2"), ZTS_PEM_CERT2);
assertNull(store.getPublicKey("coretech", "storage", "3"));
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method createSignedDomainWildCardMembers.
private SignedDomain createSignedDomainWildCardMembers(String domainName, String tenantDomain) {
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.user"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(domainName + ":role.writers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user*"));
members.add(new RoleMember().setMemberName("user_domain.user1"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(domainName + ":role.readers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user3"));
members.add(new RoleMember().setMemberName("user_domain.user4"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(domainName + ":role.all");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("*"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(domainName + ":role.tenant.readers");
role.setTrust(tenantDomain);
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 assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource(domainName + ":tenant.weather.*");
assertion.setAction("read");
assertion.setRole(domainName + ":role.tenant.readers");
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(domainName + ":policy.tenant.reader");
policies.add(policy);
ServiceIdentity service = new ServiceIdentity();
service.setName(domainName + ".storage");
setServicePublicKey(service, "0", "abcdefgh");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
service.setHosts(hosts);
List<ServiceIdentity> services = new ArrayList<>();
services.add(service);
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), pkey));
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), pkey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testProcessDomainServiceIdentities.
@Test
public void testProcessDomainServiceIdentities() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
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);
DomainData domainData = new DomainData();
domainData.setName("coretech");
domainData.setServices(services);
DataCache dataCache = new DataCache();
dataCache.setDomainData(domainData);
store.processDomainServiceIdentities(domainData, dataCache);
store.addDomainToCache(domainData.getName(), dataCache);
HostServices hostServices = store.getHostServices("host1");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 1);
assertTrue(hosts.contains("coretech.storage"));
}
Aggregations