use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method createDataCacheWildCard.
private DataCache createDataCacheWildCard(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.user*"));
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.joe"));
role.setRoleMembers(members);
roles.add(role);
dataCache.processRole(role);
role = new Role();
role.setName(domainName + ":role.editors");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("*"));
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.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheSameHosts.
@Test
public void testAddDomainToCacheSameHosts() {
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<>();
services.add(service);
dataCache.processServiceIdentity(service);
DomainData domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
/* same hosts - no changes */
dataCache = new DataCache();
service = new ServiceIdentity();
service.setName("coretech.storage");
hosts = new ArrayList<>();
hosts.add("host1");
service.setHosts(hosts);
services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(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"));
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testGetAccessibleRoles.
@Test
public void testGetAccessibleRoles() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
store.loadZMSPublicKeys();
SignedDomain signedDomain = createSignedDomain("coretech", "weather");
store.processDomain(signedDomain, true);
Set<String> accessibleRoles = new HashSet<>();
DataCache data = store.getDataCache("coretech");
store.getAccessibleRoles(data, "coretech", "user_domain.user1", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 1);
assertTrue(accessibleRoles.contains("writers"));
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testProcessTrustedDomainResourcesNull.
@Test
public void testProcessTrustedDomainResourcesNull() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = createDataCache("coretech");
Set<String> accessibleRoles = new HashSet<>();
String prefix = "coretech" + ROLE_POSTFIX;
String identity = "user_domain.user1";
String[] requestedRoleList = { "coretech:role.admin" };
store.processTrustedDomain(dataCache, identity, prefix, requestedRoleList, null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 0);
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testDeleteDomain.
@Test
public void testDeleteDomain() {
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());
}
Aggregations