Search in sources :

Example 1 with ResourceException

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

the class JDBCConnectionTest method testListResourceAccessNotRegisteredRolePrincipals.

@Test
public void testListResourceAccessNotRegisteredRolePrincipals() throws SQLException {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    // no role principals
    Mockito.when(mockResultSet.next()).thenReturn(false);
    try {
        jdbcConn.listResourceAccess("user.user1", "update", "user");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ResourceException.NOT_FOUND, ex.getCode());
    }
    jdbcConn.close();
}
Also used : ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 2 with ResourceException

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

the class JDBCConnectionTest method testSqlError.

@Test
public void testSqlError() throws SQLException {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    SQLException ex = new SQLException("sql-reason", "08S01", 9999);
    ResourceException rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.CONFLICT, rEx.getCode());
    ex = new SQLException("sql-reason", "40001", 9999);
    rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.CONFLICT, rEx.getCode());
    ex = new SQLException("sql-reason", "sql-state", 1290);
    rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.GONE, rEx.getCode());
    ex = new SQLException("sql-reason", "sql-state", 1062);
    rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.BAD_REQUEST, rEx.getCode());
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 3 with ResourceException

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

the class JDBCConnectionTest method testListPrincipalRolesInvalidPrincipal.

@Test
public void testListPrincipalRolesInvalidPrincipal() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockPrepStmt.executeQuery()).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.listPrincipalRoles("user.joe");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
    }
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 4 with ResourceException

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

the class JDBCConnectionTest method testDeletePrincipalSubDomainException.

@Test
public void testDeletePrincipalSubDomainException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockPrepStmt.executeUpdate()).thenReturn(1).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.deletePrincipal("user.jake", true);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.INTERNAL_SERVER_ERROR);
    }
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 5 with ResourceException

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

the class JDBCConnectionTest method testInsertRoleMemberNewPrincipalFailure.

@Test
public void testInsertRoleMemberNewPrincipalFailure() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
    5).thenReturn(// role id
    7).thenReturn(// principal domain id
    8).thenReturn(// principal id
    9);
    Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
    true).thenReturn(// this one is for role id
    true).thenReturn(// this one is for valid principal domain
    true).thenReturn(// principal does not exist
    false);
    // principal add returns 0
    Mockito.doReturn(0).when(mockPrepStmt).executeUpdate();
    try {
        jdbcConn.insertRoleMember("my-domain", "role1", new RoleMember().setMemberName("user.user1"), "user.admin", "audit-ref");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 500);
    }
    jdbcConn.close();
}
Also used : ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Aggregations

ResourceException (com.yahoo.athenz.zms.ResourceException)23 Test (org.testng.annotations.Test)22 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)19 SQLException (java.sql.SQLException)8 Policy (com.yahoo.athenz.zms.Policy)2 Quota (com.yahoo.athenz.zms.Quota)2 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)2 ResourceError (com.yahoo.athenz.zms.ResourceError)1 RoleMember (com.yahoo.athenz.zms.RoleMember)1