[TEST] Improve validation of do sections (#34734)

We throw parsing exception when an unknown array is found, but we don't when an unknown top-level field is found. This commit makes sure that unsupported top-level fields are not ignored in a do section.

Closes #34651
This commit is contained in:
Luca Cavanna 2018-10-24 21:27:07 +02:00 committed by GitHub
parent cd27b0b996
commit d51bc05dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 18 deletions

View File

@ -23,8 +23,8 @@
indices.refresh: {}
- do:
index: test
search:
index: test
body:
query:
script:
@ -45,8 +45,8 @@
- match: { hits.hits.1.fields.sNum1.0: 3.0 }
- do:
index: test
search:
index: test
body:
query:
script:
@ -70,8 +70,8 @@
- match: { hits.hits.1.fields.sNum1.0: 3.0 }
- do:
index: test
search:
index: test
body:
query:
script:
@ -96,8 +96,8 @@
- match: { hits.hits.2.fields.sNum1.0: 3.0 }
- do:
index: test
search:
index: test
body:
query:
script:
@ -127,8 +127,8 @@
indices.refresh: {}
- do:
index: test
search:
index: test
body:
query:
function_score:
@ -149,8 +149,8 @@
- match: { hits.hits.1._id: "1" }
- do:
index: test
search:
index: test
body:
query:
function_score:
@ -171,8 +171,8 @@
- match: { hits.hits.1._id: "2" }
- do:
index: test
search:
index: test
body:
query:
function_score:
@ -193,8 +193,8 @@
- match: { hits.hits.1._id: "1" }
- do:
index: test
search:
index: test
body:
query:
function_score:
@ -215,8 +215,8 @@
- match: { hits.hits.1._id: "1" }
- do:
index: test
search:
index: test
body:
query:
function_score:
@ -237,8 +237,8 @@
- match: { hits.hits.1._id: "1" }
- do:
index: test
search:
index: test
body:
query:
function_score:
@ -274,8 +274,8 @@
indices.refresh: {}
- do:
index: test
search:
index: test
body:
query:
function_score:
@ -325,8 +325,8 @@
- do:
index: test
search:
index: test
body:
query:
function_score:
@ -364,8 +364,8 @@
- do:
index: test
search:
index: test
body:
script_fields:
foobar:
@ -391,8 +391,8 @@
- do:
index: test
search:
index: test
body:
aggs:
value_agg:
@ -428,8 +428,8 @@
- do:
catch: bad_request
index: test
search:
index: test
body:
aggs:
genre:

View File

@ -11,8 +11,8 @@
indices.refresh: {}
- do:
index: test
search:
index: test
body:
query:
match_all: {}

View File

@ -11,8 +11,8 @@
indices.refresh: {}
- do:
index: test
search:
index: test
body:
query:
match_all: {}

View File

@ -106,6 +106,8 @@ public class DoSection implements ExecutableSection {
} else if (token.isValue()) {
if ("catch".equals(currentFieldName)) {
doSection.setCatch(parser.text());
} else {
throw new ParsingException(parser.getTokenLocation(), "unsupported field [" + currentFieldName + "]");
}
} else if (token == XContentParser.Token.START_ARRAY) {
if ("warnings".equals(currentFieldName)) {

View File

@ -23,6 +23,7 @@ import org.apache.http.HttpHost;
import org.elasticsearch.Version;
import org.elasticsearch.client.Node;
import org.elasticsearch.client.NodeSelector;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser;
@ -52,7 +53,7 @@ import static org.mockito.Mockito.when;
public class DoSectionTests extends AbstractClientYamlTestFragmentParserTestCase {
public void testWarningHeaders() throws IOException {
public void testWarningHeaders() {
{
final DoSection section = new DoSection(new XContentLocation(1, 1));
@ -358,6 +359,17 @@ public class DoSectionTests extends AbstractClientYamlTestFragmentParserTestCase
assertThat(doSection.getApiCallSection().hasBody(), equalTo(false));
}
public void testUnsupportedTopLevelField() throws Exception {
parser = createParser(YamlXContent.yamlXContent,
"max_concurrent_shard_requests: 1"
);
ParsingException e = expectThrows(ParsingException.class, () -> DoSection.parse(parser));
assertThat(e.getMessage(), is("unsupported field [max_concurrent_shard_requests]"));
parser.nextToken();
parser.nextToken();
}
public void testParseDoSectionWithHeaders() throws Exception {
parser = createParser(YamlXContent.yamlXContent,
"headers:\n" +