Search in sources :

Example 96 with MockZMSFileChangeLogStore

use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.

the class DataStoreTest method testValidateSignedDomainInvalidSignature.

@Test
public void testValidateSignedDomainInvalidSignature() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    store.loadZMSPublicKeys();
    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 domain = new DomainData();
    domain.setRoles(roles);
    signedDomain.setDomain(domain);
    signedDomain.setSignature("InvalidSignature");
    signedDomain.setKeyId("0");
    assertFalse(store.validateSignedDomain(signedDomain));
}
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) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 97 with MockZMSFileChangeLogStore

use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.

the class DataStoreTest method testDeleteDomainFromCacheServices.

@Test
public void testDeleteDomainFromCacheServices() {
    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)

Example 98 with MockZMSFileChangeLogStore

use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.

the class DataStoreTest method testProcessSignedDomainsAllInvalidDomain.

@Test
public void testProcessSignedDomainsAllInvalidDomain() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    List<SignedDomain> list = new ArrayList<>();
    // if we have only failures, then our result
    // is going to be failure
    SignedDomain signedDomain = createSignedDomain("sports", "weather");
    signedDomain.setSignature("Invalid0");
    list.add(signedDomain);
    SignedDomains signedDomains = new SignedDomains();
    signedDomains.setDomains(list);
    boolean result = store.processSignedDomains(signedDomains);
    assertFalse(result);
}
Also used : 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) SignedDomains(com.yahoo.athenz.zms.SignedDomains) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) Test(org.testng.annotations.Test)

Example 99 with MockZMSFileChangeLogStore

use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.

the class DataStoreTest method testResetLastModificationTime.

@Test
public void testResetLastModificationTime() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    store.changeLogStore.setLastModificationTimestamp("34567");
    store.changeLogStore.setLastModificationTimestamp(null);
    assertNull(((MockZMSFileChangeLogStore) store.changeLogStore).lastModTime);
    File f = new File("/tmp/zts_server_unit_tests/zts_root/.lastModTime");
    assertFalse(f.exists());
}
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) File(java.io.File) Test(org.testng.annotations.Test)

Example 100 with MockZMSFileChangeLogStore

use of com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore in project athenz by yahoo.

the class DataStoreTest method testGetHostServicesHostUpdated.

@Test
public void testGetHostServicesHostUpdated() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    List<String> services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("sports.storage");
    store.hostCache.put("host1", services);
    services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("sports.storage");
    store.hostCache.put("host2", services);
    Map<String, Set<String>> hostMap = new HashMap<>();
    Set<String> newServices = new HashSet<>();
    newServices.add("coretech.backup");
    hostMap.put("host3", newServices);
    newServices = new HashSet<>();
    newServices.add("sports.backup");
    hostMap.put("host1", newServices);
    store.addHostEntries(hostMap);
    Map<String, Set<String>> remMap = new HashMap<>();
    Set<String> remServices = new HashSet<>();
    remServices.add("sports.storage");
    remMap.put("host1", remServices);
    store.removeHostEntries(remMap);
    HostServices hostServices = store.getHostServices("host1");
    List<String> hosts = hostServices.getNames();
    assertEquals(hosts.size(), 2);
    assertTrue(hosts.contains("coretech.storage"));
    assertTrue(hosts.contains("sports.backup"));
    hostServices = store.getHostServices("host2");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 2);
    assertTrue(hosts.contains("coretech.storage"));
    assertTrue(hosts.contains("sports.storage"));
    hostServices = store.getHostServices("host3");
    hosts = hostServices.getNames();
    assertEquals(hosts.size(), 1);
    assertTrue(hosts.contains("coretech.backup"));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HostServices(com.yahoo.athenz.zts.HostServices) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)135 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)134 Test (org.testng.annotations.Test)132 HashSet (java.util.HashSet)53 ArrayList (java.util.ArrayList)52 DataCache (com.yahoo.athenz.zts.cache.DataCache)39 SignedDomain (com.yahoo.athenz.zms.SignedDomain)33 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)25 DomainData (com.yahoo.athenz.zms.DomainData)24 HashMap (java.util.HashMap)20 Role (com.yahoo.athenz.zms.Role)13 RoleMember (com.yahoo.athenz.zms.RoleMember)13 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)11 SignedDomains (com.yahoo.athenz.zms.SignedDomains)11 File (java.io.File)11 HostServices (com.yahoo.athenz.zts.HostServices)9 Set (java.util.Set)7 List (java.util.List)3 ChangeLogStore (com.yahoo.athenz.zts.store.ChangeLogStore)2 DataStore (com.yahoo.athenz.zts.store.DataStore)2