Skip to content

Commit ff56588

Browse files
committed
Fixes SecurityIntegTestCase so it always adds at least one alias
(#33296) * Fixes SecurityIntegTestCase so it always adds at least one alias `SecurityIntegTestCase.createIndicesWithRandomAliases` could randomly fail because its not gauranteed that the randomness of which aliases to add to the `IndicesAliasesRequestBuilder` would always select at least one alias to add. This change fixes the problem by keeping track of whether we have added an alias to teh request and forcing the last alias to be added if no other aliases have been added so far. Closes #30098 Closes #33123e * Addresses review comments
1 parent 908c010 commit ff56588

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecurityIntegTestCase.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import io.netty.util.ThreadDeathWatcher;
99
import io.netty.util.concurrent.GlobalEventExecutor;
10+
1011
import org.elasticsearch.Version;
1112
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
1213
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
@@ -427,14 +428,18 @@ protected void createIndicesWithRandomAliases(String... indices) {
427428
createIndex(indices);
428429

429430
if (frequently()) {
431+
boolean aliasAdded = false;
430432
IndicesAliasesRequestBuilder builder = client().admin().indices().prepareAliases();
431433
for (String index : indices) {
432434
if (frequently()) {
433435
//one alias per index with prefix "alias-"
434436
builder.addAlias(index, "alias-" + index);
437+
aliasAdded = true;
435438
}
436439
}
437-
if (randomBoolean()) {
440+
// If we get to this point and we haven't added an alias to the request we need to add one
441+
// or the request will fail so use noAliasAdded to force adding the alias in this case
442+
if (aliasAdded == false || randomBoolean()) {
438443
//one alias pointing to all indices
439444
for (String index : indices) {
440445
builder.addAlias(index, "alias");

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public void testEmptyAuthorizedIndicesSearchForAll() {
102102
assertNoSearchHits(client().prepareSearch().get());
103103
}
104104

105-
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/33123")
106105
public void testEmptyAuthorizedIndicesSearchForAllDisallowNoIndices() {
107106
createIndicesWithRandomAliases("index1", "index2");
108107
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch()

0 commit comments

Comments
 (0)