|  | @@ -58,6 +58,7 @@ import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest;
 | 
	
		
			
				|  |  |  import org.elasticsearch.search.internal.ShardSearchRequest;
 | 
	
		
			
				|  |  |  import org.elasticsearch.test.ESTestCase;
 | 
	
		
			
				|  |  |  import org.elasticsearch.threadpool.ThreadPool;
 | 
	
		
			
				|  |  | +import org.elasticsearch.transport.NoSuchRemoteClusterException;
 | 
	
		
			
				|  |  |  import org.elasticsearch.transport.TransportRequest;
 | 
	
		
			
				|  |  |  import org.elasticsearch.xpack.core.graph.action.GraphExploreAction;
 | 
	
		
			
				|  |  |  import org.elasticsearch.xpack.core.security.authc.Authentication.RealmRef;
 | 
	
	
		
			
				|  | @@ -104,6 +105,7 @@ import static org.elasticsearch.test.TestMatchers.throwableWithMessage;
 | 
	
		
			
				|  |  |  import static org.elasticsearch.xpack.core.security.test.TestRestrictedIndices.RESTRICTED_INDICES;
 | 
	
		
			
				|  |  |  import static org.elasticsearch.xpack.security.authz.AuthorizedIndicesTests.getRequestInfo;
 | 
	
		
			
				|  |  |  import static org.elasticsearch.xpack.security.support.SecuritySystemIndices.SECURITY_MAIN_ALIAS;
 | 
	
		
			
				|  |  | +import static org.hamcrest.CoreMatchers.containsString;
 | 
	
		
			
				|  |  |  import static org.hamcrest.CoreMatchers.instanceOf;
 | 
	
		
			
				|  |  |  import static org.hamcrest.CoreMatchers.is;
 | 
	
		
			
				|  |  |  import static org.hamcrest.Matchers.arrayContaining;
 | 
	
	
		
			
				|  | @@ -455,6 +457,102 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    public void testResolveIndicesAndAliasesWithoutWildcardsWithSingleIndexNoWildcardsRequest() {
 | 
	
		
			
				|  |  | +        // test 1: matching local index
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            ResolvedIndices resolvedIndices = defaultIndicesResolver.resolveIndicesAndAliasesWithoutWildcards(
 | 
	
		
			
				|  |  | +                TransportSearchAction.TYPE.name() + "[s]",
 | 
	
		
			
				|  |  | +                createSingleIndexNoWildcardsRequest(new String[] { "index10" })
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().size(), equalTo(0));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getLocal().size(), equalTo(1));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getLocal().get(0), equalTo("index10"));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // test 2: matching remote index
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            ResolvedIndices resolvedIndices = defaultIndicesResolver.resolveIndicesAndAliasesWithoutWildcards(
 | 
	
		
			
				|  |  | +                TransportSearchAction.TYPE.name() + "[s]",
 | 
	
		
			
				|  |  | +                createSingleIndexNoWildcardsRequest(new String[] { "remote:indexName" })
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().size(), equalTo(1));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().get(0), equalTo("remote:indexName"));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getLocal().size(), equalTo(0));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // test 3: missing local index
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            ResolvedIndices resolvedIndices = defaultIndicesResolver.resolveIndicesAndAliasesWithoutWildcards(
 | 
	
		
			
				|  |  | +                TransportSearchAction.TYPE.name() + "[s]",
 | 
	
		
			
				|  |  | +                createSingleIndexNoWildcardsRequest(new String[] { "zzz_no_such_index_zzz" })
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().size(), equalTo(0));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getLocal().size(), equalTo(1));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getLocal().get(0), equalTo("zzz_no_such_index_zzz"));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // test 4: missing remote index
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            ResolvedIndices resolvedIndices = defaultIndicesResolver.resolveIndicesAndAliasesWithoutWildcards(
 | 
	
		
			
				|  |  | +                TransportSearchAction.TYPE.name() + "[s]",
 | 
	
		
			
				|  |  | +                createSingleIndexNoWildcardsRequest(new String[] { "remote:zzz_no_such_index_zzz" })
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().size(), equalTo(1));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().get(0), equalTo("remote:zzz_no_such_index_zzz"));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getLocal().size(), equalTo(0));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // test 5: both local and remote indexes
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            ResolvedIndices resolvedIndices = defaultIndicesResolver.resolveIndicesAndAliasesWithoutWildcards(
 | 
	
		
			
				|  |  | +                TransportSearchAction.TYPE.name() + "[s]",
 | 
	
		
			
				|  |  | +                createSingleIndexNoWildcardsRequest(new String[] { "index10", "remote:indexName" })
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().size(), equalTo(1));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().get(0), equalTo("remote:indexName"));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getLocal().size(), equalTo(1));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getLocal().get(0), equalTo("index10"));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // test 6: remote cluster name with wildcards that does not match any configured remotes
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            NoSuchRemoteClusterException exception = expectThrows(
 | 
	
		
			
				|  |  | +                NoSuchRemoteClusterException.class,
 | 
	
		
			
				|  |  | +                () -> defaultIndicesResolver.resolveIndicesAndAliasesWithoutWildcards(
 | 
	
		
			
				|  |  | +                    TransportSearchAction.TYPE.name() + "[s]",
 | 
	
		
			
				|  |  | +                    createSingleIndexNoWildcardsRequest(new String[] { "x*x:test" })
 | 
	
		
			
				|  |  | +                )
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            assertThat(exception.getMessage(), containsString("no such remote cluster: [x*x]"));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // test 7: mix and test 2 and test 6 - should not result in exception (wildcard without matches has no effect)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            ResolvedIndices resolvedIndices = defaultIndicesResolver.resolveIndicesAndAliasesWithoutWildcards(
 | 
	
		
			
				|  |  | +                TransportSearchAction.TYPE.name() + "[s]",
 | 
	
		
			
				|  |  | +                createSingleIndexNoWildcardsRequest(new String[] { "x*x:test", "remote:indexName" })
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().size(), equalTo(1));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getRemote().get(0), equalTo("remote:indexName"));
 | 
	
		
			
				|  |  | +            assertThat(resolvedIndices.getLocal().size(), equalTo(0));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static IndicesRequest.SingleIndexNoWildcards createSingleIndexNoWildcardsRequest(String[] indexExpression) {
 | 
	
		
			
				|  |  | +        IndicesRequest.SingleIndexNoWildcards singleIndexNoWildcardsRequest = new IndicesRequest.SingleIndexNoWildcards() {
 | 
	
		
			
				|  |  | +            @Override
 | 
	
		
			
				|  |  | +            public String[] indices() {
 | 
	
		
			
				|  |  | +                return indexExpression;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            @Override
 | 
	
		
			
				|  |  | +            public IndicesOptions indicesOptions() {
 | 
	
		
			
				|  |  | +                return IndicesOptions.DEFAULT;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        return singleIndexNoWildcardsRequest;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      public void testExplicitDashIndices() {
 | 
	
		
			
				|  |  |          SearchRequest request = new SearchRequest("-index10", "-index20");
 | 
	
		
			
				|  |  |          List<String> indices = resolveIndices(request, buildAuthorizedIndices(userDashIndices, TransportSearchAction.TYPE.name()))
 |