use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testProcessTrustedDomainRoleValidWildCard.
@Test
public void testProcessTrustedDomainRoleValidWildCard() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = createDataCacheWildCard("coretech");
// first we're going tor process user1
// which should match all three roles including
// both wildcard roles
Set<String> accessibleRoles = new HashSet<>();
String prefix = "coretech" + ROLE_POSTFIX;
String identity = "user_domain.user1";
Set<String> trustedResources = new HashSet<>();
trustedResources.add("coretech:role.admin");
trustedResources.add("coretech:role.readers");
trustedResources.add("coretech:role.editors");
store.processTrustedDomain(dataCache, identity, prefix, null, trustedResources, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 3);
assertTrue(accessibleRoles.contains("admin"));
assertTrue(accessibleRoles.contains("editors"));
assertTrue(accessibleRoles.contains("readers"));
// user_domain.joe should match readers and editors
accessibleRoles.clear();
identity = "user_domain.joe";
store.processTrustedDomain(dataCache, identity, prefix, null, trustedResources, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 2);
assertTrue(accessibleRoles.contains("readers"));
assertTrue(accessibleRoles.contains("editors"));
// random service should only match editors
accessibleRoles.clear();
identity = "athenz.service";
store.processTrustedDomain(dataCache, identity, prefix, null, trustedResources, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 1);
assertTrue(accessibleRoles.contains("editors"));
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testStoreInitNoLocalDomains.
@Test
public void testStoreInitNoLocalDomains() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
((MockZMSFileChangeLogStore) store.changeLogStore).setTagHeader("2014-01-01T12:00:00");
((MockZMSFileChangeLogStore) store.changeLogStore).setLastModificationTimestamp(null);
List<SignedDomain> domains = new ArrayList<>();
/* we're going to create a new domain */
SignedDomain signedDomain = createSignedDomain("coretech", "weather");
domains.add(signedDomain);
/* we're going to update the coretech domain and set new roles */
signedDomain = createSignedDomain("sports", "weather");
domains.add(signedDomain);
SignedDomains signedDomains = new SignedDomains();
signedDomains.setDomains(domains);
((MockZMSFileChangeLogStore) store.changeLogStore).setSignedDomains(signedDomains);
boolean result = store.init();
assertTrue(result);
Set<String> accessibleRoles = new HashSet<>();
DataCache data = store.getDataCache("coretech");
store.getAccessibleRoles(data, "coretech", "user_domain.user", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 2);
assertTrue(accessibleRoles.contains("admin"));
assertTrue(accessibleRoles.contains("writers"));
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.cache.DataCache 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.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testProcessTrustedDomainRoleInvalid.
@Test
public void testProcessTrustedDomainRoleInvalid() {
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 = "coretech2" + ROLE_POSTFIX;
/* invalid prefix to cause no match */
String identity = "user_domain.user1";
String[] requestedRoleList = { "coretech:role.readers" };
Set<String> trustedResources = new HashSet<>();
trustedResources.add("coretech:role.admin");
trustedResources.add("coretech:role.readers");
store.processTrustedDomain(dataCache, identity, prefix, requestedRoleList, trustedResources, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 0);
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testGetAccessibleRolesInvalidDomain.
@Test
public void testGetAccessibleRolesInvalidDomain() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
SignedDomain signedDomain = createSignedDomain("coretech", "weather");
store.processDomain(signedDomain, true);
Set<String> accessibleRoles = new HashSet<>();
DataCache data = store.getDataCache("sports");
store.getAccessibleRoles(data, "sports", "user_domain.user", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 0);
}
Aggregations