Search in sources :

Example 6 with GoAwayFrame

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

the class TestS5x1StreamStates 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() {
    MockStreamWriter mockWriter = new MockStreamWriter();
    XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
    MockStreamRef mockStream = new MockStreamRef(futA);
    mockListener.addMockStreamToReturn(mockStream);
    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);
    Assert.assertTrue(mockStream.isCancelled());
    // 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 : MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) 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) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) MockStreamRef(org.webpieces.httpfrontend2.api.mock2.MockStreamRef) Test(org.junit.Test)

Example 7 with GoAwayFrame

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

the class TestS5x1StreamStates 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());
    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("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.http2.api.dto.highlevel.Http2Request) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 8 with GoAwayFrame

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

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

Example 9 with GoAwayFrame

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

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

Example 10 with GoAwayFrame

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

the class TestS6x5SettingsFrameErrors 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.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