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);
}
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);
}
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();
}
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;
}
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);
}
}
Aggregations