From 13a8c98cb29aca42e8cbfbdc6d066b9065fe4e27 Mon Sep 17 00:00:00 2001 From: uboness Date: Thu, 26 Nov 2015 17:05:19 +0100 Subject: [PATCH] [WIP] unified x-pack repo restructuring - added the license-plugin dir as a src dir - Made XPackPlugin customizable for tests. Now tests that need to plug in different behaviours (e.g. a custom license plugin) can do that by simply resetting the relevant delegee plugins (i.e. shield, marvel, license, watcher) in the ctor of a new XPackPlugin. Original commit: elastic/x-pack-elasticsearch@ab83104955831b0c72dd7329b3e6a08a9578a609 --- elasticsearch/x-pack/build.gradle | 11 +++- ...nsesConsumerPluginIntegrationTestCase.java | 1 + .../AbstractLicensesIntegrationTestCase.java | 7 ++- .../LicensesPluginIntegrationTests.java | 1 + .../LicensesPluginsIntegrationTests.java | 2 + .../plugin/LicensesServiceClusterTests.java | 1 + .../plugin/LicensesServiceNodeTests.java | 1 + .../collector/AbstractCollectorTestCase.java | 50 +++++++++------- .../license/LicenseIntegrationTests.java | 38 ++++++++++--- .../marvel/test/MarvelIntegTestCase.java | 10 ++-- .../integration/LicensingTests.java | 57 ++++++++++++------- .../authc/AuthenticationModuleTests.java | 4 +- .../authc/pki/PkiAuthenticationTests.java | 1 + .../filter/IpFilteringUpdateTests.java | 1 + .../ShieldNettyHttpServerTransportTests.java | 1 + .../test/ShieldIntegTestCase.java | 17 ++++-- .../test/ShieldSettingsSource.java | 13 ++++- .../org/elasticsearch/xpack/XPackPlugin.java | 14 ++++- .../watcher/license/LicenseTests.java | 1 + .../AbstractWatcherIntegrationTestCase.java | 37 ++++-------- 20 files changed, 173 insertions(+), 95 deletions(-) diff --git a/elasticsearch/x-pack/build.gradle b/elasticsearch/x-pack/build.gradle index dd39aeba445..786ea6d9198 100644 --- a/elasticsearch/x-pack/build.gradle +++ b/elasticsearch/x-pack/build.gradle @@ -44,7 +44,7 @@ dependencies { // we keep the source directories in the original structure of split plugins, // in order to facilitate backports to 2.x. TODO: remove after 5.0 release -for (String module : ['', 'license/', 'shield/', 'watcher/', 'marvel/']) { +for (String module : ['', 'license-plugin/', 'shield/', 'watcher/', 'marvel/']) { sourceSets { main { java.srcDir("${module}src/main/java") @@ -77,8 +77,13 @@ processResources { } processTestResources { - inputs.properties(expansions) - MavenFilteringHack.filter(it, expansions) + from(sourceSets.test.resources.srcDirs) { + exclude '**/*.key' + exclude '**/*.jks' + exclude '**/*.p12' + inputs.properties(expansions) + MavenFilteringHack.filter(it, expansions) + } } forbiddenPatterns { diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesConsumerPluginIntegrationTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesConsumerPluginIntegrationTestCase.java index 2a0e28ba5fe..3484a9c41a8 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesConsumerPluginIntegrationTestCase.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesConsumerPluginIntegrationTestCase.java @@ -14,6 +14,7 @@ import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.InternalTestCluster; +import org.elasticsearch.xpack.XPackPlugin; import org.junit.After; import java.util.ArrayList; diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTestCase.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTestCase.java index 02d337d2e67..fd96745b9c4 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTestCase.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTestCase.java @@ -23,6 +23,7 @@ import org.elasticsearch.license.plugin.core.*; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; +import org.elasticsearch.xpack.XPackPlugin; import java.util.ArrayList; import java.util.Collection; @@ -39,7 +40,11 @@ public abstract class AbstractLicensesIntegrationTestCase extends ESIntegTestCas @Override protected Settings nodeSettings(int nodeOrdinal) { - return Settings.EMPTY; + return Settings.builder() + .put("shield.enabled", false) + .put("marvel.enabled", false) + .put("watcher.enabled", false) + .build(); } @Override diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesPluginIntegrationTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesPluginIntegrationTests.java index f0af579cb79..e8275719ae5 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesPluginIntegrationTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesPluginIntegrationTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.license.plugin.consumer.LazyLicenseRegistrationPluginSe import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; +import org.elasticsearch.xpack.XPackPlugin; import org.junit.After; import java.util.Arrays; diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesPluginsIntegrationTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesPluginsIntegrationTests.java index ae3cfcfda36..ec293da26d6 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesPluginsIntegrationTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesPluginsIntegrationTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.license.plugin.consumer.LazyLicenseRegistrationPluginSe import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; +import org.elasticsearch.xpack.XPackPlugin; import org.junit.After; import java.util.Arrays; @@ -26,6 +27,7 @@ import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; @BadApple(bugUrl = "https://github.com/elastic/x-plugins/issues/1007") @ClusterScope(scope = TEST, numDataNodes = 0, numClientNodes = 0) public class LicensesPluginsIntegrationTests extends AbstractLicensesIntegrationTestCase { + private static final String ID_1 = EagerLicenseRegistrationPluginService.ID; private static final String ID_2 = LazyLicenseRegistrationPluginService.ID; diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTests.java index c3cbc3f81b3..756e96c3fde 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTests.java @@ -30,6 +30,7 @@ import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.InternalTestCluster; +import org.elasticsearch.xpack.XPackPlugin; import java.util.Arrays; import java.util.Collection; diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceNodeTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceNodeTests.java index edc57aaac2f..1ad36215294 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceNodeTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/LicensesServiceNodeTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.xpack.XPackPlugin; import java.util.Arrays; import java.util.Collection; diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/AbstractCollectorTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/AbstractCollectorTestCase.java index d74fbcd5aab..49ccbd0b29f 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/AbstractCollectorTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/AbstractCollectorTestCase.java @@ -7,14 +7,17 @@ package org.elasticsearch.marvel.agent.collector; import com.carrotsearch.randomizedtesting.RandomizedTest; import com.carrotsearch.randomizedtesting.SysGlobals; +import org.elasticsearch.action.ActionModule; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.license.core.License; +import org.elasticsearch.license.plugin.LicensePlugin; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; @@ -25,16 +28,13 @@ import org.elasticsearch.marvel.shield.SecuredClient; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.node.Node; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.rest.RestModule; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.xpack.XPackPlugin; import org.junit.Before; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; @@ -43,10 +43,7 @@ public class AbstractCollectorTestCase extends MarvelIntegTestCase { @Override protected Collection> nodePlugins() { - if (shieldEnabled) { - return Arrays.asList(LicensePluginForCollectors.class, XPackPlugin.class, XPackPlugin.class); - } - return Arrays.asList(LicensePluginForCollectors.class, XPackPlugin.class); + return Arrays.asList(InternalXPackPlugin.class); } @Override @@ -183,18 +180,10 @@ public class AbstractCollectorTestCase extends MarvelIntegTestCase { }, 30L, TimeUnit.SECONDS); } - public static class LicensePluginForCollectors extends Plugin { + public static class InternalLicensePlugin extends LicensePlugin { - public static final String NAME = "internal-test-licensing"; - - @Override - public String name() { - return NAME; - } - - @Override - public String description() { - return name(); + public InternalLicensePlugin() { + super(Settings.EMPTY); } @Override @@ -210,6 +199,27 @@ public class AbstractCollectorTestCase extends MarvelIntegTestCase { } }); } + + @Override + public void onModule(RestModule module) { + } + + @Override + public void onModule(ActionModule module) { + } + + @Override + public Collection> nodeServices() { + return Collections.emptyList(); + } + } + + public static class InternalXPackPlugin extends XPackPlugin { + + public InternalXPackPlugin(Settings settings) { + super(settings); + licensePlugin = new InternalLicensePlugin(); + } } public static class LicenseServiceForCollectors extends AbstractComponent implements LicenseeRegistry { diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/LicenseIntegrationTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/LicenseIntegrationTests.java index 07dd6579330..150eb3c766c 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/LicenseIntegrationTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/license/LicenseIntegrationTests.java @@ -5,16 +5,22 @@ */ package org.elasticsearch.marvel.license; +import org.elasticsearch.action.ActionModule; import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.IndexModule; +import org.elasticsearch.index.IndexService; import org.elasticsearch.license.core.License; +import org.elasticsearch.license.plugin.LicensePlugin; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; import org.elasticsearch.license.plugin.core.LicensesManagerService; +import org.elasticsearch.rest.RestModule; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.marvel.test.MarvelIntegTestCase; import org.elasticsearch.plugins.Plugin; @@ -36,7 +42,7 @@ import static org.hamcrest.Matchers.isOneOf; public class LicenseIntegrationTests extends MarvelIntegTestCase { @Override protected Collection> nodePlugins() { - return Arrays.asList(MockLicensePlugin.class, XPackPlugin.class); + return Arrays.asList(InternalXPackPlugin.class); } @Override @@ -77,13 +83,10 @@ public class LicenseIntegrationTests extends MarvelIntegTestCase { } } - public static class MockLicensePlugin extends Plugin { + public static class MockLicensePlugin extends LicensePlugin { - public static final String NAME = "internal-test-licensing"; - - @Override - public String name() { - return NAME; + public MockLicensePlugin() { + super(Settings.EMPTY); } @Override @@ -95,6 +98,20 @@ public class LicenseIntegrationTests extends MarvelIntegTestCase { public Collection nodeModules() { return Collections.singletonList(new InternalLicenseModule()); } + + @Override + public void onModule(RestModule module) { + } + + @Override + public void onModule(ActionModule module) { + } + + @Override + public Collection> nodeServices() { + return Collections.emptyList(); + } + } public static class InternalLicenseModule extends AbstractModule { @@ -148,4 +165,11 @@ public class LicenseIntegrationTests extends MarvelIntegTestCase { return null; } } + + public static class InternalXPackPlugin extends XPackPlugin { + public InternalXPackPlugin(Settings settings) { + super(settings); + licensePlugin = new MockLicensePlugin(); + } + } } 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 01e35613c00..85ca5628f58 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 @@ -18,20 +18,18 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.CountDown; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexNotFoundException; -import org.elasticsearch.shield.ShieldPlugin; -import org.elasticsearch.xpack.XPackPlugin; -import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.marvel.agent.AgentService; import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.settings.MarvelSettings; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.shield.ShieldPlugin; import org.elasticsearch.shield.authc.esusers.ESUsersRealm; import org.elasticsearch.shield.authc.support.Hasher; 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.xpack.XPackPlugin; import org.hamcrest.Matcher; import org.jboss.netty.util.internal.SystemPropertyUtil; @@ -72,6 +70,10 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder builder = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) + + //TODO: for now lets isolate marvel tests from watcher (randomize this later) + .put("watcher.enabled", false) + // we do this by default in core, but for marvel this isn't needed and only adds noise. .put("index.store.mock.check_index_on_close", false); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/LicensingTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/LicensingTests.java index 7e4376b8753..928b0a043a9 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/LicensingTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/integration/LicensingTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.integration; import org.elasticsearch.ElasticsearchSecurityException; +import org.elasticsearch.action.ActionModule; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsIndices; @@ -17,37 +18,35 @@ import org.elasticsearch.client.support.Headers; import org.elasticsearch.client.transport.NoNodeAvailableException; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.License.OperationMode; +import org.elasticsearch.license.plugin.LicensePlugin; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; import org.elasticsearch.node.Node; -import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.rest.RestModule; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.shield.ShieldPlugin; -import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.shield.authc.support.UsernamePasswordToken; import org.elasticsearch.test.ShieldIntegTestCase; import org.elasticsearch.test.ShieldSettingsSource; import org.elasticsearch.transport.Transport; +import org.elasticsearch.xpack.XPackPlugin; import org.junit.After; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Locale; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.*; /** * @@ -102,6 +101,11 @@ public class LicensingTests extends ShieldIntegTestCase { .build(); } + @Override + protected Class xpackPluginClass() { + return InternalXPackPlugin.class; + } + @After public void resetLicensing() { enableLicensing(); @@ -237,24 +241,37 @@ public class LicensingTests extends ShieldIntegTestCase { } } - public static class InternalLicensePlugin extends Plugin { - - public static final String NAME = "internal-licensing"; - - @Override - public String name() { - return NAME; - } - - @Override - public String description() { - return name(); - } + public static class InternalLicensePlugin extends LicensePlugin { @Override public Collection nodeModules() { return Collections.singletonList(new InternalLicenseModule()); } + + public InternalLicensePlugin() { + super(Settings.EMPTY); + } + + @Override + public void onModule(RestModule module) { + } + + @Override + public void onModule(ActionModule module) { + } + + @Override + public Collection> nodeServices() { + return Collections.emptyList(); + } + } + + public static class InternalXPackPlugin extends XPackPlugin { + + public InternalXPackPlugin(Settings settings) { + super(settings); + licensePlugin = new InternalLicensePlugin(); + } } public static class InternalLicenseModule extends AbstractModule { diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/AuthenticationModuleTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/AuthenticationModuleTests.java index e9d74f77d2a..eabded21bba 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/AuthenticationModuleTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/AuthenticationModuleTests.java @@ -25,9 +25,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPoolModule; import org.elasticsearch.transport.TransportMessage; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.*; /** * Unit tests for the AuthenticationModule diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/pki/PkiAuthenticationTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/pki/PkiAuthenticationTests.java index 3dda4492695..43a9227f560 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/pki/PkiAuthenticationTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/pki/PkiAuthenticationTests.java @@ -46,6 +46,7 @@ import static org.hamcrest.Matchers.is; */ @ClusterScope(numClientNodes = 0, numDataNodes = 1) public class PkiAuthenticationTests extends ShieldIntegTestCase { + @Override protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/filter/IpFilteringUpdateTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/filter/IpFilteringUpdateTests.java index ec658b00e77..0f9e986dd0b 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/filter/IpFilteringUpdateTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/filter/IpFilteringUpdateTests.java @@ -23,6 +23,7 @@ import static org.hamcrest.Matchers.is; @ClusterScope(scope = TEST, numDataNodes = 1) public class IpFilteringUpdateTests extends ShieldIntegTestCase { + private static int randomClientPort; private final boolean httpEnabled = randomBoolean(); diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/netty/ShieldNettyHttpServerTransportTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/netty/ShieldNettyHttpServerTransportTests.java index f626f7de5a4..f601cf0b5ca 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/netty/ShieldNettyHttpServerTransportTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/transport/netty/ShieldNettyHttpServerTransportTests.java @@ -28,6 +28,7 @@ import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.mock; public class ShieldNettyHttpServerTransportTests extends ESTestCase { + private ServerSSLService serverSSLService; @Before 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 3941f81894b..e9ca6f3b1da 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 @@ -6,16 +6,15 @@ package org.elasticsearch.test; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; -import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.shield.ShieldPlugin; -import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.test.ESIntegTestCase.SuppressLocalMode; +import org.elasticsearch.xpack.XPackPlugin; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -23,7 +22,7 @@ import org.junit.Rule; import org.junit.rules.ExternalResource; import java.nio.file.Path; -import java.util.*; +import java.util.Collection; import java.util.stream.Collectors; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; @@ -128,7 +127,7 @@ public abstract class ShieldIntegTestCase extends ESIntegTestCase { // TODO: disable this assertion for now, because the test framework randomly runs with mock plugins. Maybe we should run without mock plugins? // assertThat(nodeInfo.getPlugins().getInfos(), hasSize(2)); Collection pluginNames = nodeInfo.getPlugins().getInfos().stream().map(p -> p.getName()).collect(Collectors.toList()); - assertThat("plugin [" + ShieldPlugin.NAME + "] not found in [" + pluginNames + "]", pluginNames.contains(ShieldPlugin.NAME), is(true)); + assertThat("plugin [" + XPackPlugin.NAME + "] not found in [" + pluginNames + "]", pluginNames.contains(XPackPlugin.NAME), is(true)); } } @@ -235,6 +234,10 @@ public abstract class ShieldIntegTestCase extends ESIntegTestCase { return randomBoolean(); } + protected Class xpackPluginClass() { + return SHIELD_DEFAULT_SETTINGS.xpackPluginClass(); + } + private class CustomShieldSettingsSource extends ShieldSettingsSource { private CustomShieldSettingsSource(boolean sslTransportEnabled, Path configDir, Scope scope) { super(maxNumberOfNodes(), sslTransportEnabled, configDir, scope); @@ -275,6 +278,10 @@ public abstract class ShieldIntegTestCase extends ESIntegTestCase { return ShieldIntegTestCase.this.transportClientPassword(); } + @Override + protected Class xpackPluginClass() { + return ShieldIntegTestCase.this.xpackPluginClass(); + } } protected void assertGreenClusterState(Client client) { diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldSettingsSource.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldSettingsSource.java index 2be0e9ad151..658fa3e5b15 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldSettingsSource.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/test/ShieldSettingsSource.java @@ -116,6 +116,11 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ public Settings nodeSettings(int nodeOrdinal) { Path folder = ShieldTestUtils.createFolder(parentFolder, subfolderPrefix + "-" + nodeOrdinal); Settings.Builder builder = settingsBuilder().put(super.nodeSettings(nodeOrdinal)) + + //TODO: for now isolate shield tests from watcher & marvel (randomize this later) + .put("watcher.enabled", false) + .put("marvel.enabled", false) + .put("shield.audit.enabled", randomBoolean()) .put(InternalCryptoService.FILE_SETTING, writeFile(folder, "system_key", systemKey)) .put("shield.authc.realms.esusers.type", ESUsersRealm.TYPE) @@ -143,12 +148,12 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ @Override public Collection> nodePlugins() { - return Arrays.asList(XPackPlugin.class); + return Arrays.asList(xpackPluginClass()); } @Override public Collection> transportClientPlugins() { - return Collections.>singletonList(XPackPlugin.class); + return Collections.>singletonList(xpackPluginClass()); } protected String configUsers() { @@ -183,6 +188,10 @@ public class ShieldSettingsSource extends ClusterDiscoveryConfiguration.UnicastZ return systemKey; } + protected Class xpackPluginClass() { + return XPackPlugin.class; + } + private void setUser(Settings.Builder builder, String username, SecuredString password) { if (randomBoolean()) { builder.put(Headers.PREFIX + "." + UsernamePasswordToken.BASIC_AUTH_HEADER, basicAuthHeaderValue(username, password)); diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 7b2795b9366..4d2aa9531bc 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexService; +import org.elasticsearch.license.plugin.LicensePlugin; import org.elasticsearch.marvel.MarvelPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestModule; @@ -27,17 +28,19 @@ import java.util.Collection; public class XPackPlugin extends Plugin { - public static final String NAME = "xpack"; + public static final String NAME = "x-pack"; private final static ESLogger logger = Loggers.getLogger(XPackPlugin.class); protected final Settings settings; - protected final ShieldPlugin shieldPlugin; - protected final MarvelPlugin marvelPlugin; + protected LicensePlugin licensePlugin; + protected ShieldPlugin shieldPlugin; + protected MarvelPlugin marvelPlugin; protected WatcherPlugin watcherPlugin; public XPackPlugin(Settings settings) { this.settings = settings; + this.licensePlugin = new LicensePlugin(settings); this.shieldPlugin = new ShieldPlugin(settings); this.marvelPlugin = new MarvelPlugin(settings); this.watcherPlugin = new WatcherPlugin(settings); @@ -54,6 +57,7 @@ public class XPackPlugin extends Plugin { @Override public Collection nodeModules() { ArrayList modules = new ArrayList<>(); + modules.addAll(licensePlugin.nodeModules()); modules.addAll(shieldPlugin.nodeModules()); modules.addAll(watcherPlugin.nodeModules()); modules.addAll(marvelPlugin.nodeModules()); @@ -63,6 +67,7 @@ public class XPackPlugin extends Plugin { @Override public Collection> nodeServices() { ArrayList> services = new ArrayList<>(); + services.addAll(licensePlugin.nodeServices()); services.addAll(shieldPlugin.nodeServices()); services.addAll(watcherPlugin.nodeServices()); services.addAll(marvelPlugin.nodeServices()); @@ -72,6 +77,7 @@ public class XPackPlugin extends Plugin { @Override public Settings additionalSettings() { Settings.Builder builder = Settings.builder(); + builder.put(licensePlugin.additionalSettings()); builder.put(shieldPlugin.additionalSettings()); builder.put(watcherPlugin.additionalSettings()); builder.put(marvelPlugin.additionalSettings()); @@ -89,11 +95,13 @@ public class XPackPlugin extends Plugin { } public void onModule(RestModule module) { + licensePlugin.onModule(module); shieldPlugin.onModule(module); watcherPlugin.onModule(module); } public void onModule(ActionModule module) { + licensePlugin.onModule(module); shieldPlugin.onModule(module); watcherPlugin.onModule(module); } diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java index 1c51760d619..62fc0c3cc5c 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/watcher/license/LicenseTests.java @@ -19,6 +19,7 @@ import java.util.List; import static org.hamcrest.Matchers.is; public class LicenseTests extends ESTestCase { + private SimpleLicenseeRegistry licenseeRegistry = new SimpleLicenseeRegistry(); public void testPlatinumGoldTrialLicenseCanDoEverything() throws Exception { 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 3ee41a046f3..0f938d7aca2 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 @@ -20,13 +20,10 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.shield.ShieldPlugin; -import org.elasticsearch.xpack.TimeWarpedXPackPlugin; -import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.xpack.XPackPlugin; +import org.elasticsearch.shield.ShieldPlugin; import org.elasticsearch.shield.authc.esusers.ESUsersRealm; import org.elasticsearch.shield.authc.support.Hasher; import org.elasticsearch.shield.authc.support.SecuredString; @@ -36,7 +33,6 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.TestCluster; import org.elasticsearch.watcher.WatcherLifeCycleService; import org.elasticsearch.watcher.WatcherModule; -import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.watcher.WatcherService; import org.elasticsearch.watcher.WatcherState; import org.elasticsearch.watcher.actions.email.service.Authentication; @@ -57,6 +53,8 @@ import org.elasticsearch.watcher.trigger.ScheduleTriggerEngineMock; import org.elasticsearch.watcher.trigger.TriggerService; import org.elasticsearch.watcher.trigger.schedule.ScheduleModule; import org.elasticsearch.watcher.watch.Watch; +import org.elasticsearch.xpack.TimeWarpedXPackPlugin; +import org.elasticsearch.xpack.XPackPlugin; import org.hamcrest.Matcher; import org.jboss.netty.util.internal.SystemPropertyUtil; import org.junit.After; @@ -69,25 +67,14 @@ import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.atomic.AtomicReference; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; -import static org.elasticsearch.watcher.WatcherModule.HISTORY_TEMPLATE_NAME; -import static org.elasticsearch.watcher.WatcherModule.TRIGGERED_TEMPLATE_NAME; -import static org.elasticsearch.watcher.WatcherModule.WATCHES_TEMPLATE_NAME; -import static org.hamcrest.Matchers.emptyArray; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.notNullValue; +import static org.elasticsearch.watcher.WatcherModule.*; +import static org.hamcrest.Matchers.*; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNot.not; @@ -119,6 +106,10 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase logger.info("using schedule engine [" + scheduleImplName + "]"); return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) + + //TODO: for now lets isolate watcher tests from marvel (randomize this later) + .put("marvel.enabled", false) + // we do this by default in core, but for watcher this isn't needed and only adds noise. .put("index.store.mock.check_index_on_close", false) .put("scroll.size", randomIntBetween(1, 100)) @@ -153,10 +144,6 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase } else { types.add(XPackPlugin.class); } - if (shieldEnabled) { - types.add(XPackPlugin.class); - } - types.add(licensePluginClass()); return types; } @@ -191,10 +178,6 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase return randomBoolean(); } - protected Class licensePluginClass() { - return XPackPlugin.class; - } - protected boolean checkWatcherRunningOnlyOnce() { return true; }