From 078834fada72afdcb65b16236a479ecdad74f077 Mon Sep 17 00:00:00 2001 From: Albert Zaharovits Date: Tue, 16 May 2023 20:47:00 +0300 Subject: [PATCH 1/3] Skip test for turkish-like locale --- .../org/elasticsearch/test/ESTestCase.java | 5 +++ .../xpack/idp/saml/test/IdpSamlTestCase.java | 5 --- .../security/authc/saml/SamlTestCase.java | 5 --- ...ecurityNetty4HttpServerTransportTests.java | 37 +++++++++++-------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index f38a7e72ab43c..f54e529e7f683 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -2002,4 +2002,9 @@ public static void safeSleep(long millis) { throw new AssertionError("unexpected", e); } } + + protected static boolean isTurkishLocale() { + return Locale.getDefault().getLanguage().equals(new Locale("tr").getLanguage()) + || Locale.getDefault().getLanguage().equals(new Locale("az").getLanguage()); + } } diff --git a/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/test/IdpSamlTestCase.java b/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/test/IdpSamlTestCase.java index 0dbcdb18d05d9..d80e5d373fe5c 100644 --- a/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/test/IdpSamlTestCase.java +++ b/x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/test/IdpSamlTestCase.java @@ -76,11 +76,6 @@ public static void localeChecks() throws Exception { } } - private static boolean isTurkishLocale() { - return Locale.getDefault().getLanguage().equals(new Locale("tr").getLanguage()) - || Locale.getDefault().getLanguage().equals(new Locale("az").getLanguage()); - } - @AfterClass public static void restoreLocale() { if (restoreLocale != null) { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlTestCase.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlTestCase.java index 7a942b6b1974a..a5c18977f56c1 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlTestCase.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlTestCase.java @@ -53,11 +53,6 @@ public static void setupSaml() throws Exception { SamlUtils.initialize(logger); } - private static boolean isTurkishLocale() { - return Locale.getDefault().getLanguage().equals(new Locale("tr").getLanguage()) - || Locale.getDefault().getLanguage().equals(new Locale("az").getLanguage()); - } - @AfterClass public static void restoreLocale() { if (restoreLocale != null) { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java index 39a93205f8dba..09b856354357b 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java @@ -525,6 +525,10 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th } public void testMalformedRequestDispatchedNoAuthn() throws Exception { + assumeTrue( + "This test doesn't work correctly under turkish-like locale, " + "because it uses String#toUpper() for asserted error messages", + !isTurkishLocale() + ); final AtomicReference dispatchThrowableReference = new AtomicReference<>(); final AtomicInteger authnInvocationCount = new AtomicInteger(); final AtomicInteger badDispatchInvocationCount = new AtomicInteger(); @@ -574,8 +578,8 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); ByteBufUtil.copy(AsciiString.of("This is not a valid HTTP line"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); + buf.writeByte(HttpConstants.LF); + buf.writeByte(HttpConstants.LF); var writeFuture = testThreadPool.generic().submit(() -> { ch.writeInbound(buf); ch.flushInbound(); @@ -590,8 +594,8 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); ByteBufUtil.copy(AsciiString.of("GET /this/is/a/valid/but/too/long/initial/line HTTP/1.1"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); + buf.writeByte(HttpConstants.LF); + buf.writeByte(HttpConstants.LF); var writeFuture = testThreadPool.generic().submit(() -> { ch.writeInbound(buf); ch.flushInbound(); @@ -606,10 +610,10 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); + buf.writeByte(HttpConstants.LF); ByteBufUtil.copy(AsciiString.of("Host"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); + buf.writeByte(HttpConstants.LF); + buf.writeByte(HttpConstants.LF); var writeFuture = testThreadPool.generic().submit(() -> { ch.writeInbound(buf); ch.flushInbound(); @@ -624,10 +628,10 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); + buf.writeByte(HttpConstants.LF); ByteBufUtil.copy(AsciiString.of("Host: this.looks.like.a.good.url.but.is.longer.than.permitted"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); + buf.writeByte(HttpConstants.LF); + buf.writeByte(HttpConstants.LF); var writeFuture = testThreadPool.generic().submit(() -> { ch.writeInbound(buf); ch.flushInbound(); @@ -642,10 +646,11 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); - ByteBufUtil.copy(AsciiString.of("Host: invalid host value"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); + buf.writeByte(HttpConstants.LF); + ByteBufUtil.copy(AsciiString.of("Host: invalid header value"), buf); + buf.writeByte(0x01); + buf.writeByte(HttpConstants.LF); + buf.writeByte(HttpConstants.LF); var writeFuture = testThreadPool.generic().submit(() -> { ch.writeInbound(buf); ch.flushInbound(); @@ -660,9 +665,9 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); + buf.writeByte(HttpConstants.LF); ByteBufUtil.copy(AsciiString.of("Host: localhost"), buf); - ByteBufUtil.writeShortBE(buf, HttpConstants.LF); + buf.writeByte(HttpConstants.LF); testThreadPool.generic().submit(() -> { ch.writeInbound(buf); ch.flushInbound(); From d590039211aac5e72154281edb2ef60d9cb9e227 Mon Sep 17 00:00:00 2001 From: Albert Zaharovits Date: Tue, 16 May 2023 20:48:38 +0300 Subject: [PATCH 2/3] Spotless --- .../netty4/SecurityNetty4HttpServerTransportTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java index 09b856354357b..7f5787a064fc2 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java @@ -526,7 +526,7 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th public void testMalformedRequestDispatchedNoAuthn() throws Exception { assumeTrue( - "This test doesn't work correctly under turkish-like locale, " + "because it uses String#toUpper() for asserted error messages", + "This test doesn't work correctly under turkish-like locale, because it uses String#toUpper() for asserted error messages", !isTurkishLocale() ); final AtomicReference dispatchThrowableReference = new AtomicReference<>(); From 9adeee06ef0287031ea4273df7e548f8e303a517 Mon Sep 17 00:00:00 2001 From: Albert Zaharovits Date: Tue, 16 May 2023 21:03:55 +0300 Subject: [PATCH 3/3] Spotless --- .../netty4/SecurityNetty4HttpServerTransportTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java index 7f5787a064fc2..9c23b39a4dc6e 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java @@ -527,7 +527,7 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th public void testMalformedRequestDispatchedNoAuthn() throws Exception { assumeTrue( "This test doesn't work correctly under turkish-like locale, because it uses String#toUpper() for asserted error messages", - !isTurkishLocale() + isTurkishLocale() == false ); final AtomicReference dispatchThrowableReference = new AtomicReference<>(); final AtomicInteger authnInvocationCount = new AtomicInteger();