Skip to content

Commit

Permalink
Mute some security tests on problematic JDK8 build
Browse files Browse the repository at this point in the history
This commit adds some `assumeFalse` (or modifies exising ones) to mute
tests on JDK 1.8.0_292 due to JDK-8266279

On this JDK build, a race condition sometimes causes the
PBEWithSHA1AndDESede algorithm to appear as though it is unavailable.

Relates: elastic#75571, elastic#75417, elastic#75379, elastic#72639, elastic#72359
Backport of: elastic#75718
  • Loading branch information
tvernum committed Jul 28, 2021
1 parent 885bc4a commit 5740949
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import org.bouncycastle.asn1.DLTaggedObject;
import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.core.internal.io.IOUtils;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1String;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DLTaggedObject;
import org.bouncycastle.asn1.pkcs.Attribute;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.Extension;
Expand All @@ -31,20 +31,21 @@
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.network.NetworkAddress;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.PathUtils;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.TestEnvironment;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.SecuritySettingsSourceField;
import org.elasticsearch.xpack.core.ssl.CertParsingUtils;
import org.elasticsearch.xpack.core.ssl.PemUtils;
import org.elasticsearch.xpack.security.cli.CertificateGenerateTool.CAInfo;
import org.elasticsearch.xpack.security.cli.CertificateGenerateTool.CertificateInformation;
import org.elasticsearch.xpack.security.cli.CertificateGenerateTool.Name;
import org.elasticsearch.xpack.core.ssl.CertParsingUtils;
import org.elasticsearch.xpack.core.ssl.PemUtils;
import org.junit.After;
import org.junit.BeforeClass;

import javax.security.auth.x500.X500Principal;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
Expand Down Expand Up @@ -74,6 +75,7 @@
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.security.auth.x500.X500Principal;

