use of com.webpieces.hpack.api.dto.Http2Request 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());
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class TestS5_1StreamStates method testSection5_1_1TooLowStreamIdAfterHighStreamId.
/**
* 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.
*
* This is in conflict with another part of the spec!!!!! and so we pretend
* the stream is closed(as in all likely hood, the stream was closed)!!!
* and do not shutdown the whole connection for a case like this.
*
* The part it is in conflict with is closed state and receiving messages
* in closed state. The only way to resolve conflict would be to KEEP around
* state that a connection is closed. SORRY, the connection is closed so we
* clean up all memory!!!
*/
@Test
public void testSection5_1_1TooLowStreamIdAfterHighStreamId() {
Http2Request request1 = Http2Requests.createRequest(5, true);
mockChannel.send(request1);
mockListener.getSingleRequest();
Http2Request request = Http2Requests.createRequest(3, true);
mockChannel.send(request);
//WE DO NOT DO THIS which spec wants(or another test we have starts failing)
//we leave this here in case you want to comment back in and debug that.
// //no request comes in
// Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
// //cancel the first stream since whole connection is going down.
// Assert.assertEquals(1, mockListener.getNumCancelsThatCameIn());
//
// //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. Event stream ids not allowed in requests to a server frame="));
// Assert.assertTrue(mockChannel.isClosed());
//no request comes in
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
//no cancels(since we already cancelled it)
Assert.assertEquals(0, mockListener.getNumCancelsThatCameIn());
//remote receives goAway
RstStreamFrame frame = (RstStreamFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, frame.getKnownErrorCode());
Assert.assertTrue(!mockChannel.isClosed());
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class AbstractHttp2Test method sendRequestToServer.
protected PassedIn sendRequestToServer(int streamId, boolean eos) {
Http2Request request1 = Http2Requests.createRequest(streamId, eos);
mockChannel.send(request1);
PassedIn req = mockListener.getSingleRequest();
Assert.assertEquals(request1, req.request);
return req;
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testPushPromise.
@Test
public void testPushPromise() throws InterruptedException, ExecutionException, TimeoutException {
Http2Request request1 = Http2Requests.createRequest(1, true);
mockChannel.send(request1);
PassedIn incoming = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming.request);
Http2Push push = Http2Requests.createPush(request1.getStreamId());
CompletableFuture<PushPromiseListener> future = incoming.stream.openPushStream().process(push);
PushPromiseListener pushWriter = future.get(2, TimeUnit.SECONDS);
Http2Push pushRecv = (Http2Push) mockChannel.getFrameAndClear();
Assert.assertEquals(push, pushRecv);
Http2Response preEmptive = Http2Requests.createResponse(push.getPromisedStreamId());
pushWriter.processPushResponse(preEmptive);
Http2Headers preEmptRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(preEmptive, preEmptRecv);
Http2Response response = Http2Requests.createResponse(request1.getStreamId());
incoming.stream.sendResponse(response);
Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(response, responseRecv);
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testWithNoData.
@Test
public void testWithNoData() throws InterruptedException, ExecutionException, TimeoutException {
Http2Request request1 = Http2Requests.createRequest(1, true);
mockChannel.send(request1);
PassedIn incoming = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming.request);
Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), true);
incoming.stream.sendResponse(resp);
Http2Msg response = mockChannel.getFrameAndClear();
Assert.assertEquals(resp, response);
}
Aggregations