Skip to content

Commit 1b2809f

Browse files
committed
add IT for both
Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent 8a8264d commit 1b2809f

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/ppl/PPLPluginIT.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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));

integ-test/src/test/java/org/opensearch/sql/sql/QueryValidationIT.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)