Skip to content

Commit

Permalink
use self-signed cert on classpath for SSL tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ceharris committed Sep 29, 2015
1 parent 9832708 commit 692df82
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@
public class PooledSSLTCPNetSyslog4jTest extends AbstractNetSyslog4jTest {
protected void setupPoolConfig(boolean threaded, int maxActive, int maxWait) {
PooledSSLTCPNetSyslogConfig config = new PooledSSLTCPNetSyslogConfig();

// These next two lines aren't needed, but put here for code coverage
config.setKeyStore("certs/ssltest.jks");
config.setKeyStorePassword("ssltest");

config.setTrustStore("certs/ssltest.jks");
config.setTrustStorePassword("ssltest");

config.setThreaded(threaded);
config.setThrowExceptionOnWrite(true);
config.setThrowExceptionOnInitialize(true);
Expand All @@ -41,15 +34,9 @@ protected String getClientProtocol() {
return "pooledSslTcp";
}

protected String getServerProtocol() {
protected String getServerProtocol() throws Exception {
SSLTCPNetSyslogServerConfigIF config = new SSLTCPNetSyslogServerConfig();

config.setKeyStore("certs/ssltest.jks");
config.setKeyStorePassword("ssltest");

config.setTrustStore("certs/ssltest.jks");
config.setTrustStorePassword("ssltest");

SSLConfigUtil.configure(config);
SyslogServer.createThreadedInstance("pooledSslTcp", config);

return "pooledSslTcp";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.productivity.java.syslog4j.test.net;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import org.productivity.java.syslog4j.impl.net.tcp.ssl.SSLTCPNetSyslogConfigIF;
import org.productivity.java.syslog4j.server.impl.net.tcp.ssl.SSLTCPNetSyslogServerConfigIF;

public class SSLConfigUtil {

public static final String KEYSTORE = "certs/ssltest.jks";

public static final String PASSWORD = "ssltest";

public static void configure(SSLTCPNetSyslogServerConfigIF config)
throws Exception {
final String keyStorePath = keyStorePath();

config.setKeyStore(keyStorePath);
config.setKeyStorePassword(PASSWORD);

config.setTrustStore(keyStorePath);
config.setTrustStorePassword(PASSWORD);
}

public static void configure(SSLTCPNetSyslogConfigIF config)
throws Exception {
final String keyStorePath = keyStorePath();

config.setKeyStore(keyStorePath);
config.setKeyStorePassword(PASSWORD);

config.setTrustStore(keyStorePath);
config.setTrustStorePassword(PASSWORD);
}

private static String keyStorePath() throws IOException, URISyntaxException {
final URL url = SSLConfigUtil.class.getClassLoader().getResource(KEYSTORE);
return new File(url.toURI()).getAbsolutePath();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package org.productivity.java.syslog4j.test.net;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import org.junit.Ignore;
import org.productivity.java.syslog4j.Syslog;
import org.productivity.java.syslog4j.impl.net.tcp.ssl.SSLTCPNetSyslogConfig;
import org.productivity.java.syslog4j.server.SyslogServer;
Expand All @@ -20,46 +26,33 @@ protected String getServerProtocol() {
return "sslTcp";
}

public void setUp() {
public void setUp() throws Exception {
setupSslClient();
setupSslServer();

super.setUp();
}

protected void setupSslClient() {
protected void setupSslClient() throws Exception {
SSLTCPNetSyslogConfig config = new SSLTCPNetSyslogConfig("127.0.0.1",10514);

// These next two lines aren't needed, but put here for code coverage
config.setKeyStore("certs/ssltest.jks");
config.setKeyStorePassword("ssltest");

config.setTrustStore("certs/ssltest.jks");
config.setTrustStorePassword("ssltest");

SSLConfigUtil.configure(config);
Syslog.createInstance("sslTcp",config);
}

protected void setupSslServer() {
protected void setupSslServer() throws Exception {
SSLTCPNetSyslogServerConfigIF config = new SSLTCPNetSyslogServerConfig();

config.setKeyStore("certs/ssltest.jks");
config.setKeyStorePassword("ssltest");

config.setTrustStore("certs/ssltest.jks");
config.setTrustStorePassword("ssltest");

SSLConfigUtil.configure(config);
SyslogServer.createInstance("sslTcp", config);
}

protected boolean isSyslogServerTcpBacklog() {
return true;
}

public void testSendReceive() {
super._testSendReceive(true,true);
}

public void testThreadedSendReceive() {
super._testThreadedSendReceive(50,true,true);
}
Expand Down

0 comments on commit 692df82

Please sign in to comment.