use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheSamePublicKeys.
@Test
public void testAddDomainToCacheSamePublicKeys() {
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);
/* same public keys - no changes */
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_CERT1);
publicKey.setId("1");
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_CERT1);
assertNull(store.getPublicKey("coretech", "storage", "2"));
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method createDataCache.
private DataCache createDataCache(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.user1"));
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.user2"));
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 testDeleteDomainFromCachePublicKeys.
@Test
public void testDeleteDomainFromCachePublicKeys() {
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);
store.deleteDomainFromCache("coretech");
assertNull(store.getPublicKey("coretech", "storage", "0"));
assertNull(store.getPublicKey("coretech", "storage", "1"));
assertNull(store.getPublicKey("coretech", "storage", "2"));
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheAddedHosts.
@Test
public void testAddDomainToCacheAddedHosts() {
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);
/* added hosts */
dataCache = new DataCache();
service = new ServiceIdentity();
service.setName("coretech.storage");
hosts = new ArrayList<>();
hosts.add("host1");
hosts.add("host2");
service.setHosts(hosts);
services = new ArrayList<>();
dataCache.processServiceIdentity(service);
services.add(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(), 1);
assertTrue(hosts.contains("coretech.storage"));
}
use of com.yahoo.athenz.zms.DomainData in project athenz by yahoo.
the class ZMSFileChangeLogStoreTest method getSignedDomainListOneBadDomain.
@Test
public void getSignedDomainListOneBadDomain() {
ZMSFileChangeLogStore fstore = new ZMSFileChangeLogStore(FSTORE_PATH, null, null);
ZMSClient zmsClient = Mockito.mock(ZMSClient.class);
DomainData domData1 = new DomainData().setName("athenz");
SignedDomain domain1 = new SignedDomain().setDomain(domData1);
DomainData domData2 = new DomainData().setName("sports");
SignedDomain domain2 = new SignedDomain().setDomain(domData2);
List<SignedDomain> domains = new ArrayList<>();
domains.add(domain1);
domains.add(domain2);
SignedDomains domainList = new SignedDomains().setDomains(domains);
List<SignedDomain> mockDomains = new ArrayList<>();
mockDomains.add(domain1);
SignedDomains mockDomainList = new SignedDomains().setDomains(mockDomains);
Mockito.when(zmsClient.getSignedDomains("athenz", null, null, null)).thenReturn(mockDomainList);
Mockito.when(zmsClient.getSignedDomains("sports", null, null, null)).thenReturn(null);
List<SignedDomain> returnList = fstore.getSignedDomainList(zmsClient, domainList);
assertEquals(returnList.size(), 1);
assertEquals(returnList.get(0).getDomain().getName(), "athenz");
}
Aggregations