couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject git commit: COUCHDB-1511 - User docs require doc.roles
Date Mon, 30 Jul 2012 12:06:59 GMT
Updated Branches:
  refs/heads/master 09ead8a07 -> 41205000c


COUCHDB-1511 - User docs require doc.roles

A _users doc must include roles otherwise the user receives an opaque
error. This patch throws an error if it is missing and adds a test to
verify that the user receives a readable error message.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/41205000
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/41205000
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/41205000

Branch: refs/heads/master
Commit: 41205000c7d756a951021641c586b73f7489510a
Parents: 09ead8a
Author: Robert Newson <rnewson@apache.org>
Authored: Mon Jul 30 12:53:33 2012 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Mon Jul 30 12:58:52 2012 +0100

----------------------------------------------------------------------
 share/www/script/test/users_db.js  |   10 ++++++++++
 src/couchdb/couch_js_functions.hrl |    6 +++++-
 2 files changed, 15 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/41205000/share/www/script/test/users_db.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/users_db.js b/share/www/script/test/users_db.js
index 7648523..44e6c88 100644
--- a/share/www/script/test/users_db.js
+++ b/share/www/script/test/users_db.js
@@ -112,6 +112,16 @@ couchTests.users_db = function(debug) {
     }
     jchrisUserDoc.roles = [];
 
+    // "roles" must exist
+    delete jchrisUserDoc.roles;
+    try {
+      usersDb.save(jchrisUserDoc);
+      T(false && "should only allow us to save doc when roles exists");
+    } catch(e) {
+      T(e.reason == "doc.roles must exist");
+    }
+    jchrisUserDoc.roles = [];
+
     // character : is not allowed in usernames
     var joeUserDoc = CouchDB.prepareUserDoc({
       name: "joe:erlang"

http://git-wip-us.apache.org/repos/asf/couchdb/blob/41205000/src/couchdb/couch_js_functions.hrl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_js_functions.hrl b/src/couchdb/couch_js_functions.hrl
index 36e1512..2ecd851 100644
--- a/src/couchdb/couch_js_functions.hrl
+++ b/src/couchdb/couch_js_functions.hrl
@@ -31,7 +31,11 @@
             throw({forbidden: 'doc.name is required'});
         }
 
-        if (newDoc.roles && !isArray(newDoc.roles)) {
+        if (!newDoc.roles) {
+            throw({forbidden: 'doc.roles must exist'});
+        }
+
+        if (!isArray(newDoc.roles)) {
             throw({forbidden: 'doc.roles must be an array'});
         }
 


Mime
View raw message