Search in sources :

Example 11 with MockZMSFileChangeLogStore

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

the class DataStoreTest method testGetAccessibleRolesWildCards.

@Test
public void testGetAccessibleRolesWildCards() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    store.loadZMSPublicKeys();
    SignedDomain signedDomain = createSignedDomainWildCardMembers("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(), 2);
    assertTrue(accessibleRoles.contains("writers"));
    assertTrue(accessibleRoles.contains("all"));
    accessibleRoles.clear();
    store.getAccessibleRoles(data, "coretech", "user_domain.user3", null, accessibleRoles, false);
    assertEquals(accessibleRoles.size(), 3);
    assertTrue(accessibleRoles.contains("readers"));
    assertTrue(accessibleRoles.contains("writers"));
    assertTrue(accessibleRoles.contains("all"));
    accessibleRoles.clear();
    store.getAccessibleRoles(data, "coretech", "user_domain.user5", null, accessibleRoles, false);
    assertEquals(accessibleRoles.size(), 2);
    assertTrue(accessibleRoles.contains("writers"));
    assertTrue(accessibleRoles.contains("all"));
    accessibleRoles.clear();
    store.getAccessibleRoles(data, "coretech", "athenz.service", null, accessibleRoles, false);
    assertEquals(accessibleRoles.size(), 1);
    assertTrue(accessibleRoles.contains("all"));
    // make sure the prefix is fully matched
    accessibleRoles.clear();
    store.getAccessibleRoles(data, "coretech", "athenz.use", null, accessibleRoles, false);
    assertEquals(accessibleRoles.size(), 1);
    assertTrue(accessibleRoles.contains("all"));
}
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 12 with MockZMSFileChangeLogStore

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

the class DataStoreTest method testRetrieveTagHeadersValidValue.

@Test
public void testRetrieveTagHeadersValidValue() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    ((MockZMSFileChangeLogStore) store.changeLogStore).setTagHeader(null);
    Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
    List<String> values = new ArrayList<>();
    values.add("Unit-Test");
    responseHeaders.put("tag", values);
    assertEquals(((MockZMSFileChangeLogStore) store.changeLogStore).retrieveTagHeader(responseHeaders), "Unit-Test");
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) Test(org.testng.annotations.Test)

Example 13 with MockZMSFileChangeLogStore

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

the class DataStoreTest method testProcessDomainUpdatesFromZMSFailure.

@Test
public void testProcessDomainUpdatesFromZMSFailure() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    ((MockZMSFileChangeLogStore) store.changeLogStore).lastModTime = "2014-01-01T12:00:00";
    ((MockZMSFileChangeLogStore) store.changeLogStore).setSignedDomains(null);
    boolean result = store.processDomainUpdates();
    assertFalse(result);
}
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) Test(org.testng.annotations.Test)

Example 14 with MockZMSFileChangeLogStore

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

the class DataStoreTest method testRoleCheckValueRoleNull.

@Test
public void testRoleCheckValueRoleNull() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    assertNull(store.roleCheckValue(null, "coretech:role."));
}
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) Test(org.testng.annotations.Test)

Example 15 with MockZMSFileChangeLogStore

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

the class DataStoreTest method testAddDomainToCacheSamePublicKeys.

@Test
public void testAddDomainToCacheSamePublicKeys() {
    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);
    com.yahoo.athenz.zms.PublicKeyEntry publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
    publicKey.setKey(ZTS_Y64_CERT1);
    publicKey.setId("1");
    List<com.yahoo.athenz.zms.PublicKeyEntry> publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
    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);
    /* same public keys - no changes */
    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_CERT1);
    publicKey.setId("1");
    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);
    assertEquals(store.getPublicKey("coretech", "storage", "1"), ZTS_PEM_CERT1);
    assertNull(store.getPublicKey("coretech", "storage", "2"));
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) DataCache(com.yahoo.athenz.zts.cache.DataCache) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) 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