From 72fed1be7f01916386ca015dbdd6ba14876a108d Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 15 Jun 2015 23:04:40 +0200 Subject: [PATCH] Fix Shield related errors Original commit: elastic/x-pack-elasticsearch@8a2f1e0586e1121f85dd2cffd0f045478813ed0a --- .../watcher/WatcherPluginDisableTests.java | 8 +++++++ .../actions/index/IndexActionTests.java | 24 +++++++++++++++---- .../input/search/SearchInputTests.java | 10 ++++++++ .../watcher/shield/BasicShieldTests.java | 12 ++++------ .../watcher/support/TemplateUtilsTests.java | 17 +++++++++++++ .../test/AbstractWatcherIntegrationTests.java | 19 ++++++++------- .../search/SearchTransformTests.java | 11 +++++++++ 7 files changed, 81 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java b/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java index 2965173f9b5..9efdeeffc8c 100644 --- a/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java +++ b/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java @@ -45,6 +45,14 @@ public class WatcherPluginDisableTests extends ElasticsearchIntegrationTest { .build(); } + @Override + protected Settings transportClientSettings() { + return Settings.builder() + .put(super.transportClientSettings()) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) + .build(); + } + @Test public void testRestEndpoints() throws Exception { HttpServerTransport httpServerTransport = internalCluster().getDataNodeInstance(HttpServerTransport.class); diff --git a/src/test/java/org/elasticsearch/watcher/actions/index/IndexActionTests.java b/src/test/java/org/elasticsearch/watcher/actions/index/IndexActionTests.java index 84b3e51a3fa..33e8fa75038 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/index/IndexActionTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/index/IndexActionTests.java @@ -5,17 +5,15 @@ */ package org.elasticsearch.watcher.actions.index; -import com.carrotsearch.randomizedtesting.annotations.Repeat; -import org.elasticsearch.action.search.SearchResponse; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; +import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.sort.SortOrder; @@ -28,6 +26,8 @@ import org.elasticsearch.watcher.support.init.proxy.ClientProxy; import org.elasticsearch.watcher.support.xcontent.XContentSource; import org.elasticsearch.watcher.test.WatcherTestUtils; import org.elasticsearch.watcher.watch.Payload; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; import org.junit.Test; import java.util.Map; @@ -42,6 +42,22 @@ import static org.hamcrest.Matchers.*; */ public class IndexActionTests extends ElasticsearchIntegrationTest { + @Override + protected Settings nodeSettings(int nodeOrdinal) { + return Settings.builder() + .put(super.nodeSettings(nodeOrdinal)) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) + .build(); + } + + @Override + protected Settings transportClientSettings() { + return Settings.builder() + .put(super.transportClientSettings()) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) + .build(); + } + @Test public void testIndexActionExecute_SingleDoc() throws Exception { diff --git a/src/test/java/org/elasticsearch/watcher/input/search/SearchInputTests.java b/src/test/java/org/elasticsearch/watcher/input/search/SearchInputTests.java index c8af9384bbb..0937e753b7f 100644 --- a/src/test/java/org/elasticsearch/watcher/input/search/SearchInputTests.java +++ b/src/test/java/org/elasticsearch/watcher/input/search/SearchInputTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.Streams; +import org.elasticsearch.plugins.PluginsService; import org.joda.time.DateTime; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -89,9 +90,18 @@ public class SearchInputTests extends ElasticsearchIntegrationTest { //Set path so ScriptService will pick up the test scripts return settingsBuilder().put(super.nodeSettings(nodeOrdinal)) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .put("path.conf", configPath).build(); } + @Override + protected Settings transportClientSettings() { + return Settings.builder() + .put(super.transportClientSettings()) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) + .build(); + } + @Test public void testExecute() throws Exception { SearchSourceBuilder searchSourceBuilder = searchSource().query( diff --git a/src/test/java/org/elasticsearch/watcher/shield/BasicShieldTests.java b/src/test/java/org/elasticsearch/watcher/shield/BasicShieldTests.java index 7f081c538a8..fb524e7080f 100644 --- a/src/test/java/org/elasticsearch/watcher/shield/BasicShieldTests.java +++ b/src/test/java/org/elasticsearch/watcher/shield/BasicShieldTests.java @@ -5,37 +5,32 @@ */ package org.elasticsearch.watcher.shield; -import org.elasticsearch.ElasticsearchException; -import org.joda.time.DateTime; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.shield.ShieldPlugin; -import org.elasticsearch.shield.authc.AuthenticationException; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authz.AuthorizationException; import org.elasticsearch.watcher.WatcherPlugin; import org.elasticsearch.watcher.WatcherState; -import org.elasticsearch.watcher.client.WatchSourceBuilders; -import org.elasticsearch.watcher.condition.ConditionBuilders; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests; import org.elasticsearch.watcher.transport.actions.delete.DeleteWatchResponse; import org.elasticsearch.watcher.transport.actions.execute.ExecuteWatchResponse; import org.elasticsearch.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; import org.elasticsearch.watcher.transport.actions.stats.WatcherStatsResponse; -import org.elasticsearch.watcher.trigger.TriggerBuilders; import org.elasticsearch.watcher.trigger.TriggerEvent; import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule; import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent; +import org.joda.time.DateTime; import org.junit.Test; -import static org.joda.time.DateTimeZone.UTC; import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder; import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule; import static org.elasticsearch.watcher.trigger.schedule.Schedules.interval; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.core.Is.is; +import static org.joda.time.DateTimeZone.UTC; public class BasicShieldTests extends AbstractWatcherIntegrationTests { @@ -51,6 +46,7 @@ public class BasicShieldTests extends AbstractWatcherIntegrationTests { .put("plugin.types", ShieldPlugin.class.getName() + "," + WatcherPlugin.class.getName()) // Use just the transport user here, so we can test Watcher roles specifically .put("shield.user", "transport_client:changeme") + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .build(); } diff --git a/src/test/java/org/elasticsearch/watcher/support/TemplateUtilsTests.java b/src/test/java/org/elasticsearch/watcher/support/TemplateUtilsTests.java index cd6598d9626..77b7a78b0c6 100644 --- a/src/test/java/org/elasticsearch/watcher/support/TemplateUtilsTests.java +++ b/src/test/java/org/elasticsearch/watcher/support/TemplateUtilsTests.java @@ -7,6 +7,7 @@ package org.elasticsearch.watcher.support; import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.watcher.history.HistoryStore; import org.elasticsearch.watcher.support.init.proxy.ClientProxy; @@ -21,6 +22,22 @@ import static org.hamcrest.core.Is.is; @ElasticsearchIntegrationTest.ClusterScope(scope = SUITE, numClientNodes = 0, transportClientRatio = 0, randomDynamicTemplates = false, numDataNodes = 1) public class TemplateUtilsTests extends ElasticsearchIntegrationTest { + @Override + protected Settings nodeSettings(int nodeOrdinal) { + return Settings.builder() + .put(super.nodeSettings(nodeOrdinal)) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) + .build(); + } + + @Override + protected Settings transportClientSettings() { + return Settings.builder() + .put(super.transportClientSettings()) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) + .build(); + } + @Test public void testPutTemplate() throws Exception { TemplateUtils templateUtils = new TemplateUtils(Settings.EMPTY, ClientProxy.of(client())); diff --git a/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTests.java b/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTests.java index d3c4b937082..6f6c9a68a42 100644 --- a/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTests.java +++ b/src/test/java/org/elasticsearch/watcher/test/AbstractWatcherIntegrationTests.java @@ -26,6 +26,8 @@ import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.search.builder.SearchSourceBuilder; 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.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; @@ -621,6 +623,7 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg public static final String TEST_USERNAME = "test"; public static final String TEST_PASSWORD = "changeme"; + private static final String TEST_PASSWORD_HASHED = new String(Hasher.BCRYPT.hash(new SecuredString(TEST_PASSWORD.toCharArray()))); static boolean auditLogsEnabled = SystemPropertyUtil.getBoolean("tests.audit_logs", true); static byte[] systemKey = generateKey(); // must be the same for all nodes @@ -628,10 +631,10 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg public static final String IP_FILTER = "allow: all\n"; public static final String USERS = - "transport_client:{plain}changeme\n" + - TEST_USERNAME + ":{plain}" + TEST_PASSWORD + "\n" + - "admin:{plain}changeme\n" + - "monitor:{plain}changeme"; + "transport_client:" + TEST_PASSWORD_HASHED + "\n" + + TEST_USERNAME + ":" + TEST_PASSWORD_HASHED + "\n" + + "admin:" + TEST_PASSWORD_HASHED + "\n" + + "monitor:" + TEST_PASSWORD_HASHED; public static final String USER_ROLES = "transport_client:transport_client\n" + @@ -641,17 +644,17 @@ public abstract class AbstractWatcherIntegrationTests extends ElasticsearchInteg public static final String ROLES = "test:\n" + // a user for the test infra. - " cluster: cluster:monitor/nodes/info, cluster:monitor/state, cluster:monitor/health, cluster:monitor/stats, cluster:admin/settings/update, cluster:admin/repository/delete, indices:admin/template/get, indices:admin/template/put, indices:admin/template/delete\n" + + " cluster: cluster:monitor/nodes/info, cluster:monitor/state, cluster:monitor/health, cluster:monitor/stats, cluster:admin/settings/update, cluster:admin/repository/delete, cluster:monitor/nodes/liveness, indices:admin/template/get, indices:admin/template/put, indices:admin/template/delete\n" + " indices:\n" + " '*': all\n" + "\n" + "admin:\n" + - " cluster: manage_watcher, cluster:monitor/nodes/info\n" + + " cluster: manage_watcher, cluster:monitor/nodes/info, cluster:monitor/nodes/liveness\n" + "transport_client:\n" + - " cluster: cluster:monitor/nodes/info\n" + + " cluster: cluster:monitor/nodes/info, cluster:monitor/nodes/liveness\n" + "\n" + "monitor:\n" + - " cluster: monitor_watcher, cluster:monitor/nodes/info\n" + " cluster: monitor_watcher, cluster:monitor/nodes/info, cluster:monitor/nodes/liveness\\\n" ; diff --git a/src/test/java/org/elasticsearch/watcher/transform/search/SearchTransformTests.java b/src/test/java/org/elasticsearch/watcher/transform/search/SearchTransformTests.java index c8fbfd2c1f1..13a4cb3ee0c 100644 --- a/src/test/java/org/elasticsearch/watcher/transform/search/SearchTransformTests.java +++ b/src/test/java/org/elasticsearch/watcher/transform/search/SearchTransformTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.client.Requests; import org.elasticsearch.common.bytes.BytesReference; import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.io.Streams; +import org.elasticsearch.plugins.PluginsService; import org.joda.time.DateTime; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -86,9 +87,19 @@ public class SearchTransformTests extends ElasticsearchIntegrationTest { //Set path so ScriptService will pick up the test scripts return settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) + // we're not extending from the base watcher test case, so we should prevent the watcher plugin from being loaded + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .put("path.conf", configPath).build(); } + @Override + protected Settings transportClientSettings() { + return Settings.builder() + .put(super.transportClientSettings()) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) + .build(); + } + @Override public Settings indexSettings() { return settingsBuilder()