File tree Expand file tree Collapse file tree
integ-test/src/test/java/org/opensearch/sql Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,6 +96,17 @@ public void sqlEnableSettingsTest() throws IOException {
9696 updateClusterSettings (new ClusterSetting (PERSISTENT , "plugins.ppl.enabled" , null ));
9797 }
9898
99+ @ Test
100+ public void testQueryEndpointShouldFailWithInvalidPayload () throws IOException {
101+ exceptionRule .expect (ResponseException .class );
102+ exceptionRule .expect (hasProperty ("response" , statusCode (400 )));
103+
104+ Request post = new Request ("POST" , "/_plugins/_ppl" );
105+ post .setJsonEntity ("{ \" query\" : [\" search source=test\" ] }" );
106+
107+ client ().performRequest (post );
108+ }
109+
99110 protected Request makePPLRequest (String query ) {
100111 Request post = new Request ("POST" , "/_plugins/_ppl" );
101112 post .setJsonEntity (String .format (Locale .ROOT , "{\n " + " \" query\" : \" %s\" \n " + "}" , query ));
Original file line number Diff line number Diff line change @@ -82,6 +82,27 @@ public void aggregationFunctionInSelectGroupByMultipleFields() throws IOExceptio
8282 "SELECT SUM(age) FROM opensearch-sql_test_index_account GROUP BY state.keyword" );
8383 }
8484
85+ @ Test
86+ public void testSqlQueryWithArrayPayloadShouldFailWithBadRequest () throws IOException {
87+ expectResponseException ()
88+ .hasStatusCode (BAD_REQUEST )
89+ .hasErrorType ("IllegalArgumentException" )
90+ .containsMessage ("Failed to parse request payload" );
91+
92+ whenExecuteMalformedPayload ();
93+ }
94+
95+ private static void whenExecuteMalformedPayload () throws IOException {
96+ Request request = new Request ("POST" , QUERY_API_ENDPOINT );
97+ request .setJsonEntity ("{ \" query\" : [\" SELECT * FROM opensearch-sql_test_index_account\" ] }" );
98+
99+ RequestOptions .Builder restOptionsBuilder = RequestOptions .DEFAULT .toBuilder ();
100+ restOptionsBuilder .addHeader ("Content-Type" , "application/json" );
101+ request .setOptions (restOptionsBuilder );
102+
103+ client ().performRequest (request );
104+ }
105+
85106 public ResponseExceptionAssertion expectResponseException () {
86107 return new ResponseExceptionAssertion (exceptionRule );
87108 }
You can’t perform that action at this time.
0 commit comments