Search in sources :

Example 6 with GoAwayFrame

use of com.webpieces.http2parser.api.dto.GoAwayFrame 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(CompletableFuture.<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(dataGen.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();
    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) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) 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 7 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)

Example 8 with GoAwayFrame

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

the class TestC6_5SettingsFrameErrors method testSection6_5SettingsStreamIdNonZeroValue.

@Test
public void testSection6_5SettingsStreamIdNonZeroValue() {
    //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 01" + //setting 1 (enable push)
    "00 02 00 00 00 01" + //setting 2 (max streams)
    "00 03 00 00 01 00";
    mockChannel.writeHexBack(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 9 with GoAwayFrame

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

the class TestC6_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.writeHexBack(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 10 with GoAwayFrame

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

the class TestS4FrameSizeAndHeaders 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() {
    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.sendHexBack(badHeaderFrame);
    //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.COMPRESSION_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: HttpSocket[Http2ChannelCache1]:stream1:(HEADER_DECODE) Error from hpack library", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) 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