Search in sources :

Example 11 with SslConnection

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());
}
Also used : SslConnection(org.eclipse.jetty.io.ssl.SslConnection) SslHandshakeListener(org.eclipse.jetty.io.ssl.SslHandshakeListener) Metric(com.yahoo.athenz.common.metrics.Metric) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Test(org.testng.annotations.Test)

Example 12 with SslConnection

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;
}
Also used : SslConnection(org.eclipse.jetty.io.ssl.SslConnection) SSLEngine(javax.net.ssl.SSLEngine) InetSocketAddress(java.net.InetSocketAddress) SocketChannelEndPoint(org.eclipse.jetty.io.SocketChannelEndPoint)

Aggregations

SslConnection (org.eclipse.jetty.io.ssl.SslConnection)12 SSLEngine (javax.net.ssl.SSLEngine)9 EndPoint (org.eclipse.jetty.io.EndPoint)6 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 SslHandshakeListener (org.eclipse.jetty.io.ssl.SslHandshakeListener)3 Metric (com.yahoo.athenz.common.metrics.Metric)2 File (java.io.File)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 ServletException (javax.servlet.ServletException)2 AbstractConnection (org.eclipse.jetty.io.AbstractConnection)2 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)2 Connection (org.eclipse.jetty.io.Connection)2 SocketChannelEndPoint (org.eclipse.jetty.io.SocketChannelEndPoint)2 Test (org.testng.annotations.Test)2 EOFException (java.io.EOFException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ByteBuffer (java.nio.ByteBuffer)1 SelectionKey (java.nio.channels.SelectionKey)1 SocketChannel (java.nio.channels.SocketChannel)1