Add unit tests that validate that header validation exception is propagated to the child channels (#11076)
Motivation: We should validate the exception is actually propagted Modifications: Add unit tests Result: Verify all works as expected
This commit is contained in:
parent
29a4dd6ea7
commit
5de2ddeac2
@ -24,12 +24,14 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
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.util.AsciiString;
|
||||
import io.netty.util.AttributeKey;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -59,6 +61,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;
|
||||
@ -68,6 +71,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<C extends Http2FrameCodec> {
|
||||
private final Http2Headers request = new DefaultHttp2Headers()
|
||||
@ -209,6 +213,42 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
|
||||
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.<Exception>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.<Exception>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();
|
||||
|
Loading…
Reference in New Issue
Block a user