use of com.yahoo.athenz.common.server.store.ChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testRemovePublicKeys.
@Test
public void testRemovePublicKeys() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null, ztsMetric);
store.publicKeyCache.put("coretech.storage_0", "PublicKey0");
store.publicKeyCache.put("sports.storage_0", "PublicKey0");
store.publicKeyCache.put("sports.storage_1", "PublicKey1");
Map<String, String> remKeys = new HashMap<>();
remKeys.put("sports.storage_0", "PublicKey0");
store.removePublicKeys(remKeys);
assertEquals(store.publicKeyCache.size(), 2);
assertTrue(store.publicKeyCache.containsKey("coretech.storage_0"));
assertTrue(store.publicKeyCache.containsKey("sports.storage_1"));
}
use of com.yahoo.athenz.common.server.store.ChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheUpdatedDomain.
@Test
public void testAddDomainToCacheUpdatedDomain() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null, ztsMetric);
DataCache dataCache = new DataCache();
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);
List<Role> roles = new ArrayList<>();
roles.add(role);
DomainData domainData = new DomainData();
domainData.setRoles(roles);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
/* update member list */
role = new Role();
role.setName("coretech:role.admin");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user1"));
members.add(new RoleMember().setMemberName("user_domain.user2"));
role.setRoleMembers(members);
roles = new ArrayList<>();
roles.add(role);
dataCache = new DataCache();
domainData = new DomainData();
domainData.setRoles(roles);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
DomainData domain = store.getDomainData("coretech");
assertNotNull(domain);
assertEquals(domain.getRoles().size(), 1);
assertEquals(domain.getRoles().get(0).getName(), "coretech:role.admin");
assertEquals(domain.getRoles().get(0).getRoleMembers().size(), 2);
boolean user1 = false;
boolean user2 = false;
for (RoleMember member : domain.getRoles().get(0).getRoleMembers()) {
switch(member.getMemberName()) {
case "user_domain.user1":
user1 = true;
break;
case "user_domain.user2":
user2 = true;
break;
}
}
assertTrue(user1);
assertTrue(user2);
}
use of com.yahoo.athenz.common.server.store.ChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testProcessSingleTrustedDomainRoleAddRoleFalse.
@Test
public void testProcessSingleTrustedDomainRoleAddRoleFalse() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null, ztsMetric);
Set<String> accessibleRoles = new HashSet<>();
String prefix = "coretech2" + ROLE_POSTFIX;
String role = "coretech:role.readers";
/* invalid role causing no match */
Set<MemberRole> memberRoles = new HashSet<>();
memberRoles.add(new MemberRole("coretech:role.admin", 0));
memberRoles.add(new MemberRole("coretech:role.readers", 0));
store.processSingleTrustedDomainRole(role, prefix, null, memberRoles, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 0);
}
use of com.yahoo.athenz.common.server.store.ChangeLogStore in project athenz by yahoo.
the class DataStoreTest method testProcessDomainCheck.
@Test
public void testProcessDomainCheck() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null, ztsMetric);
DomainData domainData = new DomainData();
assertTrue(store.processDomainCheck(null, domainData));
domainData.setEnabled(Boolean.TRUE);
assertTrue(store.processDomainCheck(null, domainData));
domainData.setEnabled(false);
assertFalse(store.processDomainCheck(null, domainData));
DomainData localData = new DomainData();
assertTrue(store.processDomainCheck(localData, domainData));
domainData.setEnabled(true);
localData.setModified(Timestamp.fromMillis(100));
domainData.setModified(Timestamp.fromMillis(200));
assertTrue(store.processDomainCheck(localData, domainData));
localData.setModified(Timestamp.fromMillis(201));
assertFalse(store.processDomainCheck(localData, domainData));
}
use of com.yahoo.athenz.common.server.store.ChangeLogStore 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, ztsMetric);
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"));
}
Aggregations