Skip to content

Commit dc02278

Browse files
authored
Disable specific locales for tests in fips mode (#38938)
* Disable specific locales for tests in fips mode The Bouncy Castle FIPS provider that we use for running our tests in fips mode has an issue with locale sensitive handling of Dates as described in bcgit/bc-java#405 This causes certificate validation to fail if any given test that includes some form of certificate validation happens to run in one of the locales. This manifested earlier in #33081 which was handled insufficiently in #33299 This change ensures that the problematic 3 locales * th-TH * ja-JP-u-ca-japanese-x-lvariant-JP * th-TH-u-nu-thai-x-lvariant-TH will not be used when running our tests in a FIPS 140 JVM. It also reverts #33299
1 parent 04e18ad commit dc02278

File tree

4 files changed

+18
-35
lines changed

4 files changed

+18
-35
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ public static void restoreContentType() {
327327
Requests.INDEX_CONTENT_TYPE = XContentType.JSON;
328328
}
329329

330+
@BeforeClass
331+
public static void ensureSupportedLocale() {
332+
if (isUnusableLocale()) {
333+
Logger logger = LogManager.getLogger(ESTestCase.class);
334+
logger.warn("Attempting to run tests in an unusable locale in a FIPS JVM. Certificate expiration validation will fail, " +
335+
"switching to English. See: https://github.com/bcgit/bc-java/issues/405");
336+
Locale.setDefault(Locale.ENGLISH);
337+
}
338+
}
339+
330340
@Before
331341
public final void before() {
332342
logger.info("{}before test", getTestParamsForLogging());
@@ -1419,6 +1429,12 @@ public TestAnalysis(IndexAnalyzers indexAnalyzers,
14191429
}
14201430
}
14211431

1432+
private static boolean isUnusableLocale() {
1433+
return inFipsJvm() && (Locale.getDefault().toLanguageTag().equals("th-TH")
1434+
|| Locale.getDefault().toLanguageTag().equals("ja-JP-u-ca-japanese-x-lvariant-JP")
1435+
|| Locale.getDefault().toLanguageTag().equals("th-TH-u-nu-thai-x-lvariant-TH"));
1436+
}
1437+
14221438
public static boolean inFipsJvm() {
14231439
return Security.getProviders()[0].getName().toLowerCase(Locale.ROOT).contains("fips");
14241440
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ssl/RestrictedTrustManagerTests.java

-33
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
*/
66
package org.elasticsearch.xpack.core.ssl;
77

8-
import org.apache.logging.log4j.Logger;
9-
import org.apache.logging.log4j.LogManager;
108
import org.elasticsearch.test.ESTestCase;
119
import org.hamcrest.Description;
1210
import org.hamcrest.TypeSafeMatcher;
13-
import org.junit.AfterClass;
1411
import org.junit.Assert;
1512
import org.junit.Before;
16-
import org.junit.BeforeClass;
1713

1814
import javax.net.ssl.X509ExtendedTrustManager;
1915

@@ -32,7 +28,6 @@
3228
import java.util.Collections;
3329
import java.util.HashMap;
3430
import java.util.List;
35-
import java.util.Locale;
3631
import java.util.Map;
3732
import java.util.Objects;
3833
import java.util.regex.Pattern;
@@ -45,34 +40,6 @@ public class RestrictedTrustManagerTests extends ESTestCase {
4540
private int numberOfClusters;
4641
private int numberOfNodes;
4742

48-
private static Locale restoreLocale;
49-
50-
@BeforeClass
51-
public static void ensureSupportedLocale() throws Exception {
52-
Logger logger = LogManager.getLogger(RestrictedTrustManagerTests.class);
53-
if (isUnusableLocale()) {
54-
// See: https://github.com/elastic/elasticsearch/issues/33081
55-
logger.warn("Attempting to run RestrictedTrustManagerTests tests in an unusable locale in a FIPS JVM. Certificate expiration " +
56-
"validation will fail, switching to English");
57-
restoreLocale = Locale.getDefault();
58-
Locale.setDefault(Locale.ENGLISH);
59-
}
60-
}
61-
62-
private static boolean isUnusableLocale() {
63-
return inFipsJvm() && (Locale.getDefault().toLanguageTag().equals("th-TH")
64-
|| Locale.getDefault().toLanguageTag().equals("ja-JP-u-ca-japanese-x-lvariant-JP")
65-
|| Locale.getDefault().toLanguageTag().equals("th-TH-u-nu-thai-x-lvariant-TH"));
66-
}
67-
68-
@AfterClass
69-
public static void restoreLocale() throws Exception {
70-
if (restoreLocale != null) {
71-
Locale.setDefault(restoreLocale);
72-
restoreLocale = null;
73-
}
74-
}
75-
7643
@Before
7744
public void readCertificates() throws GeneralSecurityException, IOException {
7845

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static boolean isTurkishLocale() {
5353
}
5454

5555
@AfterClass
56-
public static void restoreLocale() throws Exception {
56+
public static void restoreLocale() {
5757
if (restoreLocale != null) {
5858
Locale.setDefault(restoreLocale);
5959
restoreLocale = null;

x-pack/qa/evil-tests/src/test/java/org/elasticsearch/xpack/security/authc/kerberos/KerberosTestCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static void setupKerberos() throws Exception {
9898
}
9999

100100
@AfterClass
101-
public static void restoreLocale() throws Exception {
101+
public static void restoreLocale() {
102102
if (restoreLocale != null) {
103103
Locale.setDefault(restoreLocale);
104104
restoreLocale = null;

0 commit comments

Comments
 (0)