From ae4a272e46adb0ad06fba19063763a01cc04c5bc Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 24 Nov 2017 19:03:03 +0100 Subject: [PATCH] Add tests for HttpObjectDecoder related to limits Motivation: HttpObjectDecoder will throw a TooLongFrameException when either the max size for the initial line or the header size was exceeed. We have no tests for this. Modifications: Add test cases. Result: More tests. --- .../codec/http/HttpRequestDecoderTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java index 39b08bb652..e516a6edfd 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java @@ -18,6 +18,7 @@ package io.netty.handler.codec.http; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.handler.codec.TooLongFrameException; import io.netty.util.CharsetUtil; import org.junit.Test; @@ -235,4 +236,30 @@ public class HttpRequestDecoderTest { cnt.release(); assertFalse(channel.finishAndReleaseAll()); } + + @Test + public void testTooLargeInitialLine() { + EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder(10, 1024, 1024)); + String requestStr = "GET /some/path HTTP/1.1\r\n" + + "Host: localhost1\r\n\r\n"; + + assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII))); + HttpRequest request = (HttpRequest) channel.readInbound(); + assertTrue(request.getDecoderResult().isFailure()); + assertTrue(request.getDecoderResult().cause() instanceof TooLongFrameException); + assertFalse(channel.finish()); + } + + @Test + public void testTooLargeHeaders() { + EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder(1024, 10, 1024)); + String requestStr = "GET /some/path HTTP/1.1\r\n" + + "Host: localhost1\r\n\r\n"; + + assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII))); + HttpRequest request = (HttpRequest) channel.readInbound(); + assertTrue(request.getDecoderResult().isFailure()); + assertTrue(request.getDecoderResult().cause() instanceof TooLongFrameException); + assertFalse(channel.finish()); + } }