use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheRemovedPublicKeysVersions.
@Test
public void testAddDomainToCacheRemovedPublicKeysVersions() {
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");
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
List<com.yahoo.athenz.zms.PublicKeyEntry> publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
com.yahoo.athenz.zms.PublicKeyEntry publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT1);
publicKey.setId("1");
publicKeys.add(publicKey);
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT2);
publicKey.setId("2");
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
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);
/* update multiple version public keys */
dataCache = new DataCache();
service = new ServiceIdentity();
service.setName("coretech.storage");
publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT0);
publicKey.setId("0");
publicKeys.add(publicKey);
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT2);
publicKey.setId("2");
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
assertEquals(store.getPublicKey("coretech", "storage", "0"), ZTS_PEM_CERT0);
assertNull(store.getPublicKey("coretech", "storage", "1"));
assertEquals(store.getPublicKey("coretech", "storage", "2"), ZTS_PEM_CERT2);
assertNull(store.getPublicKey("coretech", "storage", "3"));
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheNewDomain.
@Test
public void testAddDomainToCacheNewDomain() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
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);
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(), 1);
assertEquals(domain.getRoles().get(0).getRoleMembers().get(0).getMemberName(), "user_domain.user");
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataStoreTest method testProcessDomainServiceIdentitiesNullPolicies.
@Test
public void testProcessDomainServiceIdentitiesNullPolicies() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = new DataCache();
DomainData domainData = new DomainData();
domainData.setName("coretech");
dataCache.setDomainData(domainData);
store.processDomainServiceIdentities(domainData, dataCache);
HostServices hostServices = store.getHostServices("host1");
List<String> hosts = hostServices.getNames();
assertNull(hosts);
}
use of com.yahoo.athenz.zts.cache.DataCache 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);
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.zts.cache.DataCache in project athenz by yahoo.
the class ZTSImplTest method testAccess.
@Test
public void testAccess() {
DataCache domain = new DataCache();
DomainData domainData = new DomainData();
domainData.setName("coretechtrust");
domain.setDomainData(domainData);
domainData.setRoles(new ArrayList<Role>());
Role role1 = createRoleObject("coretechtrust", "role1", null, "user_domain.user1", null);
Role role2 = createRoleObject("coretechtrust", "role2", null, "user_domain.user2", null);
domainData.getRoles().add(role1);
domainData.getRoles().add(role2);
Policy policy = createPolicyObject("coretechtrust", "access", "coretechtrust:role.role1", false, "update", "coretechtrust:table1", AssertionEffect.ALLOW);
domainData.setPolicies(new com.yahoo.athenz.zms.SignedPolicies());
domainData.getPolicies().setContents(new com.yahoo.athenz.zms.DomainPolicies());
domainData.getPolicies().getContents().setPolicies(new ArrayList<Policy>());
domainData.getPolicies().getContents().getPolicies().add(policy);
store.getCacheStore().put("coretechtrust", domain);
Principal principal1 = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user1;s=signature", 0, null);
assertTrue(authorizer.access("update", "coretechtrust:table1", principal1, null));
assertFalse(authorizer.access("update", "coretechtrust:table2", principal1, null));
assertFalse(authorizer.access("delete", "coretechtrust:table1", principal1, null));
Principal principal2 = SimplePrincipal.create("user_domain", "user2", "v=U1;d=user_domain;n=user2;s=signature", 0, null);
assertFalse(authorizer.access("update", "coretechtrust:table1", principal2, null));
Principal principal3 = SimplePrincipal.create("user_domain", "user3", "v=U1;d=user_domain;n=user3;s=signature", 0, null);
assertFalse(authorizer.access("update", "coretechtrust:table1", principal3, null));
store.getCacheStore().invalidate("coretechtrust");
}
Aggregations