diff options
author | Paul Joseph Davis <davisp@apache.org> | 2009-04-18 18:34:31 +0000 |
---|---|---|
committer | Paul Joseph Davis <davisp@apache.org> | 2009-04-18 18:34:31 +0000 |
commit | daa9d65a53dedaac5aeeb6394d4c0b6f99fa930c (patch) | |
tree | 71a35ed91de64d76b29a44776a0d6d93efc5e75a /share/www | |
parent | 1df7a4e6a659550cde173381a0e0f9d770417d59 (diff) |
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
Diffstat (limited to 'share/www')
-rw-r--r-- | share/www/script/test/basics.js | 28 | ||||
-rw-r--r-- | share/www/script/test/view_errors.js | 14 |
2 files changed, 42 insertions, 0 deletions
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."); }; |