Search in sources :

Example 41 with ChangeLogStore

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"));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 42 with ChangeLogStore

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);
}
Also used : MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 43 with ChangeLogStore

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);
}
Also used : MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 44 with ChangeLogStore

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));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 45 with ChangeLogStore

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"));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) HostServices(com.yahoo.athenz.zts.HostServices) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Aggregations

ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)262 Test (org.testng.annotations.Test)258 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore)107 ZMSFileChangeLogStore (com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore)106 DataStore (com.yahoo.athenz.zts.store.DataStore)106 Path (java.nio.file.Path)71 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)57 DataCache (com.yahoo.athenz.zts.cache.DataCache)41 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)40 X509Certificate (java.security.cert.X509Certificate)35 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)34 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)27 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)23 HttpServletRequest (javax.servlet.http.HttpServletRequest)21 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 Response (javax.ws.rs.core.Response)17 Principal (com.yahoo.athenz.auth.Principal)16 MockStatusCheckerNoException (com.yahoo.athenz.zts.status.MockStatusCheckerNoException)12 File (java.io.File)12 IOException (java.io.IOException)12