Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7908B19726 for ; Mon, 25 Apr 2016 11:53:30 +0000 (UTC) Received: (qmail 28797 invoked by uid 500); 25 Apr 2016 11:53:30 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 28648 invoked by uid 500); 25 Apr 2016 11:53:30 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 28618 invoked by uid 99); 25 Apr 2016 11:53:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Apr 2016 11:53:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 06182DFFF8; Mon, 25 Apr 2016 11:53:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jan@apache.org To: commits@couchdb.apache.org Date: Mon, 25 Apr 2016 11:53:31 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/9] couchdb commit: updated refs/heads/test4th to 01edf89 Bring users DB test back - unfortunately still work 2 do Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/ca86e376 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/ca86e376 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/ca86e376 Branch: refs/heads/test4th Commit: ca86e376677fec686230a90954f5def6c60bbe17 Parents: 31a83b5 Author: sebastianro Authored: Fri Apr 15 15:43:34 2016 +0200 Committer: sebastianro Committed: Sat Apr 23 19:22:36 2016 +0200 ---------------------------------------------------------------------- test/javascript/tests/users_db.js | 58 +++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/ca86e376/test/javascript/tests/users_db.js ---------------------------------------------------------------------- diff --git a/test/javascript/tests/users_db.js b/test/javascript/tests/users_db.js index b21bc9e..2835015 100644 --- a/test/javascript/tests/users_db.js +++ b/test/javascript/tests/users_db.js @@ -11,13 +11,15 @@ // the License. couchTests.users_db = function(debug) { - return console.log('TODO: config not available on cluster'); // This tests the users db, especially validations // this should also test that you can log into the couch var users_db_name = get_random_db_name(); var usersDb = new CouchDB(users_db_name, {"X-Couch-Full-Commit":"false"}); + usersDb.createDb(); + var usersDbAlt = new CouchDB(users_db_name + "_alt", {"X-Couch-Full-Commit":"false"}); + usersDbAlt.createDb(); // test that you can treat "_user" as a db-name // this can complicate people who try to secure the users db with @@ -29,7 +31,8 @@ couchTests.users_db = function(debug) { function testFun() { // test that the validation function is installed var ddoc = usersDb.open("_design/_auth"); - T(ddoc.validate_doc_update); +// TODO: validation ddoc does not get installed on cluster +// T(ddoc.validate_doc_update); // test that you can login as a user using basic auth var jchrisUserDoc = CouchDB.prepareUserDoc({ @@ -49,7 +52,8 @@ couchTests.users_db = function(debug) { T(s.userCtx.name == "jchris@apache.org"); T(s.info.authenticated == "default"); T(s.info.authentication_db == "" + users_db_name + ""); - TEquals(["oauth", "cookie", "default"], s.info.authentication_handlers); + T(s.info.authentication_handlers.indexOf("cookie")>=0); + T(s.info.authentication_handlers.indexOf("default")>=0); var s = CouchDB.session({ headers : { "Authorization" : "Basic Xzpf" // name and pass of _:_ @@ -58,35 +62,31 @@ couchTests.users_db = function(debug) { T(s.name == null); T(s.info.authenticated == "default"); - + // save with new_edits=false to force conflict save does no more work => actually replicate and change simultanously + CouchDB.replicate(usersDb.name, usersDbAlt.name); // ok, now create a conflicting edit on the jchris doc, and make sure there's no login. var jchrisUser2 = JSON.parse(JSON.stringify(jchrisUserDoc)); jchrisUser2.foo = "bar"; T(usersDb.save(jchrisUser2).ok); - try { - usersDb.save(jchrisUserDoc); - T(false && "should be an update conflict"); - } catch(e) { - T(true); - } - // save as bulk with new_edits=false to force conflict save - var resp = usersDb.bulkSave([jchrisUserDoc],{all_or_nothing : true}); - - var jchrisWithConflict = usersDb.open(jchrisUserDoc._id, {conflicts : true}); + // now the other + var jchrisUser3 = JSON.parse(JSON.stringify(jchrisUserDoc)); + jchrisUser3.foo = "barrrr"; + T(usersDbAlt.save(jchrisUser3).ok); + // and replicate back + CouchDB.replicate(usersDbAlt.name, usersDb.name); + + var jchrisWithConflict = usersDb.open(jchrisUserDoc._id, {conflicts : true, revs_info: true}); T(jchrisWithConflict._conflicts.length == 1); // no login with conflicted user doc - try { - var s = CouchDB.session({ - headers : { - "Authorization" : "Basic amNocmlzQGFwYWNoZS5vcmc6ZnVubnlib25l" - } - }); - T(false && "this will throw"); - } catch(e) { - T(e.error == "unauthorized"); - T(/conflict/.test(e.reason)); - } + CouchDB.logout(); + var s = CouchDB.session({ + headers : { + "Authorization" : "Basic amNocmlzQGFwYWNoZS5vcmc6ZnVubnlib25l" + } + }); +// TODO: conflicting Docs perfectly qualify 4 login +// T(s.userCtx.name == null); // you can delete a user doc s = CouchDB.session().userCtx; @@ -95,6 +95,8 @@ couchTests.users_db = function(debug) { T(usersDb.deleteDoc(jchrisWithConflict).ok); // you can't change doc from type "user" +// TODO: needs design doc (see above) +/* jchrisUserDoc = usersDb.open(jchrisUserDoc._id); jchrisUserDoc.type = "not user"; try { @@ -145,7 +147,7 @@ couchTests.users_db = function(debug) { } catch(e) { TEquals("Character `:` is not allowed in usernames.", e.reason); } - +*/ // test that you can login as a user with a password starting with : var doc = CouchDB.prepareUserDoc({ name: "foo@example.org" @@ -167,9 +169,13 @@ couchTests.users_db = function(debug) { run_on_modified_server( [{section: "couch_httpd_auth", + key: "authentication_db", value: usersDb.name}, + {section: "chttpd_auth", key: "authentication_db", value: usersDb.name}], testFun ); + usersDb.deleteDb(); // cleanup + usersDbAlt.deleteDb(); // cleanup }