[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:
parent
cd27b0b996
commit
d51bc05dce
|
@ -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:
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
index: test
|
||||
search:
|
||||
index: test
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
indices.refresh: {}
|
||||
|
||||
- do:
|
||||
index: test
|
||||
search:
|
||||
index: test
|
||||
body:
|
||||
query:
|
||||
match_all: {}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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" +
|
||||
|
|
Loading…
Reference in New Issue