use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataCacheTest method testSingleHostSingleService.
@Test
public void testSingleHostSingleService() {
Domain domain = new Domain();
domain.setName("testDomain");
ServiceIdentity service = new ServiceIdentity();
service.setName("testDomain.storage");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
service.setHosts(hosts);
DataCache cache = new DataCache();
cache.processServiceIdentity(service);
Map<String, Set<String>> hostMap = cache.getHostMap();
assertEquals(hostMap.size(), 1);
assertTrue(hostMap.containsKey("host1"));
Set<String> set = hostMap.get("host1");
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 testPublicKeysMultipleVersionFormat.
@Test
public void testPublicKeysMultipleVersionFormat() {
Domain domain = new Domain();
domain.setName("testDomain");
ServiceIdentity service1 = new ServiceIdentity();
service1.setName("testDomain.storage1");
com.yahoo.athenz.zms.PublicKeyEntry keyEntry0 = new com.yahoo.athenz.zms.PublicKeyEntry();
keyEntry0.setId("0");
keyEntry0.setKey(ZTS_Y64_CERT0);
List<com.yahoo.athenz.zms.PublicKeyEntry> listKeys1 = new ArrayList<>();
listKeys1.add(keyEntry0);
service1.setPublicKeys(listKeys1);
ServiceIdentity service2 = new ServiceIdentity();
service2.setName("testDomain.storage2");
com.yahoo.athenz.zms.PublicKeyEntry keyEntry1 = new com.yahoo.athenz.zms.PublicKeyEntry();
keyEntry1.setId("0");
keyEntry1.setKey(ZTS_Y64_CERT1);
com.yahoo.athenz.zms.PublicKeyEntry keyEntry3 = new com.yahoo.athenz.zms.PublicKeyEntry();
keyEntry3.setId("3");
keyEntry3.setKey(ZTS_Y64_CERT2);
com.yahoo.athenz.zms.PublicKeyEntry keyEntry4 = new com.yahoo.athenz.zms.PublicKeyEntry();
keyEntry4.setId("4");
keyEntry4.setKey(ZTS_Y64_CERT3);
List<com.yahoo.athenz.zms.PublicKeyEntry> listKeys = new ArrayList<>();
listKeys.add(keyEntry1);
listKeys.add(keyEntry3);
listKeys.add(keyEntry4);
service2.setPublicKeys(listKeys);
ServiceIdentity service3 = new ServiceIdentity();
service3.setName("testDomain.storage3");
DataCache cache = new DataCache();
cache.processServiceIdentity(service1);
cache.processServiceIdentity(service2);
cache.processServiceIdentity(service3);
Map<String, String> publicKeyMap = cache.getPublicKeyMap();
assertEquals(publicKeyMap.size(), 4);
assertEquals(publicKeyMap.get("testDomain.storage1_0"), ZTS_PEM_CERT0);
assertEquals(publicKeyMap.get("testDomain.storage2_0"), ZTS_PEM_CERT1);
assertEquals(publicKeyMap.get("testDomain.storage2_3"), ZTS_PEM_CERT2);
assertEquals(publicKeyMap.get("testDomain.storage2_4"), ZTS_PEM_CERT3);
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataCacheTest method testProcessRoleMembersWithWildcardsMultipleRoles.
@Test
public void testProcessRoleMembersWithWildcardsMultipleRoles() {
List<RoleMember> members1 = new ArrayList<>();
members1.add(new RoleMember().setMemberName("user_domain.user1"));
members1.add(new RoleMember().setMemberName("user_domain.user2"));
members1.add(new RoleMember().setMemberName("user_domain.*"));
members1.add(new RoleMember().setMemberName("user_domain.user*"));
members1.add(new RoleMember().setMemberName("*"));
List<RoleMember> members2 = new ArrayList<>();
members2.add(new RoleMember().setMemberName("user_domain.user1"));
members2.add(new RoleMember().setMemberName("user_domain.user3"));
members2.add(new RoleMember().setMemberName("user_domain.*"));
members2.add(new RoleMember().setMemberName("*"));
DataCache cache = new DataCache();
cache.processRoleMembers("dom.role1", members1);
cache.processRoleMembers("dom.role2", members2);
Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
assertNotNull(set1);
assertTrue(set1.contains(new MemberRole("dom.role1", 0)));
assertTrue(set1.contains(new MemberRole("dom.role2", 0)));
assertEquals(set1.size(), 2);
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");
assertNotNull(set3);
assertTrue(set3.contains(new MemberRole("dom.role2", 0)));
assertEquals(set3.size(), 1);
Set<MemberRole> set4 = cache.getAllMemberRoleSet();
assertNotNull(set4);
assertTrue(set4.contains(new MemberRole("dom.role1", 0)));
assertTrue(set4.contains(new MemberRole("dom.role2", 0)));
assertEquals(set4.size(), 2);
Map<String, Set<MemberRole>> setMap = cache.getPrefixMemberRoleSetMap();
assertNotNull(setMap);
assertEquals(setMap.size(), 2);
Set<MemberRole> set5 = setMap.get("user_domain.");
assertNotNull(set5);
assertTrue(set5.contains(new MemberRole("dom.role1", 0)));
assertTrue(set5.contains(new MemberRole("dom.role2", 0)));
assertEquals(set4.size(), 2);
Set<MemberRole> set6 = setMap.get("user_domain.user");
assertNotNull(set6);
assertTrue(set6.contains(new MemberRole("dom.role1", 0)));
assertEquals(set6.size(), 1);
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataCacheTest method testDomainSetGet.
@Test
public void testDomainSetGet() {
DomainData domain = new DomainData();
domain.setName("testDomain");
DataCache cache = new DataCache();
cache.setDomainData(domain);
DomainData dom = cache.getDomainData();
assertNotNull(dom);
assertEquals(dom.getName(), "testDomain");
}
use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.
the class DataCacheTest method testPolicyWithInvalidDomainNoRoles.
@Test
public void testPolicyWithInvalidDomainNoRoles() {
Domain domain = new Domain();
domain.setName("testDomain");
Policy policy = new Policy();
policy.setName("testDomain.policy.policy1");
Assertion assertion = new Assertion();
assertion.setAction("assume_role");
assertion.setEffect(AssertionEffect.ALLOW);
assertion.setResource("testDomain.role");
assertion.setRole("testDomain.role.role1");
List<Assertion> assertList = new ArrayList<Assertion>();
assertList.add(assertion);
policy.setAssertions(assertList);
HashMap<String, Role> roleList = new HashMap<>();
DataCache cache = new DataCache();
cache.processPolicy(domain.getName(), policy, roleList);
Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
assertNull(set1);
}
Aggregations