diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a937ad9329ac..9baa321cd96b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,7 +91,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fix weighted routing metadata deserialization error on process restart ([#4691](https://github.com/opensearch-project/OpenSearch/pull/4691)) - Refactor Base Action class javadocs to OpenSearch.API ([#4732](https://github.com/opensearch-project/OpenSearch/pull/4732)) - Migrate client transports to Apache HttpClient / Core 5.x ([#4459](https://github.com/opensearch-project/OpenSearch/pull/4459)) -- Changed http code on create index API with bad input raising NotXContentException to 400([#4773](https://github.com/opensearch-project/OpenSearch/pull/4773)) +- Changed http code on create index API with bad input raising NotXContentException to 400 ([#4773](https://github.com/opensearch-project/OpenSearch/pull/4773)) - Refactored BalancedAllocator.Balancer to LocalShardsBalancer ([#4761](https://github.com/opensearch-project/OpenSearch/pull/4761)) - Fail weight update when decommission ongoing and fail decommission when attribute not weighed away ([#4839](https://github.com/opensearch-project/OpenSearch/pull/4839)) ### Deprecated diff --git a/server/src/test/java/org/opensearch/rest/RestControllerTests.java b/server/src/test/java/org/opensearch/rest/RestControllerTests.java index bd4c7c9a4f824..83906a3891700 100644 --- a/server/src/test/java/org/opensearch/rest/RestControllerTests.java +++ b/server/src/test/java/org/opensearch/rest/RestControllerTests.java @@ -53,6 +53,7 @@ import org.opensearch.http.HttpServerTransport; import org.opensearch.http.HttpStats; import org.opensearch.indices.breaker.HierarchyCircuitBreakerService; +import org.opensearch.rest.action.admin.indices.RestCreateIndexAction; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.test.client.NoOpNodeClient; import org.opensearch.test.rest.FakeRestRequest; @@ -562,6 +563,18 @@ public void testHandleBadRequestWithHtmlSpecialCharsInUri() { assertThat(channel.getRestResponse().content().utf8ToString(), containsString("invalid uri has been requested")); } + public void testHandleBadInputWithCreateIndex() { + final FakeRestRequest fakeRestRequest = new FakeRestRequest.Builder(NamedXContentRegistry.EMPTY) + .withPath("/foo") + .withMethod(RestRequest.Method.PUT) + .withContent(new BytesArray("ddd"), XContentType.JSON) + .build(); + final AssertingChannel channel = new AssertingChannel(fakeRestRequest, true, RestStatus.BAD_REQUEST); + restController.registerHandler(RestRequest.Method.PUT, "/foo", new RestCreateIndexAction()); + restController.dispatchRequest(fakeRestRequest, channel, client.threadPool().getThreadContext()); + assertEquals(channel.getRestResponse().content().utf8ToString(), "{\"error\":{\"root_cause\":[{\"type\":\"not_x_content_exception\",\"reason\":\"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes\"}],\"type\":\"not_x_content_exception\",\"reason\":\"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes\"},\"status\":400}"); + } + public void testDispatchUnsupportedHttpMethod() { final boolean hasContent = randomBoolean(); final RestRequest request = RestRequest.request(xContentRegistry(), new HttpRequest() {