Merge pull request elastic/elasticsearch#424 from jpountz/enhancement/qa_shield

Add Shield testing to qa/smoke-test-plugins.

Original commit: elastic/x-pack-elasticsearch@e5916e4522
This commit is contained in:
Adrien Grand 2015-08-11 10:55:54 +02:00
commit 2322e42a70
5 changed files with 72 additions and 8 deletions

View File

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

View File

@ -4,6 +4,20 @@
<import file="${elasticsearch.integ.antfile.default}"/>
<!-- redefined to work with auth -->
<macrodef name="waitfor-elasticsearch">
<attribute name="port"/>
<attribute name="timeoutproperty"/>
<sequential>
<echo>Waiting for elasticsearch to become available on port @{port}...</echo>
<waitfor maxwait="30" maxwaitunit="second"
checkevery="500" checkeveryunit="millisecond"
timeoutproperty="@{timeoutproperty}">
<socket server="127.0.0.1" port="@{port}"/>
</waitfor>
</sequential>
</macrodef>
<target name="start-external-cluster-with-plugins" depends="setup-workspace">
<ac:for list="${xplugins.list}" param="xplugin.name">
<sequential>
@ -27,6 +41,20 @@
<install-plugin name="${plugin.name}" file="@{file}"/>
</sequential>
</ac:for>
<startup-elasticsearch/>
<local name="home"/>
<property name="home" location="${integ.scratch}/elasticsearch-${elasticsearch.version}"/>
<echo>Setting up Shield auth</echo>
<run-script script="${home}/bin/shield/esusers" args="useradd test_user -p changeme -r admin"/>
<run-script script="${home}/bin/shield/esusers" args="useradd marvel_export -p changeme -r marvel_agent"/>
<startup-elasticsearch additional.args="-Des.marvel.agent.exporter.es.hosts=http://marvel_export:changeme@localhost:${integ.http.port}" />
<echo>Checking we can connect with basic auth on port ${integ.http.port}...</echo>
<local name="temp.file"/>
<tempfile property="temp.file" destdir="${java.io.tmpdir}"/>
<get src="http://127.0.0.1:${integ.http.port}" dest="${temp.file}"
username="test_user" password="changeme" verbose="true" retries="10"/>
</target>
</project>

View File

@ -25,10 +25,18 @@
<elasticsearch.integ.antfile>${project.basedir}/integration-tests.xml</elasticsearch.integ.antfile>
<tests.rest.suite>smoke_test_plugins</tests.rest.suite>
<tests.rest.load_packaged>false</tests.rest.load_packaged>
<!-- TODO: improve these smoke tests to support auth and add 'elasticsearch-shield' to this list -->
<xplugins.list>elasticsearch-watcher,elasticsearch-marvel,elasticsearch-license</xplugins.list>
<xplugins.list>elasticsearch-license,elasticsearch-marvel,elasticsearch-shield,elasticsearch-watcher</xplugins.list>
</properties>
<dependencies>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>elasticsearch-shield</artifactId>
<version>2.0.0-beta1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
@ -74,14 +82,13 @@
<overWrite>true</overWrite>
</artifactItem>
<!-- Shield is harder to test through REST
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>elasticsearch-shield</artifactId>
<version>${elasticsearch.version}</version>
<type>zip</type>
<overWrite>true</overWrite>
</artifactItem>-->
</artifactItem>
<artifactItem>
<groupId>org.elasticsearch.plugin</groupId>

View File

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

View File

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