Skip to content

Commit 4f744f8

Browse files
authored
Merge pull request #935 from the-thing/certificate-test
Additional SSL test logging
2 parents 10ac4c2 + abbb136 commit 4f744f8

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

quickfixj-core/src/test/java/quickfix/mina/ssl/SSLCertificateTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.security.cert.Certificate;
5555
import java.security.cert.X509Certificate;
5656
import java.util.HashMap;
57+
import java.util.List;
5758
import java.util.Properties;
5859
import java.util.concurrent.CountDownLatch;
5960
import java.util.concurrent.TimeUnit;
@@ -819,8 +820,42 @@ public void start() throws RuntimeError, ConfigError {
819820
}
820821

821822
public void stop() {
823+
try {
824+
logSSLInfo();
825+
} catch (Exception e) {
826+
LOGGER.error("Failed to log SSL info", e);
827+
}
828+
822829
connector.stop();
823830
}
831+
832+
private void logSSLInfo() throws Exception {
833+
List<SessionID> sessionsIDs = connector.getSessions();
834+
LOGGER.info("All session IDs: {}", sessionsIDs);
835+
836+
for (SessionID sessionID : sessionsIDs) {
837+
Session session = findSession(sessionID);
838+
839+
if (session == null) {
840+
LOGGER.info("No session found for ID: {}", sessionID);
841+
continue;
842+
}
843+
844+
SSLSession sslSession = findSSLSession(session);
845+
846+
if (sslSession == null) {
847+
LOGGER.info("No SSL session found for session: {}", session);
848+
continue;
849+
}
850+
851+
Throwable exception = this.exception.get();
852+
String exceptionMessage = exception != null ? exception.getMessage() : null;
853+
Class<?> exceptionType = exception != null ? exception.getClass() : null;
854+
855+
LOGGER.info("SSL session info [sessionID={},isLoggedOn={},sslSession={},peerCertificates={},localCertificates={},peerPrincipal={},exceptionMessage={},exceptionType={}]",
856+
sessionID, session.isLoggedOn(), sslSession, sslSession.getPeerCertificates(), sslSession.getLocalCertificates(), sslSession.getPeerPrincipal(), exceptionMessage, exceptionType);
857+
}
858+
}
824859
}
825860

826861
static class TestAcceptor extends TestConnector {

quickfixj-core/src/test/java/quickfix/mina/ssl/SecureSocketTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public void testLogonWithBadCertificate() throws Exception {
7070
ThreadedSocketInitiator initiator = new ThreadedSocketInitiator(clientApplication,
7171
new MemoryStoreFactory(), settings, new DefaultMessageFactory());
7272
final CountDownLatch exceptionCaught = new CountDownLatch(1);
73-
initiator.setIoFilterChainBuilder(chain -> chain.addLast("ExceptionCatcher", new IoFilterAdapter() {
74-
public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) throws Exception {
73+
initiator.setIoFilterChainBuilder(chain -> chain.addFirst("ExceptionCatcher", new IoFilterAdapter() {
74+
public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) {
7575
log.info("MINA exception: {}", cause.getMessage());
7676
exceptionCaught.countDown();
7777
nextFilter.exceptionCaught(session, cause);
@@ -81,7 +81,7 @@ public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable
8181
try {
8282
log.info("Do login");
8383
initiator.start();
84-
assertTrue("no exception thrown", exceptionCaught.await(5, TimeUnit.SECONDS));
84+
assertTrue("no exception thrown", exceptionCaught.await(10, TimeUnit.SECONDS));
8585
} finally {
8686
initiator.stop();
8787
}

0 commit comments

Comments
 (0)