use of org.eclipse.jetty.io.ssl.SslConnection in project athenz by yahoo.
the class JettyConnectionLoggerTest method testFailedHandshakeInnerCause.
@Test
public void testFailedHandshakeInnerCause() throws Exception {
// First start q connection
ConnectionLog connectionLog = Mockito.mock(ConnectionLog.class);
Metric metric = Mockito.mock(Metric.class);
JettyConnectionLogger jettyConnectionLogger = new JettyConnectionLogger(connectionLog, metric);
MockedConnection failedMockedConnection = getMockConnection();
SslConnection mockConnection = failedMockedConnection.sslConnection;
// Now simulate handshake failure for mockConnection
SslHandshakeListener.Event event = Mockito.mock(SslHandshakeListener.Event.class);
when(event.getSSLEngine()).thenReturn(failedMockedConnection.sslEngine);
SSLHandshakeException sslHandshakeException = new SSLHandshakeException(GENERAL_SSL_ERROR);
SSLHandshakeException innerCause1 = new SSLHandshakeException(GENERAL_SSL_ERROR);
SSLHandshakeException innerCause2 = new SSLHandshakeException(GENERAL_SSL_ERROR);
SSLHandshakeException innerCause3 = new SSLHandshakeException("Last cause (most specific reason)");
innerCause2.initCause(innerCause3);
innerCause1.initCause(innerCause2);
sslHandshakeException.initCause(innerCause1);
ArgumentCaptor<ConnectionLogEntry> connectionLogEntryArgumentCaptor = ArgumentCaptor.forClass(ConnectionLogEntry.class);
when(mockConnection.getEndPoint().isOpen()).thenReturn(false);
jettyConnectionLogger.handshakeFailed(event, sslHandshakeException);
Mockito.verify(connectionLog, Mockito.times(1)).log(connectionLogEntryArgumentCaptor.capture());
assertEquals(GENERAL_SSL_ERROR, connectionLogEntryArgumentCaptor.getValue().sslHandshakeFailureMessage().get());
assertEquals("Last cause (most specific reason)", connectionLogEntryArgumentCaptor.getValue().sslHandshakeFailureCause().get());
}
use of org.eclipse.jetty.io.ssl.SslConnection in project athenz by yahoo.
the class JettyConnectionLoggerTest method getMockConnection.
private MockedConnection getMockConnection() throws Exception {
MockedConnection mockedConnection = new MockedConnection();
SSLEngine sslEngine = Mockito.mock(SSLEngine.class);
mockedConnection.sslEngine = sslEngine;
SslConnection sslConnection = Mockito.mock(SslConnection.class);
when(sslConnection.getSSLEngine()).thenReturn(sslEngine);
SocketChannelEndPoint socketChannelEndPoint = Mockito.mock(SocketChannelEndPoint.class);
when(socketChannelEndPoint.getLocalAddress()).thenReturn(new InetSocketAddress(InetAddress.getLocalHost(), 4444));
when(socketChannelEndPoint.getRemoteAddress()).thenReturn(new InetSocketAddress(InetAddress.getLocalHost(), 5555));
when(sslConnection.getEndPoint()).thenReturn(socketChannelEndPoint);
mockedConnection.endpoint = socketChannelEndPoint;
mockedConnection.sslConnection = sslConnection;
return mockedConnection;
}
Aggregations