From b39c3c2d21d0f06a0dc2b74fbe102a584e7d9f22 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Fri, 13 Aug 2021 13:31:44 -0500 Subject: [PATCH 1/6] Adding deprecation check for es.unsafely_permit_handshake_from_incompatible_builds --- x-pack/plugin/deprecation/build.gradle | 4 ++++ .../xpack/deprecation/DeprecationChecks.java | 3 ++- .../deprecation/NodeDeprecationChecks.java | 22 +++++++++++++++++++ .../NodeDeprecationChecksTests.java | 21 ++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/deprecation/build.gradle b/x-pack/plugin/deprecation/build.gradle index 0c1e8fd680335..3a84778177119 100644 --- a/x-pack/plugin/deprecation/build.gradle +++ b/x-pack/plugin/deprecation/build.gradle @@ -14,3 +14,7 @@ dependencies { compileOnly project(":x-pack:plugin:core") implementation project(path: xpackModule('monitoring')) } + +tasks.named("test").configure { + systemProperty 'tests.security.manager', 'false' +} diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index dddccceb358ac..448cd64082a0e 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -95,7 +95,8 @@ private DeprecationChecks() { NodeDeprecationChecks::checkSingleDataNodeWatermarkSetting, NodeDeprecationChecks::checkImplicitlyDisabledSecurityOnBasicAndTrial, NodeDeprecationChecks::checkMonitoringExporterPassword, - NodeDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting + NodeDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting, + NodeDeprecationChecks::checkNoPermitHandshakeFromIncompatibleBuilds ) ).collect(Collectors.toList()); } diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index 4968eea4ed60f..3a56d11934e90 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -595,4 +595,26 @@ static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(f DeprecationIssue.Level.CRITICAL ); } + + static DeprecationIssue checkNoPermitHandshakeFromIncompatibleBuilds(final Settings settings, + final PluginsAndModules pluginsAndModules, + final ClusterState clusterState, + final XPackLicenseState licenseState) { + final String PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY = "es.unsafely_permit_handshake_from_incompatible_builds"; + if (System.getProperty(PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY) != null) { + final String message = String.format( + Locale.ROOT, + "system property [%s] must not be set", + PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY + ); + final String details = String.format( + Locale.ROOT, + "remove the system property [%s]", + PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY + ); + String url = "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_transport_changes"; + return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details, false, null); + } + return null; + } } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 0886f0dfe28fd..b4e083fce463a 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -863,4 +863,25 @@ public void testImplicitlyConfiguredSecurityOnGoldPlus() { final List issues = getDeprecationIssues(settings, pluginsAndModules, licenseState); assertThat(issues, empty()); } + + public void testCheckNoPermitHandshakeFromIncompatibleBuilds() { + final DeprecationIssue expectedNullIssue = + NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(Settings.EMPTY, + null, + ClusterState.EMPTY_STATE, + new XPackLicenseState(Settings.EMPTY, () -> 0)); + assertEquals(null, expectedNullIssue); + System.setProperty("es.unsafely_permit_handshake_from_incompatible_builds", randomAlphaOfLengthBetween(1, 10)); + + final DeprecationIssue issue = + NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(Settings.EMPTY, + null, + ClusterState.EMPTY_STATE, + new XPackLicenseState(Settings.EMPTY, () -> 0)); + assertNotNull(issue.getDetails()); + assertThat(issue.getDetails(), containsString("remove the system property ")); + assertThat(issue.getUrl(), + equalTo("https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_transport_changes")); + System.clearProperty("es.unsafely_permit_handshake_from_incompatible_builds"); + } } From a29a791d781d879185b828c927df4207125dee7f Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Fri, 13 Aug 2021 13:48:51 -0500 Subject: [PATCH 2/6] suppressing build error --- .../xpack/deprecation/NodeDeprecationChecksTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index b4e083fce463a..0cd688e6f8b35 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -20,6 +20,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.core.Set; +import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.env.Environment; import org.elasticsearch.license.License; import org.elasticsearch.license.XPackLicenseState; @@ -864,6 +865,7 @@ public void testImplicitlyConfiguredSecurityOnGoldPlus() { assertThat(issues, empty()); } + @SuppressForbidden(reason = "sets and unsets es.unsafely_permit_handshake_from_incompatible_builds") public void testCheckNoPermitHandshakeFromIncompatibleBuilds() { final DeprecationIssue expectedNullIssue = NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(Settings.EMPTY, From 2877d283e43d6aa47bc9304c39dcf01dbfad9d3d Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 26 Aug 2021 17:14:49 -0500 Subject: [PATCH 3/6] feedback from code review --- .../elasticsearch/transport/TransportService.java | 2 +- .../xpack/deprecation/NodeDeprecationChecks.java | 13 +++++++------ .../deprecation/NodeDeprecationChecksTests.java | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/transport/TransportService.java b/server/src/main/java/org/elasticsearch/transport/TransportService.java index 4ae74abdbff8e..32fa1c7615a25 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportService.java @@ -70,7 +70,7 @@ public class TransportService extends AbstractLifecycleComponent private static final Logger logger = LogManager.getLogger(TransportService.class); - private static final String PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY = "es.unsafely_permit_handshake_from_incompatible_builds"; + public static final String PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY = "es.unsafely_permit_handshake_from_incompatible_builds"; private static final boolean PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS; static { diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index 3a56d11934e90..4fb2578834399 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -30,6 +30,7 @@ import org.elasticsearch.script.ScriptService; import org.elasticsearch.threadpool.FixedExecutorBuilder; import org.elasticsearch.transport.RemoteClusterService; +import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.security.authc.RealmConfig; import org.elasticsearch.xpack.core.security.authc.RealmSettings; @@ -600,17 +601,17 @@ static DeprecationIssue checkNoPermitHandshakeFromIncompatibleBuilds(final Setti final PluginsAndModules pluginsAndModules, final ClusterState clusterState, final XPackLicenseState licenseState) { - final String PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY = "es.unsafely_permit_handshake_from_incompatible_builds"; - if (System.getProperty(PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY) != null) { + if (System.getProperty(TransportService.PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY) != null) { final String message = String.format( Locale.ROOT, - "system property [%s] must not be set", - PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY + "the [%s] system property is deprecated and will be removed in the next major release", + TransportService.PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY ); final String details = String.format( Locale.ROOT, - "remove the system property [%s]", - PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY + "allowing handshakes from incompatibile builds is deprecated and will be removed in the next major release; the [%s] " + + "system property must be removed", + TransportService.PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY ); String url = "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_transport_changes"; return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details, false, null); diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 0cd688e6f8b35..ef2fdafb9155b 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -881,7 +881,7 @@ public void testCheckNoPermitHandshakeFromIncompatibleBuilds() { ClusterState.EMPTY_STATE, new XPackLicenseState(Settings.EMPTY, () -> 0)); assertNotNull(issue.getDetails()); - assertThat(issue.getDetails(), containsString("remove the system property ")); + assertThat(issue.getDetails(), containsString("system property is deprecated and will be removed in the next major release")); assertThat(issue.getUrl(), equalTo("https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_transport_changes")); System.clearProperty("es.unsafely_permit_handshake_from_incompatible_builds"); From 0635ad511a7df246cc1f4d19fc7a91cae71c2397 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 26 Aug 2021 17:53:21 -0500 Subject: [PATCH 4/6] fixing unit tests --- .../NodeDeprecationChecksTests.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index ef2fdafb9155b..5c3560ad65287 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -874,16 +874,18 @@ public void testCheckNoPermitHandshakeFromIncompatibleBuilds() { new XPackLicenseState(Settings.EMPTY, () -> 0)); assertEquals(null, expectedNullIssue); System.setProperty("es.unsafely_permit_handshake_from_incompatible_builds", randomAlphaOfLengthBetween(1, 10)); - - final DeprecationIssue issue = - NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(Settings.EMPTY, - null, - ClusterState.EMPTY_STATE, - new XPackLicenseState(Settings.EMPTY, () -> 0)); - assertNotNull(issue.getDetails()); - assertThat(issue.getDetails(), containsString("system property is deprecated and will be removed in the next major release")); - assertThat(issue.getUrl(), - equalTo("https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_transport_changes")); - System.clearProperty("es.unsafely_permit_handshake_from_incompatible_builds"); + try { + final DeprecationIssue issue = + NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(Settings.EMPTY, + null, + ClusterState.EMPTY_STATE, + new XPackLicenseState(Settings.EMPTY, () -> 0)); + assertNotNull(issue.getDetails()); + assertThat(issue.getDetails(), containsString("system property must be removed")); + assertThat(issue.getUrl(), + equalTo("https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_transport_changes")); + } finally { + System.clearProperty("es.unsafely_permit_handshake_from_incompatible_builds"); + } } } From 298dc8f77bc14804c18a19dbbd1845d4c73399bd Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Wed, 1 Sep 2021 15:50:57 -0500 Subject: [PATCH 5/6] avoiding disabling unit test security manager --- x-pack/plugin/deprecation/build.gradle | 4 ---- .../xpack/deprecation/NodeDeprecationChecks.java | 10 +++++++++- .../xpack/deprecation/NodeDeprecationChecksTests.java | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/deprecation/build.gradle b/x-pack/plugin/deprecation/build.gradle index 3a84778177119..0c1e8fd680335 100644 --- a/x-pack/plugin/deprecation/build.gradle +++ b/x-pack/plugin/deprecation/build.gradle @@ -14,7 +14,3 @@ dependencies { compileOnly project(":x-pack:plugin:core") implementation project(path: xpackModule('monitoring')) } - -tasks.named("test").configure { - systemProperty 'tests.security.manager', 'false' -} diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index 4fb2578834399..933b7a3b82ad2 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -597,11 +597,18 @@ static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(f ); } + /* + * This is here so that the unit test can simulate setting a system property without actually having to set the system property, + * which requires disabling the security manager for the unit test. + */ + static String permitsHandshakesFromIncompatibleBuildsSupplier = + System.getProperty(TransportService.PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY); + static DeprecationIssue checkNoPermitHandshakeFromIncompatibleBuilds(final Settings settings, final PluginsAndModules pluginsAndModules, final ClusterState clusterState, final XPackLicenseState licenseState) { - if (System.getProperty(TransportService.PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY) != null) { + if (permitsHandshakesFromIncompatibleBuildsSupplier != null) { final String message = String.format( Locale.ROOT, "the [%s] system property is deprecated and will be removed in the next major release", @@ -618,4 +625,5 @@ static DeprecationIssue checkNoPermitHandshakeFromIncompatibleBuilds(final Setti } return null; } + } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 5c3560ad65287..39185ee61e465 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -873,7 +873,7 @@ public void testCheckNoPermitHandshakeFromIncompatibleBuilds() { ClusterState.EMPTY_STATE, new XPackLicenseState(Settings.EMPTY, () -> 0)); assertEquals(null, expectedNullIssue); - System.setProperty("es.unsafely_permit_handshake_from_incompatible_builds", randomAlphaOfLengthBetween(1, 10)); + NodeDeprecationChecks.permitsHandshakesFromIncompatibleBuildsSupplier = randomAlphaOfLengthBetween(1, 10); try { final DeprecationIssue issue = NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(Settings.EMPTY, @@ -885,7 +885,8 @@ public void testCheckNoPermitHandshakeFromIncompatibleBuilds() { assertThat(issue.getUrl(), equalTo("https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_transport_changes")); } finally { - System.clearProperty("es.unsafely_permit_handshake_from_incompatible_builds"); + // Setting this back so that other tests don't fail + NodeDeprecationChecks.permitsHandshakesFromIncompatibleBuildsSupplier = null; } } } From 3f7ef45840506517398b8bc4201084d7afecbba5 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 2 Sep 2021 17:17:47 -0500 Subject: [PATCH 6/6] moving the System.getProperty() call to a function --- .../xpack/deprecation/DeprecationChecks.java | 5 +++- .../deprecation/NodeDeprecationChecks.java | 13 +++------ .../NodeDeprecationChecksTests.java | 28 ++++++++----------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index be71ef7e8c559..a026823656c6d 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -12,6 +12,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.XPackSettings; import java.util.Arrays; @@ -98,7 +99,9 @@ private DeprecationChecks() { NodeDeprecationChecks::checkSearchRemoteSettings, NodeDeprecationChecks::checkMonitoringExporterPassword, NodeDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting, - NodeDeprecationChecks::checkNoPermitHandshakeFromIncompatibleBuilds, + (settings, pluginsAndModules, clusterState, licenseState) -> + NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(settings, pluginsAndModules, clusterState, + licenseState, () -> System.getProperty(TransportService.PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY)), NodeDeprecationChecks::checkTransportClientProfilesFilterSetting, NodeDeprecationChecks::checkDelayClusterStateRecoverySettings, NodeDeprecationChecks::checkFixedAutoQueueSizeThreadpool, diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index c4c092ff49e33..8478e97e00547 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -52,6 +52,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; +import java.util.function.Supplier; import java.util.stream.Collectors; import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING; @@ -667,18 +668,12 @@ static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(f ); } - /* - * This is here so that the unit test can simulate setting a system property without actually having to set the system property, - * which requires disabling the security manager for the unit test. - */ - static String permitsHandshakesFromIncompatibleBuildsSupplier = - System.getProperty(TransportService.PERMIT_HANDSHAKES_FROM_INCOMPATIBLE_BUILDS_KEY); - static DeprecationIssue checkNoPermitHandshakeFromIncompatibleBuilds(final Settings settings, final PluginsAndModules pluginsAndModules, final ClusterState clusterState, - final XPackLicenseState licenseState) { - if (permitsHandshakesFromIncompatibleBuildsSupplier != null) { + final XPackLicenseState licenseState, + Supplier permitsHandshakesFromIncompatibleBuildsSupplier) { + if (permitsHandshakesFromIncompatibleBuildsSupplier.get() != null) { final String message = String.format( Locale.ROOT, "the [%s] system property is deprecated and will be removed in the next major release", diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index a00f3618d9909..c58e66b0df2f7 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -969,23 +969,19 @@ public void testCheckNoPermitHandshakeFromIncompatibleBuilds() { NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(Settings.EMPTY, null, ClusterState.EMPTY_STATE, - new XPackLicenseState(Settings.EMPTY, () -> 0)); + new XPackLicenseState(Settings.EMPTY, () -> 0), + () -> null); assertEquals(null, expectedNullIssue); - NodeDeprecationChecks.permitsHandshakesFromIncompatibleBuildsSupplier = randomAlphaOfLengthBetween(1, 10); - try { - final DeprecationIssue issue = - NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(Settings.EMPTY, - null, - ClusterState.EMPTY_STATE, - new XPackLicenseState(Settings.EMPTY, () -> 0)); - assertNotNull(issue.getDetails()); - assertThat(issue.getDetails(), containsString("system property must be removed")); - assertThat(issue.getUrl(), - equalTo("https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_transport_changes")); - } finally { - // Setting this back so that other tests don't fail - NodeDeprecationChecks.permitsHandshakesFromIncompatibleBuildsSupplier = null; - } + final DeprecationIssue issue = + NodeDeprecationChecks.checkNoPermitHandshakeFromIncompatibleBuilds(Settings.EMPTY, + null, + ClusterState.EMPTY_STATE, + new XPackLicenseState(Settings.EMPTY, () -> 0), + () -> randomAlphaOfLengthBetween(1, 10)); + assertNotNull(issue.getDetails()); + assertThat(issue.getDetails(), containsString("system property must be removed")); + assertThat(issue.getUrl(), + equalTo("https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_transport_changes")); } public void testCheckTransportClientProfilesFilterSetting() {