Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,22 @@ public Map<String, OriginalIndices> groupIndices(
boolean returnLocalAll
) {
final Map<String, OriginalIndices> originalIndicesMap = new HashMap<>();
final Map<String, List<String>> groupedIndices = groupClusterIndices(remoteClusterNames, indices);
final Map<String, List<String>> groupedIndices;
/*
* We could use IndicesAndAliasesResolverField.NO_INDICES_OR_ALIASES_ARRAY but that'd require adding dependency on its
* module and doing so results in a circular dependency warnings.
*/
if (indices.length == 2 && indices[0].equals("*") && indices[1].equals("-*")) {
groupedIndices = Map.of();
/*
* We set returnLocalAll to false because this semantic ["*", "-*"] specifically means that it's alright to return
* an empty response and in this context we do not want to fallback to the local cluster.
*/
returnLocalAll = false;
} else {
groupedIndices = groupClusterIndices(remoteClusterNames, indices);
}

if (groupedIndices.isEmpty()) {
if (returnLocalAll) {
// search on _all in the local cluster if neither local indices nor remote indices were specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,15 @@ public void testResolveClusterUnderRCS1() throws Exception {
);
assertThat(exc.getMessage(), containsString(indexOptionTuple.v1()));
}
// TODO: The security pathways are not using the new
// RemoteClusterService.groupIndices(IndicesOptions indicesOptions, String[] indices, boolean returnLocalAll) method
// so this use case still behaves badly - fix in follow on PR
// {
// // TEST CASE 13: Resolution against wildcarded remote cluster expression that matches no remotes
// final Request remoteOnly1 = new Request("GET", "_resolve/cluster/no_such_remote*:*");
// Response response = performRequestWithRemoteSearchUser(remoteOnly1);
// assertOK(response);
// Map<String, Object> responseMap = responseAsMap(response);
// assertThat(responseMap.get(LOCAL_CLUSTER_NAME_REPRESENTATION), nullValue());
// Map<String, Object> remoteMap = (Map<String, Object>) responseMap.get("my_remote_cluster");
// assertThat((Boolean) remoteMap.get("connected"), equalTo(true));
// assertThat((Boolean) remoteMap.get("matching_indices"), equalTo(false));
// assertThat(remoteMap.get("version"), notNullValue());
// }
{
// TEST CASE 13: Resolution against wildcarded remote cluster expression that matches no remotes should result in an
// empty response and not fall back to the local cluster.
final Request remoteOnly1 = new Request("GET", "_resolve/cluster/no_such_remote*:*");
Response response = performRequestWithRemoteSearchUser(remoteOnly1);
assertOK(response);
Map<String, Object> responseMap = responseAsMap(response);
assertThat(responseMap.isEmpty(), is(true));
}
}

private Response performRequestWithRemoteSearchUser(final Request request) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,15 @@ public void testResolveCluster() throws Exception {
);
assertThat(exc.getMessage(), containsString(indexOptionTuple.v1()));
}
// TODO: fix this in a follow-on PR
// {
// // TEST CASE 13: Resolution against wildcarded remote cluster expression that matches no remotes
// final Request remoteOnly1 = new Request("GET", "_resolve/cluster/no_such_remote*:*");
// Response response = performRequestWithRemoteSearchUser(remoteOnly1);
// assertOK(response);
// Map<String, Object> responseMap = responseAsMap(response);
// assertThat(responseMap.get(LOCAL_CLUSTER_NAME_REPRESENTATION), nullValue());
// Map<String, Object> remoteMap = (Map<String, Object>) responseMap.get("my_remote_cluster");
// assertThat((Boolean) remoteMap.get("connected"), equalTo(true));
// assertThat((Boolean) remoteMap.get("matching_indices"), equalTo(false));
// assertThat(remoteMap.get("version"), notNullValue());
// }
{
// TEST CASE 13: Resolution against wildcarded remote cluster expression that matches no remotes should result in an
// empty response and not fall back to the local cluster.
final Request remoteOnly1 = new Request("GET", "_resolve/cluster/no_such_remote*:*");
Response response = performRequestWithRemoteSearchUser(remoteOnly1);
assertOK(response);
Map<String, Object> responseMap = responseAsMap(response);
assertThat(responseMap.isEmpty(), is(true));
}
}

private Response performRequestWithRemoteSearchUser(final Request request) throws IOException {
Expand Down