From 12e9dcc6842c1c3797d623891ae14638f336b87c Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 11 Aug 2015 10:23:46 +0200 Subject: [PATCH] Add Shield testing to qa/smoke-test-plugins. Original commit: elastic/x-pack-elasticsearch@fbbc6cefda0aa34f06bc435a325274565e6fc43b --- .../marvel/agent/support/AgentUtils.java | 3 ++ qa/smoke-test-plugins/integration-tests.xml | 30 ++++++++++++++++++- qa/smoke-test-plugins/pom.xml | 15 +++++++--- .../test/smoke_test_plugins/10_basic.yaml | 5 ++-- .../smoketest/SmokeTestPluginsIT.java | 27 +++++++++++++++++ 5 files changed, 72 insertions(+), 8 deletions(-) diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/support/AgentUtils.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/support/AgentUtils.java index e1a6452eae7..6da93ca512e 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/support/AgentUtils.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/support/AgentUtils.java @@ -140,6 +140,9 @@ public class AgentUtils { private static Pattern urlPwdSanitizer = Pattern.compile("([" + userInfoChars + "]+?):[" + userInfoChars + "]+?@"); public static String santizeUrlPwds(Object text) { + if (text == null) { + return null; + } Matcher matcher = urlPwdSanitizer.matcher(text.toString()); return matcher.replaceAll("$1:XXXXXX@"); } diff --git a/qa/smoke-test-plugins/integration-tests.xml b/qa/smoke-test-plugins/integration-tests.xml index 55f144f5cbb..83d05491aaf 100644 --- a/qa/smoke-test-plugins/integration-tests.xml +++ b/qa/smoke-test-plugins/integration-tests.xml @@ -4,6 +4,20 @@ + + + + + + Waiting for elasticsearch to become available on port @{port}... + + + + + + @@ -27,6 +41,20 @@ - + + + + + Setting up Shield auth + + + + + + Checking we can connect with basic auth on port ${integ.http.port}... + + + diff --git a/qa/smoke-test-plugins/pom.xml b/qa/smoke-test-plugins/pom.xml index aad50d7ee03..6193fd9205f 100644 --- a/qa/smoke-test-plugins/pom.xml +++ b/qa/smoke-test-plugins/pom.xml @@ -25,10 +25,18 @@ ${project.basedir}/integration-tests.xml smoke_test_plugins false - - elasticsearch-watcher,elasticsearch-marvel,elasticsearch-license + elasticsearch-license,elasticsearch-marvel,elasticsearch-shield,elasticsearch-watcher + + + org.elasticsearch.plugin + elasticsearch-shield + 2.0.0-beta1-SNAPSHOT + test + + + @@ -74,14 +82,13 @@ true - + org.elasticsearch.plugin diff --git a/qa/smoke-test-plugins/rest-api-spec/test/smoke_test_plugins/10_basic.yaml b/qa/smoke-test-plugins/rest-api-spec/test/smoke_test_plugins/10_basic.yaml index abd4ae73945..dd1ada2ec73 100644 --- a/qa/smoke-test-plugins/rest-api-spec/test/smoke_test_plugins/10_basic.yaml +++ b/qa/smoke-test-plugins/rest-api-spec/test/smoke_test_plugins/10_basic.yaml @@ -12,6 +12,5 @@ - match: { nodes.$master.plugins.11.name: license } - match: { nodes.$master.plugins.13.name: marvel } -# Add shield when we figure out how to rest test it -# - match: { nodes.$master.plugins.13.name: shield } - - match: { nodes.$master.plugins.15.name: watcher } + - match: { nodes.$master.plugins.14.name: shield } + - match: { nodes.$master.plugins.16.name: watcher } diff --git a/qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsIT.java b/qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsIT.java index 23d3fbcb09c..ebaef4ba102 100644 --- a/qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsIT.java +++ b/qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsIT.java @@ -7,14 +7,24 @@ package org.elasticsearch.smoketest; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; + +import org.elasticsearch.client.support.Headers; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.shield.ShieldPlugin; +import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.RestTestCandidate; import org.elasticsearch.test.rest.parser.RestTestParseException; import java.io.IOException; +import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; + public class SmokeTestPluginsIT extends ESRestTestCase { + private static final String USER = "test_user"; + private static final String PASS = "changeme"; + public SmokeTestPluginsIT(@Name("yaml") RestTestCandidate testCandidate) { super(testCandidate); } @@ -23,5 +33,22 @@ public class SmokeTestPluginsIT extends ESRestTestCase { public static Iterable parameters() throws IOException, RestTestParseException { return ESRestTestCase.createParameters(0, 1); } + + @Override + protected Settings restClientSettings() { + String token = basicAuthHeaderValue(USER, new SecuredString(PASS.toCharArray())); + return Settings.builder() + .put(Headers.PREFIX + ".Authorization", token) + .build(); + } + + @Override + protected Settings externalClusterClientSettings() { + return Settings.builder() + .put("shield.user", USER + ":" + PASS) + .put("plugin.types", ShieldPlugin.class.getName()) + .build(); + } + }