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.
This commit is contained in:
Jason Tedor 2019-06-04 18:21:20 -04:00
parent 72eb9c2d44
commit aad1b3a2a0
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
7 changed files with 13 additions and 7 deletions

View File

@ -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<String>) () -> System.getProperty("java.version"));
String version = AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("java.specification.version"));
String[] components = version.split("\\.");
if (components.length > 0) {
final int major = Integer.valueOf(components[0]);

View File

@ -281,7 +281,8 @@ public class AzureDiscoveryClusterFormationTests extends ESIntegTestCase {
return "TLSv1.2";
} else {
JavaVersion full =
AccessController.doPrivileged((PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.version")));
AccessController.doPrivileged(
(PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.specification.version")));
if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) {
return "TLSv1.2";
}

View File

@ -205,7 +205,8 @@ public class HttpExporterSslIT extends MonitoringIntegTestCase {
return Collections.singletonList("TLSv1.2");
} else {
JavaVersion full =
AccessController.doPrivileged((PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.version")));
AccessController.doPrivileged(
(PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.specification.version")));
if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) {
return Collections.singletonList("TLSv1.2");
}

View File

@ -733,7 +733,8 @@ public class SamlRealmTests extends SamlTestCase {
return Collections.singletonList("TLSv1.2");
} else {
JavaVersion full =
AccessController.doPrivileged((PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.version")));
AccessController.doPrivileged(
(PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.specification.version")));
if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) {
return Collections.singletonList("TLSv1.2");
}

View File

@ -213,7 +213,8 @@ public class SSLClientAuthTests extends SecurityIntegTestCase {
return XPackSettings.DEFAULT_SUPPORTED_PROTOCOLS;
}
JavaVersion full =
AccessController.doPrivileged((PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.version")));
AccessController.doPrivileged(
(PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.specification.version")));
if (full.compareTo(JavaVersion.parse("11.0.3")) < 0) {
return Collections.singletonList("TLSv1.2");
}

View File

@ -151,7 +151,8 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
return Collections.singletonList("TLSv1.2");
} else {
JavaVersion full =
AccessController.doPrivileged((PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.version")));
AccessController.doPrivileged(
(PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.specification.version")));
if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) {
return Collections.singletonList("TLSv1.2");
}

View File

@ -760,7 +760,8 @@ public class HttpClientTests extends ESTestCase {
return Collections.singletonList("TLSv1.2");
} else {
JavaVersion full =
AccessController.doPrivileged((PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.version")));
AccessController.doPrivileged(
(PrivilegedAction<JavaVersion>) () -> JavaVersion.parse(System.getProperty("java.specification.version")));
if (full.compareTo(JavaVersion.parse("12.0.1")) < 0) {
return Collections.singletonList("TLSv1.2");
}