Fix Shield related errors

Original commit: elastic/x-pack-elasticsearch@8a2f1e0586
This commit is contained in:
Martijn van Groningen 2015-06-15 23:04:40 +02:00
parent e03b4c1b83
commit 72fed1be7f
7 changed files with 81 additions and 20 deletions

View File

@ -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);

View File

@ -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 {

View File

@ -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(

View File

@ -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();
}

View File

@ -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()));

View File

@ -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"
;

View File

@ -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()