Skip to content

Commit 1483bf7

Browse files
Fix SecurityNetty4HttpServerTransportTests (elastic#96178)
Skips SecurityNetty4HttpServerTransportTests testMalformedRequestDispatchedNoAuthn under turkish-like locales because the asserted messages are internally processed with String#toUpper(). This results in different error messages under such locales, and it's easier to skip the test entirely than to assert the different messages. Closes: elastic#95983
1 parent 928d910 commit 1483bf7

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,4 +1824,9 @@ public String toString() {
18241824
return String.format(Locale.ROOT, "%s: %s", level.name(), message);
18251825
}
18261826
}
1827+
1828+
protected static boolean isTurkishLocale() {
1829+
return Locale.getDefault().getLanguage().equals(new Locale("tr").getLanguage())
1830+
|| Locale.getDefault().getLanguage().equals(new Locale("az").getLanguage());
1831+
}
18271832
}

x-pack/plugin/identity-provider/src/test/java/org/elasticsearch/xpack/idp/saml/test/IdpSamlTestCase.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ public static void localeChecks() throws Exception {
7676
}
7777
}
7878

79-
private static boolean isTurkishLocale() {
80-
return Locale.getDefault().getLanguage().equals(new Locale("tr").getLanguage())
81-
|| Locale.getDefault().getLanguage().equals(new Locale("az").getLanguage());
82-
}
83-
8479
@AfterClass
8580
public static void restoreLocale() {
8681
if (restoreLocale != null) {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlTestCase.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ public static void setupSaml() throws Exception {
5252
SamlUtils.initialize(logger);
5353
}
5454

55-
private static boolean isTurkishLocale() {
56-
return Locale.getDefault().getLanguage().equals(new Locale("tr").getLanguage())
57-
|| Locale.getDefault().getLanguage().equals(new Locale("az").getLanguage());
58-
}
59-
6055
@AfterClass
6156
public static void restoreLocale() {
6257
if (restoreLocale != null) {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th
610610
}
611611

612612
public void testMalformedRequestDispatchedNoAuthn() throws Exception {
613+
assumeTrue(
614+
"This test doesn't work correctly under turkish-like locale, because it uses String#toUpper() for asserted error messages",
615+
isTurkishLocale() == false
616+
);
613617
final AtomicReference<Throwable> dispatchThrowableReference = new AtomicReference<>();
614618
final AtomicInteger authnInvocationCount = new AtomicInteger();
615619
final AtomicInteger badDispatchInvocationCount = new AtomicInteger();
@@ -660,8 +664,8 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th
660664
EmbeddedChannel ch = new EmbeddedChannel(handler);
661665
ByteBuf buf = ch.alloc().buffer();
662666
ByteBufUtil.copy(AsciiString.of("This is not a valid HTTP line"), buf);
663-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
664-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
667+
buf.writeByte(HttpConstants.LF);
668+
buf.writeByte(HttpConstants.LF);
665669
testThreadPool.generic().submit(() -> {
666670
ch.writeInbound(buf);
667671
ch.flushInbound();
@@ -675,8 +679,8 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th
675679
EmbeddedChannel ch = new EmbeddedChannel(handler);
676680
ByteBuf buf = ch.alloc().buffer();
677681
ByteBufUtil.copy(AsciiString.of("GET /this/is/a/valid/but/too/long/initial/line HTTP/1.1"), buf);
678-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
679-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
682+
buf.writeByte(HttpConstants.LF);
683+
buf.writeByte(HttpConstants.LF);
680684
testThreadPool.generic().submit(() -> {
681685
ch.writeInbound(buf);
682686
ch.flushInbound();
@@ -690,10 +694,10 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th
690694
EmbeddedChannel ch = new EmbeddedChannel(handler);
691695
ByteBuf buf = ch.alloc().buffer();
692696
ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf);
693-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
697+
buf.writeByte(HttpConstants.LF);
694698
ByteBufUtil.copy(AsciiString.of("Host"), buf);
695-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
696-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
699+
buf.writeByte(HttpConstants.LF);
700+
buf.writeByte(HttpConstants.LF);
697701
testThreadPool.generic().submit(() -> {
698702
ch.writeInbound(buf);
699703
ch.flushInbound();
@@ -707,10 +711,10 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th
707711
EmbeddedChannel ch = new EmbeddedChannel(handler);
708712
ByteBuf buf = ch.alloc().buffer();
709713
ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf);
710-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
714+
buf.writeByte(HttpConstants.LF);
711715
ByteBufUtil.copy(AsciiString.of("Host: this.looks.like.a.good.url.but.is.longer.than.permitted"), buf);
712-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
713-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
716+
buf.writeByte(HttpConstants.LF);
717+
buf.writeByte(HttpConstants.LF);
714718
testThreadPool.generic().submit(() -> {
715719
ch.writeInbound(buf);
716720
ch.flushInbound();
@@ -724,10 +728,11 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th
724728
EmbeddedChannel ch = new EmbeddedChannel(handler);
725729
ByteBuf buf = ch.alloc().buffer();
726730
ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf);
727-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
728-
ByteBufUtil.copy(AsciiString.of("Host: invalid host value"), buf);
729-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
730-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
731+
buf.writeByte(HttpConstants.LF);
732+
ByteBufUtil.copy(AsciiString.of("Host: invalid header value"), buf);
733+
buf.writeByte(0x01);
734+
buf.writeByte(HttpConstants.LF);
735+
buf.writeByte(HttpConstants.LF);
731736
testThreadPool.generic().submit(() -> {
732737
ch.writeInbound(buf);
733738
ch.flushInbound();
@@ -741,9 +746,9 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th
741746
EmbeddedChannel ch = new EmbeddedChannel(handler);
742747
ByteBuf buf = ch.alloc().buffer();
743748
ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf);
744-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
749+
buf.writeByte(HttpConstants.LF);
745750
ByteBufUtil.copy(AsciiString.of("Host: localhost"), buf);
746-
ByteBufUtil.writeShortBE(buf, HttpConstants.LF);
751+
buf.writeByte(HttpConstants.LF);
747752
testThreadPool.generic().submit(() -> {
748753
ch.writeInbound(buf);
749754
ch.flushInbound();

0 commit comments

Comments
 (0)