Search in sources :

Example 46 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testDeletePrincipalFailure.

@Test
public void testDeletePrincipalFailure() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    // both delete requests as failure
    Mockito.when(mockPrepStmt.executeUpdate()).thenReturn(0);
    Mockito.when(mockResultSet.next()).thenReturn(true);
    boolean requestSuccess = jdbcConn.deletePrincipal("user.jake", true);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "user.jake");
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "user.jake.%");
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 47 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testInsertDomain.

@Test
public void testInsertDomain() 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.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, "my domain");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "cloud_services");
    Mockito.verify(mockPrepStmt, times(1)).setString(4, "e5e97240-e94e-11e4-8163-6d083f3f473f");
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, true);
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(6, false);
    Mockito.verify(mockPrepStmt, times(1)).setString(7, "");
    Mockito.verify(mockPrepStmt, times(1)).setInt(8, 0);
    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 48 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testUpdateDomain.

@Test
public void testUpdateDomain() 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").setAccount("123456789").setYpmId(Integer.valueOf(1011)).setApplicationId("application_id");
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.updateDomain(domain);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "my domain");
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "cloud_services");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "e5e97240-e94e-11e4-8163-6d083f3f473f");
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(4, true);
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, false);
    Mockito.verify(mockPrepStmt, times(1)).setString(6, "123456789");
    Mockito.verify(mockPrepStmt, times(1)).setInt(7, 1011);
    Mockito.verify(mockPrepStmt, times(1)).setString(8, "application_id");
    Mockito.verify(mockPrepStmt, times(1)).setString(9, "my-domain");
    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 49 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testGetAssertion.

@Test
public void testGetAssertion() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(true);
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE)).thenReturn("role1");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_RESOURCE)).thenReturn("my-domain:*");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ACTION)).thenReturn("*");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_EFFECT)).thenReturn("ALLOW");
    Assertion assertion = jdbcConn.getAssertion("my-domain", "policy1", Long.valueOf(101));
    assertEquals("my-domain:role.role1", assertion.getRole());
    assertEquals("my-domain:*", assertion.getResource());
    assertEquals("*", assertion.getAction());
    assertEquals("ALLOW", assertion.getEffect().toString());
    Mockito.verify(mockPrepStmt, times(1)).setInt(1, 101);
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "my-domain");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "policy1");
    jdbcConn.close();
}
Also used : Assertion(com.yahoo.athenz.zms.Assertion) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 50 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testGetAssertionException.

@Test
public void testGetAssertionException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockPrepStmt.executeQuery()).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.getAssertion("my-domain", "policy1", Long.valueOf(101));
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Aggregations

JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)307 Test (org.testng.annotations.Test)307 ResourceException (com.yahoo.athenz.zms.ResourceException)131 SQLException (java.sql.SQLException)125 Assertion (com.yahoo.athenz.zms.Assertion)16 PrincipalRole (com.yahoo.athenz.zms.PrincipalRole)15 Role (com.yahoo.athenz.zms.Role)14 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)11 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)11 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)11 Domain (com.yahoo.athenz.zms.Domain)10 Entity (com.yahoo.athenz.zms.Entity)8 Quota (com.yahoo.athenz.zms.Quota)8 Policy (com.yahoo.athenz.zms.Policy)7 ResourceAccessList (com.yahoo.athenz.zms.ResourceAccessList)7 ArrayList (java.util.ArrayList)7 RoleMember (com.yahoo.athenz.zms.RoleMember)6 Struct (com.yahoo.rdl.Struct)6 Timestamp (com.yahoo.rdl.Timestamp)6 DomainModifiedList (com.yahoo.athenz.zms.DomainModifiedList)5