-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TEST] prevent yaml tests from using raw requests (#26044)
Raw requests are supported only by the java yaml test runner and were introduced to test docs snippets. Some yaml tests ended up using them (see #23497) which causes failures for other language clients. This commit migrates those yaml tests to Java tests that send requests through the Java low-level REST client, and also moves the ability to send raw requests to a special client that's only available when testing docs snippets. Closes #25694
- Loading branch information
Showing
22 changed files
with
262 additions
and
194 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...on/integ-test-zip/src/test/java/org/elasticsearch/test/rest/RequestsWithoutContentIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.test.rest; | ||
|
||
import org.elasticsearch.client.ResponseException; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
public class RequestsWithoutContentIT extends ESRestTestCase { | ||
|
||
public void testIndexMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
randomBoolean() ? "POST" : "PUT", "/idx/type/123")); | ||
assertResponseException(responseException, "request body is required"); | ||
} | ||
|
||
public void testBulkMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
randomBoolean() ? "POST" : "PUT", "/_bulk")); | ||
assertResponseException(responseException, "request body is required"); | ||
} | ||
|
||
public void testPutSettingsMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
"PUT", "/_settings")); | ||
assertResponseException(responseException, "request body is required"); | ||
} | ||
|
||
public void testPutMappingsMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
randomBoolean() ? "POST" : "PUT", "/test_index/test_type/_mapping")); | ||
assertResponseException(responseException, "request body is required"); | ||
} | ||
|
||
public void testPutIndexTemplateMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
randomBoolean() ? "PUT" : "POST", "/_template/my_template")); | ||
assertResponseException(responseException, "request body is required"); | ||
} | ||
|
||
public void testMultiSearchMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
randomBoolean() ? "POST" : "GET", "/_msearch")); | ||
assertResponseException(responseException, "request body or source parameter is required"); | ||
} | ||
|
||
public void testPutPipelineMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
"PUT", "/_ingest/pipeline/my_pipeline")); | ||
assertResponseException(responseException, "request body or source parameter is required"); | ||
} | ||
|
||
public void testSimulatePipelineMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
randomBoolean() ? "POST" : "GET", "/_ingest/pipeline/my_pipeline/_simulate")); | ||
assertResponseException(responseException, "request body or source parameter is required"); | ||
} | ||
|
||
public void testPutScriptMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
randomBoolean() ? "POST" : "PUT", "/_scripts/lang")); | ||
assertResponseException(responseException, "request body is required"); | ||
} | ||
|
||
private static void assertResponseException(ResponseException responseException, String message) { | ||
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode()); | ||
assertThat(responseException.getMessage(), containsString(message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...tache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateWithoutContentIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.script.mustache; | ||
|
||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
public class SearchTemplateWithoutContentIT extends ESRestTestCase { | ||
|
||
public void testSearchTemplateMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
randomBoolean() ? "POST" : "GET", "/_search/template")); | ||
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode()); | ||
assertThat(responseException.getMessage(), containsString("request body or source parameter is required")); | ||
} | ||
|
||
public void testMultiSearchTemplateMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
randomBoolean() ? "POST" : "GET", "/_msearch/template")); | ||
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode()); | ||
assertThat(responseException.getMessage(), containsString("request body or source parameter is required")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexWithoutContentIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.reindex; | ||
|
||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
public class ReindexWithoutContentIT extends ESRestTestCase { | ||
|
||
public void testReindexMissingBody() throws IOException { | ||
ResponseException responseException = expectThrows(ResponseException.class, () -> client().performRequest( | ||
"POST", "/_reindex")); | ||
assertEquals(400, responseException.getResponse().getStatusLine().getStatusCode()); | ||
assertThat(responseException.getMessage(), containsString("request body is required")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_script/10_basic.yml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.