From daa9d65a53dedaac5aeeb6394d4c0b6f99fa930c Mon Sep 17 00:00:00 2001 From: Paul Joseph Davis Date: Sat, 18 Apr 2009 18:34:31 +0000 Subject: Resolves COUCHDB-306 - Wacky error responses to malformed documents Mostly adds improvements to the parsing of Json bodies for _bulk_docs and multi-get queries. Includes tests in basics.js and view_errors.js. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@766373 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/basics.js | 28 ++++++++++++++++++++++++++++ share/www/script/test/view_errors.js | 14 ++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'share/www/script') diff --git a/share/www/script/test/basics.js b/share/www/script/test/basics.js index 8adf5a84..2eb49ebe 100644 --- a/share/www/script/test/basics.js +++ b/share/www/script/test/basics.js @@ -168,4 +168,32 @@ couchTests.basics = function(debug) { // deleting a non-existent doc should be 404 xhr = CouchDB.request("DELETE", "/test_suite_db/doc-does-not-exist"); T(xhr.status == 404); + + // Check some common error responses. + // PUT body not an object + xhr = CouchDB.request("PUT", "/test_suite_db/bar", {body: "[]"}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "Document must be a JSON object"); + + // Body of a _bulk_docs is not an object + xhr = CouchDB.request("POST", "/test_suite_db/_bulk_docs", {body: "[]"}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "Body must be a JSON object"); + + // Body of an _all_docs multi-get is not a {"key": [...]} structure. + xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body: "[]"}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "Body must be a JSON object"); + var data = "{\"keys\": 1}"; + xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body:data}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "`keys` member must be a array."); }; diff --git a/share/www/script/test/view_errors.js b/share/www/script/test/view_errors.js index 60ccca59..b9a6aa63 100644 --- a/share/www/script/test/view_errors.js +++ b/share/www/script/test/view_errors.js @@ -94,4 +94,18 @@ couchTests.view_errors = function(debug) { } catch(e) { T(e.error == "query_parse_error"); } + + // Check error responses for invalid multi-get bodies. + var path = "/test_suite_db/_design/test/_view/no_reduce"; + var xhr = CouchDB.request("POST", path, {body: "[]"}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "Body must be a JSON object"); + var data = "{\"keys\": 1}"; + xhr = CouchDB.request("POST", path, {body:data}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "`keys` member must be a array."); }; -- cgit v1.2.3