Search in sources :

Example 76 with DataCache

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;
}
Also used : Role(com.yahoo.athenz.zms.Role) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) DataCache(com.yahoo.athenz.zts.cache.DataCache) RoleMember(com.yahoo.athenz.zms.RoleMember)

Example 77 with 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"));
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) HostServices(com.yahoo.athenz.zts.HostServices) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 78 with DataCache

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"));
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 79 with DataCache

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);
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 80 with DataCache

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());
}
Also used : Role(com.yahoo.athenz.zms.Role) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) File(java.io.File) RoleMember(com.yahoo.athenz.zms.RoleMember) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Aggregations

DataCache (com.yahoo.athenz.zts.cache.DataCache)84 Test (org.testng.annotations.Test)68 ArrayList (java.util.ArrayList)44 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)39 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)38 DomainData (com.yahoo.athenz.zms.DomainData)32 Role (com.yahoo.athenz.zms.Role)31 HashSet (java.util.HashSet)24 RoleMember (com.yahoo.athenz.zms.RoleMember)23 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)17 SignedDomain (com.yahoo.athenz.zms.SignedDomain)14 Policy (com.yahoo.athenz.zms.Policy)13 Domain (com.yahoo.athenz.zms.Domain)12 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)12 Set (java.util.Set)12 Assertion (com.yahoo.athenz.zms.Assertion)7 HostServices (com.yahoo.athenz.zts.HostServices)6 HashMap (java.util.HashMap)6 SignedDomains (com.yahoo.athenz.zms.SignedDomains)5 Principal (com.yahoo.athenz.auth.Principal)4