diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTest.java index be079e9ea1..211ef092cb 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTest.java @@ -26,12 +26,14 @@ import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; import io.netty.channel.WriteBufferWaterMark; import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpScheme; import io.netty.handler.codec.http2.Http2Exception.StreamException; import io.netty.handler.codec.http2.LastInboundHandler.Consumer; import io.netty.util.AsciiString; import io.netty.util.AttributeKey; +import org.hamcrest.CoreMatchers; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -60,6 +62,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -69,6 +72,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.hamcrest.MatcherAssert.assertThat; public abstract class Http2MultiplexTest { private final Http2Headers request = new DefaultHttp2Headers() @@ -218,6 +222,42 @@ public abstract class Http2MultiplexTest { assertNull(inboundHandler.readInbound()); } + @Test + public void headerMultipleContentLengthValidationShouldPropagate() { + LastInboundHandler inboundHandler = new LastInboundHandler(); + request.addLong(HttpHeaderNames.CONTENT_LENGTH, 0); + request.addLong(HttpHeaderNames.CONTENT_LENGTH, 1); + Http2StreamChannel channel = newInboundStream(3, false, inboundHandler); + try { + inboundHandler.checkException(); + fail(); + } catch (Exception e) { + assertThat(e, CoreMatchers.instanceOf(StreamException.class)); + } + assertNull(inboundHandler.readInbound()); + assertFalse(channel.isActive()); + } + + @Test + public void headerContentLengthNotMatchValidationShouldPropagate() { + LastInboundHandler inboundHandler = new LastInboundHandler(); + request.addLong(HttpHeaderNames.CONTENT_LENGTH, 1); + Http2StreamChannel channel = newInboundStream(3, false, inboundHandler); + assertTrue(channel.isActive()); + + frameInboundWriter.writeInboundData(channel.stream().id(), bb("foo"), 0, false); + try { + inboundHandler.checkException(); + fail(); + } catch (Exception e) { + assertThat(e, CoreMatchers.instanceOf(StreamException.class)); + } + Http2HeadersFrame headersFrame = new DefaultHttp2HeadersFrame(request).stream(channel.stream()); + assertEquals(headersFrame, inboundHandler.readInbound()); + assertNull(inboundHandler.readInbound()); + assertFalse(channel.isActive()); + } + @Test public void framesShouldBeMultiplexed() { LastInboundHandler handler1 = new LastInboundHandler();