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.
This commit is contained in:
Norman Maurer 2017-11-24 19:03:03 +01:00
parent 777b400fd6
commit ae4a272e46

View File

@ -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());
}
}