import static org.elasticsearch.test.FileMatchers.pathExists;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -267,7 +269,8 @@ public void testGeneratingCsr() throws Exception {

public void testGeneratingSignedCertificates() throws Exception {
assumeFalse("JDK bug JDK-8266279, https://github.com/elastic/elasticsearch/issues/72639",
JavaVersion.current().compareTo(JavaVersion.parse("8")) == 0);
"1.8.0_292".equals(System.getProperty("java.version")));

Path tempDir = initTempDir();
Path outputFile = tempDir.resolve("out.zip");
Path instanceFile = writeInstancesTo(tempDir.resolve("instances.yml"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

package org.elasticsearch.xpack.security.cli;

import joptsimple.OptionSet;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import joptsimple.OptionSet;

import org.bouncycastle.asn1.DERIA5String;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DLSequence;
Expand All @@ -23,7 +25,6 @@
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest;
import org.bouncycastle.util.io.pem.PemObject;
import org.bouncycastle.util.io.pem.PemReader;
import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.common.CheckedBiFunction;
import org.elasticsearch.common.CheckedFunction;
Expand All @@ -39,7 +40,6 @@
import org.junit.Before;
import org.junit.BeforeClass;

import javax.security.auth.x500.X500Principal;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -81,6 +81,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.security.auth.x500.X500Principal;

import static java.util.Collections.singletonMap;
import static org.elasticsearch.test.FileMatchers.isDirectory;
Expand Down Expand Up @@ -116,10 +117,13 @@ public static void muteInFips() {
assumeFalse("Can't run in a FIPS JVM", inFipsJvm());
}

public void testGenerateSingleCertificateSigningRequest() throws Exception {
@BeforeClass
public static void muteOnBrokenJdk() {
assumeFalse("JDK bug JDK-8266279, https://github.com/elastic/elasticsearch/issues/72359",
JavaVersion.current().compareTo(JavaVersion.parse("8")) == 0);
"1.8.0_292".equals(System.getProperty("java.version")));
}

public void testGenerateSingleCertificateSigningRequest() throws Exception {
final Path outFile = testRoot.resolve("csr.zip").toAbsolutePath();

final List<String> hostNames = randomHostNames();
Expand Down Expand Up @@ -220,8 +224,6 @@ public void testGenerateSingleCertificateSigningRequest() throws Exception {
}

public void testGenerateSingleCertificateWithExistingCA() throws Exception {
assumeFalse("JDK bug JDK-8266279, https://github.com/elastic/elasticsearch/issues/72359",
JavaVersion.current().compareTo(JavaVersion.parse("8")) == 0);
final Path outFile = testRoot.resolve("certs.zip").toAbsolutePath();

final List<String> hostNames = randomHostNames();
Expand Down Expand Up @@ -335,8 +337,6 @@ public void testGenerateSingleCertificateWithExistingCA() throws Exception {
}

public void testGenerateMultipleCertificateWithNewCA() throws Exception {
assumeFalse("JDK bug JDK-8266279, https://github.com/elastic/elasticsearch/issues/72359",
JavaVersion.current().compareTo(JavaVersion.parse("8")) == 0);
final Path outFile = testRoot.resolve("certs.zip").toAbsolutePath();

final int numberCerts = randomIntBetween(3, 6);
Expand Down Expand Up @@ -478,8 +478,6 @@ public void testGenerateMultipleCertificateWithNewCA() throws Exception {
}

public void testParsingValidityPeriod() throws Exception {
assumeFalse("JDK bug JDK-8266279, https://github.com/elastic/elasticsearch/issues/72359",
JavaVersion.current().compareTo(JavaVersion.parse("8")) == 0);
final HttpCertificateCommand command = new HttpCertificateCommand();
final MockTerminal terminal = new MockTerminal();

Expand Down Expand Up @@ -533,8 +531,6 @@ public void testParsingValidityPeriod() throws Exception {
}

public void testValidityPeriodToString() throws Exception {
assumeFalse("JDK bug JDK-8266279, https://github.com/elastic/elasticsearch/issues/72359",
JavaVersion.current().compareTo(JavaVersion.parse("8")) == 0);
assertThat(HttpCertificateCommand.toString(Period.ofYears(2)), is("2y"));
assertThat(HttpCertificateCommand.toString(Period.ofMonths(5)), is("5m"));
assertThat(HttpCertificateCommand.toString(Period.ofDays(60)), is("60d"));
Expand All @@ -548,8 +544,6 @@ public void testValidityPeriodToString() throws Exception {
}

public void testGuessFileType() throws Exception {
assumeFalse("JDK bug JDK-8266279, https://github.com/elastic/elasticsearch/issues/72359",
JavaVersion.current().compareTo(JavaVersion.parse("8")) == 0);
MockTerminal terminal = new MockTerminal();

final Path caCert = getDataPath("ca.crt");
Expand Down Expand Up @@ -577,8 +571,6 @@ public void testGuessFileType() throws Exception {
}

public void testTextFileSubstitutions() throws Exception {
assumeFalse("JDK bug JDK-8266279, https://github.com/elastic/elasticsearch/issues/72359",
JavaVersion.current().compareTo(JavaVersion.parse("8")) == 0);
CheckedBiFunction<String, Map<String, String>, String, Exception> copy = (source, subs) -> {
try (InputStream in = new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8));
StringWriter out = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.elasticsearch.xpack.core.security.authc.support.UserRoleMapper;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.BeforeClass;
import org.mockito.Mockito;
import org.opensaml.saml.common.xml.SAMLConstants;
import org.opensaml.saml.metadata.resolver.impl.AbstractReloadingMetadataResolver;
Expand Down Expand Up @@ -113,6 +114,12 @@ public void setupEnv() throws PrivilegedActionException {
threadContext = new ThreadContext(globalSettings);
}

@BeforeClass
public static void muteOnBrokenJdk() {
assumeFalse("JDK bug JDK-8266279, https://github.com/elastic/elasticsearch/issues/75571",
"1.8.0_292".equals(System.getProperty("java.version")));
}

public void testReadIdpMetadataFromFile() throws Exception {
final Path path = getDataPath("idp1.xml");
Tuple<RealmConfig, SSLService> config = buildConfig(path.toString());
Expand Down

0 comments on commit 5740949

Please sign in to comment.