Ejemplo n.º 1
0
        public void VerifyChannelHandlerCanBeReusedInPipeline()
        {
            _connection.Setup(x => x.IsServer).Returns(true);
            _handler = NewHandler();
            // Only read the connection preface...after preface is read internal state of Http2ConnectionHandler
            // is expected to change relative to the pipeline.
            IByteBuffer preface = Http2CodecUtil.ConnectionPrefaceBuf();

            _handler.ChannelRead(_ctx.Object, preface);
            _decoder.Verify(
                x => x.DecodeFrame(
                    It.IsAny <IChannelHandlerContext>(),
                    It.IsAny <IByteBuffer>(),
                    It.IsAny <List <object> >()),
                Times.Never());

            // Now remove and add the this.handler...this is setting up the test condition.
            _handler.HandlerRemoved(_ctx.Object);
            _handler.HandlerAdded(_ctx.Object);

            // Now verify we can continue as normal, reading connection preface plus more.
            IByteBuffer prefacePlusSome = AddSettingsHeader(Unpooled.Buffer().WriteBytes(Http2CodecUtil.ConnectionPrefaceBuf()));

            _handler.ChannelRead(_ctx.Object, prefacePlusSome);
            _decoder.Verify(
                x => x.DecodeFrame(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.IsAny <IByteBuffer>(),
                    It.IsAny <List <object> >()),
                Times.AtLeastOnce);
        }
Ejemplo n.º 2
0
        public void ServerReceivingValidClientPrefaceStringShouldContinueReadingFrames()
        {
            _connection.Setup(x => x.IsServer).Returns(true);
            _handler = NewHandler();
            IByteBuffer prefacePlusSome = AddSettingsHeader(Unpooled.Buffer().WriteBytes(Http2CodecUtil.ConnectionPrefaceBuf()));

            _handler.ChannelRead(_ctx.Object, prefacePlusSome);
            _decoder.Verify(
                x => x.DecodeFrame(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.IsAny <IByteBuffer>(),
                    It.IsAny <List <object> >()),
                Times.AtLeastOnce);
        }
Ejemplo n.º 3
0
        public void ServerReceivingInvalidClientPrefaceStringShouldHandleException()
        {
            _connection.Setup(x => x.IsServer).Returns(true);
            _handler = NewHandler();
            _handler.ChannelRead(_ctx.Object, Unpooled.CopiedBuffer("BAD_PREFACE", Encoding.UTF8));
            var captor = new ArgumentCaptor <IByteBuffer>();

            _frameWriter.Verify(
                x => x.WriteGoAwayAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == 0),
                    It.Is <Http2Error>(v => v == Http2Error.ProtocolError),
                    It.Is <IByteBuffer>(v => captor.Capture(v)),
                    It.Is <IPromise>(v => v == _promise)));
            Assert.Equal(0, captor.GetValue().ReferenceCount);
        }
Ejemplo n.º 4
0
        public void ServerReceivingHttp1ClientPrefaceStringShouldIncludePreface()
        {
            _connection.Setup(x => x.IsServer).Returns(true);
            _handler = NewHandler();
            _handler.ChannelRead(_ctx.Object, Unpooled.CopiedBuffer("GET /path HTTP/1.1", Encoding.ASCII));
            var captor = new ArgumentCaptor <IByteBuffer>();

            _frameWriter.Verify(
                x => x.WriteGoAwayAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == 0),
                    It.Is <Http2Error>(v => v == Http2Error.ProtocolError),
                    It.Is <IByteBuffer>(v => captor.Capture(v)),
                    It.Is <IPromise>(v => v == _promise)));
            Assert.Equal(0, captor.GetValue().ReferenceCount);
            Assert.Contains("/path", _goAwayDebugCap);
        }
Ejemplo n.º 5
0
        public void ServerReceivingClientPrefaceStringFollowedByNonSettingsShouldHandleException()
        {
            _connection.Setup(x => x.IsServer).Returns(true);
            _handler = NewHandler();

            // Create a connection preface followed by a bunch of zeros (i.e. not a settings frame).
            IByteBuffer buf = Unpooled.Buffer().WriteBytes(Http2CodecUtil.ConnectionPrefaceBuf()).WriteZero(10);

            _handler.ChannelRead(_ctx.Object, buf);
            var captor = new ArgumentCaptor <IByteBuffer>();

            _frameWriter.Verify(
                x => x.WriteGoAwayAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == 0),
                    It.Is <Http2Error>(v => v == Http2Error.ProtocolError),
                    It.Is <IByteBuffer>(v => captor.Capture(v)),
                    It.Is <IPromise>(v => v == _promise)),
                Times.AtLeastOnce);
            Assert.Equal(0, captor.GetValue().ReferenceCount);
        }