Search in sources :

Example 21 with GoAwayFrame

use of com.webpieces.http2.api.dto.lowlevel.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 {
    MockStreamWriter mockWriter = new MockStreamWriter();
    XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
    MockStreamRef mockStream = new MockStreamRef(futA);
    mockListener.addMockStreamToReturn(mockStream);
    int streamId = 1;
    PassedIn info = sendRequestToServer(streamId, false);
    ResponseStream stream = info.stream;
    Http2Request request = info.request;
    Assert.assertFalse(mockStream.isCancelled());
    // send data that goes with request
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
    dataFrame.setData(DATA_GEN.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());
    Assert.assertTrue(mockListener.isClosed());
    Assert.assertTrue(mockStream.isCancelled());
    CancelReason failResp = mockStream.getCancelInfo();
    ShutdownStream reset = (ShutdownStream) failResp;
    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());
    XFuture<StreamWriter> future = stream.process(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.http2.api.dto.highlevel.Http2Response) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) ConnectionClosedException(com.webpieces.http2engine.api.error.ConnectionClosedException) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Example 22 with GoAwayFrame

use of com.webpieces.http2.api.dto.lowlevel.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());
    Assert.assertTrue(mockListener.isClosed());
    // 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.http2.api.dto.lowlevel.lib.Http2Frame) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 23 with GoAwayFrame

use of com.webpieces.http2.api.dto.lowlevel.GoAwayFrame 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(XFuture.<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.http2.api.dto.lowlevel.CancelReason) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 24 with GoAwayFrame

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

the class TestC6x5SettingsFrameErrors 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.writeHexBack(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.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 25 with GoAwayFrame

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

the class TestC6x5SettingsFrameErrors method testSection6_5AckNonEmptyPayload.

@Test
public void testSection6_5AckNonEmptyPayload() {
    // server's settings frame is finally coming in as well with maxConcurrent=1
    HeaderSettings settings = new HeaderSettings();
    settings.setMaxConcurrentStreams(1L);
    mockChannel.write(HeaderSettings.createSettingsFrame(settings));
    // clear the ack frame
    mockChannel.getFrameAndClear();
    String badAckFrame = // length
    "00 00 01" + // type
    "04" + // flags (ack)
    "01" + // R + streamid
    "00 00 00 00" + // payload
    "00";
    // ack client frame
    mockChannel.writeHexBack(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) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Aggregations

GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)27 Test (org.junit.Test)25 DataWrapper (org.webpieces.data.api.DataWrapper)18 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)11 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)7 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)7 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)5 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)4 MockStreamRef (org.webpieces.httpfrontend2.api.mock2.MockStreamRef)3 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)3 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)2 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)2 ByteBuffer (java.nio.ByteBuffer)2 ResponseStream (org.webpieces.frontend2.api.ResponseStream)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 CancelReasonCode (com.webpieces.http2.api.dto.error.CancelReasonCode)1