From 134cdb22bba42a0ce9095399ba128ff4305e54fc Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 16 Dec 2015 18:13:56 -0800 Subject: [PATCH] Fix xplugins to suppress mock transport and transport service This is the xplugins side of elastic/elasticsearchelastic/elasticsearch#15495 Original commit: elastic/x-pack-elasticsearch@9c29c057a5d99b8d78c95c9d6b616f87235a3ef9 --- .../elasticsearch/license/plugin/LicensePlugin.java | 10 +++++++--- .../marvel/test/MarvelIntegTestCase.java | 11 +++++++++++ .../java/org/elasticsearch/shield/ShieldPlugin.java | 6 ++++-- .../shield/audit/AuditTrailModuleTests.java | 11 +++++++++-- .../shield/audit/index/IndexAuditTrailTests.java | 2 +- .../index/RemoteIndexAuditTrailStartingTests.java | 2 +- .../shield/transport/TransportFilterTests.java | 4 ++-- .../org/elasticsearch/test/ShieldIntegTestCase.java | 12 ++++++++++++ .../test/AbstractWatcherIntegrationTestCase.java | 10 ++++++++++ 9 files changed, 57 insertions(+), 11 deletions(-) diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/LicensePlugin.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/LicensePlugin.java index dadb239372f..1525e27e686 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/LicensePlugin.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/LicensePlugin.java @@ -35,6 +35,7 @@ public class LicensePlugin extends Plugin { public static final String NAME = "license"; private final boolean isEnabled; + protected final boolean transportClient; static { MetaData.registerPrototype(LicensesMetaData.TYPE, LicensesMetaData.PROTO); @@ -48,6 +49,7 @@ public class LicensePlugin extends Plugin { } else { this.isEnabled = true; } + transportClient = "transport".equals(settings.get(Client.CLIENT_TYPE_SETTING)); } @Override @@ -61,9 +63,11 @@ public class LicensePlugin extends Plugin { } public void onModule(NetworkModule module) { - module.registerRestHandler(RestPutLicenseAction.class); - module.registerRestHandler(RestGetLicenseAction.class); - module.registerRestHandler(RestDeleteLicenseAction.class); + if (transportClient == false) { + module.registerRestHandler(RestPutLicenseAction.class); + module.registerRestHandler(RestGetLicenseAction.class); + module.registerRestHandler(RestDeleteLicenseAction.class); + } } public void onModule(ActionModule module) { diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java index edb7e97c1a1..5c973fa091d 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/test/MarvelIntegTestCase.java @@ -29,6 +29,8 @@ import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.crypto.InternalCryptoService; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.TestCluster; +import org.elasticsearch.test.transport.AssertingLocalTransport; +import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.xpack.XPackPlugin; import org.hamcrest.Matcher; import org.jboss.netty.util.internal.SystemPropertyUtil; @@ -41,6 +43,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -99,6 +102,14 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase { .build(); } + @Override + protected Collection> getMockPlugins() { + Set> plugins = new HashSet<>(super.getMockPlugins()); + plugins.remove(MockTransportService.TestPlugin.class); // shield has its own transport service + plugins.remove(AssertingLocalTransport.TestPlugin.class); // shield has its own transport + return plugins; + } + @Override protected Collection> nodePlugins() { return Collections.singletonList(XPackPlugin.class); diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java index fdf1ce197c7..d1d7471904d 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java @@ -192,8 +192,10 @@ public class ShieldPlugin extends Plugin { } public void onModule(NetworkModule module) { - // we want to expose the shield rest action even when the plugin is disabled - module.registerRestHandler(RestShieldInfoAction.class); + if (clientMode == false) { + // we want to expose the shield rest action even when the plugin is disabled + module.registerRestHandler(RestShieldInfoAction.class); + } if (enabled == false) { return; diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/AuditTrailModuleTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/AuditTrailModuleTests.java index 1ce2aeb1a62..f4a67e90f6d 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/AuditTrailModuleTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/AuditTrailModuleTests.java @@ -18,6 +18,8 @@ import org.elasticsearch.shield.audit.logfile.LoggingAuditTrail; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPoolModule; +import org.elasticsearch.transport.Transport; +import org.elasticsearch.transport.local.LocalTransport; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; @@ -54,11 +56,16 @@ public class AuditTrailModuleTests extends ESTestCase { try { Injector injector = Guice.createInjector( new SettingsModule(settings, new SettingsFilter(settings)), + new NetworkModule(new NetworkService(settings), settings, false) { + @Override + protected void configure() { + bind(Transport.class).to(LocalTransport.class).asEagerSingleton(); + } + }, new AuditTrailModule(settings), new CircuitBreakerModule(settings), new ThreadPoolModule(pool), - new Version.Module(Version.CURRENT), - new NetworkModule(new NetworkService(settings), settings, false) + new Version.Module(Version.CURRENT) ); AuditTrail auditTrail = injector.getInstance(AuditTrail.class); assertThat(auditTrail, instanceOf(AuditTrailService.class)); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java index ecac2284805..522f0710b94 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java @@ -157,7 +157,7 @@ public class IndexAuditTrailTests extends ShieldIntegTestCase { return builder.build(); } }; - cluster2 = new InternalTestCluster("network", randomLong(), createTempDir(), numNodes, numNodes, cluster2Name, cluster2SettingsSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, true); + cluster2 = new InternalTestCluster("network", randomLong(), createTempDir(), numNodes, numNodes, cluster2Name, cluster2SettingsSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, getMockPlugins()); cluster2.beforeTest(getRandom(), 0.5); remoteClient = cluster2.client(); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/RemoteIndexAuditTrailStartingTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/RemoteIndexAuditTrailStartingTests.java index decd5f6630b..dd83018bcd6 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/RemoteIndexAuditTrailStartingTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/audit/index/RemoteIndexAuditTrailStartingTests.java @@ -106,7 +106,7 @@ public class RemoteIndexAuditTrailStartingTests extends ShieldIntegTestCase { return builder.build(); } }; - remoteCluster = new InternalTestCluster("network", randomLong(), createTempDir(), numNodes, numNodes, cluster2Name, cluster2SettingsSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, true); + remoteCluster = new InternalTestCluster("network", randomLong(), createTempDir(), numNodes, numNodes, cluster2Name, cluster2SettingsSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, getMockPlugins()); remoteCluster.beforeTest(getRandom(), 0.5); } diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java index 3bf60884e1a..734503e168e 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java @@ -63,8 +63,8 @@ public class TransportFilterTests extends ESIntegTestCase { } @Override - protected boolean enableMockModules() { - return false; + protected Collection> getMockPlugins() { + return Collections.emptyList(); } @Override diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldIntegTestCase.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldIntegTestCase.java index de09dcddbaa..c9d715e08ed 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldIntegTestCase.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldIntegTestCase.java @@ -14,6 +14,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.test.ESIntegTestCase.SuppressLocalMode; +import org.elasticsearch.test.transport.AssertingLocalTransport; +import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.xpack.XPackPlugin; import org.junit.AfterClass; import org.junit.Before; @@ -23,6 +25,8 @@ import org.junit.rules.ExternalResource; import java.nio.file.Path; import java.util.Collection; +import java.util.HashSet; +import java.util.Set; import java.util.stream.Collectors; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; @@ -145,6 +149,14 @@ public abstract class ShieldIntegTestCase extends ESIntegTestCase { .build(); } + @Override + protected Collection> getMockPlugins() { + Set> plugins = new HashSet<>(super.getMockPlugins()); + plugins.remove(MockTransportService.TestPlugin.class); // shield has its own transport service + plugins.remove(AssertingLocalTransport.TestPlugin.class); // shield has its own transport + return plugins; + } + @Override protected Collection> nodePlugins() { return customShieldSettingsSource.nodePlugins(); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java index 0f938d7aca2..d0e9ca88bf5 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -31,6 +31,8 @@ import org.elasticsearch.shield.crypto.InternalCryptoService; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.TestCluster; +import org.elasticsearch.test.transport.AssertingLocalTransport; +import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.watcher.WatcherLifeCycleService; import org.elasticsearch.watcher.WatcherModule; import org.elasticsearch.watcher.WatcherService; @@ -127,6 +129,14 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase return excludes; } + @Override + protected Collection> getMockPlugins() { + Set> plugins = new HashSet<>(super.getMockPlugins()); + plugins.remove(MockTransportService.TestPlugin.class); // shield has its own transport service + plugins.remove(AssertingLocalTransport.TestPlugin.class); // shield has its own transport + return plugins; + } + @Override protected Collection> nodePlugins() { return pluginTypes();