diff --git a/docs/changelog/125562.yaml b/docs/changelog/125562.yaml new file mode 100644 index 0000000000000..1e53662fabb7e --- /dev/null +++ b/docs/changelog/125562.yaml @@ -0,0 +1,6 @@ +pr: 125562 +summary: Improve handling of empty response +area: Infra/REST API +type: bug +issues: + - 57639 diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java index 3613d7390fda2..c9cbe8637a141 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java @@ -17,13 +17,15 @@ import org.elasticsearch.test.rest.RestActionTestCase; import org.elasticsearch.xcontent.XContentType; import org.junit.Before; -import org.mockito.Mockito; import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.Map; +import static org.elasticsearch.rest.RestResponseUtils.setUpXContentMock; +import static org.mockito.Mockito.mock; + public final class RestMultiSearchTemplateActionTests extends RestActionTestCase { final List contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7)); @@ -31,8 +33,8 @@ public final class RestMultiSearchTemplateActionTests extends RestActionTestCase public void setUpAction() { controller().registerHandler(new RestMultiSearchTemplateAction(Settings.EMPTY)); // todo how to workaround this? we get AssertionError without this - verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(MultiSearchTemplateResponse.class)); - verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(MultiSearchTemplateResponse.class)); + verifyingClient.setExecuteVerifier((actionType, request) -> setUpXContentMock(mock(MultiSearchTemplateResponse.class))); + verifyingClient.setExecuteLocallyVerifier((actionType, request) -> setUpXContentMock(mock(MultiSearchTemplateResponse.class))); } public void testTypeInPath() { diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_balance/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_balance/10_basic.yml index edb167ddbdf6e..82a086bdc3fa4 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_balance/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_balance/10_basic.yml @@ -180,6 +180,11 @@ setup: - requires: cluster_features: ["gte_v8.8.0"] reason: "reset API added in in 8.8.0" + test_runner_features: [ capabilities ] + capabilities: + - method: DELETE + path: /_internal/desired_balance + capabilities: [ plain_text_empty_response ] - do: _internal.delete_desired_balance: { } diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/10_basic.yml index 1d1aa524ffb21..fc962329a6250 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/10_basic.yml @@ -3,6 +3,11 @@ setup: - requires: cluster_features: ["gte_v8.13.0"] reason: "API added in in 8.1.0 but modified in 8.13 (node_version field removed)" + test_runner_features: [ capabilities ] + capabilities: + - method: DELETE + path: /_internal/desired_nodes + capabilities: [ plain_text_empty_response ] --- teardown: - do: diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/11_old_format.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/11_old_format.yml index 4df1252bef273..a9a2071a530cd 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/11_old_format.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/11_old_format.yml @@ -6,6 +6,11 @@ setup: - requires: cluster_features: ["gte_v8.3.0"] reason: "API added in in 8.1.0 but modified in 8.3" + test_runner_features: [ capabilities ] + capabilities: + - method: DELETE + path: /_internal/desired_nodes + capabilities: [ plain_text_empty_response ] --- teardown: - do: diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/20_dry_run.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/20_dry_run.yml index 87fc015347348..ba07cd1dfc836 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/20_dry_run.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.desired_nodes/20_dry_run.yml @@ -3,6 +3,11 @@ setup: - requires: cluster_features: ["gte_v8.4.0"] reason: "Support for the dry run option was added in in 8.4.0" + test_runner_features: [ capabilities ] + capabilities: + - method: DELETE + path: /_internal/desired_nodes + capabilities: [ plain_text_empty_response ] --- teardown: - do: diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.voting_config_exclusions/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.voting_config_exclusions/10_basic.yml index 327344c8daf55..1794323245243 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.voting_config_exclusions/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cluster.voting_config_exclusions/10_basic.yml @@ -1,3 +1,16 @@ +setup: + - requires: + test_runner_features: [ capabilities ] + capabilities: + - method: POST + path: /_cluster/voting_config_exclusions + capabilities: [ plain_text_empty_response ] + - method: DELETE + path: /_cluster/voting_config_exclusions + capabilities: [ plain_text_empty_response ] + reason: needs these capabilities + +--- teardown: - do: cluster.delete_voting_config_exclusions: {} diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/VotingConfigurationIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/VotingConfigurationIT.java index fd03591ebb1c5..6cf3363d43e38 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/VotingConfigurationIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/VotingConfigurationIT.java @@ -9,22 +9,24 @@ package org.elasticsearch.cluster.coordination; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest; -import org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction; +import org.elasticsearch.client.Request; +import org.elasticsearch.client.Response; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.transport.TransportService; +import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; -import java.util.concurrent.ExecutionException; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; @@ -38,18 +40,39 @@ protected Collection> nodePlugins() { return Collections.singletonList(MockTransportService.TestPlugin.class); } - public void testAbdicateAfterVotingConfigExclusionAdded() throws ExecutionException, InterruptedException { + @Override + protected boolean addMockHttpTransport() { + return false; // enable HTTP + } + + public void testAbdicateAfterVotingConfigExclusionAdded() throws IOException { internalCluster().setBootstrapMasterNodeIndex(0); internalCluster().startNodes(2); final String originalMaster = internalCluster().getMasterName(); + final var restClient = getRestClient(); logger.info("--> excluding master node {}", originalMaster); - client().execute( - TransportAddVotingConfigExclusionsAction.TYPE, - new AddVotingConfigExclusionsRequest(TEST_REQUEST_TIMEOUT, originalMaster) - ).get(); + final var excludeRequest = new Request("POST", "/_cluster/voting_config_exclusions"); + excludeRequest.addParameter("node_names", originalMaster); + assertEmptyResponse(restClient.performRequest(excludeRequest)); + clusterAdmin().prepareHealth(TEST_REQUEST_TIMEOUT).setWaitForEvents(Priority.LANGUID).get(); assertNotEquals(originalMaster, internalCluster().getMasterName()); + + final var clearRequest = new Request("DELETE", "/_cluster/voting_config_exclusions"); + clearRequest.addParameter("wait_for_removal", "false"); + assertEmptyResponse(restClient.performRequest(clearRequest)); + + assertThat( + internalCluster().getInstance(ClusterService.class).state().metadata().coordinationMetadata().getVotingConfigExclusions(), + empty() + ); + } + + private void assertEmptyResponse(Response response) throws IOException { + assertEquals("text/plain; charset=UTF-8", response.getHeader("content-type")); + assertEquals(0, response.getEntity().getContentLength()); + assertEquals(0, response.getEntity().getContent().readAllBytes().length); } public void testElectsNodeNotInVotingConfiguration() throws Exception { diff --git a/server/src/main/java/org/elasticsearch/action/ActionResponse.java b/server/src/main/java/org/elasticsearch/action/ActionResponse.java index 2c1002505d47b..ac9057b66df47 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionResponse.java +++ b/server/src/main/java/org/elasticsearch/action/ActionResponse.java @@ -11,11 +11,10 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.rest.action.EmptyResponseListener; import org.elasticsearch.transport.TransportResponse; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; - -import java.io.IOException; +import org.elasticsearch.xcontent.ToXContent; +import org.elasticsearch.xcontent.XContent; /** * Base class for responses to action requests. @@ -24,24 +23,25 @@ public abstract class ActionResponse extends TransportResponse { public ActionResponse() {} - public ActionResponse(StreamInput in) throws IOException { - super(in); - } + public ActionResponse(StreamInput in) {} + + /** + * A response with no payload. This is deliberately not an implementation of {@link ToXContent} or similar because an empty response + * has no valid {@link XContent} representation. Use {@link EmptyResponseListener} to convert this to a valid (plain-text) REST + * response instead. + */ + public static final class Empty extends ActionResponse { + + private Empty() { /* singleton */ } - public static final class Empty extends ActionResponse implements ToXContentObject { public static final ActionResponse.Empty INSTANCE = new ActionResponse.Empty(); @Override public String toString() { - return "EmptyActionResponse{}"; + return "ActionResponse.Empty{}"; } @Override public void writeTo(StreamOutput out) {} - - @Override - public XContentBuilder toXContent(final XContentBuilder builder, final Params params) { - return builder; - } } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/EmptyResponseListener.java b/server/src/main/java/org/elasticsearch/rest/action/EmptyResponseListener.java new file mode 100644 index 0000000000000..43f67c8dbbc4c --- /dev/null +++ b/server/src/main/java/org/elasticsearch/rest/action/EmptyResponseListener.java @@ -0,0 +1,38 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.rest.action; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestResponse; +import org.elasticsearch.rest.RestStatus; + +/** + * A listener which converts a successful {@link ActionResponse.Empty} action response into a {@code 200 OK} REST response with empty body. + */ +public final class EmptyResponseListener extends RestResponseListener { + public EmptyResponseListener(RestChannel channel) { + super(channel); + } + + @Override + public RestResponse buildResponse(ActionResponse.Empty ignored) throws Exception { + // Content-type header is not required for an empty body but some clients may expect it; the empty body is a valid text/plain entity + // so we use that here. + return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY); + } + + /** + * Capability name for APIs that previously would return an invalid zero-byte {@code application/json} response so that the YAML test + * runner can avoid those APIs. + */ + public static final String PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME = "plain_text_empty_response"; +} diff --git a/server/src/main/java/org/elasticsearch/rest/action/RestBuilderListener.java b/server/src/main/java/org/elasticsearch/rest/action/RestBuilderListener.java index f3fcbc7ef9345..bf675ff3b1574 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/RestBuilderListener.java +++ b/server/src/main/java/org/elasticsearch/rest/action/RestBuilderListener.java @@ -27,6 +27,7 @@ public final RestResponse buildResponse(Response response) throws Exception { try (XContentBuilder builder = channel.newBuilder()) { final RestResponse restResponse = buildResponse(response, builder); assert assertBuilderClosed(builder); + assert restResponse.content() != null && restResponse.content().length() > 0 : "Use EmptyResponseListener for empty responses"; return restResponse; } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java index b9662a8fe8874..dd34885531ec9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java @@ -18,13 +18,15 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.RestToXContentListener; +import org.elasticsearch.rest.action.EmptyResponseListener; import java.io.IOException; import java.util.List; +import java.util.Set; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout; +import static org.elasticsearch.rest.action.EmptyResponseListener.PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME; public class RestAddVotingConfigExclusionAction extends BaseRestHandler { private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(30L); @@ -48,6 +50,11 @@ public List routes() { ); } + @Override + public Set supportedCapabilities() { + return Set.of(PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME); + } + @Override public boolean canTripCircuitBreaker() { return false; @@ -59,7 +66,7 @@ protected RestChannelConsumer prepareRequest(final RestRequest request, final No return channel -> client.execute( TransportAddVotingConfigExclusionsAction.TYPE, votingConfigExclusionsRequest, - new RestToXContentListener<>(channel) + new EmptyResponseListener(channel) ); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java index 1e1b3742bf454..2eee91d4e86f5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java @@ -14,13 +14,15 @@ import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.RestToXContentListener; +import org.elasticsearch.rest.action.EmptyResponseListener; import java.io.IOException; import java.util.List; +import java.util.Set; import static org.elasticsearch.rest.RestRequest.Method.DELETE; import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout; +import static org.elasticsearch.rest.action.EmptyResponseListener.PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME; public class RestClearVotingConfigExclusionsAction extends BaseRestHandler { @@ -39,10 +41,15 @@ public String getName() { return "clear_voting_config_exclusions_action"; } + @Override + public Set supportedCapabilities() { + return Set.of(PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME); + } + @Override protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final var req = resolveVotingConfigExclusionsRequest(request); - return channel -> client.execute(TransportClearVotingConfigExclusionsAction.TYPE, req, new RestToXContentListener<>(channel)); + return channel -> client.execute(TransportClearVotingConfigExclusionsAction.TYPE, req, new EmptyResponseListener(channel)); } static ClearVotingConfigExclusionsRequest resolveVotingConfigExclusionsRequest(final RestRequest request) { diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDesiredBalanceAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDesiredBalanceAction.java index 16da7208279e8..a432bf5e589c7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDesiredBalanceAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDesiredBalanceAction.java @@ -17,10 +17,13 @@ import org.elasticsearch.rest.RestUtils; import org.elasticsearch.rest.Scope; import org.elasticsearch.rest.ServerlessScope; -import org.elasticsearch.rest.action.RestToXContentListener; +import org.elasticsearch.rest.action.EmptyResponseListener; import java.io.IOException; import java.util.List; +import java.util.Set; + +import static org.elasticsearch.rest.action.EmptyResponseListener.PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME; @ServerlessScope(Scope.INTERNAL) public class RestDeleteDesiredBalanceAction extends BaseRestHandler { @@ -35,9 +38,14 @@ public List routes() { return List.of(new Route(RestRequest.Method.DELETE, "_internal/desired_balance")); } + @Override + public Set supportedCapabilities() { + return Set.of(PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME); + } + @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { final var req = new DesiredBalanceRequest(RestUtils.getMasterNodeTimeout(request)); - return channel -> client.execute(TransportDeleteDesiredBalanceAction.TYPE, req, new RestToXContentListener<>(channel)); + return channel -> client.execute(TransportDeleteDesiredBalanceAction.TYPE, req, new EmptyResponseListener(channel)); } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDesiredNodesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDesiredNodesAction.java index abf66504f1c48..9f4b833017d5b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDesiredNodesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteDesiredNodesAction.java @@ -14,13 +14,15 @@ import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.RestToXContentListener; +import org.elasticsearch.rest.action.EmptyResponseListener; import java.io.IOException; import java.util.List; +import java.util.Set; import static org.elasticsearch.rest.RestUtils.getAckTimeout; import static org.elasticsearch.rest.RestUtils.getMasterNodeTimeout; +import static org.elasticsearch.rest.action.EmptyResponseListener.PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME; public class RestDeleteDesiredNodesAction extends BaseRestHandler { @Override @@ -33,13 +35,18 @@ public List routes() { return List.of(new Route(RestRequest.Method.DELETE, "_internal/desired_nodes")); } + @Override + public Set supportedCapabilities() { + return Set.of(PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME); + } + @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { final var deleteDesiredNodesRequest = new AcknowledgedRequest.Plain(getMasterNodeTimeout(request), getAckTimeout(request)); return restChannel -> client.execute( TransportDeleteDesiredNodesAction.TYPE, deleteDesiredNodesRequest, - new RestToXContentListener<>(restChannel) + new EmptyResponseListener(restChannel) ); } } diff --git a/server/src/test/java/org/elasticsearch/rest/action/RestBuilderListenerTests.java b/server/src/test/java/org/elasticsearch/rest/action/RestBuilderListenerTests.java index 03ae366050646..21a14e1349293 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/RestBuilderListenerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/RestBuilderListenerTests.java @@ -23,16 +23,19 @@ public class RestBuilderListenerTests extends ESTestCase { + // bypass the check that XContent responses are never empty - we're ignoring the builder and sending a text/plain response anyway + private static final BytesArray NONEMPTY_BODY = new BytesArray(new byte[] { '\n' }); + public void testXContentBuilderClosedInBuildResponse() throws Exception { AtomicReference builderAtomicReference = new AtomicReference<>(); RestBuilderListener builderListener = new RestBuilderListener( new FakeRestChannel(new FakeRestRequest(), true, 1) ) { @Override - public RestResponse buildResponse(Empty empty, XContentBuilder builder) throws Exception { + public RestResponse buildResponse(Empty empty, XContentBuilder builder) { builderAtomicReference.set(builder); builder.close(); - return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY); + return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, NONEMPTY_BODY); } }; @@ -47,9 +50,9 @@ public void testXContentBuilderNotClosedInBuildResponseAssertionsDisabled() thro new FakeRestChannel(new FakeRestRequest(), true, 1) ) { @Override - public RestResponse buildResponse(Empty empty, XContentBuilder builder) throws Exception { + public RestResponse buildResponse(Empty empty, XContentBuilder builder) { builderAtomicReference.set(builder); - return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY); + return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, NONEMPTY_BODY); } @Override @@ -64,15 +67,15 @@ boolean assertBuilderClosed(XContentBuilder xContentBuilder) { assertTrue(builderAtomicReference.get().generator().isClosed()); } - public void testXContentBuilderNotClosedInBuildResponseAssertionsEnabled() throws Exception { + public void testXContentBuilderNotClosedInBuildResponseAssertionsEnabled() { assumeTrue("tests are not being run with assertions", RestBuilderListener.class.desiredAssertionStatus()); RestBuilderListener builderListener = new RestBuilderListener( new FakeRestChannel(new FakeRestRequest(), true, 1) ) { @Override - public RestResponse buildResponse(Empty empty, XContentBuilder builder) throws Exception { - return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY); + public RestResponse buildResponse(Empty empty, XContentBuilder builder) { + return new RestResponse(RestStatus.OK, RestResponse.TEXT_CONTENT_TYPE, NONEMPTY_BODY); } }; diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java index 0a9abacd82635..b6f8395c34957 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java @@ -16,13 +16,14 @@ import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.RestActionTestCase; import org.junit.Before; -import org.mockito.Mockito; import java.util.Collections; import java.util.List; import java.util.Map; +import static org.elasticsearch.rest.RestResponseUtils.setUpXContentMock; import static org.hamcrest.Matchers.instanceOf; +import static org.mockito.Mockito.mock; public final class RestGetActionTests extends RestActionTestCase { final List contentTypeHeader = Collections.singletonList(randomCompatibleMediaType(RestApiVersion.V_7)); @@ -32,7 +33,7 @@ public void setUpAction() { controller().registerHandler(new RestGetAction()); verifyingClient.setExecuteVerifier((actionType, request) -> { assertThat(request, instanceOf(GetRequest.class)); - return Mockito.mock(GetResponse.class); + return setUpXContentMock(mock(GetResponse.class)); }); } diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiGetActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiGetActionTests.java index ed793f3127a93..8ee441e4c2198 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiGetActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiGetActionTests.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; +import static org.elasticsearch.rest.RestResponseUtils.setUpXContentMock; import static org.hamcrest.Matchers.instanceOf; public final class RestMultiGetActionTests extends RestActionTestCase { @@ -38,7 +39,7 @@ public void setUpAction() { controller().registerHandler(new RestMultiGetAction(Settings.EMPTY)); verifyingClient.setExecuteVerifier((actionType, request) -> { assertThat(request, instanceOf(MultiGetRequest.class)); - return Mockito.mock(MultiGetResponse.class); + return setUpXContentMock(Mockito.mock(MultiGetResponse.class)); }); } diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java index 0e247d70b2ba3..07b090113aea7 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java @@ -27,14 +27,16 @@ import java.util.List; import java.util.Map; +import static org.elasticsearch.rest.RestResponseUtils.setUpXContentMock; + public final class RestMultiTermVectorsActionTests extends RestActionTestCase { final List contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7)); @Before public void setUpAction() { controller().registerHandler(new RestMultiTermVectorsAction()); - verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(MultiTermVectorsResponse.class)); - verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(MultiTermVectorsResponse.class)); + verifyingClient.setExecuteVerifier((actionType, request) -> setUpXContentMock(Mockito.mock(MultiTermVectorsResponse.class))); + verifyingClient.setExecuteLocallyVerifier((actionType, request) -> setUpXContentMock(Mockito.mock(MultiTermVectorsResponse.class))); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java index a69c167c12729..6e81fc4ff18d9 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Map; +import static org.elasticsearch.rest.RestResponseUtils.setUpXContentMock; + public final class RestTermVectorsActionTests extends RestActionTestCase { final List contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7)); @@ -33,8 +35,8 @@ public final class RestTermVectorsActionTests extends RestActionTestCase { public void setUpAction() { controller().registerHandler(new RestTermVectorsAction()); // todo how to workaround this? we get AssertionError without this - verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(TermVectorsResponse.class)); - verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(TermVectorsResponse.class)); + verifyingClient.setExecuteVerifier((actionType, request) -> setUpXContentMock(Mockito.mock(TermVectorsResponse.class))); + verifyingClient.setExecuteLocallyVerifier((actionType, request) -> setUpXContentMock(Mockito.mock(TermVectorsResponse.class))); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/search/RestExplainActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/search/RestExplainActionTests.java index ddbe7243d304b..2766a97eec6ad 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/search/RestExplainActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/search/RestExplainActionTests.java @@ -22,6 +22,8 @@ import java.util.List; import java.util.Map; +import static org.elasticsearch.rest.RestResponseUtils.setUpXContentMock; + public final class RestExplainActionTests extends RestActionTestCase { final List contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7)); @@ -29,8 +31,8 @@ public final class RestExplainActionTests extends RestActionTestCase { public void setUpAction() { RestExplainAction action = new RestExplainAction(); controller().registerHandler(action); - verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(ExplainResponse.class)); - verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(ExplainResponse.class)); + verifyingClient.setExecuteVerifier((actionType, request) -> setUpXContentMock(Mockito.mock(ExplainResponse.class))); + verifyingClient.setExecuteLocallyVerifier((actionType, request) -> setUpXContentMock(Mockito.mock(ExplainResponse.class))); } public void testTypeInPath() { diff --git a/server/src/test/java/org/elasticsearch/search/vectors/QueryVectorBuilderTests.java b/server/src/test/java/org/elasticsearch/search/vectors/QueryVectorBuilderTests.java index a12f218db3450..29e73d598eb40 100644 --- a/server/src/test/java/org/elasticsearch/search/vectors/QueryVectorBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/search/vectors/QueryVectorBuilderTests.java @@ -64,6 +64,6 @@ protected void doAssertClientRequest(ActionRequest request, TestQueryVectorBuild @Override protected ActionResponse createResponse(float[] array, TestQueryVectorBuilderPlugin.TestQueryVectorBuilder builder) { - return new ActionResponse.Empty(); + return ActionResponse.Empty.INSTANCE; } } diff --git a/test/framework/src/main/java/org/elasticsearch/rest/RestResponseUtils.java b/test/framework/src/main/java/org/elasticsearch/rest/RestResponseUtils.java index a88c1c1e3c118..7f68e937e4deb 100644 --- a/test/framework/src/main/java/org/elasticsearch/rest/RestResponseUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/rest/RestResponseUtils.java @@ -12,14 +12,19 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.core.CheckedConsumer; -import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xcontent.ToXContent; +import org.elasticsearch.xcontent.XContentBuilder; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; import java.util.Iterator; +import static org.elasticsearch.test.ESTestCase.asInstanceOf; +import static org.elasticsearch.test.ESTestCase.fail; import static org.elasticsearch.transport.BytesRefRecycler.NON_RECYCLING_INSTANCE; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; public class RestResponseUtils { private RestResponseUtils() {} @@ -48,7 +53,7 @@ public static BytesReference getBodyContent(RestResponse restResponse) { out.flush(); return out.bytes(); } catch (Exception e) { - return ESTestCase.fail(e); + return fail(e); } } @@ -60,7 +65,18 @@ public static String getTextBodyContent(Iterator T setUpXContentMock(T mock) { + try { + when(mock.toXContent(any(), any())).thenAnswer( + invocation -> asInstanceOf(XContentBuilder.class, invocation.getArgument(0)).startObject().endObject() + ); + } catch (IOException e) { + fail(e); + } + return mock; + } } diff --git a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java index 5dc45ebabfdb0..2ed9c66e24368 100644 --- a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java +++ b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java @@ -50,6 +50,9 @@ public ClientYamlTestResponse(Response response) throws IOException { byte[] bytes = EntityUtils.toByteArray(response.getEntity()); // skip parsing if we got text back (e.g. if we called _cat apis) if (bodyContentType != null) { + if (bytes.length == 0) { + throw new IllegalArgumentException("Empty body is invalid for content-type [" + contentType + "]"); + } this.parsedResponse = ObjectPath.createFromXContent(bodyContentType.xContent(), new BytesArray(bytes)); } this.body = bytes; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationCacheResetAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationCacheResetAction.java index 3e9fbbb5a072a..a57cc75280362 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationCacheResetAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationCacheResetAction.java @@ -67,7 +67,7 @@ public boolean equals(Object obj) { } } - public static class Response extends BaseNodesResponse implements Writeable, ToXContentObject { + public static class Response extends BaseNodesResponse implements Writeable { public Response(ClusterName clusterName, List nodes, List failures) { super(clusterName, nodes, failures); } @@ -82,11 +82,6 @@ protected void writeNodesTo(StreamOutput out, List nodes) { TransportAction.localOnly(); } - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) { - return builder; - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/RestDeprecationCacheResetAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/RestDeprecationCacheResetAction.java index 9184dceecbfe8..7db2a6b3a8c03 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/RestDeprecationCacheResetAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/RestDeprecationCacheResetAction.java @@ -7,15 +7,17 @@ package org.elasticsearch.xpack.deprecation.logging; +import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.RestToXContentListener; +import org.elasticsearch.rest.action.EmptyResponseListener; -import java.io.IOException; import java.util.List; +import java.util.Set; import static org.elasticsearch.rest.RestRequest.Method.DELETE; +import static org.elasticsearch.rest.action.EmptyResponseListener.PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME; public class RestDeprecationCacheResetAction extends BaseRestHandler { @@ -30,8 +32,17 @@ public String getName() { } @Override - public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + public Set supportedCapabilities() { + return Set.of(PLAIN_TEXT_EMPTY_RESPONSE_CAPABILITY_NAME); + } + + @Override + public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { DeprecationCacheResetAction.Request resetRequest = new DeprecationCacheResetAction.Request(); - return channel -> client.execute(DeprecationCacheResetAction.INSTANCE, resetRequest, new RestToXContentListener<>(channel)); + return channel -> client.execute( + DeprecationCacheResetAction.INSTANCE, + resetRequest, + new EmptyResponseListener(channel).map(ignored -> ActionResponse.Empty.INSTANCE) + ); } } diff --git a/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java index 4961efd7253ec..b50353391747f 100644 --- a/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java +++ b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/rest/action/RestGraphActionTests.java @@ -17,13 +17,14 @@ import org.elasticsearch.test.rest.RestActionTestCase; import org.elasticsearch.xcontent.XContentType; import org.junit.Before; -import org.mockito.Mockito; import java.util.Collections; import java.util.List; import java.util.Map; +import static org.elasticsearch.rest.RestResponseUtils.setUpXContentMock; import static org.hamcrest.Matchers.instanceOf; +import static org.mockito.Mockito.mock; public final class RestGraphActionTests extends RestActionTestCase { private final List compatibleMediaType = Collections.singletonList(randomCompatibleMediaType(RestApiVersion.V_7)); @@ -33,7 +34,7 @@ public void setUpAction() { controller().registerHandler(new RestGraphAction()); verifyingClient.setExecuteVerifier((actionType, request) -> { assertThat(request, instanceOf(GraphExploreRequest.class)); - return Mockito.mock(GraphExploreResponse.class); + return setUpXContentMock(mock(GraphExploreResponse.class)); }); } @@ -58,4 +59,5 @@ public void testTypeInPath() { assertCriticalWarnings(RestGraphAction.TYPES_DEPRECATION_MESSAGE); } } + } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java index 794aeebb6078d..10b270eb762d0 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestDeletePipelineAction.java @@ -16,7 +16,6 @@ import org.elasticsearch.rest.Scope; import org.elasticsearch.rest.ServerlessScope; import org.elasticsearch.rest.action.RestActionListener; -import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xpack.logstash.action.DeletePipelineAction; import org.elasticsearch.xpack.logstash.action.DeletePipelineRequest; import org.elasticsearch.xpack.logstash.action.DeletePipelineResponse; @@ -49,7 +48,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli @Override protected void processResponse(DeletePipelineResponse deletePipelineResponse) { final RestStatus status = deletePipelineResponse.isDeleted() ? RestStatus.OK : RestStatus.NOT_FOUND; - channel.sendResponse(new RestResponse(status, XContentType.JSON.mediaType(), BytesArray.EMPTY)); + channel.sendResponse(new RestResponse(status, RestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)); } } ); diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java index a9992e168bc66..5255ec97a7ccf 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/rest/RestPutPipelineAction.java @@ -16,7 +16,6 @@ import org.elasticsearch.rest.ServerlessScope; import org.elasticsearch.rest.action.RestActionListener; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xpack.logstash.Pipeline; import org.elasticsearch.xpack.logstash.action.PutPipelineAction; import org.elasticsearch.xpack.logstash.action.PutPipelineRequest; @@ -55,9 +54,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli new PutPipelineRequest(id, content, request.getXContentType()), new RestActionListener<>(restChannel) { @Override - protected void processResponse(PutPipelineResponse putPipelineResponse) throws Exception { + protected void processResponse(PutPipelineResponse putPipelineResponse) { channel.sendResponse( - new RestResponse(putPipelineResponse.status(), XContentType.JSON.mediaType(), BytesArray.EMPTY) + new RestResponse(putPipelineResponse.status(), RestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY) ); } } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/inference/RestUpdateTrainedModelDeploymentActionTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/inference/RestUpdateTrainedModelDeploymentActionTests.java index cce6b284a524d..ea079a4886194 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/inference/RestUpdateTrainedModelDeploymentActionTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/inference/RestUpdateTrainedModelDeploymentActionTests.java @@ -18,6 +18,7 @@ import java.util.HashMap; +import static org.elasticsearch.rest.RestResponseUtils.setUpXContentMock; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.mockito.Mockito.mock; @@ -33,7 +34,7 @@ public void testNumberOfAllocationInParam() { assertEquals(request.getNumberOfAllocations().intValue(), 5); executeCalled.set(true); - return mock(CreateTrainedModelAssignmentAction.Response.class); + return setUpXContentMock(mock(CreateTrainedModelAssignmentAction.Response.class)); })); var params = new HashMap(); params.put("number_of_allocations", "5"); @@ -56,7 +57,7 @@ public void testNumberOfAllocationInBody() { assertEquals(request.getNumberOfAllocations().intValue(), 6); executeCalled.set(true); - return mock(CreateTrainedModelAssignmentAction.Response.class); + return setUpXContentMock(mock(CreateTrainedModelAssignmentAction.Response.class)); })); final String content = """ diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/profile/RestSuggestProfilesActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/profile/RestSuggestProfilesActionTests.java index 26412106229a1..8ee48ebc0f986 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/profile/RestSuggestProfilesActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/profile/RestSuggestProfilesActionTests.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.security.rest.action.profile; +import org.apache.lucene.search.TotalHits; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; @@ -33,7 +34,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -54,7 +54,7 @@ public void init() { verifyingClient.setExecuteLocallyVerifier(((actionType, actionRequest) -> { assertThat(actionRequest, instanceOf(SuggestProfilesRequest.class)); requestHolder.set((SuggestProfilesRequest) actionRequest); - return mock(SuggestProfilesResponse.class); + return new SuggestProfilesResponse(new SuggestProfilesResponse.ProfileHit[0], 0, new TotalHits(0, TotalHits.Relation.EQUAL_TO)); })); } diff --git a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/130_operator_privileges.yml b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/130_operator_privileges.yml index 2b5c3b418eb84..4fa34dac9e33e 100644 --- a/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/130_operator_privileges.yml +++ b/x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/130_operator_privileges.yml @@ -2,9 +2,13 @@ "Test operator privileges will work in the mixed cluster": - requires: - test_runner_features: headers + test_runner_features: [headers, capabilities] cluster_features: ["gte_v7.11.0"] reason: "operator privileges are available since 7.11" + capabilities: + - method: DELETE + path: /_cluster/voting_config_exclusions + capabilities: [ plain_text_empty_response ] # The default user ("test_user") is an operator, so this works - do: