Search in sources :

Example 6 with MockResponseListener

use of org.webpieces.http2client.mock.MockResponseListener in project webpieces by deanhiller.

the class TestC4FrameSizeAndHeaders method testSection4_2CanSendLargestFrame.

/**
	 * success case of edge testing off by one or not
	 */
@Test
public void testSection4_2CanSendLargestFrame() {
    MockStreamWriter mockStreamWriter = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(mockStreamWriter));
    Http2Request request = sendRequestToServer(listener1);
    sendResponseFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize()];
    dataFrame.setData(dataGen.wrapByteArray(buf));
    //endOfStream=false
    mockChannel.write(dataFrame);
    DataFrame fr = (DataFrame) mockStreamWriter.getSingleFrame();
    Assert.assertEquals(localSettings.getMaxFrameSize(), fr.getData().getReadableSize());
}
Also used : Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test)

Example 7 with MockResponseListener

use of org.webpieces.http2client.mock.MockResponseListener in project webpieces by deanhiller.

the class TestC4FrameSizeAndHeaders method testSection4_3BadDecompression.

/**
	 *  A decoding error in a header block MUST be treated as a connection error (Section 5.4.1) of type COMPRESSION_ERROR.
	 *  
	 */
@Test
public void testSection4_3BadDecompression() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    //has to be 1 since we use 1 in the response
    Assert.assertEquals(1, request.getStreamId());
    String badHeaderFrame = // length
    "00 00 10" + // type
    "01" + // flags (ack)
    "05" + // R + streamid
    "00 00 00 01" + //payload 
    "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
    //endOfStream=false
    mockChannel.writeHexBack(badHeaderFrame);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.COMPRESSION_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:(HEADER_DECODE) Error from hpack library", msg);
    Assert.assertTrue(mockChannel.isClosed());
    List<CancelReason> results = listener1.getRstStreams();
    Assert.assertEquals(1, results.size());
    ShutdownStream failResp = (ShutdownStream) results.get(0);
    Assert.assertEquals(CancelReasonCode.HEADER_DECODE, failResp.getCause().getReasonCode());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 8 with MockResponseListener

use of org.webpieces.http2client.mock.MockResponseListener in project webpieces by deanhiller.

the class TestC5_1StreamStates method testSection5_1ReceiveBadFrameAfterReceiveEndStream.

/**
	 * An endpoint MUST NOT send frames other than PRIORITY on a closed stream. An endpoint 
	 * that receives any frame other than PRIORITY after receiving a RST_STREAM MUST 
	 * treat that as a stream error (Section 5.4.2) of type STREAM_CLOSED. Similarly, an 
	 * endpoint that receives any frames after receiving a frame with the 
	 * -----END_STREAM flag---- set MUST treat that as a connection error (Section 5.4.1) of 
	 * type STREAM_CLOSED, unless the frame is permitted as described below.
	 * 
	 */
@Test
public void testSection5_1ReceiveBadFrameAfterReceiveEndStream() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    sendEosResponseFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    mockChannel.write(dataFrame);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:" + "(CLOSED_STREAM) Stream must have been closed as it no longer exists.  " + "high mark=1  your frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
    Assert.assertTrue(mockChannel.isClosed());
    Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
    //send new request on closed connection
    Http2Request request1 = Requests.createRequest();
    CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 9 with MockResponseListener

use of org.webpieces.http2client.mock.MockResponseListener in project webpieces by deanhiller.

the class TestC5_1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
	 * Receiving any type of frame other than HEADERS, RST_STREAM, or PRIORITY on a
	 * stream in this state MUST be treated as a connection 
	 * error (Section 5.4.1) of type PROTOCOL_ERROR.
	 */
@Test
public void testSection5_1BadFrameReceivedInReservedRemoteState() {
    MockPushListener pushListener = new MockPushListener();
    pushListener.setIncomingRespDefault(CompletableFuture.<Void>completedFuture(null));
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    listener1.addReturnValuePush(pushListener);
    Http2Request request = sendRequestToServer(listener1);
    Http2Push push = sendPushFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(push.getPromisedStreamId(), false);
    mockChannel.write(dataFrame);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(remote)", msg);
    Assert.assertTrue(mockChannel.isClosed());
    ShutdownStream failResp1 = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp1.getCause().getReasonCode());
    ShutdownStream failResp2 = (ShutdownStream) listener1.getSingleCancelPush();
    Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp2.getCause().getReasonCode());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Push(com.webpieces.hpack.api.dto.Http2Push) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) MockPushListener(org.webpieces.http2client.mock.MockPushListener) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 10 with MockResponseListener

use of org.webpieces.http2client.mock.MockResponseListener in project webpieces by deanhiller.

the class TestC5_1StreamStates method testSection5_1ReceivePriorityAfterReceiveRstStreamFrame.

/**
	 * An endpoint MUST NOT send frames other than ----PRIORITY---- on a closed stream. An endpoint 
	 * that receives any frame other than ----PRIORITY---- after receiving a ----RST_STREAM---- MUST 
	 * treat that as a stream error (Section 5.4.2) of type STREAM_CLOSED. Similarly, an 
	 * endpoint that receives any frames after receiving a frame with the 
	 * END_STREAM flag set MUST treat that as a connection error (Section 5.4.1) of 
	 * type STREAM_CLOSED, unless the frame is permitted as described below.
	 * 
	 */
@Test
public void testSection5_1ReceivePriorityAfterReceiveRstStreamFrame() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    sendResetFromServer(listener1, request);
    PriorityDetails details = new PriorityDetails();
    details.setStreamDependency(3);
    PriorityFrame dataFrame = new PriorityFrame(request.getStreamId(), details);
    mockChannel.write(dataFrame);
    //priority is ignored
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
    Assert.assertFalse(mockChannel.isClosed());
    Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
}
Also used : Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) PriorityDetails(com.webpieces.http2parser.api.dto.lib.PriorityDetails) PriorityFrame(com.webpieces.http2parser.api.dto.PriorityFrame) Test(org.junit.Test)

Aggregations

MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)15 Test (org.junit.Test)14 Http2Request (com.webpieces.hpack.api.dto.Http2Request)13 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)10 StreamWriter (com.webpieces.http2engine.api.StreamWriter)8 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)8 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)7 DataWrapper (org.webpieces.data.api.DataWrapper)7 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)4 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)4 Http2Response (com.webpieces.hpack.api.dto.Http2Response)2 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2 RequestHolder (org.webpieces.http2client.util.RequestHolder)2 RequestsSent (org.webpieces.http2client.util.RequestsSent)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)1 Http2Push (com.webpieces.hpack.api.dto.Http2Push)1 StreamHandle (com.webpieces.http2engine.api.StreamHandle)1 CancelReason (com.webpieces.http2parser.api.dto.CancelReason)1 PriorityFrame (com.webpieces.http2parser.api.dto.PriorityFrame)1 RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)1