Skip to content

Commit 436d5c4

Browse files
authored
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 db3d32c commit 436d5c4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 6 additions & 2 deletions
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;
@@ -44,7 +45,6 @@
4445
import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken;
4546
import org.elasticsearch.xpack.core.security.client.SecurityClient;
4647
import org.elasticsearch.xpack.security.LocalStateSecurity;
47-
4848
import org.elasticsearch.xpack.security.support.SecurityIndexManager;
4949
import org.junit.AfterClass;
5050
import org.junit.Before;
@@ -420,14 +420,18 @@ protected void createIndicesWithRandomAliases(String... indices) {
420420
createIndex(indices);
421421

422422
if (frequently()) {
423+
boolean aliasAdded = false;
423424
IndicesAliasesRequestBuilder builder = client().admin().indices().prepareAliases();
424425
for (String index : indices) {
425426
if (frequently()) {
426427
//one alias per index with prefix "alias-"
427428
builder.addAlias(index, "alias-" + index);
429+
aliasAdded = true;
428430
}
429431
}
430-
if (randomBoolean()) {
432+
// If we get to this point and we haven't added an alias to the request we need to add one
433+
// or the request will fail so use noAliasAdded to force adding the alias in this case
434+
if (aliasAdded == false || randomBoolean()) {
431435
//one alias pointing to all indices
432436
for (String index : indices) {
433437
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)