You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2017/11/02 14:47:33 UTC

[GitHub] eiri closed pull request #955: Return error 400 on invalid new_edits value

eiri closed pull request #955: Return error 400 on invalid new_edits value
URL: https://github.com/apache/couchdb/pull/955
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 7e467508e3..dbbb454cb3 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 b9e971698c..ae8a087425 100644
--- a/test/javascript/tests/bulk_docs.js
+++ b/test/javascript/tests/bulk_docs.js
@@ -110,6 +110,26 @@ 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 `docs` causes error
+  var req = CouchDB.request("POST", "/" + db_name + "/_bulk_docs", {
+    body: JSON.stringify({"docs": "foo"})
+  });
+
+  T(req.status == 400);
+  result = JSON.parse(req.responseText);
+  T(result.error == "bad_request");
+  T(result.reason == "`docs` parameter must be an array.");
+
+  // 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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services