Search in sources :

Example 1 with ShutdownStream

use of com.webpieces.http2engine.api.error.ShutdownStream in project webpieces by deanhiller.

the class TestC5x1StreamStates 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(XFuture.<Void>completedFuture(null));
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<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.http2.api.dto.highlevel.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) MockPushListener(org.webpieces.http2client.mock.MockPushListener) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 2 with ShutdownStream

use of com.webpieces.http2engine.api.error.ShutdownStream in project webpieces by deanhiller.

the class TestC4FrameSizeAndHeaders method testSection4_2FrameTooLarge.

/**
 * An endpoint MUST send an error code of FRAME_SIZE_ERROR if a frame
 * exceeds the size defined in SETTINGS_MAX_FRAME_SIZE, exceeds any
 * limit defined for the frame type, or is too small to contain
 * mandatory frame data. A frame size error in a frame that could alter
 * the state of the entire connection MUST be treated as a connection
 * error (Section 5.4.1); this includes any frame carrying a header
 * block (Section 4.3) (that is, HEADERS, PUSH_PROMISE, and
 * CONTINUATION), SETTINGS, and any frame with a stream identifier of 0.
 */
@Test
public void testSection4_2FrameTooLarge() {
    MockStreamWriter mockStreamWriter = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(mockStreamWriter));
    Http2Request request = sendRequestToServer(listener1);
    sendResponseFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
    dataFrame.setData(DATA_GEN.wrapByteArray(buf));
    // endOfStream=false
    mockChannel.write(dataFrame);
    // remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.FRAME_SIZE_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: stream1:(EXCEEDED_MAX_FRAME_SIZE) Frame size=16389 was greater than max=16385", msg);
    Assert.assertTrue(mockChannel.isClosed());
    ShutdownStream failResp = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, failResp.getCause().getReasonCode());
    // send new request on closed connection
    Http2Request request1 = Requests.createRequest();
    StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
    XFuture<StreamWriter> future = streamRef.getWriter();
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.error.ConnectionClosedException) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test)

Example 3 with ShutdownStream

use of com.webpieces.http2engine.api.error.ShutdownStream in project webpieces by deanhiller.

the class TestC4FrameSizeAndHeaders method testSection4_3InterleavedFrames.

/**
 * Each header block is processed as a discrete unit. Header blocks
 * MUST be transmitted as a contiguous sequence of frames, with no interleaved
 * frames of any other type or from any other stream. The last frame in a
 * sequence of HEADERS or CONTINUATION frames has the END_HEADERS flag set. The
 * last frame in a sequence of PUSH_PROMISE or CONTINUATION frames has the
 * END_HEADERS flag set. This allows a header block to be logically equivalent to a single frame.
 *
 * Header block fragments can only be sent as the payload of HEADERS, PUSH_PROMISE, or
 * CONTINUATION frames because these frames carry data that can modify the
 * compression context maintained by a receiver. An endpoint receiving
 * HEADERS, PUSH_PROMISE, or CONTINUATION frames needs to reassemble header
 * blocks and perform decompression even if the frames are to be discarded. A receiver
 * MUST terminate the connection with a connection error (Section 5.4.1) of
 * type COMPRESSION_ERROR if it does not decompress a header block.
 */
@Test
public void testSection4_3InterleavedFrames() {
    MockStreamWriter mockStreamWriter = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(mockStreamWriter));
    Http2Request request = sendRequestToServer(listener1);
    // has to be 1 since we use 1 in the response
    Assert.assertEquals(1, request.getStreamId());
    List<Http2Frame> frames = createInterleavedFrames();
    // for this test, need interleaved
    Assert.assertTrue(frames.size() >= 3);
    mockChannel.writeFrame(frames.get(0));
    Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
    mockChannel.writeFrame(frames.get(1));
    ShutdownStream reset = (ShutdownStream) listener1.getSingleRstStream();
    Assert.assertEquals(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, reset.getCause().getReasonCode());
    // 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.assertTrue(msg.contains("Headers/continuations from two different streams per spec cannot be interleaved. "));
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 4 with ShutdownStream

use of com.webpieces.http2engine.api.error.ShutdownStream in project webpieces by deanhiller.

the class Level5BResets method resetAllClientStreams.

private void resetAllClientStreams(ConnectionCancelled reset) {
    ConcurrentMap<Integer, Stream> streams = streamState.closeEngine();
    for (Stream stream : streams.values()) {
        ShutdownStream str = new ShutdownStream(stream.getStreamId(), reset);
        fireRstToClient(stream, str);
    }
}
Also used : ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Stream(com.webpieces.http2engine.impl.shared.data.Stream)

Example 5 with ShutdownStream

use of com.webpieces.http2engine.api.error.ShutdownStream 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)

Aggregations

ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)9 Test (org.junit.Test)6 DataWrapper (org.webpieces.data.api.DataWrapper)6 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)5 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)5 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)5 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)3 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2 StreamRef (com.webpieces.http2.api.streaming.StreamRef)2 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)2 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)2 MockPushListener (org.webpieces.http2client.mock.MockPushListener)2 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)2 Http2Push (com.webpieces.hpack.api.dto.Http2Push)1 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)1 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)1 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)1 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)1 ConnectionCancelled (com.webpieces.http2engine.api.error.ConnectionCancelled)1