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
This commit is contained in:
Colin Goodheart-Smithe 2018-08-31 17:47:05 +01:00 committed by GitHub
parent db3d32ce91
commit 436d5c4eee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -7,6 +7,7 @@ package org.elasticsearch.test;
import io.netty.util.ThreadDeathWatcher;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
@ -44,7 +45,6 @@ import org.elasticsearch.xpack.core.security.authc.support.Hasher;
import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken;
import org.elasticsearch.xpack.core.security.client.SecurityClient;
import org.elasticsearch.xpack.security.LocalStateSecurity;
import org.elasticsearch.xpack.security.support.SecurityIndexManager;
import org.junit.AfterClass;
import org.junit.Before;
@ -420,14 +420,18 @@ public abstract class SecurityIntegTestCase extends ESIntegTestCase {
createIndex(indices);
if (frequently()) {
boolean aliasAdded = false;
IndicesAliasesRequestBuilder builder = client().admin().indices().prepareAliases();
for (String index : indices) {
if (frequently()) {
//one alias per index with prefix "alias-"
builder.addAlias(index, "alias-" + index);
aliasAdded = true;
}
}
if (randomBoolean()) {
// If we get to this point and we haven't added an alias to the request we need to add one
// or the request will fail so use noAliasAdded to force adding the alias in this case
if (aliasAdded == false || randomBoolean()) {
//one alias pointing to all indices
for (String index : indices) {
builder.addAlias(index, "alias");

View File

@ -102,7 +102,6 @@ public class ReadActionsTests extends SecurityIntegTestCase {
assertNoSearchHits(client().prepareSearch().get());
}
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/33123")
public void testEmptyAuthorizedIndicesSearchForAllDisallowNoIndices() {
createIndicesWithRandomAliases("index1", "index2");
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch()