Search in sources :

Example 1 with GoAwayFrame

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

the class TestS6_5SettingsFrameErrors method testSection6_5_2MaxFrameSizeOutsideAllowedRange.

@Test
public void testSection6_5_2MaxFrameSizeOutsideAllowedRange() {
    //server's settings frame is finally coming in as well with maxConcurrent=1
    String badStreamIdSettings = // length
    "00 00 0C" + // type
    "04" + //flags
    "00" + //R + streamid
    "00 00 00 00" + //setting 1 (enable push)
    "00 02 00 00 00 01" + //setting 2 (initial window size)
    "00 05 00 00 00 00";
    mockChannel.sendHexBack(badStreamIdSettings);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 2 with GoAwayFrame

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

the class TestS6_5SettingsFrameErrors method testSection6_5AckNonEmptyPayload.

@Test
public void testSection6_5AckNonEmptyPayload() {
    String badAckFrame = // length
    "00 00 01" + // type
    "04" + // flags (ack)
    "01" + // R + streamid
    "00 00 00 00" + //payload 
    "00";
    //ack client frame
    mockChannel.sendHexBack(badAckFrame);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: stream0:(FRAME_SIZE_INCORRECT) size of payload of a settings frame ack must be 0 but was=1", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 3 with GoAwayFrame

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

the class TestS6_5SettingsFrameErrors method testSection6_5_2InitialWindowSizeTooLarge.

@Test
public void testSection6_5_2InitialWindowSizeTooLarge() {
    //server's settings frame is finally coming in as well with maxConcurrent=1
    String badStreamIdSettings = // length
    "00 00 0C" + // type
    "04" + //flags
    "00" + //R + streamid
    "00 00 00 00" + //setting 1 (enable push)
    "00 02 00 00 00 01" + //setting 2 (initial window size)
    "00 04 FF FF FF FF";
    mockChannel.sendHexBack(badStreamIdSettings);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.FLOW_CONTROL_ERROR, goAway.getKnownErrorCode());
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 4 with GoAwayFrame

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

the class TestC5_1StreamStates method testSection5_1ReceiveBadFrameAfterReceiveRstStreamFrame.

/**
	 * 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_1ReceiveBadFrameAfterReceiveRstStreamFrame() {
    MockStreamWriter mockWriter = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(mockWriter));
    Http2Request request = sendRequestToServer(listener1);
    sendResetFromServer(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) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 5 with GoAwayFrame

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

the class TestC6_5SettingsFrameErrors method testSection6_5SettingsFrameLengthMultipleNotSixOctects.

@Test
public void testSection6_5SettingsFrameLengthMultipleNotSixOctects() {
    //server's settings frame is finally coming in as well with maxConcurrent=1
    String badStreamIdSettings = // length
    "00 00 0B" + // type
    "04" + //flags
    "00" + //R + streamid
    "00 00 00 00" + //setting 1 (enable push)
    "00 02 00 00 00 01" + //setting 2 (max streams)
    "00 03 00 00 01";
    mockChannel.writeHexBack(badStreamIdSettings);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.FRAME_SIZE_ERROR, goAway.getKnownErrorCode());
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Aggregations

GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)17 Test (org.junit.Test)17 DataWrapper (org.webpieces.data.api.DataWrapper)9 Http2Request (com.webpieces.hpack.api.dto.Http2Request)6 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)6 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)4 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)3 StreamWriter (com.webpieces.http2engine.api.StreamWriter)3 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)3 Http2Push (com.webpieces.hpack.api.dto.Http2Push)2 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)1 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)1 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)1 ResponseStream (org.webpieces.frontend2.api.ResponseStream)1 MockPushListener (org.webpieces.http2client.mock.MockPushListener)1 Cancel (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel)1 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)1