Search in sources :

Example 56 with ChangeLogStore

use of com.yahoo.athenz.common.server.store.ChangeLogStore in project athenz by yahoo.

the class DataStoreTest method testRemoveHostEntrieNullMap.

@Test
public void testRemoveHostEntrieNullMap() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    List<String> services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("coretech.backup");
    store.hostCache.put("host1", services);
    services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("coretech.backup");
    store.hostCache.put("host2", services);
    store.removeHostEntries(null);
    assertEquals(store.hostCache.size(), 2);
    List<String> retServices = store.hostCache.get("host1");
    assertEquals(retServices.size(), 2);
    assertTrue(retServices.contains("coretech.storage"));
    assertTrue(retServices.contains("coretech.backup"));
    retServices = store.hostCache.get("host2");
    assertEquals(retServices.size(), 2);
    assertTrue(retServices.contains("coretech.storage"));
    assertTrue(retServices.contains("coretech.backup"));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 57 with ChangeLogStore

use of com.yahoo.athenz.common.server.store.ChangeLogStore in project athenz by yahoo.

the class DataStoreTest method testAddHostEntrieNullMap.

@Test
public void testAddHostEntrieNullMap() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    List<String> services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("coretech.backup");
    store.hostCache.put("host1", services);
    services = new ArrayList<>();
    services.add("coretech.storage");
    services.add("coretech.backup");
    store.hostCache.put("host2", services);
    store.addHostEntries(null);
    assertEquals(store.hostCache.size(), 2);
    List<String> retServices = store.hostCache.get("host1");
    assertEquals(retServices.size(), 2);
    assertTrue(retServices.contains("coretech.storage"));
    assertTrue(retServices.contains("coretech.backup"));
    retServices = store.hostCache.get("host2");
    assertEquals(retServices.size(), 2);
    assertTrue(retServices.contains("coretech.storage"));
    assertTrue(retServices.contains("coretech.backup"));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 58 with ChangeLogStore

use of com.yahoo.athenz.common.server.store.ChangeLogStore 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, ztsMetric);
    SignedDomain signedDomain = createSignedDomain("coretech", "weather");
    store.processSignedDomain(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);
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 59 with ChangeLogStore

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

Example 60 with ChangeLogStore

use of com.yahoo.athenz.common.server.store.ChangeLogStore in project athenz by yahoo.

the class DataStoreTest method testRemovePublicKeysEmpty.

@Test
public void testRemovePublicKeysEmpty() {
    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");
    Map<String, String> remKeys = new HashMap<>();
    store.removePublicKeys(remKeys);
    assertEquals(store.publicKeyCache.size(), 1);
    assertTrue(store.publicKeyCache.containsKey("coretech.storage_0"));
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) 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