use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class TestC5x1StreamStates method testSection5_1ReceiveBadFrameAfterReceiveEndStream.
/**
* An endpoint MUST NOT send frames other than PRIORITY on a closed stream. An endpoint
* that receives any frame other than PRIORITY after receiving a RST_STREAM MUST
* treat that as a stream error (Section 5.4.2) of type STREAM_CLOSED. Similarly, an
* endpoint that receives any frames after receiving a frame with the
* -----END_STREAM flag---- set MUST treat that as a connection error (Section 5.4.1) of
* type STREAM_CLOSED, unless the frame is permitted as described below.
*/
@Test
public void testSection5_1ReceiveBadFrameAfterReceiveEndStream() {
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
Http2Request request = sendRequestToServer(listener1);
sendEosResponseFromServer(listener1, request);
DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
mockChannel.write(dataFrame);
// remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, goAway.getKnownErrorCode());
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:" + "(CLOSED_STREAM) Stream must have been closed as it no longer exists. " + "high mark=1 your frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
Assert.assertTrue(mockChannel.isClosed());
Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
// send new request on closed connection
Http2Request request1 = Requests.createRequest();
StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
XFuture<StreamWriter> future = streamRef.getWriter();
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.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class TestC5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.
/**
* Receiving any type of frame other than HEADERS, RST_STREAM, or PRIORITY 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() {
MockPushListener pushListener = new MockPushListener();
pushListener.setIncomingRespDefault(XFuture.<Void>completedFuture(null));
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
listener1.addReturnValuePush(pushListener);
Http2Request request = sendRequestToServer(listener1);
Http2Push push = sendPushFromServer(listener1, request);
DataFrame dataFrame = new DataFrame(push.getPromisedStreamId(), false);
mockChannel.write(dataFrame);
// 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: MockHttp2Channel1:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(remote)", msg);
Assert.assertTrue(mockChannel.isClosed());
ShutdownStream failResp1 = (ShutdownStream) listener1.getSingleRstStream();
Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp1.getCause().getReasonCode());
ShutdownStream failResp2 = (ShutdownStream) listener1.getSingleCancelPush();
Assert.assertEquals(CancelReasonCode.BAD_FRAME_RECEIVED_FOR_THIS_STATE, failResp2.getCause().getReasonCode());
}
use of com.webpieces.http2.api.dto.error.ConnectionException 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());
Assert.assertTrue(mockListener.isClosed());
// 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());
}
use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class TestS4FrameSizeAndHeaders method testBadSizePriorityFrame.
/**
* 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 testBadSizePriorityFrame() {
String priorityFrame = // length
"00 00 06" + // type
"02" + // flags
"00" + // R + streamid
"00 00 00 01" + // stream dependency
"80 00 00 04" + // weight
"05 00";
// endOfStream=false
mockChannel.sendHexBack(priorityFrame);
// no request comes in
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
Assert.assertTrue(mockListener.isClosed());
// 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:(FRAME_SIZE_INCORRECT) priority size not 5 and instead is=6", msg);
Assert.assertTrue(mockChannel.isClosed());
}
use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class SettingsMarshaller method unmarshal.
@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper payload) {
FrameHeaderData frameHeaderData = state.getFrameHeaderData();
int payloadLength = frameHeaderData.getPayloadLength();
int streamId = frameHeaderData.getStreamId();
SettingsFrame frame = new SettingsFrame();
super.unmarshalFrame(state, frame);
byte flags = state.getFrameHeaderData().getFlagsByte();
frame.setAck((flags & 0x1) == 0x1);
if (frame.isAck()) {
if (payloadLength != 0) {
throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "size of payload of a settings frame ack must be 0 but was=" + payloadLength);
}
} else if (payloadLength % 6 != 0) {
throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "payload size must be a multiple of 6 but was=" + state.getFrameHeaderData().getPayloadLength());
} else if (streamId != 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "settings frame had stream id=" + streamId);
ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(payload);
List<Http2Setting> settingsList = unmarshal(payloadByteBuffer);
frame.setSettings(settingsList);
bufferPool.releaseBuffer(payloadByteBuffer);
return frame;
}
Aggregations