Skip to content

Commit

Permalink
[TEST] Improve validation of do sections (#34734)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javanna committed Nov 1, 2018
1 parent fbb5c10 commit 5a5166a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
Expand Up @@ -23,8 +23,8 @@
indices.refresh: {}

- do:
index: test
search:
index: test
body:
query:
script:
Expand All @@ -45,8 +45,8 @@
- match: { hits.hits.1.fields.sNum1.0: 3.0 }

- do:
index: test
search:
index: test
body:
query:
script:
Expand All @@ -70,8 +70,8 @@
- match: { hits.hits.1.fields.sNum1.0: 3.0 }

- do:
index: test
search:
index: test
body:
query:
script:
Expand All @@ -96,8 +96,8 @@
- match: { hits.hits.2.fields.sNum1.0: 3.0 }

- do:
index: test
search:
index: test
body:
query:
script:
Expand Down Expand Up @@ -127,8 +127,8 @@
indices.refresh: {}

- do:
index: test
search:
index: test
body:
query:
function_score:
Expand All @@ -149,8 +149,8 @@
- match: { hits.hits.1._id: "1" }

- do:
index: test
search:
index: test
body:
query:
function_score:
Expand All @@ -171,8 +171,8 @@
- match: { hits.hits.1._id: "2" }

- do:
index: test
search:
index: test
body:
query:
function_score:
Expand All @@ -193,8 +193,8 @@
- match: { hits.hits.1._id: "1" }

- do:
index: test
search:
index: test
body:
query:
function_score:
Expand All @@ -215,8 +215,8 @@
- match: { hits.hits.1._id: "1" }

- do:
index: test
search:
index: test
body:
query:
function_score:
Expand All @@ -237,8 +237,8 @@
- match: { hits.hits.1._id: "1" }

- do:
index: test
search:
index: test
body:
query:
function_score:
Expand Down Expand Up @@ -274,8 +274,8 @@
indices.refresh: {}

- do:
index: test
search:
index: test
body:
query:
function_score:
Expand Down Expand Up @@ -325,8 +325,8 @@


- do:
index: test
search:
index: test
body:
query:
function_score:
Expand Down Expand Up @@ -364,8 +364,8 @@


- do:
index: test
search:
index: test
body:
script_fields:
foobar:
Expand All @@ -391,8 +391,8 @@


- do:
index: test
search:
index: test
body:
aggs:
value_agg:
Expand Down Expand Up @@ -428,8 +428,8 @@

- do:
catch: bad_request
index: test
search:
index: test
body:
aggs:
genre:
Expand Down
Expand Up @@ -11,8 +11,8 @@
indices.refresh: {}

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

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

- do:
index: test
search:
index: test
body:
query:
match_all: {}
Expand All @@ -26,8 +26,8 @@
- match: { hits.hits.0.fields.sNum1.0: 2 }

- do:
index: test
search:
index: test
body:
query:
match_all: {}
Expand Down
Expand Up @@ -106,6 +106,8 @@ public static DoSection parse(XContentParser parser) throws IOException {
} 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)) {
Expand Down
Expand Up @@ -22,6 +22,7 @@
import org.apache.http.HttpHost;
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.XContent;
import org.elasticsearch.common.xcontent.XContentLocation;
Expand Down Expand Up @@ -52,7 +53,7 @@

public class DoSectionTests extends AbstractClientYamlTestFragmentParserTestCase {

public void testWarningHeaders() throws IOException {
public void testWarningHeaders() {
{
final DoSection section = new DoSection(new XContentLocation(1, 1));

Expand Down Expand Up @@ -424,6 +425,17 @@ public void testParseDoSectionWithCatch() throws Exception {
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" +
Expand Down

0 comments on commit 5a5166a

Please sign in to comment.