Search in sources :

Example 11 with GoAwayFrame

use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.

the class TestS5_1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.

/**
	 * reserved local
	 * 
	 * A PRIORITY or WINDOW_UPDATE frame MAY be received in this state. Receiving any 
	 * type of frame other than RST_STREAM, PRIORITY, or WINDOW_UPDATE 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() {
    Http2Request request = Http2Requests.createRequest(1, true);
    mockChannel.send(request);
    PassedIn in = mockListener.getSingleRequest();
    ResponseStream stream = in.stream;
    Http2Push push = Http2Requests.createPush(request.getStreamId());
    stream.openPushStream().process(push);
    Http2Msg pushMsg = mockChannel.getFrameAndClear();
    Assert.assertEquals(push, pushMsg);
    //send bad frame in this state
    DataFrame data = Http2Requests.createData1(push.getPromisedStreamId(), false);
    mockChannel.send(data);
    Cancel info = mockListener.getCancelInfo();
    Assert.assertEquals(stream, info.stream);
    //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: HttpSocket[Http2ChannelCache1]:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(local)", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Cancel(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel) Http2Push(com.webpieces.hpack.api.dto.Http2Push) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 12 with GoAwayFrame

use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.

the class TestS5_1StreamStates method testSection5_1_1BadEvenStreamId.

/**
	 * The identifier of a newly established stream MUST be numerically 
	 * greater than all streams that the initiating endpoint has opened 
	 * or reserved. This governs streams that are opened using a HEADERS 
	 * frame and streams that are reserved using PUSH_PROMISE. An endpoint 
	 * that receives an unexpected stream identifier MUST respond with 
	 * a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
	 */
@Test
public void testSection5_1_1BadEvenStreamId() {
    Http2Request request = Http2Requests.createRequest(2, true);
    mockChannel.send(request);
    //no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //no cancels
    Assert.assertEquals(0, mockListener.getNumCancelsThatCameIn());
    //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("Bad stream id.  Even stream ids not allowed in requests to a server request="));
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.hpack.api.dto.Http2Request) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 13 with GoAwayFrame

use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.

the class TestS4FrameSizeAndHeaders 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() {
    List<Http2Frame> frames = createInterleavedFrames();
    //for this test, need interleaved
    Assert.assertTrue(frames.size() >= 3);
    mockChannel.sendFrame(frames.get(0));
    mockChannel.sendFrame(frames.get(1));
    //no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //no cancels
    Assert.assertEquals(0, mockListener.getNumCancelsThatCameIn());
    //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) Http2Frame(com.webpieces.http2parser.api.dto.lib.Http2Frame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 14 with GoAwayFrame

use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.

the class TestS4FrameSizeAndHeaders 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.
	 * @throws TimeoutException 
	 * @throws ExecutionException 
	 * @throws InterruptedException 
	 */
@Test
public void testSection4_2FrameTooLarge() throws InterruptedException, ExecutionException, TimeoutException {
    int streamId = 1;
    PassedIn info = sendRequestToServer(streamId, false);
    ResponseStream stream = info.stream;
    Http2Request request = info.request;
    //send data that goes with request
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
    dataFrame.setData(dataGen.wrapByteArray(buf));
    //endOfStream=false
    mockChannel.send(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());
    Cancel failResp = mockListener.getCancelInfo();
    ShutdownStream reset = (ShutdownStream) failResp.reset;
    Assert.assertEquals(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, reset.getCause().getReasonCode());
    //send response with request not complete but failed as well anyways
    Http2Response response = Http2Requests.createResponse(request.getStreamId());
    CompletableFuture<StreamWriter> future = stream.sendResponse(response);
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Cancel(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel) StreamWriter(com.webpieces.http2engine.api.StreamWriter) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Test(org.junit.Test)

Example 15 with GoAwayFrame

use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.

the class TestS5_1StreamStates method testSection5_1BadFrameReceivedInIdleState.

/**
	 * Receiving any frame other than HEADERS 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_1BadFrameReceivedInIdleState() {
    DataFrame dataFrame = new DataFrame(1, false);
    mockChannel.send(dataFrame);
    //no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //no cancels
    Assert.assertEquals(0, mockListener.getNumCancelsThatCameIn());
    //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: HttpSocket[Http2ChannelCache1]:stream1:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "Stream in idle state and received this frame which should not happen in idle state.  " + "frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Aggregations

GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)26 Test (org.junit.Test)23 DataWrapper (org.webpieces.data.api.DataWrapper)17 Http2Request (com.webpieces.hpack.api.dto.Http2Request)10 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)8 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)7 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)5 StreamWriter (com.webpieces.http2engine.api.StreamWriter)5 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)5 Http2Push (com.webpieces.hpack.api.dto.Http2Push)2 Http2Frame (com.webpieces.http2parser.api.dto.lib.Http2Frame)2 ByteBuffer (java.nio.ByteBuffer)2 ResponseStream (org.webpieces.frontend2.api.ResponseStream)2 Cancel (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 Http2Response (com.webpieces.hpack.api.dto.Http2Response)1 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)1 CancelReason (com.webpieces.http2parser.api.dto.CancelReason)1 CancelReasonCode (com.webpieces.http2parser.api.dto.error.CancelReasonCode)1