Search in sources :

Example 21 with DataCache

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"));
}
Also used : Set(java.util.Set) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) Domain(com.yahoo.athenz.zms.Domain) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 22 with DataCache

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);
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) DataCache(com.yahoo.athenz.zts.cache.DataCache) Domain(com.yahoo.athenz.zms.Domain) Test(org.testng.annotations.Test)

Example 23 with DataCache

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);
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) RoleMember(com.yahoo.athenz.zms.RoleMember) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 24 with DataCache

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");
}
Also used : DomainData(com.yahoo.athenz.zms.DomainData) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 25 with DataCache

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);
}
Also used : Policy(com.yahoo.athenz.zms.Policy) Role(com.yahoo.athenz.zms.Role) HashMap(java.util.HashMap) Assertion(com.yahoo.athenz.zms.Assertion) ArrayList(java.util.ArrayList) Domain(com.yahoo.athenz.zms.Domain) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Aggregations

DataCache (com.yahoo.athenz.zts.cache.DataCache)84 Test (org.testng.annotations.Test)68 ArrayList (java.util.ArrayList)44 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)39 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)38 DomainData (com.yahoo.athenz.zms.DomainData)32 Role (com.yahoo.athenz.zms.Role)31 HashSet (java.util.HashSet)24 RoleMember (com.yahoo.athenz.zms.RoleMember)23 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)17 SignedDomain (com.yahoo.athenz.zms.SignedDomain)14 Policy (com.yahoo.athenz.zms.Policy)13 Domain (com.yahoo.athenz.zms.Domain)12 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)12 Set (java.util.Set)12 Assertion (com.yahoo.athenz.zms.Assertion)7 HostServices (com.yahoo.athenz.zts.HostServices)6 HashMap (java.util.HashMap)6 SignedDomains (com.yahoo.athenz.zms.SignedDomains)5 Principal (com.yahoo.athenz.auth.Principal)4