Ejemplo n.º 1
0
        public void ServerShouldCreateStreamIfNeededBeforeSending431()
        {
            int padding = 0;

            _handler = NewHandler();
            Http2Exception e = new HeaderListSizeException(STREAM_ID, Http2Error.ProtocolError,
                                                           "Header size exceeded max allowed size 8196", true);

            _connection.Setup(x => x.Stream(It.Is <int>(v => v == STREAM_ID))).Returns(default(IHttp2Stream));
            _remote
            .Setup(x => x.CreateStream(
                       It.Is <int>(v => v == STREAM_ID),
                       It.Is <bool>(v => v == true)))
            .Returns(_stream.Object);
            _stream.Setup(x => x.Id).Returns(STREAM_ID);

            _connection.Setup(x => x.IsServer).Returns(true);
            _stream.Setup(x => x.IsHeadersSent).Returns(false);
            _remote.Setup(x => x.LastStreamCreated).Returns(STREAM_ID);
            _frameWriter
            .Setup(x => x.WriteRstStreamAsync(
                       It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                       It.Is <int>(v => v == STREAM_ID),
                       It.Is <Http2Error>(v => v == Http2Error.ProtocolError),
                       It.Is <IPromise>(v => v == _promise)))
            .Returns(_future);
            _handler.ExceptionCaught(_ctx.Object, e);

            _remote.Verify(
                x => x.CreateStream(
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <bool>(v => v == true)));
            _encoder.Verify(
                x => x.WriteHeadersAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == STREAM_ID),
                    It.IsAny <IHttp2Headers>(),
                    It.Is <int>(v => v == padding),
                    It.Is <bool>(v => v == true),
                    It.Is <IPromise>(v => v == _promise)));

            _frameWriter.Verify(
                x => x.WriteRstStreamAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <Http2Error>(v => v == Http2Error.ProtocolError),
                    It.Is <IPromise>(v => v == _promise)));
        }
Ejemplo n.º 2
0
        public void ServerShouldSend431OnHeaderSizeErrorWhenDecodingInitialHeaders()
        {
            int padding = 0;

            _handler = NewHandler();
            Http2Exception e = new HeaderListSizeException(STREAM_ID, Http2Error.ProtocolError,
                                                           "Header size exceeded max allowed size 8196", true);

            _stream.Setup(x => x.Id).Returns(STREAM_ID);
            _connection.Setup(x => x.IsServer).Returns(true);
            _stream.Setup(x => x.IsHeadersSent).Returns(false);
            _remote.Setup(x => x.LastStreamCreated).Returns(STREAM_ID);
            _frameWriter
            .Setup(x => x.WriteRstStreamAsync(
                       It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                       It.Is <int>(v => v == STREAM_ID),
                       It.Is <Http2Error>(v => v == Http2Error.ProtocolError),
                       It.Is <IPromise>(v => v == _promise)))
            .Returns(_future);

            _handler.ExceptionCaught(_ctx.Object, e);

            var captor = new ArgumentCaptor <IHttp2Headers>();

            _encoder.Verify(
                x => x.WriteHeadersAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <IHttp2Headers>(v => captor.Capture(v)),
                    It.Is <int>(v => v == padding),
                    It.Is <bool>(v => v == true),
                    It.Is <IPromise>(v => v == _promise)));
            IHttp2Headers headers = captor.GetValue();

            Assert.Equal(HttpResponseStatus.RequestHeaderFieldsTooLarge.CodeAsText, headers.Status);
            _frameWriter.Verify(
                x => x.WriteRstStreamAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <Http2Error>(v => v == Http2Error.ProtocolError),
                    It.Is <IPromise>(v => v == _promise)));
        }