Skip to content

Commit 3d2f7aa

Browse files
Undo behaviour tweak and add tests
1 parent dcdb29e commit 3d2f7aa

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

x-pack/plugin/fleet/src/internalClusterTest/java/org/elasticsearch/xpack/fleet/action/FleetSearchRemoteIndicesDisallowedIT.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,43 @@ public void testEndpointsShouldRejectRemoteIndices() {
5252
);
5353
}
5454

55+
{
56+
/*
57+
* It is possible, however, to sneak in multiple indices and a remote index if checkpoints are not specified.
58+
* Unfortunately, that's the current behaviour and the Fleet team does not want us to touch it.
59+
*/
60+
Request request = new Request("POST", "/foo,bar:baz/_fleet/_fleet_msearch");
61+
request.setJsonEntity("{}\n{}\n");
62+
try {
63+
getRestClient().performRequest(request);
64+
} catch (Exception e) {
65+
throw new AssertionError(e);
66+
}
67+
}
68+
5569
{
5670
// This is fine, there are no remote indices.
5771
Request request = new Request("POST", "/foo/_fleet/_fleet_msearch");
5872
request.setJsonEntity("{\"index\": \"bar*\"}\n{}\n");
5973
try {
6074
getRestClient().performRequest(request);
61-
} catch (Exception r) {
62-
throw new AssertionError(r);
75+
} catch (Exception e) {
76+
throw new AssertionError(e);
6377
}
6478
}
6579

6680
{
6781
// This is not valid. We shouldn't be passing multiple indices.
6882
Request request = new Request("POST", "/foo/_fleet/_fleet_msearch");
69-
request.setJsonEntity("{\"index\": \"bar*,baz\"}\n{}\n");
70-
83+
request.setJsonEntity("{\"index\": \"bar,baz\", \"wait_for_checkpoints\": 1 }\n{}\n");
7184
ResponseException responseException = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request));
7285
assertThat(responseException.getMessage(), Matchers.containsString("Fleet search API only supports searching a single index."));
7386
}
7487

7588
{
7689
// This is not valid. We shouldn't be passing remote indices.
7790
Request request = new Request("POST", "/foo/_fleet/_fleet_msearch");
78-
request.setJsonEntity("{\"index\": \"bar*\"}\n{}\n{\"index\": \"remote:index\"}\n{}\n");
91+
request.setJsonEntity("{\"index\": \"bar:baz\", \"wait_for_checkpoints\": 1 }\n{}\n");
7992
ResponseException responseException = expectThrows(ResponseException.class, () -> getRestClient().performRequest(request));
8093
assertThat(responseException.getMessage(), Matchers.containsString("Fleet search API does not support remote indices. Found:"));
8194
}

x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/rest/RestFleetMultiSearchAction.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
107107
"Fleet search API param wait_for_checkpoints is only supported with an index to search specified. "
108108
+ "No index specified."
109109
);
110+
} else if (indices.length > 1) {
111+
throw new IllegalArgumentException(
112+
"Fleet search API only supports searching a single index. Found: [" + Arrays.toString(indices) + "]."
113+
);
110114
}
111115
}
112-
if (indices.length > 1) {
113-
throw new IllegalArgumentException(
114-
"Fleet search API only supports searching a single index. Found: [" + Arrays.toString(indices) + "]."
115-
);
116-
}
117116

118-
if (RemoteClusterService.isRemoteIndexName(indices[0])) {
117+
if (indices.length == 1 && RemoteClusterService.isRemoteIndexName(indices[0])) {
119118
throw new IllegalArgumentException("Fleet search API does not support remote indices. Found: [" + indices[0] + "].");
120119
}
121120
long[] checkpoints = searchRequest.getWaitForCheckpoints().get("*");

0 commit comments

Comments
 (0)