Search in sources :

Example 66 with ChangeLogStore

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

the class DataStoreTest method testProcessSingleTrustedDomainRoleAddRoleTrue.

@Test
public void testProcessSingleTrustedDomainRoleAddRoleTrue() {
    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 = "coretech" + 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);
    assertTrue(accessibleRoles.contains("readers"));
}
Also used : MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 67 with ChangeLogStore

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

the class DataStoreTest method testRemovePublicKeysAll.

@Test
public void testRemovePublicKeysAll() {
    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("coretech.storage_0", "PublicKey0");
    remKeys.put("sports.storage_0", "PublicKey0");
    remKeys.put("sports.storage_1", "PublicKey1");
    store.removePublicKeys(remKeys);
    assertEquals(store.publicKeyCache.size(), 0);
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 68 with ChangeLogStore

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

the class DataStoreTest method testAddPublicKeysUpdateValue.

@Test
public void testAddPublicKeysUpdateValue() {
    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> addKeys = new HashMap<>();
    addKeys.put("coretech.storage_0", "PublicKey0");
    addKeys.put("sports.storage_0", "PublicKey100");
    addKeys.put("sports.storage_1", "PublicKey101");
    store.addPublicKeys(addKeys);
    assertEquals(store.publicKeyCache.size(), 3);
    String value = store.publicKeyCache.get("coretech.storage_0");
    assertEquals(value, "PublicKey0");
    value = store.publicKeyCache.get("sports.storage_0");
    assertEquals(value, "PublicKey100");
    value = store.publicKeyCache.get("sports.storage_1");
    assertEquals(value, "PublicKey101");
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 69 with ChangeLogStore

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

Example 70 with ChangeLogStore

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

the class DataStoreTest method testRoleMatchInSetPlain.

@Test
public void testRoleMatchInSetPlain() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    Set<MemberRole> checkSet = new HashSet<>();
    checkSet.add(new MemberRole("writers", 0));
    checkSet.add(new MemberRole("readers", 0));
    assertTrue(store.roleMatchInSet("writers", checkSet));
    assertTrue(store.roleMatchInSet("readers", checkSet));
    assertFalse(store.roleMatchInSet("admin", checkSet));
    assertFalse(store.roleMatchInSet("testwriters", checkSet));
    assertFalse(store.roleMatchInSet("writerstest", checkSet));
}
Also used : MemberRole(com.yahoo.athenz.zts.cache.MemberRole) 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