From 06d84f00e44668d4cea6ba9f3da6a59db65397f8 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 13 Aug 2015 12:21:50 +0200 Subject: [PATCH] Tests: Move Shield "run core REST tests" to qa. Close elastic/elasticsearch#404 Original commit: elastic/x-pack-elasticsearch@1250e1449e64cd3fa2316652834b2c1500ac4e2a --- qa/pom.xml | 1 + .../integration-tests.xml | 8 + qa/shield-core-rest-tests/pom.xml | 149 ++++++++++++++++++ .../java/org/elasticsearch/shield/RestIT.java | 54 +++++++ qa/smoke-test-plugins/integration-tests.xml | 76 +-------- shield/pom.xml | 3 +- .../org/elasticsearch/test/ShieldRestIT.java | 27 ---- .../test/ShieldRestTestCase.java | 102 ------------ .../main/resources/ant/shield-overrides.xml | 97 ++++++++++++ 9 files changed, 312 insertions(+), 205 deletions(-) create mode 100644 qa/shield-core-rest-tests/integration-tests.xml create mode 100644 qa/shield-core-rest-tests/pom.xml create mode 100644 qa/shield-core-rest-tests/src/test/java/org/elasticsearch/shield/RestIT.java delete mode 100644 shield/src/test/java/org/elasticsearch/test/ShieldRestIT.java delete mode 100644 shield/src/test/java/org/elasticsearch/test/ShieldRestTestCase.java create mode 100644 x-dev-tools/src/main/resources/ant/shield-overrides.xml diff --git a/qa/pom.xml b/qa/pom.xml index f945456bbef..026c0758c50 100644 --- a/qa/pom.xml +++ b/qa/pom.xml @@ -320,6 +320,7 @@ smoke-test-plugins + shield-core-rest-tests smoke-test-watcher-with-shield diff --git a/qa/shield-core-rest-tests/integration-tests.xml b/qa/shield-core-rest-tests/integration-tests.xml new file mode 100644 index 00000000000..4da32222a8f --- /dev/null +++ b/qa/shield-core-rest-tests/integration-tests.xml @@ -0,0 +1,8 @@ + + + + + + + diff --git a/qa/shield-core-rest-tests/pom.xml b/qa/shield-core-rest-tests/pom.xml new file mode 100644 index 00000000000..92868396962 --- /dev/null +++ b/qa/shield-core-rest-tests/pom.xml @@ -0,0 +1,149 @@ + + + + 4.0.0 + + + org.elasticsearch.qa + x-plugins-qa + 2.0.0-SNAPSHOT + + + + + shield-core-rest-tests + QA: Shield core REST tests + Run core REST tests with Shield enabled + + + true + ${project.basedir}/integration-tests.xml + true + indices.get/10_basic/*allow_no_indices*,cat.count/10_basic/Test cat count output,cat.aliases/10_basic/Empty cluster,indices.segments/10_basic/no segments test,indices.clear_cache/10_basic/clear_cache test,indices.status/10_basic/Indices status test,cat.indices/10_basic/Test cat indices output,cat.recovery/10_basic/Test cat recovery output,cat.shards/10_basic/Test cat shards output,termvector/20_issue7121/*,index/10_with_id/Index with ID,indices.get_alias/20_emtpy/*,cat.segments/10_basic/Test cat segments output,indices.put_settings/10_basic/Test indices settings allow_no_indices,indices.put_settings/10_basic/Test indices settings ignore_unavailable,indices.refresh/10_basic/Indices refresh test no-match wildcard,indices.stats/10_index/Index - star*,indices.recovery/10_basic/Indices recovery test*,template/30_render_search_template/*,indices.shard_stores/10_basic/no indices test,cat.nodeattrs/10_basic/Test cat nodes attrs output + elasticsearch-license,elasticsearch-shield + + + + + org.elasticsearch.plugin + elasticsearch-shield + ${elasticsearch.version} + test + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + integ-setup-dependencies + pre-integration-test + + copy + + + ${skip.integ.tests} + true + ${integ.deps}/plugins + + + + + org.elasticsearch.distribution.zip + elasticsearch + ${elasticsearch.version} + zip + true + ${integ.deps} + + + + + org.elasticsearch.plugin + elasticsearch-license + ${elasticsearch.version} + zip + true + + + + org.elasticsearch.plugin + elasticsearch-shield + ${elasticsearch.version} + zip + true + + + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + + integ-setup + pre-integration-test + + run + + + + + + + + + + ${skip.integ.tests} + + + + + integ-teardown + post-integration-test + + run + + + + + + ${skip.integ.tests} + + + + + + ant-contrib + ant-contrib + 1.0b3 + + + ant + ant + + + + + org.apache.ant + ant-nodeps + 1.8.1 + + + + + + + diff --git a/qa/shield-core-rest-tests/src/test/java/org/elasticsearch/shield/RestIT.java b/qa/shield-core-rest-tests/src/test/java/org/elasticsearch/shield/RestIT.java new file mode 100644 index 00000000000..a0b1de402e0 --- /dev/null +++ b/qa/shield-core-rest-tests/src/test/java/org/elasticsearch/shield/RestIT.java @@ -0,0 +1,54 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.shield; + +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 RestIT extends ESRestTestCase { + + private static final String USER = "test_user"; + private static final String PASS = "changeme"; + + public RestIT(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + + @ParametersFactory + 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(); + } + +} + diff --git a/qa/smoke-test-plugins/integration-tests.xml b/qa/smoke-test-plugins/integration-tests.xml index c0c7bf175f6..4da32222a8f 100644 --- a/qa/smoke-test-plugins/integration-tests.xml +++ b/qa/smoke-test-plugins/integration-tests.xml @@ -3,80 +3,6 @@ xmlns:ac="antlib:net.sf.antcontrib"> + - - - - - - Waiting for elasticsearch to become available on port @{port}... - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Setting up Shield auth - - - - - - - - - - - - - - - - - - - - - - - - - - - - Checking we can connect with basic auth on port ${integ.http.port}... - - - - diff --git a/shield/pom.xml b/shield/pom.xml index 18f6f6a4e1b..6b0ed1f7e16 100644 --- a/shield/pom.xml +++ b/shield/pom.xml @@ -16,12 +16,13 @@ + + true ${basedir}/src/main/assemblies/plugin.xml org.elasticsearch.shield.ShieldPlugin false - indices.get/10_basic/*allow_no_indices*,cat.count/10_basic/Test cat count output,cat.aliases/10_basic/Empty cluster,indices.segments/10_basic/no segments test,indices.clear_cache/10_basic/clear_cache test,indices.status/10_basic/Indices status test,cat.indices/10_basic/Test cat indices output,cat.recovery/10_basic/Test cat recovery output,cat.shards/10_basic/Test cat shards output,termvector/20_issue7121/*,index/10_with_id/Index with ID,indices.get_alias/20_emtpy/*,cat.segments/10_basic/Test cat segments output,indices.put_settings/10_basic/Test indices settings allow_no_indices,indices.put_settings/10_basic/Test indices settings ignore_unavailable,indices.refresh/10_basic/Indices refresh test no-match wildcard,indices.stats/10_index/Index - star*,indices.recovery/10_basic/Indices recovery test*,template/30_render_search_template/*,indices.shard_stores/10_basic/no indices test,cat.nodeattrs/10_basic/Test cat nodes attrs output ${basedir}/dev-tools/integration-tests.xml diff --git a/shield/src/test/java/org/elasticsearch/test/ShieldRestIT.java b/shield/src/test/java/org/elasticsearch/test/ShieldRestIT.java deleted file mode 100644 index d0480c23492..00000000000 --- a/shield/src/test/java/org/elasticsearch/test/ShieldRestIT.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.test; - -import com.carrotsearch.randomizedtesting.annotations.Name; -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; - -import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; - -import java.io.IOException; - -/** Runs rest tests against external cluster */ -public class ShieldRestIT extends ShieldRestTestCase { - public ShieldRestIT(@Name("yaml") RestTestCandidate testCandidate) { - super(testCandidate); - } - - @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { - return ESRestTestCase.createParameters(0, 1); - } -} diff --git a/shield/src/test/java/org/elasticsearch/test/ShieldRestTestCase.java b/shield/src/test/java/org/elasticsearch/test/ShieldRestTestCase.java deleted file mode 100644 index 0b531798eca..00000000000 --- a/shield/src/test/java/org/elasticsearch/test/ShieldRestTestCase.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.test; - -import com.carrotsearch.randomizedtesting.annotations.Name; -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.util.LuceneTestCase.Slow; -import org.elasticsearch.client.support.Headers; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.node.Node; -import org.elasticsearch.shield.authc.support.SecuredString; -import org.elasticsearch.shield.authc.support.UsernamePasswordToken; -import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.client.RestException; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.IOException; - -import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; - -/** - * Allows to run Elasticsearch REST tests against a cluster with shield installed. - * Subclasses {@link ShieldIntegTestCase} that contains all the needed code to override the global - * cluster settings and make sure shield is properly installed and configured. - * Delegates all of the tests to {@link org.elasticsearch.test.rest.ESRestTestCase}. - */ -@ESRestTestCase.Rest -@ESIntegTestCase.ClusterScope(randomDynamicTemplates = false) -@LuceneTestCase.SuppressFsync // we aren't trying to test this here, and it can make the test slow -@LuceneTestCase.SuppressCodecs("*") // requires custom completion postings format -public abstract class ShieldRestTestCase extends ShieldIntegTestCase { - - private final DelegatedRestTestCase delegate; - - public ShieldRestTestCase(@Name("yaml") RestTestCandidate testCandidate) { - delegate = new DelegatedRestTestCase(testCandidate); - } - - @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.builder() - .put(delegate.nodeSettings(nodeOrdinal)) - .put(super.nodeSettings(nodeOrdinal)) - .put(Node.HTTP_ENABLED, true) - .build(); - } - - @BeforeClass - public static void initExecutionContext() throws IOException, RestException { - ESRestTestCase.initExecutionContext(); - } - - @AfterClass - public static void close() { - ESRestTestCase.close(); - } - - @Test - public void test() throws IOException { - delegate.test(); - } - - @Before - public void reset() throws IOException, RestException { - delegate.reset(); - } - - class DelegatedRestTestCase extends ESRestTestCase { - - DelegatedRestTestCase(RestTestCandidate candidate) { - super(candidate); - } - - @Override - protected Settings restClientSettings() { - return Settings.builder() - .put(Headers.PREFIX + "." + UsernamePasswordToken.BASIC_AUTH_HEADER, basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME, - new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))).build(); - } - - @Override - public Settings nodeSettings(int ordinal) { - return Settings.builder() - .put(super.nodeSettings(ordinal)) - .put(ShieldRestTestCase.super.nodeSettings(ordinal)) - .put(Node.HTTP_ENABLED, true) - .build(); - } - - @Override - protected Settings transportClientSettings() { - return ShieldRestTestCase.this.transportClientSettings(); - } - } -} diff --git a/x-dev-tools/src/main/resources/ant/shield-overrides.xml b/x-dev-tools/src/main/resources/ant/shield-overrides.xml new file mode 100644 index 00000000000..79c1e3eb624 --- /dev/null +++ b/x-dev-tools/src/main/resources/ant/shield-overrides.xml @@ -0,0 +1,97 @@ + + + + + + + + + Waiting for elasticsearch to become available on port @{port}... + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + Setting up Shield auth + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Checking we can connect with basic auth on port ${integ.http.port}... + + + + + +