From 4689e307bf20ac03ffedb9e44ac2208fc092c1ad Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Fri, 29 Sep 2023 14:28:24 -0400 Subject: [PATCH] Small update to test Signed-off-by: Craig Perkins --- .../org/opensearch/http/netty4/Netty4BlockingPlugin.java | 8 ++------ .../opensearch/http/netty4/Netty4HeaderVerifierIT.java | 5 +++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4BlockingPlugin.java b/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4BlockingPlugin.java index 853ea34eb7fbc..0acf3e50325c7 100644 --- a/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4BlockingPlugin.java +++ b/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4BlockingPlugin.java @@ -32,15 +32,10 @@ import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; import io.netty.util.ReferenceCountUtil; public class Netty4BlockingPlugin extends Netty4ModulePlugin { - public Netty4BlockingPlugin() { - super(); - } - public class Netty4BlockingHttpServerTransport extends Netty4HttpServerTransport { public Netty4BlockingHttpServerTransport( @@ -109,11 +104,12 @@ public class ExampleBlockingNetty4HeaderVerifier extends ChannelInboundHandlerAd public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof HttpRequest)) { ctx.fireChannelRead(msg); + return; } HttpRequest request = (HttpRequest) msg; if (!isAuthenticated(request)) { - final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED); + final FullHttpResponse response = new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.UNAUTHORIZED); ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); ReferenceCountUtil.release(msg); } else { diff --git a/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4HeaderVerifierIT.java b/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4HeaderVerifierIT.java index e4437761851af..33af5ed185b12 100644 --- a/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4HeaderVerifierIT.java +++ b/modules/transport-netty4/src/internalClusterTest/java/org/opensearch/http/netty4/Netty4HeaderVerifierIT.java @@ -52,14 +52,15 @@ public void testThatNettyHttpServerRequestBlockedWithHeaderVerifier() throws Exc final FullHttpRequest blockedRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"); blockedRequest.headers().add("blockme", "Not Allowed"); blockedRequest.headers().add(HOST, "localhost"); - blockedRequest.headers().add("scheme", "http"); final List responses = new ArrayList<>(); - try (Netty4HttpClient nettyHttpClient = Netty4HttpClient.http2()) { + try (Netty4HttpClient nettyHttpClient = Netty4HttpClient.http()) { try { FullHttpResponse blockedResponse = nettyHttpClient.send(transportAddress.address(), blockedRequest); responses.add(blockedResponse); assertThat(blockedResponse.status().code(), equalTo(401)); + } catch (Exception e) { + e.printStackTrace(); } finally { responses.forEach(ReferenceCounted::release); }