From aad1b3a2a0d825c6ecb7e753772ca8ef55600760 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 4 Jun 2019 18:21:20 -0400 Subject: [PATCH] Fix version parsing in various tests (#42871) This commit fixes the version parsing in various tests. The issue here is that the parsing was relying on java.version. However, java.version can contain additional characters such as -ea for early access builds. See JEP 233: Name Syntax ------------------------------ -------------- java.version $VNUM(\-$PRE)? java.runtime.version $VSTR java.vm.version $VSTR java.specification.version $VNUM java.vm.specification.version $VNUM Instead, we want java.specification.version. --- .../org/elasticsearch/client/RestClientBuilderIntegTests.java | 2 +- .../azure/classic/AzureDiscoveryClusterFormationTests.java | 3 ++- .../xpack/monitoring/exporter/http/HttpExporterSslIT.java | 3 ++- .../xpack/security/authc/saml/SamlRealmTests.java | 3 ++- .../java/org/elasticsearch/xpack/ssl/SSLClientAuthTests.java | 3 ++- .../watcher/actions/webhook/WebhookHttpsIntegrationTests.java | 3 ++- .../xpack/watcher/common/http/HttpClientTests.java | 3 ++- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderIntegTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderIntegTests.java index 780cc447ba8..ca6443f6c6b 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderIntegTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientBuilderIntegTests.java @@ -134,7 +134,7 @@ public class RestClientBuilderIntegTests extends RestClientTestCase { * 12.0.1 so we pin to TLSv1.2 when running on an earlier JDK. */ private static String getProtocol() { - String version = AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty("java.version")); + String version = AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty("java.specification.version")); String[] components = version.split("\\."); if (components.length > 0) { final int major = Integer.valueOf(components[0]); diff --git a/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java b/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java index 8bfb373f644..7f45708c76a 100644 --- a/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java +++ b/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java @@ -281,7 +281,8 @@ public class AzureDiscoveryClusterFormationTests extends ESIntegTestCase { return "TLSv1.2"; } else { JavaVersion full = - AccessController.doPrivileged((PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.version"))); + AccessController.doPrivileged( + (PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.specification.version"))); if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) { return "TLSv1.2"; } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterSslIT.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterSslIT.java index 9e16f669ae8..333388358be 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterSslIT.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterSslIT.java @@ -205,7 +205,8 @@ public class HttpExporterSslIT extends MonitoringIntegTestCase { return Collections.singletonList("TLSv1.2"); } else { JavaVersion full = - AccessController.doPrivileged((PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.version"))); + AccessController.doPrivileged( + (PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.specification.version"))); if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) { return Collections.singletonList("TLSv1.2"); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlRealmTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlRealmTests.java index aea50691119..32e436f1d77 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlRealmTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlRealmTests.java @@ -733,7 +733,8 @@ public class SamlRealmTests extends SamlTestCase { return Collections.singletonList("TLSv1.2"); } else { JavaVersion full = - AccessController.doPrivileged((PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.version"))); + AccessController.doPrivileged( + (PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.specification.version"))); if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) { return Collections.singletonList("TLSv1.2"); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/ssl/SSLClientAuthTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/ssl/SSLClientAuthTests.java index 85f18ddff92..3deee4b68c5 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/ssl/SSLClientAuthTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/ssl/SSLClientAuthTests.java @@ -213,7 +213,8 @@ public class SSLClientAuthTests extends SecurityIntegTestCase { return XPackSettings.DEFAULT_SUPPORTED_PROTOCOLS; } JavaVersion full = - AccessController.doPrivileged((PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.version"))); + AccessController.doPrivileged( + (PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.specification.version"))); if (full.compareTo(JavaVersion.parse("11.0.3")) < 0) { return Collections.singletonList("TLSv1.2"); } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java index d93657acdc0..985e26e7665 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java @@ -151,7 +151,8 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest return Collections.singletonList("TLSv1.2"); } else { JavaVersion full = - AccessController.doPrivileged((PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.version"))); + AccessController.doPrivileged( + (PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.specification.version"))); if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) { return Collections.singletonList("TLSv1.2"); } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java index 3ae96499b6a..5edcd10935e 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/common/http/HttpClientTests.java @@ -760,7 +760,8 @@ public class HttpClientTests extends ESTestCase { return Collections.singletonList("TLSv1.2"); } else { JavaVersion full = - AccessController.doPrivileged((PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.version"))); + AccessController.doPrivileged( + (PrivilegedAction) () -> JavaVersion.parse(System.getProperty("java.specification.version"))); if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) { return Collections.singletonList("TLSv1.2"); }