Search in sources :

Example 21 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslCloseClient method testBasicCloseFromServer.

// @Test
public void testBasicCloseFromServer() throws GeneralSecurityException, IOException, InterruptedException, ExecutionException, TimeoutException {
    SslAction action = svrSslParser.close();
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
    mockChannel.forceDataRead(mockJdk, action.getEncryptedData());
    Assert.assertTrue(mockClientDataListener.isClosed());
    SslAction action2 = parseIncoming();
    Assert.assertEquals(SslActionEnum.LINK_SUCCESSFULLY_CLOSED, action2.getSslAction());
}
Also used : SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 22 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslCloseClient method parseIncoming.

private SslAction parseIncoming() throws InterruptedException, ExecutionException, TimeoutException {
    DataWrapper payload = mockChannel.nextPayload();
    XFuture<List<SslAction>> resultFuture2 = svrSslParser.parseIncoming(payload);
    List<SslAction> result2 = resultFuture2.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(1, result2.size());
    return result2.get(0);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) List(java.util.List) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 23 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslCloseClient method setup.

@Before
public void setup() throws GeneralSecurityException, IOException, InterruptedException, ExecutionException, TimeoutException {
    svrSslParser = createSslSvrParser();
    channel = createClientChannel("server", mockJdk);
    int port = 8443;
    mockChannel.setNumBytesToConsume(100000);
    mockChannel.addConnectReturnValue(true);
    // trick the selector into thinking we are on the selector thread
    mockJdk.setThread(Thread.currentThread());
    connectFuture = channel.connect(new InetSocketAddress("localhost", port), mockClientDataListener);
    // not connected until ssl handshake is complete
    Assert.assertFalse(connectFuture.isDone());
    SslAction result = parseIncoming();
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, result.getSslAction());
    mockChannel.forceDataRead(mockJdk, result.getEncryptedData());
    Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, parseIncoming().getSslAction());
    Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, parseIncoming().getSslAction());
    DataWrapper payload = mockChannel.nextPayload();
    XFuture<List<SslAction>> resultFuture2 = svrSslParser.parseIncoming(payload);
    List<SslAction> result2 = resultFuture2.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, result2.get(0).getSslAction());
    Assert.assertEquals(SslActionEnum.SEND_LINK_ESTABLISHED_TO_APP, result2.get(1).getSslAction());
    // client is still NOT connected yet until the SSL handshake final messages are received
    Assert.assertFalse(connectFuture.isDone());
    mockChannel.forceDataRead(mockJdk, result2.get(0).getEncryptedData());
    connectFuture.get(2, TimeUnit.SECONDS);
    transferBigData();
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) InetSocketAddress(java.net.InetSocketAddress) List(java.util.List) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 24 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslBasicClient method testCombineBuffers.

// @Test
public void testCombineBuffers() throws InterruptedException, ExecutionException, TimeoutException {
    // in this case, combine the output of all 3 of the client engine...
    DataWrapper fullData = dataGen.chainDataWrappers(mockChannel.nextPayload(), mockChannel.nextPayload(), mockChannel.nextPayload());
    XFuture<List<SslAction>> resultFuture2 = svrSslParser.parseIncoming(fullData);
    List<SslAction> result2 = resultFuture2.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, result2.get(0).getSslAction());
    Assert.assertEquals(SslActionEnum.SEND_LINK_ESTABLISHED_TO_APP, result2.get(1).getSslAction());
    // client is still NOT connected yet until the SSL handshake final messages are received
    Assert.assertFalse(connectFuture.isDone());
    mockChannel.forceDataRead(mockJdk, result2.get(0).getEncryptedData());
    connectFuture.get(2, TimeUnit.SECONDS);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ArrayList(java.util.ArrayList) List(java.util.List) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 25 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslBasicClient method parseIncoming.

private SslAction parseIncoming() throws InterruptedException, ExecutionException, TimeoutException {
    DataWrapper payload = mockChannel.nextPayload();
    XFuture<List<SslAction>> resultFuture2 = svrSslParser.parseIncoming(payload);
    List<SslAction> result2 = resultFuture2.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(1, result2.size());
    return result2.get(0);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ArrayList(java.util.ArrayList) List(java.util.List) SslAction(org.webpieces.ssl.api.dto.SslAction)

Aggregations

SslAction (org.webpieces.ssl.api.dto.SslAction)27 DataWrapper (org.webpieces.data.api.DataWrapper)11 List (java.util.List)10 ArrayList (java.util.ArrayList)6 InetSocketAddress (java.net.InetSocketAddress)4 ByteBuffer (java.nio.ByteBuffer)4 ConnectionOpen (org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen)4 Before (org.junit.Before)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 SSLEngine (javax.net.ssl.SSLEngine)1 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)1 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)1 BufferPool (org.webpieces.data.api.BufferPool)1 TwoPools (org.webpieces.data.api.TwoPools)1 Channel (org.webpieces.nio.api.channels.Channel)1 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)1 MockSvrChannel (org.webpieces.nio.api.mocks.MockSvrChannel)1 MockSvrSideJdkChannel (org.webpieces.nio.api.mocks.MockSvrSideJdkChannel)1 SSLMetrics (org.webpieces.ssl.api.SSLMetrics)1