Search in sources :

Example 6 with MemberRole

use of com.yahoo.athenz.zts.cache.MemberRole in project athenz by yahoo.

the class DataStoreTest method testRoleMatchInSetExpiration.

@Test
public void testRoleMatchInSetExpiration() {
    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("expired", System.currentTimeMillis() - 100000));
    checkSet.add(new MemberRole("notexpired", System.currentTimeMillis() + 100000));
    assertFalse(store.roleMatchInSet("expired", checkSet));
    assertTrue(store.roleMatchInSet("notexpired", checkSet));
}
Also used : MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 7 with MemberRole

use of com.yahoo.athenz.zts.cache.MemberRole in project athenz by yahoo.

the class DataStoreTest method testRoleMatchInSetRegex.

@Test
public void testRoleMatchInSetRegex() {
    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("coretech:role.readers", 0));
    checkSet.add(new MemberRole("coretech:role.writers", 0));
    checkSet.add(new MemberRole("*:role.update", 0));
    checkSet.add(new MemberRole("weather:role.*", 0));
    assertTrue(store.roleMatchInSet("coretech:role.readers", checkSet));
    assertTrue(store.roleMatchInSet("coretech:role.writers", checkSet));
    assertTrue(store.roleMatchInSet("sports:role.update", checkSet));
    assertTrue(store.roleMatchInSet("weather:role.update", checkSet));
    assertFalse(store.roleMatchInSet("coretech:role.admin", checkSet));
}
Also used : MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 8 with MemberRole

use of com.yahoo.athenz.zts.cache.MemberRole 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 9 with MemberRole

use of com.yahoo.athenz.zts.cache.MemberRole 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)

Example 10 with MemberRole

use of com.yahoo.athenz.zts.cache.MemberRole in project athenz by yahoo.

the class DataStoreTest method testProcessStandardMembershipRoleSuffixInValid.

@Test
public void testProcessStandardMembershipRoleSuffixInValid() {
    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[] requestedRoleList = { "2admin" };
    Set<MemberRole> memberRoles = new HashSet<>();
    memberRoles.add(new MemberRole("coretech:role.admin", 0));
    memberRoles.add(new MemberRole("coretech:role.readers", 0));
    store.processStandardMembership(memberRoles, prefix, requestedRoleList, 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)

Aggregations

MemberRole (com.yahoo.athenz.zts.cache.MemberRole)18 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)16 Test (org.testng.annotations.Test)16 DataCache (com.yahoo.athenz.zts.cache.DataCache)4 com.yahoo.athenz.zms (com.yahoo.athenz.zms)1