From 93b8ef49e9b5a3e75368fe9d23fcea5631ac17d4 Mon Sep 17 00:00:00 2001 From: Albert Zaharovits Date: Mon, 15 Jan 2018 18:34:17 +0200 Subject: [PATCH] Fix CI failure elastic/x-pack-elasticsearch#3568 Bad test design & excessive randomness Original commit: elastic/x-pack-elasticsearch@076d0b246ab95965658810ed796fb9be2724518c --- .../logfile/LoggingAuditTrailFilterTests.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrailFilterTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrailFilterTests.java index 8f361a249be..18ab7a89849 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrailFilterTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/audit/logfile/LoggingAuditTrailFilterTests.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.NamedXContentRegistry; @@ -908,10 +909,7 @@ public class LoggingAuditTrailFilterTests extends ESTestCase { } else { _unfilteredRoles = randomListFromLengthBetween(unfilteredPolicy, 1, unfilteredPolicy.size()); // add roles from other filter policies - final List otherRoles = new ArrayList<>(); - for (int j = 0; j < randomIntBetween(1, 4); j++) { - otherRoles.add(FILTER_MARKER + randomAlphaOfLengthBetween(1, 4)); - } + final List otherRoles = randomNonEmptyListOfFilteredNames("other"); _unfilteredRoles.addAll(randomListFromLengthBetween(otherRoles, 1, otherRoles.size())); settingsBuilder.putList("xpack.security.audit.logfile.events.ignore_filters.otherPolicy.roles", otherRoles); } @@ -1161,7 +1159,7 @@ public class LoggingAuditTrailFilterTests extends ESTestCase { Collections.emptyList()); } } - // filtered roles are a subset of the roles of any policy + // filtered indices are a subset of the indices of any policy final List filterPolicy = randomFrom(allFilteredIndices); final String[] filteredIndices = randomListFromLengthBetween(filterPolicy, 1, filterPolicy.size()).toArray(new String[0]); // unfiltered index sets either have indices distinct from any other in any @@ -1177,10 +1175,7 @@ public class LoggingAuditTrailFilterTests extends ESTestCase { } else { _unfilteredIndices = randomListFromLengthBetween(unfilteredPolicy, 1, unfilteredPolicy.size()); // add indices from other filter policies - final List otherIndices = new ArrayList<>(); - for (int j = 0; j < randomIntBetween(1, 4); j++) { - otherIndices.add(FILTER_MARKER + randomAlphaOfLengthBetween(1, 4)); - } + final List otherIndices = randomNonEmptyListOfFilteredNames("other"); _unfilteredIndices.addAll(randomListFromLengthBetween(otherIndices, 1, otherIndices.size())); settingsBuilder.putList("xpack.security.audit.logfile.events.ignore_filters.otherPolicy.indices", otherIndices); } @@ -1506,10 +1501,10 @@ public class LoggingAuditTrailFilterTests extends ESTestCase { return ans; } - private List randomNonEmptyListOfFilteredNames() { + private List randomNonEmptyListOfFilteredNames(String... namePrefix) { final List filtered = new ArrayList<>(4); for (int i = 0; i < randomIntBetween(1, 4); i++) { - filtered.add(FILTER_MARKER + randomAlphaOfLengthBetween(1, 4)); + filtered.add(FILTER_MARKER + Strings.arrayToCommaDelimitedString(namePrefix) + randomAlphaOfLengthBetween(1, 4)); } return filtered; }