use of org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel 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());
}
use of org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel in project webpieces by deanhiller.
the class TestHttp2Errors method testFarEndClosedSocket.
@Test
public void testFarEndClosedSocket() throws InterruptedException, ExecutionException {
MockStreamWriter mockSw = new MockStreamWriter();
mockListener.addMockStreamToReturn(mockSw);
MockStreamWriter mockSw2 = new MockStreamWriter();
mockListener.addMockStreamToReturn(mockSw2);
Http2Request request1 = Http2Requests.createRequest(1, true);
Http2Request request2 = Http2Requests.createRequest(3, true);
mockChannel.send(request1);
PassedIn in1 = mockListener.getSingleRequest();
mockChannel.send(request2);
PassedIn in2 = mockListener.getSingleRequest();
mockChannel.close();
List<Cancel> cancels = mockListener.getCancels();
Assert.assertEquals(in1.stream, cancels.get(0).stream);
Assert.assertEquals(in2.stream, cancels.get(1).stream);
}
use of org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel in project webpieces by deanhiller.
the class TestHttp11Errors method testFarEndClosed.
@Test
public void testFarEndClosed() {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
mockChannel.write(req);
PassedIn in1 = mockListener.getSingleRequest();
mockChannel.write(req2);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
mockChannel.simulateClose();
List<Cancel> cancels = mockListener.getCancels();
Assert.assertEquals(in1.stream, cancels.get(0).stream);
}
use of org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel 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());
}
Aggregations