Skip to content

Commit 8ae1eeb

Browse files
authored
[TESTS] Disable specific locales for RestrictedTrustManagerTest (elastic#33299)
Disable specific Thai and Japanese locales as Certificate expiration validation fails due to the date parsing of BouncyCastle (that manifests in a FIPS 140 JVM as this is the only place we use BouncyCastle). Added the locale switching logic here instead of subclassing ESTestCase as these are the only tests that fail for these locales and JVM combination. Resolves elastic#33081
1 parent 736053c commit 8ae1eeb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
*/
66
package org.elasticsearch.xpack.core.ssl;
77

8+
import org.apache.logging.log4j.Logger;
9+
import org.elasticsearch.common.logging.Loggers;
810
import org.elasticsearch.common.settings.Settings;
911
import org.elasticsearch.test.ESTestCase;
1012
import org.hamcrest.Description;
1113
import org.hamcrest.TypeSafeMatcher;
14+
import org.junit.AfterClass;
1215
import org.junit.Assert;
1316
import org.junit.Before;
17+
import org.junit.BeforeClass;
18+
1419
import javax.net.ssl.X509ExtendedTrustManager;
1520

1621
import java.io.IOException;
@@ -28,6 +33,7 @@
2833
import java.util.Collections;
2934
import java.util.HashMap;
3035
import java.util.List;
36+
import java.util.Locale;
3137
import java.util.Map;
3238
import java.util.Objects;
3339
import java.util.regex.Pattern;
@@ -40,6 +46,34 @@ public class RestrictedTrustManagerTests extends ESTestCase {
4046
private int numberOfClusters;
4147
private int numberOfNodes;
4248

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

0 commit comments

Comments
 (0)