From 4a780637e9600889da4501ac127d6289d59daaef Mon Sep 17 00:00:00 2001 From: Konrad Beiske Date: Sun, 27 Sep 2015 11:30:38 +0200 Subject: [PATCH] Change found-license-plugin to use standard value for install name and initial smoke test for found-license-plugin Original commit: elastic/x-pack-elasticsearch@526c0c6da4fc3c9ee80beec15139cc32ab25e93b --- qa/pom.xml | 1 + .../integration-tests.xml | 114 +++++++++ .../pom.xml | 216 ++++++++++++++++++ .../smoketest/WatcherWithShieldIT.java | 97 ++++++++ .../WatcherWithShieldInsufficientRoleIT.java | 40 ++++ .../watcher-with-shield-roles.yml | 20 ++ 6 files changed, 488 insertions(+) create mode 100644 qa/smoke-test-found-license-with-shield-and-watcher/integration-tests.xml create mode 100644 qa/smoke-test-found-license-with-shield-and-watcher/pom.xml create mode 100644 qa/smoke-test-found-license-with-shield-and-watcher/src/test/java/org/elasticsearch/smoketest/WatcherWithShieldIT.java create mode 100644 qa/smoke-test-found-license-with-shield-and-watcher/src/test/java/org/elasticsearch/smoketest/WatcherWithShieldInsufficientRoleIT.java create mode 100644 qa/smoke-test-found-license-with-shield-and-watcher/watcher-with-shield-roles.yml diff --git a/qa/pom.xml b/qa/pom.xml index dd048c6e41e..939f806b459 100644 --- a/qa/pom.xml +++ b/qa/pom.xml @@ -304,6 +304,7 @@ shield-core-rest-tests smoke-test-watcher-with-shield smoke-test-watcher-with-groovy + smoke-test-found-license-with-shield-and-watcher shield-example-realm shield-tribe-node-tests shield-client-tests diff --git a/qa/smoke-test-found-license-with-shield-and-watcher/integration-tests.xml b/qa/smoke-test-found-license-with-shield-and-watcher/integration-tests.xml new file mode 100644 index 00000000000..7961590747f --- /dev/null +++ b/qa/smoke-test-found-license-with-shield-and-watcher/integration-tests.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + Waiting for elasticsearch to become available on port @{port}... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Adding roles.yml with watcher roles + + + Adding shield users... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Checking we can connect with basic auth on port ${integ.http.port}... + + + + + diff --git a/qa/smoke-test-found-license-with-shield-and-watcher/pom.xml b/qa/smoke-test-found-license-with-shield-and-watcher/pom.xml new file mode 100644 index 00000000000..f292f4bc0ab --- /dev/null +++ b/qa/smoke-test-found-license-with-shield-and-watcher/pom.xml @@ -0,0 +1,216 @@ + + + + + + 4.0.0 + + + org.elasticsearch.qa + x-plugins-qa + 3.0.0-SNAPSHOT + + + smoke-test-found-license-with-shield-and-watcher + QA: Smoke Test Shield and Watcher works with Found license + Installs Watcher and Shield and runs Watcher's rest tests and checks if the Shield integrations work correctly when run with Found License plugin + + + true + ${project.basedir}/integration-tests.xml + false + found-license-plugin,shield,watcher + hijack/10_basic/*,array_compare_watch/10_basic/Basic array_compare watch + + + + + org.elasticsearch.plugin + shield + ${elasticsearch.version} + test + + + org.elasticsearch.plugin + watcher + ${project.version} + test + + + org.elasticsearch + found-license-plugin + ${project.version} + test + + + + + + + + ../../watcher/src/test/resources/rest-api-spec + true + rest-api-spec + + api/*.json + test/**/*.yaml + + + + + ${elasticsearch.tools.directory}/rest-api-spec + rest-api-spec + + + api/info.json + api/cluster.health.json + api/cluster.state.json + + api/index.json + api/get.json + api/delete.json + api/delete-by-query.json + api/bulk.json + api/update.json + api/search.json + api/indices.delete.json + api/indices.refresh.json + + + + + + 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 + found-license-plugin + ${elasticsearch.version} + zip + true + + + + org.elasticsearch.plugin + watcher + ${elasticsearch.version} + zip + true + + + + org.elasticsearch.plugin + 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/smoke-test-found-license-with-shield-and-watcher/src/test/java/org/elasticsearch/smoketest/WatcherWithShieldIT.java b/qa/smoke-test-found-license-with-shield-and-watcher/src/test/java/org/elasticsearch/smoketest/WatcherWithShieldIT.java new file mode 100644 index 00000000000..3c5022f7b34 --- /dev/null +++ b/qa/smoke-test-found-license-with-shield-and-watcher/src/test/java/org/elasticsearch/smoketest/WatcherWithShieldIT.java @@ -0,0 +1,97 @@ +/* + * 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.smoketest; + +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.BasicHttpClientConnectionManager; +import org.elasticsearch.client.support.Headers; +import org.elasticsearch.common.network.NetworkAddress; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.shield.ShieldPlugin; +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.parser.RestTestParseException; +import org.junit.After; +import org.junit.Before; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.URI; +import java.util.Collection; +import java.util.Collections; + +import static org.elasticsearch.shield.authc.support.UsernamePasswordToken.basicAuthHeaderValue; + +public class WatcherWithShieldIT extends ESRestTestCase { + + private final static String TEST_ADMIN_USERNAME = "test_admin"; + private final static String TEST_ADMIN_PASSWORD = "changeme"; + + public WatcherWithShieldIT(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + + @ParametersFactory + public static Iterable parameters() throws IOException, RestTestParseException { + return ESRestTestCase.createParameters(0, 1); + } + + @Before + public void startWatcher() throws Exception { + try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) { + InetSocketAddress address = cluster().httpAddresses()[0]; + HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.formatAddress(address.getAddress()), address.getPort(), "/_watcher/_start", null, null)); + String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecuredString(TEST_ADMIN_PASSWORD.toCharArray())); + request.addHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, token); + client.execute(request); + } + } + + @After + public void stopWatcher() throws Exception { + try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) { + InetSocketAddress address = cluster().httpAddresses()[0]; + HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.formatAddress(address.getAddress()), address.getPort(), "/_watcher/_stop", null, null)); + String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecuredString(TEST_ADMIN_PASSWORD.toCharArray())); + request.addHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, token); + client.execute(request); + } + } + + @Override + protected Settings restClientSettings() { + String[] credentials = getCredentials(); + String token = basicAuthHeaderValue(credentials[0], new SecuredString(credentials[1].toCharArray())); + return Settings.builder() + .put(Headers.PREFIX + ".Authorization", token) + .build(); + } + + @Override + protected Settings externalClusterClientSettings() { + return Settings.builder() + .put("shield.user", TEST_ADMIN_USERNAME + ":" + TEST_ADMIN_PASSWORD) + .build(); + } + + protected String[] getCredentials() { + return new String[]{"watcher_manager", "changeme"}; + } + + @Override + protected Collection> transportClientPlugins() { + return Collections.>singleton(ShieldPlugin.class); + } + +} + diff --git a/qa/smoke-test-found-license-with-shield-and-watcher/src/test/java/org/elasticsearch/smoketest/WatcherWithShieldInsufficientRoleIT.java b/qa/smoke-test-found-license-with-shield-and-watcher/src/test/java/org/elasticsearch/smoketest/WatcherWithShieldInsufficientRoleIT.java new file mode 100644 index 00000000000..7bf94128f8e --- /dev/null +++ b/qa/smoke-test-found-license-with-shield-and-watcher/src/test/java/org/elasticsearch/smoketest/WatcherWithShieldInsufficientRoleIT.java @@ -0,0 +1,40 @@ +/* + * 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.smoketest; + +import com.carrotsearch.randomizedtesting.annotations.Name; +import org.elasticsearch.test.rest.RestTestCandidate; +import org.junit.Test; + +import java.io.IOException; + +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.containsString; + +public class WatcherWithShieldInsufficientRoleIT extends WatcherWithShieldIT { + + public WatcherWithShieldInsufficientRoleIT(@Name("yaml") RestTestCandidate testCandidate) { + super(testCandidate); + } + + @Test + public void test() throws IOException { + try { + super.test(); + fail(); + } catch(AssertionError ae) { + assertThat(ae.getMessage(), anyOf(containsString("action [cluster:monitor/watcher/"), containsString("action [cluster:admin/watcher/"))); + assertThat(ae.getMessage(), containsString("returned [403 Forbidden]")); + assertThat(ae.getMessage(), containsString("is unauthorized for user [powerless_user]")); + } + } + + @Override + protected String[] getCredentials() { + return new String[]{"powerless_user", "changeme"}; + } +} + diff --git a/qa/smoke-test-found-license-with-shield-and-watcher/watcher-with-shield-roles.yml b/qa/smoke-test-found-license-with-shield-and-watcher/watcher-with-shield-roles.yml new file mode 100644 index 00000000000..8228084ac69 --- /dev/null +++ b/qa/smoke-test-found-license-with-shield-and-watcher/watcher-with-shield-roles.yml @@ -0,0 +1,20 @@ +admin: + cluster: all + indices: + '*': all + +watcher_manager: + cluster: manage_watcher, cluster:monitor/nodes/info, cluster:monitor/health + indices: + '.watch_history-*': all + +watcher_monitor: + cluster: monitor_watcher + indices: + '.watch_history-*': read + +crapy_role: + cluster: + - cluster:monitor/nodes/info + - cluster:monitor/health + - cluster:monitor/nodes/liveness \ No newline at end of file