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..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 @@ -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() == false + ); 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();