[TESTS] Disable specific locales for RestrictedTrustManagerTest (#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 #33081
This commit is contained in:
Ioannis Kakavas 2018-09-14 09:42:03 +03:00 committed by GitHub
parent 736053c658
commit 8ae1eeb303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 0 deletions

View File

@ -5,12 +5,17 @@
*/
package org.elasticsearch.xpack.core.ssl;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESTestCase;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import javax.net.ssl.X509ExtendedTrustManager;
import java.io.IOException;
@ -28,6 +33,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
@ -40,6 +46,34 @@ public class RestrictedTrustManagerTests extends ESTestCase {
private int numberOfClusters;
private int numberOfNodes;
private static Locale restoreLocale;
@BeforeClass
public static void ensureSupportedLocale() throws Exception {
Logger logger = Loggers.getLogger(RestrictedTrustManagerTests.class);
if (isUnusableLocale()) {
// See: https://github.com/elastic/elasticsearch/issues/33081
logger.warn("Attempting to run RestrictedTrustManagerTests tests in an unusable locale in a FIPS JVM. Certificate expiration " +
"validation will fail, switching to English");
restoreLocale = Locale.getDefault();
Locale.setDefault(Locale.ENGLISH);
}
}
private static boolean isUnusableLocale() {
return inFipsJvm() && (Locale.getDefault().toLanguageTag().equals("th-TH")
|| Locale.getDefault().toLanguageTag().equals("ja-JP-u-ca-japanese-x-lvariant-JP")
|| Locale.getDefault().toLanguageTag().equals("th-TH-u-nu-thai-x-lvariant-TH"));
}
@AfterClass
public static void restoreLocale() throws Exception {
if (restoreLocale != null) {
Locale.setDefault(restoreLocale);
restoreLocale = null;
}
}
@Before
public void readCertificates() throws GeneralSecurityException, IOException {