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:
parent
d8cb9ce09f
commit
9ef83234f3
@ -17,6 +17,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.AsciiString;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.junit.Test;
|
||||
@ -293,4 +294,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 = channel.readInbound();
|
||||
assertTrue(request.decoderResult().isFailure());
|
||||
assertTrue(request.decoderResult().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 = channel.readInbound();
|
||||
assertTrue(request.decoderResult().isFailure());
|
||||
assertTrue(request.decoderResult().cause() instanceof TooLongFrameException);
|
||||
assertFalse(channel.finish());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user