diff options
author | Eric Avdey <eiri@eiri.ca> | 2017-11-02 10:51:13 -0300 |
---|---|---|
committer | Eric Avdey <eiri@eiri.ca> | 2017-11-02 11:47:28 -0300 |
commit | cde2f180873205aead88a6916595544b599e99bc (patch) | |
tree | 10c7f3a5c8cffef78019f7ba7d20ff99c26f9417 | |
parent | 2e49d7cf9b7fdcd597c8d806e5530047051f1250 (diff) | |
download | couchdb-cde2f180873205aead88a6916595544b599e99bc.tar.gz |
Return error 400 on invalid new_edits value
End-point `_bulk_docs` crashes if provided
with non-boolean value for `new_edits` parameter.
This patch changes it to return "Bad Request"
error instead.
-rw-r--r-- | src/chttpd/src/chttpd_db.erl | 4 | ||||
-rw-r--r-- | test/javascript/tests/bulk_docs.js | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl index 7e467508e..dbbb454cb 100644 --- a/src/chttpd/src/chttpd_db.erl +++ b/src/chttpd/src/chttpd_db.erl @@ -451,7 +451,9 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>], user_ctx=Ctx}=Req, {accepted, Errors} -> ErrorsJson = lists:map(fun update_doc_result_to_json/1, Errors), send_json(Req, 202, ErrorsJson) - end + end; + _ -> + throw({bad_request, <<"`new_edits` parameter must be a boolean.">>}) end; db_req(#httpd{path_parts=[_,<<"_bulk_docs">>]}=Req, _Db) -> diff --git a/test/javascript/tests/bulk_docs.js b/test/javascript/tests/bulk_docs.js index b9e971698..9f88e8195 100644 --- a/test/javascript/tests/bulk_docs.js +++ b/test/javascript/tests/bulk_docs.js @@ -110,6 +110,16 @@ couchTests.bulk_docs = function(debug) { T(result.error == "bad_request"); T(result.reason == "POST body must include `docs` parameter."); + // verify that sending a request with invalid `new_edits` causes error + var req = CouchDB.request("POST", "/" + db_name + "/_bulk_docs", { + body: JSON.stringify({"docs": [], "new_edits": 0}) + }); + + T(req.status == 400); + result = JSON.parse(req.responseText); + T(result.error == "bad_request"); + T(result.reason == "`new_edits` parameter must be a boolean."); + // jira-911 db.deleteDb(); // avoid Heisenbugs w/ files remaining - create a new name |