use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testValidateSignedDomainInvalidSignature.
@Test
public void testValidateSignedDomainInvalidSignature() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
store.loadZMSPublicKeys();
SignedDomain signedDomain = new SignedDomain();
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);
DomainData domain = new DomainData();
domain.setRoles(roles);
signedDomain.setDomain(domain);
signedDomain.setSignature("InvalidSignature");
signedDomain.setKeyId("0");
assertFalse(store.validateSignedDomain(signedDomain));
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testDeleteDomainFromCacheServices.
@Test
public void testDeleteDomainFromCacheServices() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
SignedDomain signedDomain = new SignedDomain();
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);
DomainData domainData = new DomainData();
domainData.setName("coretech");
domainData.setRoles(roles);
signedDomain.setDomain(domainData);
signedDomain.setKeyId("0");
((MockZMSFileChangeLogStore) store.changeLogStore).put("coretech", JSON.bytes(signedDomain));
DataCache dataCache = new DataCache();
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
store.deleteDomainFromCache("coretech");
store.changeLogStore.removeLocalDomain("coretech");
assertNull(store.getCacheStore().getIfPresent("coretech"));
File file = new File("/tmp/zts_server_unit_tests/zts_root/coretech");
assertFalse(file.exists());
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testProcessSignedDomainsAllInvalidDomain.
@Test
public void testProcessSignedDomainsAllInvalidDomain() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
List<SignedDomain> list = new ArrayList<>();
// if we have only failures, then our result
// is going to be failure
SignedDomain signedDomain = createSignedDomain("sports", "weather");
signedDomain.setSignature("Invalid0");
list.add(signedDomain);
SignedDomains signedDomains = new SignedDomains();
signedDomains.setDomains(list);
boolean result = store.processSignedDomains(signedDomains);
assertFalse(result);
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testResetLastModificationTime.
@Test
public void testResetLastModificationTime() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
store.changeLogStore.setLastModificationTimestamp("34567");
store.changeLogStore.setLastModificationTimestamp(null);
assertNull(((MockZMSFileChangeLogStore) store.changeLogStore).lastModTime);
File f = new File("/tmp/zts_server_unit_tests/zts_root/.lastModTime");
assertFalse(f.exists());
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testGetHostServicesHostUpdated.
@Test
public void testGetHostServicesHostUpdated() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
List<String> services = new ArrayList<>();
services.add("coretech.storage");
services.add("sports.storage");
store.hostCache.put("host1", services);
services = new ArrayList<>();
services.add("coretech.storage");
services.add("sports.storage");
store.hostCache.put("host2", services);
Map<String, Set<String>> hostMap = new HashMap<>();
Set<String> newServices = new HashSet<>();
newServices.add("coretech.backup");
hostMap.put("host3", newServices);
newServices = new HashSet<>();
newServices.add("sports.backup");
hostMap.put("host1", newServices);
store.addHostEntries(hostMap);
Map<String, Set<String>> remMap = new HashMap<>();
Set<String> remServices = new HashSet<>();
remServices.add("sports.storage");
remMap.put("host1", remServices);
store.removeHostEntries(remMap);
HostServices hostServices = store.getHostServices("host1");
List<String> hosts = hostServices.getNames();
assertEquals(hosts.size(), 2);
assertTrue(hosts.contains("coretech.storage"));
assertTrue(hosts.contains("sports.backup"));
hostServices = store.getHostServices("host2");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 2);
assertTrue(hosts.contains("coretech.storage"));
assertTrue(hosts.contains("sports.storage"));
hostServices = store.getHostServices("host3");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 1);
assertTrue(hosts.contains("coretech.backup"));
}
Aggregations