Search in sources :

Example 11 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCCertRecordStoreTest method testEnableNotifications.

@Test
public void testEnableNotifications() {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    JDBCCertRecordStore store = new JDBCCertRecordStore(mockDataSrc);
    boolean isEnabled = store.enableNotifications(null, null, null);
    assertFalse(isEnabled);
    NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
    RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
    String serverName = "testServer";
    isEnabled = store.enableNotifications(notificationManager, rolesProvider, serverName);
    // Not supported for FileCertStore even if all dependencies provided
    assertFalse(isEnabled);
}
Also used : NotificationManager(com.yahoo.athenz.common.server.notification.NotificationManager) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Example 12 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCCertRecordStoreTest method testLog.

@Test
public void testLog() {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    JDBCCertRecordStore store = new JDBCCertRecordStore(mockDataSrc);
    File file = new File("src/test/resources/cert_log.pem");
    String pem = null;
    try {
        pem = new String(Files.readAllBytes(file.toPath()));
    } catch (IOException ex) {
        fail();
    }
    X509Certificate cert = Crypto.loadX509Certificate(pem);
    Principal principal = SimplePrincipal.create("user", "joe", "creds");
    // make sure no exceptions are thrown when processing log request
    store.log(principal, "10.11.12.13", "athens.provider", "1234", cert);
}
Also used : IOException(java.io.IOException) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 13 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCSSHRecordStoreTest method testGetConnection.

@Test
public void testGetConnection() throws SQLException {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    Connection mockConn = Mockito.mock(Connection.class);
    Mockito.doReturn(mockConn).when(mockDataSrc).getConnection();
    JDBCSSHRecordStore store = new JDBCSSHRecordStore(mockDataSrc);
    assertNotNull(store.getConnection());
    store.clearConnections();
}
Also used : Connection(java.sql.Connection) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 14 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCWorkloadRecordStoreFactory method create.

@Override
public WorkloadRecordStore create(PrivateKeyStore keyStore) {
    final String jdbcStore = System.getProperty(ZTSConsts.ZTS_PROP_WORKLOAD_JDBC_STORE);
    final String jdbcUser = System.getProperty(ZTSConsts.ZTS_PROP_WORKLOAD_JDBC_USER);
    final String password = System.getProperty(ZTSConsts.ZTS_PROP_WORKLOAD_JDBC_PASSWORD, "");
    final String jdbcAppName = System.getProperty(ZTSConsts.ZTS_PROP_WORKLOAD_JDBC_APP_NAME, JDBC);
    String jdbcPassword = keyStore.getApplicationSecret(jdbcAppName, password);
    Properties props = new Properties();
    props.setProperty(ZTSConsts.DB_PROP_USER, jdbcUser);
    props.setProperty(ZTSConsts.DB_PROP_PASSWORD, jdbcPassword);
    props.setProperty(ZTSConsts.DB_PROP_VERIFY_SERVER_CERT, System.getProperty(ZTSConsts.ZTS_PROP_WORKLOAD_JDBC_VERIFY_SERVER_CERT, "false"));
    props.setProperty(ZTSConsts.DB_PROP_USE_SSL, System.getProperty(ZTSConsts.ZTS_PROP_WORKLOAD_JDBC_USE_SSL, "false"));
    PoolableDataSource src = DataSourceFactory.create(jdbcStore, props);
    // set default timeout for our connections
    JDBCWorkloadRecordStore workloadStore = new JDBCWorkloadRecordStore(src);
    int opTimeout = Integer.parseInt(System.getProperty(ZTSConsts.ZTS_PROP_WORKLOAD_OP_TIMEOUT, "10"));
    workloadStore.setOperationTimeout(opTimeout);
    return workloadStore;
}
Also used : Properties(java.util.Properties) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource)

Example 15 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCWorkloadRecordStoreTest method testGetConnectionException.

@Test
public void testGetConnectionException() throws SQLException {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    Mockito.doThrow(new SQLException()).when(mockDataSrc).getConnection();
    try {
        JDBCWorkloadRecordStore store = new JDBCWorkloadRecordStore(mockDataSrc);
        store.getConnection();
        fail();
    } catch (RuntimeException ex) {
        assertTrue(true);
    }
}
Also used : SQLException(java.sql.SQLException) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Aggregations

PoolableDataSource (com.yahoo.athenz.common.server.db.PoolableDataSource)30 Test (org.testng.annotations.Test)22 Connection (java.sql.Connection)11 JDBCObjectStore (com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore)7 SQLException (java.sql.SQLException)7 JDBCObjectStore (com.yahoo.athenz.zms.store.jdbc.JDBCObjectStore)5 Properties (java.util.Properties)4 Principal (com.yahoo.athenz.auth.Principal)2 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)2 RolesProvider (com.yahoo.athenz.common.server.db.RolesProvider)2 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)2 ResourceException (com.yahoo.athenz.zms.ResourceException)2 File (java.io.File)1 IOException (java.io.IOException)1 X509Certificate (java.security.cert.X509Certificate)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1