From 092fcd3675fd8816ba3c34ccee6e21efc491a668 Mon Sep 17 00:00:00 2001 From: jaymode Date: Tue, 6 Feb 2018 13:31:41 -0700 Subject: [PATCH] Test: do not check cluster stats in audit qa project This commit wraps the TestCluster in one that does not check stats to prevent tripping an assertion for the accounting breaker as the index audit trail is running in the background and will affect the value of the breakers. See elastic/x-pack-elasticsearch#157 Original commit: elastic/x-pack-elasticsearch@381ebbd413d78ea7a592dd6b4c4cd32feb1b6a89 --- qa/audit-tests/build.gradle | 1 + .../xpack/security/audit/IndexAuditIT.java | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/qa/audit-tests/build.gradle b/qa/audit-tests/build.gradle index 34b6deaef3f..e468846048b 100644 --- a/qa/audit-tests/build.gradle +++ b/qa/audit-tests/build.gradle @@ -19,6 +19,7 @@ integTestCluster { distribution 'zip' plugin xpackProject('plugin').path setting 'xpack.ml.enabled', 'false' + setting 'xpack.monitoring.enabled', 'false' setting 'xpack.security.audit.enabled', 'true' setting 'xpack.security.audit.outputs', 'index' setting 'logger.level', 'DEBUG' diff --git a/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java b/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java index 1d4b8004463..3467316c24f 100644 --- a/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java +++ b/qa/audit-tests/src/test/java/org/elasticsearch/xpack/security/audit/IndexAuditIT.java @@ -10,20 +10,25 @@ import org.apache.http.message.BasicHeader; import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse; import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.client.Client; import org.elasticsearch.client.Response; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.TestCluster; import org.elasticsearch.xpack.core.XPackClientPlugin; import org.elasticsearch.xpack.core.security.SecurityField; import org.elasticsearch.xpack.security.audit.index.IndexAuditTrail; import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken; +import java.io.IOException; +import java.net.InetSocketAddress; import java.util.Arrays; import java.util.Collection; import java.util.concurrent.TimeUnit; @@ -37,6 +42,70 @@ public class IndexAuditIT extends ESIntegTestCase { private static final String USER = "test_user"; private static final String PASS = "x-pack-test-password"; + @Override + protected TestCluster buildTestCluster(Scope scope, long seed) throws IOException { + TestCluster testCluster = super.buildTestCluster(scope, seed); + return new TestCluster(seed) { + + @Override + public void afterTest() throws IOException { + testCluster.afterTest(); + } + + @Override + public Client client() { + return testCluster.client(); + } + + @Override + public int size() { + return testCluster.size(); + } + + @Override + public int numDataNodes() { + return testCluster.numDataNodes(); + } + + @Override + public int numDataAndMasterNodes() { + return testCluster.numDataAndMasterNodes(); + } + + @Override + public InetSocketAddress[] httpAddresses() { + return testCluster.httpAddresses(); + } + + @Override + public void close() throws IOException { + testCluster.close(); + } + + @Override + public void ensureEstimatedStats() { + // stats are not going to be accurate for these tests since the index audit trail + // is running and changing the values so we wrap the test cluster to skip these + // checks + } + + @Override + public String getClusterName() { + return testCluster.getClusterName(); + } + + @Override + public Iterable getClients() { + return testCluster.getClients(); + } + + @Override + public NamedWriteableRegistry getNamedWriteableRegistry() { + return testCluster.getNamedWriteableRegistry(); + } + }; + } + public void testIndexAuditTrailWorking() throws Exception { Response response = getRestClient().performRequest("GET", "/", new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,