use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testProcessDomainRoles.
@Test
public void testProcessDomainRoles() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
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);
DomainData domainData = new DomainData();
domainData.setName("coretech");
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.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testStoreInitLocalDomainUpdated.
@Test
public void testStoreInitLocalDomainUpdated() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore setupStore = new DataStore(clogStore, null);
setupStore.loadZMSPublicKeys();
SignedDomain signedDomain = createSignedDomain("coretech", "weather");
setupStore.processDomain(signedDomain, true);
/* create a new store instance */
DataStore store = new DataStore(clogStore, null);
((MockZMSFileChangeLogStore) store.changeLogStore).setTagHeader("2014-01-01T12:00:00");
List<SignedDomain> domains = new ArrayList<>();
/* we're going to create a new domain */
signedDomain = createSignedDomain("sports", "weather");
domains.add(signedDomain);
/* we're going to update the coretech domain and set new roles */
signedDomain = createSignedDomain("coretech", "weather");
Role role = new Role();
role.setName("coretech:role.admin");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user8"));
role.setRoleMembers(members);
List<Role> roles = new ArrayList<>();
roles.add(role);
signedDomain.getDomain().setRoles(roles);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(signedDomain.getDomain()), pkey));
domains.add(signedDomain);
SignedDomains signedDomains = new SignedDomains();
signedDomains.setDomains(domains);
((MockZMSFileChangeLogStore) store.changeLogStore).setSignedDomains(signedDomains);
List<String> domainNames = new ArrayList<>();
domainNames.add("coretech");
domainNames.add("sports");
((MockZMSFileChangeLogStore) store.changeLogStore).setDomainList(domainNames);
boolean result = store.init();
assertTrue(result);
Set<String> accessibleRoles = new HashSet<>();
DataCache data = store.getDataCache("coretech");
store.getAccessibleRoles(data, "coretech", "user_domain.user1", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 0);
accessibleRoles = new HashSet<>();
store.getAccessibleRoles(data, "coretech", "user_domain.user8", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 1);
assertTrue(accessibleRoles.contains("admin"));
accessibleRoles = new HashSet<>();
data = store.getDataCache("sports");
store.getAccessibleRoles(data, "sports", "user_domain.user", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 2);
assertTrue(accessibleRoles.contains("admin"));
assertTrue(accessibleRoles.contains("writers"));
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testAddHostEntriesNotPresent.
@Test
public void testAddHostEntriesNotPresent() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
Map<String, Set<String>> hostMap = new HashMap<>();
Set<String> services = new HashSet<>();
services.add("coretech.storage");
services.add("coretech.backup");
hostMap.put("host1", services);
services = new HashSet<>();
services.add("coretech.storage");
services.add("coretech.backup");
hostMap.put("host2", services);
store.addHostEntries(hostMap);
assertEquals(store.hostCache.size(), 2);
List<String> retServices = store.hostCache.get("host1");
assertEquals(retServices.size(), 2);
assertTrue(retServices.contains("coretech.storage"));
assertTrue(retServices.contains("coretech.backup"));
retServices = store.hostCache.get("host2");
assertEquals(retServices.size(), 2);
assertTrue(retServices.contains("coretech.storage"));
assertTrue(retServices.contains("coretech.backup"));
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testProcessLocalDomainsDeletedDomain.
@Test
public void testProcessLocalDomainsDeletedDomain() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore setupStore = new DataStore(clogStore, null);
setupStore.loadZMSPublicKeys();
SignedDomain signedDomain = createSignedDomain("coretech", "weather");
setupStore.processDomain(signedDomain, true);
signedDomain = createSignedDomain("sports", "weather");
setupStore.processDomain(signedDomain, true);
DataStore store = new DataStore(clogStore, null);
List<String> zmsList = new ArrayList<>();
zmsList.add("coretech");
((MockZMSFileChangeLogStore) store.changeLogStore).setDomainList(zmsList);
List<String> list = new ArrayList<>();
list.add("coretech");
list.add("sports");
boolean result = store.processLocalDomains(list);
assertTrue(result);
assertNotNull(store.getDomainData("coretech"));
assertNull(store.getDomainData("sports"));
File file = new File("/tmp/zts_server_unit_tests/zts_root/sports");
assertFalse(file.exists());
}
use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testGetDomainListFromZMS.
@Test
public void testGetDomainListFromZMS() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
List<String> list = new ArrayList<>();
list.add("Test1");
((MockZMSFileChangeLogStore) store.changeLogStore).setDomainList(list);
Set<String> zmsDomainList = store.changeLogStore.getServerDomainList();
assertEquals(zmsDomainList.size(), 1);
assertTrue(zmsDomainList.contains("Test1"));
}
Aggregations