use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataCacheTest method testMultipleHostsSkipDuplicate.
@Test
public void testMultipleHostsSkipDuplicate() {
Domain domain = new Domain();
domain.setName("testDomain");
ServiceIdentity service = new ServiceIdentity();
service.setName("testDomain.storage");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
hosts.add("host2");
hosts.add("host1");
service.setHosts(hosts);
DataCache cache = new DataCache();
cache.processServiceIdentity(service);
Map<String, Set<String>> hostMap = cache.getHostMap();
assertEquals(hostMap.size(), 2);
assertTrue(hostMap.containsKey("host1"));
Set<String> set = hostMap.get("host1");
assertEquals(set.size(), 1);
assertTrue(set.contains("testDomain.storage"));
assertTrue(hostMap.containsKey("host2"));
set = hostMap.get("host2");
assertEquals(set.size(), 1);
assertTrue(set.contains("testDomain.storage"));
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataCacheTest method testSimpleRole.
@Test
public void testSimpleRole() {
Role role = new Role();
role.setName("dom.role1");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user1"));
members.add(new RoleMember().setMemberName("user_domain.user2"));
role.setRoleMembers(members);
DataCache cache = new DataCache();
cache.processRole(role);
Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
assertNotNull(set1);
assertTrue(set1.contains(new MemberRole("dom.role1", 0)));
assertEquals(set1.size(), 1);
Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
assertNotNull(set2);
assertTrue(set2.contains(new MemberRole("dom.role1", 0)));
assertEquals(set2.size(), 1);
Set<MemberRole> set3 = cache.getMemberRoleSet("user_domain.user3");
assertNull(set3);
Map<String, Set<String>> map = cache.getTrustMap();
assertNotNull(map);
assertEquals(map.size(), 0);
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataCacheTest method testProcessRoleMembers.
@Test
public void testProcessRoleMembers() {
List<RoleMember> members1 = new ArrayList<>();
members1.add(new RoleMember().setMemberName("user_domain.user1"));
members1.add(new RoleMember().setMemberName("user_domain.user2"));
DataCache cache = new DataCache();
cache.processRoleMembers("dom.role1", members1);
Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
assertNotNull(set1);
assertTrue(set1.contains(new MemberRole("dom.role1", 0)));
assertEquals(set1.size(), 1);
Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
assertNotNull(set2);
assertTrue(set2.contains(new MemberRole("dom.role1", 0)));
assertEquals(set2.size(), 1);
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataCacheTest method testSimpleRoleDuplicateMember.
@Test
public void testSimpleRoleDuplicateMember() {
Role role = new Role();
role.setName("dom.role1");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user1"));
members.add(new RoleMember().setMemberName("user_domain.user2"));
members.add(new RoleMember().setMemberName("user_domain.user1"));
members.add(new RoleMember().setMemberName("user_domain.user1"));
role.setRoleMembers(members);
DataCache cache = new DataCache();
cache.processRole(role);
Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
assertNotNull(set1);
assertTrue(set1.contains(new MemberRole("dom.role1", 0)));
assertEquals(set1.size(), 1);
Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
assertNotNull(set2);
assertTrue(set2.contains(new MemberRole("dom.role1", 0)));
assertEquals(set2.size(), 1);
Set<MemberRole> set3 = cache.getMemberRoleSet("user_domain.user3");
assertNull(set3);
Map<String, Set<String>> map = cache.getTrustMap();
assertNotNull(map);
assertEquals(map.size(), 0);
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataCacheTest method testPolicyWithAssertions.
@Test
public void testPolicyWithAssertions() {
Domain domain = new Domain();
domain.setName("testDomain");
Role role1 = new Role();
role1.setName("testDomain.role.role1");
List<RoleMember> members1 = new ArrayList<>();
members1.add(new RoleMember().setMemberName("user_domain.user1"));
members1.add(new RoleMember().setMemberName("user_domain.user2"));
role1.setRoleMembers(members1);
Role role2 = new Role();
role2.setName("testDomain.role.role2");
List<RoleMember> members2 = new ArrayList<>();
members2.add(new RoleMember().setMemberName("user_domain.user2"));
role2.setRoleMembers(members2);
Role role3 = new Role();
role3.setName("testDomain.role.role3");
List<RoleMember> members3 = new ArrayList<>();
members3.add(new RoleMember().setMemberName("user_domain.user3"));
role3.setRoleMembers(members3);
Policy policy = new Policy();
policy.setName("testDomain.policy.policy1");
Assertion assertion1 = new Assertion();
assertion1.setAction("assume_role");
assertion1.setEffect(AssertionEffect.ALLOW);
assertion1.setResource("testDomain.roleA");
assertion1.setRole("testDomain.role.role1");
Assertion assertion2 = new Assertion();
assertion2.setAction("read");
assertion2.setEffect(AssertionEffect.ALLOW);
assertion2.setResource("testDomain.data:*");
assertion2.setRole("testDomain.role.role1");
List<Assertion> assertList = new ArrayList<Assertion>();
assertList.add(assertion1);
assertList.add(assertion2);
policy.setAssertions(assertList);
DataCache cache = new DataCache();
cache.processRole(role1);
cache.processRole(role2);
cache.processRole(role3);
HashMap<String, Role> roleList = new HashMap<>();
roleList.put(role1.getName(), role1);
roleList.put(role2.getName(), role2);
roleList.put(role3.getName(), role3);
cache.processPolicy(domain.getName(), policy, roleList);
Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
assertNotNull(set1);
assertTrue(set1.contains(new MemberRole("testDomain.role.role1", 0)));
assertTrue(set1.contains(new MemberRole("testDomain.roleA", 0)));
assertEquals(set1.size(), 2);
Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
assertNotNull(set2);
assertTrue(set2.contains(new MemberRole("testDomain.role.role1", 0)));
assertTrue(set2.contains(new MemberRole("testDomain.role.role2", 0)));
assertTrue(set2.contains(new MemberRole("testDomain.roleA", 0)));
assertEquals(set2.size(), 3);
Set<MemberRole> set3 = cache.getMemberRoleSet("user_domain.user3");
assertNotNull(set3);
assertTrue(set3.contains(new MemberRole("testDomain.role.role3", 0)));
assertEquals(set3.size(), 1);
}
Aggregations