Skip to content

Commit

Permalink
[TEST] prevent yaml tests from using raw requests (#26044)
Browse files Browse the repository at this point in the history
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
javanna committed Aug 7, 2017
1 parent cf44b82 commit 4ba9f65
Show file tree
Hide file tree
Showing 22 changed files with 262 additions and 194 deletions.
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@

import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.elasticsearch.Version;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.http.HttpHost;
import org.elasticsearch.test.rest.yaml.ClientYamlDocsTestClient;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ClientYamlTestClient;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec;

import java.io.IOException;
import java.util.List;

public class DocsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
Expand Down Expand Up @@ -52,5 +58,11 @@ protected void afterIfFailed(List<Throwable> errors) {
protected boolean randomizeContentType() {
return false;
}

@Override
protected ClientYamlTestClient initClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient,
List<HttpHost> hosts, Version esVersion) throws IOException {
return new ClientYamlDocsTestClient(restSpec, restClient, hosts, esVersion);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,3 @@ teardown:
catch: missing
ingest.get_pipeline:
id: "my_pipeline"

---
"missing body":

- skip:
version: " - 5.99.99"
reason: NPE caused by missing body fixed in 6.0.0

- do:
catch: /request body or source parameter is required/
raw:
method: PUT
path: _ingest/pipeline/my_pipeline
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,3 @@ teardown:
- length: { docs.0.processor_results.1: 2 }
- match: { docs.0.processor_results.1.tag: "rename-1" }
- match: { docs.0.processor_results.1.doc._source.new_status: 200 }

---
"missing body":

- skip:
version: " - 5.99.99"
reason: NPE caused by missing body fixed in 6.0.0

- do:
catch: /request body or source parameter is required/
raw:
method: POST
path: _ingest/pipeline/my_pipeline/_simulate
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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,3 @@
nodes.info: {}

- match: { nodes.$master.modules.0.name: lang-mustache }

---
"missing body":

- skip:
version: " - 5.99.99"
reason: NPE caused by missing body fixed in 6.0.0

- do:
catch: /request body is required/
raw:
method: POST
path: _search/template/1
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,3 @@
- match: { hits.total: 1 }
- length: { hits.hits: 1 }
- length: { profile: 1 }

---
"missing body":

- skip:
version: " - 5.99.99"
reason: NPE caused by missing body fixed in 6.0.0

- do:
catch: /request body or source parameter is required/
raw:
method: POST
path: _search/template
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,3 @@ setup:
- match: { responses.0.hits.total: 2 }
- match: { responses.1.hits.total: 1 }
- match: { responses.2.hits.total: 1 }

---
"missing body":

- skip:
version: " - 5.99.99"
reason: NPE caused by missing body fixed in 6.0.0

- do:
catch: /request body or source parameter is required/
raw:
method: POST
path: _msearch/template
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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,3 @@
index: source
metric: search
- match: {indices.source.total.search.open_contexts: 0}

---
"missing body":

- skip:
version: " - 5.99.99"
reason: NPE caused by missing body fixed in 6.0.0

- do:
catch: /request body is required/
raw:
method: POST
path: _reindex
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@

- match: { count: 2 }

---
"missing body":

- skip:
version: " - 5.4.99"
reason: NPE caused by missing body fixed in 5.5.0

- do:
catch: /request body is required/
raw:
method: POST
path: _bulk

---
"empty action":

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,3 @@
include_defaults: true

- match: {defaults.node.attr.testattr: "test"}

---
"missing body":

- skip:
version: " - 5.4.99"
reason: NPE caused by missing body fixed in 5.5.0

- do:
catch: /request body is required/
raw:
method: PUT
path: _settings
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,3 @@
type: type
id: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
body: { foo: bar }

---
"missing body":

- skip:
version: " - 5.4.99"
reason: NPE caused by missing body fixed in 5.5.0

- do:
catch: /request body is required/
raw:
method: POST
path: idx/type/123
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,3 @@
properties:
"":
type: keyword

---
"missing body":

- skip:
version: " - 5.4.99"
reason: NPE caused by missing body fixed in 5.5.0

- do:
catch: /request body is required/
raw:
method: POST
path: test_index/test_type/_mapping
Loading

0 comments on commit 4ba9f65

Please sign in to comment.