Search in sources :

Example 21 with Domain

use of com.yahoo.athenz.zms.Domain in project athenz by yahoo.

the class DataCacheTest method testPolicyWithNoAssertions.

@Test
public void testPolicyWithNoAssertions() {
    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");
    HashMap<String, Role> roleList = new HashMap<>();
    roleList.put(role1.getName(), role1);
    roleList.put(role2.getName(), role2);
    roleList.put(role3.getName(), role3);
    DataCache cache = new DataCache();
    cache.processRole(role1);
    cache.processRole(role2);
    cache.processRole(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)));
    assertEquals(set1.size(), 1);
    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)));
    assertEquals(set2.size(), 2);
    Set<MemberRole> set3 = cache.getMemberRoleSet("user_domain.user3");
    assertNotNull(set3);
    assertTrue(set3.contains(new MemberRole("testDomain.role.role3", 0)));
    assertEquals(set3.size(), 1);
}
Also used : Role(com.yahoo.athenz.zms.Role) Policy(com.yahoo.athenz.zms.Policy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Domain(com.yahoo.athenz.zms.Domain) RoleMember(com.yahoo.athenz.zms.RoleMember) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 22 with Domain

use of com.yahoo.athenz.zms.Domain in project athenz by yahoo.

the class DataCacheTest method testMultipleHostsSingleService.

@Test
public void testMultipleHostsSingleService() {
    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");
    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"));
}
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 23 with Domain

use of com.yahoo.athenz.zms.Domain in project athenz by yahoo.

the class JDBCConnectionTest method testInsertDomainNullFields.

@Test
public void testInsertDomainNullFields() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Domain domain = new Domain().setName("my-domain").setEnabled(true).setAuditEnabled(false);
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.insertDomain(domain);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "");
    Mockito.verify(mockPrepStmt, times(1)).setString(4, "");
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, true);
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(6, false);
    jdbcConn.close();
}
Also used : AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Domain(com.yahoo.athenz.zms.Domain) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 24 with Domain

use of com.yahoo.athenz.zms.Domain in project athenz by yahoo.

the class JDBCConnectionTest method testUpdateDomainException.

@Test
public void testUpdateDomainException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Domain domain = new Domain().setName("my-domain").setEnabled(true).setAuditEnabled(false).setDescription("my domain").setId(UUID.fromString("e5e97240-e94e-11e4-8163-6d083f3f473f")).setOrg("cloud_services");
    Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.updateDomain(domain);
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Domain(com.yahoo.athenz.zms.Domain) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Aggregations

Domain (com.yahoo.athenz.zms.Domain)24 Test (org.testng.annotations.Test)23 DataCache (com.yahoo.athenz.zts.cache.DataCache)12 ArrayList (java.util.ArrayList)12 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)11 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)10 Policy (com.yahoo.athenz.zms.Policy)6 Role (com.yahoo.athenz.zms.Role)6 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)6 HashMap (java.util.HashMap)6 Assertion (com.yahoo.athenz.zms.Assertion)5 RoleMember (com.yahoo.athenz.zms.RoleMember)5 Set (java.util.Set)5 SQLException (java.sql.SQLException)3 ResourceException (com.yahoo.athenz.zms.ResourceException)2 File (java.io.File)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1