Search in sources :

Example 16 with MemberRole

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

the class DataStoreTest method testProcessDomainRolesDelete.

@Test
public void testProcessDomainRolesDelete() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    DomainData domainData = getDomainData(true);
    store.processDomainData(domainData);
    DataCache dataCache = store.getDataCache("coretech");
    assertEquals(dataCache.getMemberRoleSet("user_domain.user").size(), 2);
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.admin", 0)));
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.readers", 0)));
    // Getting getRolesRequireRoleCert will return the tagged role
    List<String> rolesRequireRoleCert = store.requireRoleCertCache.getRolesRequireRoleCert("user_domain.user");
    assertEquals(rolesRequireRoleCert.size(), 1);
    assertEquals(rolesRequireRoleCert.get(0), "coretech:role.readers");
    // Now remove the tagged role and verify cache is updated
    domainData = getDomainData(false);
    store.processDomainData(domainData);
    dataCache = store.getDataCache("coretech");
    assertEquals(dataCache.getMemberRoleSet("user_domain.user").size(), 1);
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.admin", 0)));
    rolesRequireRoleCert = store.requireRoleCertCache.getRolesRequireRoleCert("user_domain.user");
    assertEquals(rolesRequireRoleCert.size(), 0);
}
Also used : MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 17 with MemberRole

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

the class DataStoreTest method testProcessStandardMembershipRoleSuffixValid.

@Test
public void testProcessStandardMembershipRoleSuffixValid() {
    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 = { "admin" };
    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(), 1);
}
Also used : MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) Test(org.testng.annotations.Test)

Example 18 with MemberRole

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

the class DataStoreTest method testProcessDomainRolesWithRequireRole.

@Test
public void testProcessDomainRolesWithRequireRole() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null, ztsMetric);
    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);
    roles.add(role);
    role = new Role();
    role.setName("coretech:role.readers");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    // Set tag
    Map<String, TagValueList> tags = new HashMap<>();
    tags.put(ZTS_ISSUE_ROLE_CERT_TAG, new TagValueList().setList(Collections.singletonList("true")));
    role.setTags(tags);
    roles.add(role);
    role = new Role();
    role.setName("coretech:role.different.tag");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    // Set tag
    tags = new HashMap<>();
    tags.put("othertag", new TagValueList().setList(Collections.singletonList("true")));
    role.setTags(tags);
    roles.add(role);
    role = new Role();
    role.setName("coretech:role.tag.set.false");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user"));
    role.setRoleMembers(members);
    // Set tag
    tags = new HashMap<>();
    tags.put(ZTS_ISSUE_ROLE_CERT_TAG, new TagValueList().setList(Collections.singletonList("false")));
    role.setTags(tags);
    roles.add(role);
    DomainData domainData = new DomainData();
    domainData.setName("coretech");
    domainData.setRoles(roles);
    DataCache dataCache = new DataCache();
    store.processDomainRoles(domainData, dataCache);
    assertEquals(dataCache.getMemberRoleSet("user_domain.user").size(), 4);
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.admin", 0)));
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.readers", 0)));
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.different.tag", 0)));
    assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.tag.set.false", 0)));
    List<String> rolesRequireRoleCert = store.getRolesRequireRoleCert("user_domain.user");
    assertEquals(rolesRequireRoleCert.size(), 1);
    assertEquals(rolesRequireRoleCert.get(0), "coretech:role.readers");
}
Also used : DataCache(com.yahoo.athenz.zts.cache.DataCache) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) 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