summaryrefslogtreecommitdiff
path: root/rest-api-spec/src
diff options
context:
space:
mode:
authorAlex Benusovich <qwerty4030@gmail.com>2017-06-05 08:08:14 -0700
committerJay Modi <jaymode@users.noreply.github.com>2017-06-05 09:08:14 -0600
commit5463294ec4bf3c6d22532840c3c2fd28a1f035bc (patch)
treefdbc2bca09a9f67ac19c94dc7b0f200a78db2c6d /rest-api-spec/src
parent73307a2144fbdf63c551eeccdc7e93dc30e59a92 (diff)
Fixed NPEs caused by requests without content. (#23497)
REST handlers that require a body will throw an an ElasticsearchParseException "request body required". REST handlers that require a body OR source param will throw an ElasticsearchParseException "request body or source param required". Replaced asserts in BulkRequest parsing code with a more descriptive IllegalArgumentException if the line contains an empty object. Updated bulk REST test to verify an empty action line is rejected properly. Updated BulkRequestTests with randomized testing for an empty action line. Used try-with-resouces for XContentParser in AbstractBulkByQueryRestHandler.
Diffstat (limited to 'rest-api-spec/src')
-rw-r--r--rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml30
-rw-r--r--rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_script/10_basic.yml12
-rw-r--r--rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_settings/10_basic.yml12
-rw-r--r--rest-api-spec/src/main/resources/rest-api-spec/test/index/10_with_id.yml13
-rw-r--r--rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/10_basic.yml13
-rw-r--r--rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_template/10_basic.yml13
-rw-r--r--rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml12
7 files changed, 105 insertions, 0 deletions
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml
index 3573f8ba75..29a565ba0f 100644
--- a/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml
+++ b/rest-api-spec/src/main/resources/rest-api-spec/test/bulk/10_basic.yml
@@ -58,3 +58,33 @@
index: test
- match: { count: 2 }
+
+---
+"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: _bulk
+
+---
+"empty action":
+
+ - skip:
+ version: " - 5.99.99"
+ reason: confusing exception messaged caused by empty object fixed in 6.0.0
+
+ - do:
+ catch: /Malformed action\/metadata line \[3\], expected FIELD_NAME but found \[END_OBJECT\]/
+ headers:
+ Content-Type: application/json
+ bulk:
+ body: |
+ {"index": {"_index": "test_index", "_type": "test_type", "_id": "test_id"}}
+ {"f1": "v1", "f2": 42}
+ {}
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_script/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_script/10_basic.yml
new file mode 100644
index 0000000000..bfab22fd65
--- /dev/null
+++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_script/10_basic.yml
@@ -0,0 +1,12 @@
+---
+"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: _scripts/lang
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_settings/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_settings/10_basic.yml
index 083466f94a..31f504a510 100644
--- a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_settings/10_basic.yml
+++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.put_settings/10_basic.yml
@@ -75,3 +75,15 @@
- match: {defaults.node.attr.testattr: "test"}
+---
+"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: PUT
+ path: _settings
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/index/10_with_id.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/index/10_with_id.yml
index 8ac55ec79f..b15aad5aaa 100644
--- a/rest-api-spec/src/main/resources/rest-api-spec/test/index/10_with_id.yml
+++ b/rest-api-spec/src/main/resources/rest-api-spec/test/index/10_with_id.yml
@@ -32,3 +32,16 @@
type: type
id: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
body: { foo: bar }
+
+---
+"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: idx/type/123
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/10_basic.yml
index 1d33f2d31b..10253fbcef 100644
--- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/10_basic.yml
+++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_mapping/10_basic.yml
@@ -67,3 +67,16 @@
properties:
"":
type: keyword
+
+---
+"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: test_index/test_type/_mapping
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_template/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_template/10_basic.yml
index 01bd7afc58..face649ea4 100644
--- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_template/10_basic.yml
+++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_template/10_basic.yml
@@ -210,3 +210,16 @@
catch: missing
indices.get_template:
name: "my_template"
+
+---
+"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: PUT
+ path: _template/my_template
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml
index 6e6b0cd3b4..5c78e6824c 100644
--- a/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml
+++ b/rest-api-spec/src/main/resources/rest-api-spec/test/msearch/10_basic.yml
@@ -62,3 +62,15 @@ setup:
- match: { responses.3.error.root_cause.0.index: index_3 }
- match: { responses.4.hits.total: 4 }
+---
+"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