|
11 | 11 | import org.elasticsearch.action.support.WriteRequest;
|
12 | 12 | import org.elasticsearch.client.Client;
|
13 | 13 | import org.elasticsearch.common.ParseField;
|
| 14 | +import org.elasticsearch.common.bytes.BytesArray; |
14 | 15 | import org.elasticsearch.common.bytes.BytesReference;
|
15 | 16 | import org.elasticsearch.common.logging.Loggers;
|
16 | 17 | import org.elasticsearch.common.settings.Settings;
|
|
19 | 20 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
20 | 21 | import org.elasticsearch.common.xcontent.XContentParser;
|
21 | 22 | import org.elasticsearch.common.xcontent.XContentType;
|
| 23 | +import org.elasticsearch.common.xcontent.json.JsonXContent; |
22 | 24 | import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
23 | 25 | import org.elasticsearch.index.query.QueryBuilder;
|
24 | 26 | import org.elasticsearch.index.query.ScriptQueryBuilder;
|
@@ -296,6 +298,38 @@ public void testParserBadActions() throws Exception {
|
296 | 298 | }
|
297 | 299 | }
|
298 | 300 |
|
| 301 | + public void testParserConsumesEntireDefinition() throws Exception { |
| 302 | + WatchParser wp = createWatchparser(); |
| 303 | + String watchDef="{\n" + |
| 304 | + " \"trigger\": {\n" + |
| 305 | + " \"schedule\": {\n" + |
| 306 | + " \"interval\": \"10s\"\n" + |
| 307 | + " }\n" + |
| 308 | + " },\n" + |
| 309 | + " \"input\": {\n" + |
| 310 | + " \"simple\": {}\n" + |
| 311 | + " }},\n" + /* NOTICE EXTRA CLOSING CURLY BRACE */ |
| 312 | + " \"condition\": {\n" + |
| 313 | + " \"script\": {\n" + |
| 314 | + " \"inline\": \"return false\"\n" + |
| 315 | + " }\n" + |
| 316 | + " },\n" + |
| 317 | + " \"actions\": {\n" + |
| 318 | + " \"logging\": {\n" + |
| 319 | + " \"logging\": {\n" + |
| 320 | + " \"text\": \"{{ctx.payload}}\"\n" + |
| 321 | + " }\n" + |
| 322 | + " }\n" + |
| 323 | + " }\n" + |
| 324 | + "}"; |
| 325 | + try { |
| 326 | + wp.parseWithSecrets("failure", false, new BytesArray(watchDef), new DateTime(), XContentType.JSON, true); |
| 327 | + fail("This watch should fail to parse as there is an extra closing curly brace in the middle of the watch"); |
| 328 | + } catch (ElasticsearchParseException pe) { |
| 329 | + assertThat(pe.getMessage().contains("unexpected data beyond"), is(true)); |
| 330 | + } |
| 331 | + } |
| 332 | + |
299 | 333 | public void testParserDefaults() throws Exception {
|
300 | 334 | Schedule schedule = randomSchedule();
|
301 | 335 | ScheduleRegistry scheduleRegistry = registry(schedule);
|
|
0 commit comments