You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ei...@apache.org on 2017/11/02 14:47:32 UTC
[couchdb] 01/02: Return error 400 on invalid new_edits value
This is an automated email from the ASF dual-hosted git repository.
eiri pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit cde2f180873205aead88a6916595544b599e99bc
Author: Eric Avdey <ei...@eiri.ca>
AuthorDate: Thu Nov 2 10:51:13 2017 -0300
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.
---
src/chttpd/src/chttpd_db.erl | 4 +++-
test/javascript/tests/bulk_docs.js | 10 ++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 7e46750..dbbb454 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 b9e9716..9f88e81 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
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.