From 79a9576596821a15a1c6de468ee3816da2a10d28 Mon Sep 17 00:00:00 2001 From: jaymode Date: Thu, 11 Jan 2018 14:32:23 -0700 Subject: [PATCH] Test: do not wipe templates from clusters in audit tests This commit adds both the security index template and the audit index template to the excluded templates for the RemoteIndexAuditTrailStartingTests and IndexAuditTrailTests. By allowing the templates to remain in place, we make it easier for subsequent tests in the suite to have their audit trails started. Relates elastic/x-pack-elasticsearch#435 Original commit: elastic/x-pack-elasticsearch@6e54de19f9445ef90ca5b4a8666974aeabd9a511 --- .../xpack/security/audit/index/IndexAuditTrailTests.java | 6 ++++-- .../audit/index/RemoteIndexAuditTrailStartingTests.java | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java index b178d9944f6..9655114c065 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.MockSecureSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.concurrent.EsExecutors; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.search.SearchHit; @@ -43,6 +44,7 @@ import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.xpack.ml.MachineLearning; +import org.elasticsearch.xpack.security.SecurityLifecycleService; import org.elasticsearch.xpack.security.audit.index.IndexAuditTrail.Message; import org.elasticsearch.xpack.security.authc.AuthenticationToken; import org.elasticsearch.xpack.security.transport.filter.IPFilter; @@ -243,13 +245,13 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { } if (remoteCluster != null) { - remoteCluster.wipe(Collections.emptySet()); + remoteCluster.wipe(excludeTemplates()); } } @Override protected Set excludeTemplates() { - return Collections.singleton(IndexAuditTrail.INDEX_TEMPLATE_NAME); + return Sets.newHashSet(SecurityLifecycleService.SECURITY_TEMPLATE_NAME, IndexAuditTrail.INDEX_TEMPLATE_NAME); } @Override diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java index c0f1e690de2..6cd03fa80e9 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/RemoteIndexAuditTrailStartingTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; import org.elasticsearch.test.InternalTestCluster; @@ -17,6 +18,7 @@ import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecuritySettingsSource; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.xpack.ml.MachineLearning; +import org.elasticsearch.xpack.security.SecurityLifecycleService; import org.elasticsearch.xpack.security.audit.AuditTrail; import org.elasticsearch.xpack.security.audit.AuditTrailService; import org.junit.After; @@ -69,7 +71,7 @@ public class RemoteIndexAuditTrailStartingTests extends SecurityIntegTestCase { @Override protected Set excludeTemplates() { - return Collections.singleton(IndexAuditTrail.INDEX_TEMPLATE_NAME); + return Sets.newHashSet(SecurityLifecycleService.SECURITY_TEMPLATE_NAME, IndexAuditTrail.INDEX_TEMPLATE_NAME); } @Before @@ -123,11 +125,11 @@ public class RemoteIndexAuditTrailStartingTests extends SecurityIntegTestCase { .forEach((auditTrail) -> ((IndexAuditTrail) auditTrail).stop())); // first stop both audit trails otherwise we keep on indexing if (remoteCluster != null) { - toStop.add(() -> StreamSupport.stream(remoteCluster.getInstances(AuditTrailService.class).spliterator(), false) + toStop.add(() -> StreamSupport.stream(remoteCluster.getInstances(AuditTrailService.class).spliterator(), false) .map(s -> s.getAuditTrails()).flatMap(List::stream) .filter(t -> t.name().equals(IndexAuditTrail.NAME)) .forEach((auditTrail) -> ((IndexAuditTrail) auditTrail).stop())); - toStop.add(() -> remoteCluster.wipe(Collections.emptySet())); + toStop.add(() -> remoteCluster.wipe(excludeTemplates())); toStop.add(remoteCluster::afterTest); toStop.add(remoteCluster); }