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 1F73C17A0A for ; Wed, 28 Jan 2015 15:51:55 +0000 (UTC) Received: (qmail 75196 invoked by uid 500); 28 Jan 2015 15:51:50 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 75100 invoked by uid 500); 28 Jan 2015 15:51:50 -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 74573 invoked by uid 99); 28 Jan 2015 15:51:50 -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; Wed, 28 Jan 2015 15:51:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9C843E0F0D; Wed, 28 Jan 2015 15:51:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kxepal@apache.org To: commits@couchdb.apache.org Date: Wed, 28 Jan 2015 15:52:03 -0000 Message-Id: <0603e81c02ea419d9f8347e61ba31f80@git.apache.org> In-Reply-To: <106b99bb3f2f4447ba7d6a797d24f3d4@git.apache.org> References: <106b99bb3f2f4447ba7d6a797d24f3d4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [16/46] couchdb commit: updated refs/heads/master to 6f41698 http://git-wip-us.apache.org/repos/asf/couchdb/blob/e2d9c9b1/share/www/script/test/purge.js ---------------------------------------------------------------------- diff --git a/share/www/script/test/purge.js b/share/www/script/test/purge.js deleted file mode 100644 index 2968913..0000000 --- a/share/www/script/test/purge.js +++ /dev/null @@ -1,145 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -couchTests.purge = function(debug) { - var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"}); - db.deleteDb(); - db.createDb(); - if (debug) debugger; - - /* - purge is not to be confused with a document deletion. It removes the - document and all edit history from the local instance of the database. - */ - - var numDocs = 10; - - var designDoc = { - _id:"_design/test", - language: "javascript", - views: { - all_docs_twice: {map: "function(doc) { emit(doc.integer, null); emit(doc.integer, null) }"}, - single_doc: {map: "function(doc) { if (doc._id == \"1\") { emit(1, null) }}"} - } - }; - - T(db.save(designDoc).ok); - - db.bulkSave(makeDocs(1, numDocs + 1)); - - // go ahead and validate the views before purging - var rows = db.view("test/all_docs_twice").rows; - for (var i = 0; i < numDocs; i++) { - T(rows[2*i].key == i+1); - T(rows[(2*i)+1].key == i+1); - } - T(db.view("test/single_doc").total_rows == 1); - - var info = db.info(); - var doc1 = db.open("1"); - var doc2 = db.open("2"); - - // purge the documents - var xhr = CouchDB.request("POST", "/test_suite_db/_purge", { - body: JSON.stringify({"1":[doc1._rev], "2":[doc2._rev]}) - }); - T(xhr.status == 200); - - var result = JSON.parse(xhr.responseText); - var newInfo = db.info(); - - // purging increments the update sequence - T(info.update_seq+1 == newInfo.update_seq); - // and it increments the purge_seq - T(info.purge_seq+1 == newInfo.purge_seq); - T(result.purge_seq == newInfo.purge_seq); - - T(result.purged["1"][0] == doc1._rev); - T(result.purged["2"][0] == doc2._rev); - - T(db.open("1") == null); - T(db.open("2") == null); - - var rows = db.view("test/all_docs_twice").rows; - for (var i = 2; i < numDocs; i++) { - T(rows[2*(i-2)].key == i+1); - T(rows[(2*(i-2))+1].key == i+1); - } - T(db.view("test/single_doc").total_rows == 0); - - // purge sequences are preserved after compaction (COUCHDB-1021) - T(db.compact().ok); - T(db.last_req.status == 202); - // compaction isn't instantaneous, loop until done - while (db.info().compact_running) {}; - var compactInfo = db.info(); - T(compactInfo.purge_seq == newInfo.purge_seq); - - // purge documents twice in a row without loading views - // (causes full view rebuilds) - - var doc3 = db.open("3"); - var doc4 = db.open("4"); - - xhr = CouchDB.request("POST", "/test_suite_db/_purge", { - body: JSON.stringify({"3":[doc3._rev]}) - }); - - T(xhr.status == 200); - - xhr = CouchDB.request("POST", "/test_suite_db/_purge", { - body: JSON.stringify({"4":[doc4._rev]}) - }); - - T(xhr.status == 200); - result = JSON.parse(xhr.responseText); - T(result.purge_seq == db.info().purge_seq); - - var rows = db.view("test/all_docs_twice").rows; - for (var i = 4; i < numDocs; i++) { - T(rows[2*(i-4)].key == i+1); - T(rows[(2*(i-4))+1].key == i+1); - } - T(db.view("test/single_doc").total_rows == 0); - - // COUCHDB-1065 - var dbA = new CouchDB("test_suite_db_a"); - var dbB = new CouchDB("test_suite_db_b"); - dbA.deleteDb(); - dbA.createDb(); - dbB.deleteDb(); - dbB.createDb(); - var docA = {_id:"test", a:1}; - var docB = {_id:"test", a:2}; - dbA.save(docA); - dbB.save(docB); - CouchDB.replicate(dbA.name, dbB.name); - var xhr = CouchDB.request("POST", "/" + dbB.name + "/_purge", { - body: JSON.stringify({"test":[docA._rev]}) - }); - TEquals(200, xhr.status, "single rev purge after replication succeeds"); - - var xhr = CouchDB.request("GET", "/" + dbB.name + "/test?rev=" + docA._rev); - TEquals(404, xhr.status, "single rev purge removes revision"); - - var xhr = CouchDB.request("POST", "/" + dbB.name + "/_purge", { - body: JSON.stringify({"test":[docB._rev]}) - }); - TEquals(200, xhr.status, "single rev purge after replication succeeds"); - var xhr = CouchDB.request("GET", "/" + dbB.name + "/test?rev=" + docB._rev); - TEquals(404, xhr.status, "single rev purge removes revision"); - - var xhr = CouchDB.request("POST", "/" + dbB.name + "/_purge", { - body: JSON.stringify({"test":[docA._rev, docB._rev]}) - }); - TEquals(200, xhr.status, "all rev purge after replication succeeds"); -}; http://git-wip-us.apache.org/repos/asf/couchdb/blob/e2d9c9b1/share/www/script/test/reader_acl.js ---------------------------------------------------------------------- diff --git a/share/www/script/test/reader_acl.js b/share/www/script/test/reader_acl.js deleted file mode 100644 index ff770c7..0000000 --- a/share/www/script/test/reader_acl.js +++ /dev/null @@ -1,219 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy -// of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -couchTests.reader_acl = function(debug) { - // this tests read access control - - var usersDb = new CouchDB("test_suite_users", {"X-Couch-Full-Commit":"false"}); - var secretDb = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"}); - function testFun() { - try { - usersDb.deleteDb(); - try { - usersDb.createDb(); - } catch(e) { - if(usersDb.last_req.status != 412) { - throw e; - } - } - secretDb.deleteDb(); - secretDb.createDb(); - - // create a user with top-secret-clearance - var jchrisUserDoc = CouchDB.prepareUserDoc({ - name: "jchris@apache.org", - roles : ["top-secret"] - }, "funnybone"); - T(usersDb.save(jchrisUserDoc).ok); - usersDb.ensureFullCommit(); - - T(CouchDB.session().userCtx.name == null); - - // set secret db to be read controlled - T(secretDb.save({_id:"baz",foo:"bar"}).ok); - T(secretDb.open("baz").foo == "bar"); - - T(secretDb.setSecObj({ - "members" : { - roles : ["super-secret-club"], - names : ["joe","barb"] - } - }).ok); - } finally { - CouchDB.logout(); - } - } - - // split into 2 funs so we can test restart behavior - function testFun2() { - try { - // can't read it as jchris b/c he's missing the needed role - T(CouchDB.login("jchris@apache.org", "funnybone").ok); - T(CouchDB.session().userCtx.name == "jchris@apache.org"); - - try { - secretDb.open("baz"); - T(false && "can't open a doc from a secret db") ; - } catch(e) { - T(true) - } - - CouchDB.logout(); - - // make anyone with the top-secret role an admin - // db admins are automatically members - T(secretDb.setSecObj({ - "admins" : { - roles : ["top-secret"], - names : [] - }, - "members" : { - roles : ["super-secret-club"], - names : ["joe","barb"] - } - }).ok); - - - T(CouchDB.login("jchris@apache.org", "funnybone").ok); - - // db admin can read - T(secretDb.open("baz").foo == "bar"); - - // and run temp views - TEquals(secretDb.query(function(doc) { - emit(null, null) - }).total_rows, 1); - - CouchDB.logout(); - T(CouchDB.session().userCtx.roles.indexOf("_admin") != -1); - - // admin now adds the top-secret role to the db's members - // and removes db-admins - T(secretDb.setSecObj({ - "admins" : { - roles : [], - names : [] - }, - "members" : { - roles : ["super-secret-club", "top-secret"], - names : ["joe","barb"] - } - }).ok); - - // server _admin can always read - T(secretDb.open("baz").foo == "bar"); - - // and run temp views - TEquals(secretDb.query(function(doc) { - emit(null, null) - }).total_rows, 1); - - T(secretDb.save({ - "_id" : "_design/foo", - views : { - bar : { - map : "function(doc){emit(null, null)}" - } - } - }).ok) - - // now top-secret users can read too - T(CouchDB.login("jchris@apache.org", "funnybone").ok); - T(CouchDB.session().userCtx.roles.indexOf("_admin") == -1); - T(secretDb.open("baz").foo == "bar"); - // members can query stored views - T(secretDb.view("foo/bar").total_rows == 1); - - // members can't do temp views - try { - var results = secretDb.query(function(doc) { - emit(null, null); - }); - T(false && "temp view should be admin only"); - } catch (e) { - T(true && "temp view is admin only"); - } - - CouchDB.logout(); - - // works with readers (backwards compat with 1.0) - T(secretDb.setSecObj({ - "admins" : { - roles : [], - names : [] - }, - "readers" : { - roles : ["super-secret-club", "top-secret"], - names : ["joe","barb"] - } - }).ok); - - T(CouchDB.login("jchris@apache.org", "funnybone").ok); - T(CouchDB.session().userCtx.roles.indexOf("_admin") == -1); - T(secretDb.open("baz").foo == "bar"); - - // can't set non string reader names or roles - try { - secretDb.setSecObj({ - "members" : { - roles : ["super-secret-club", {"top-secret":"awesome"}], - names : ["joe","barb"] - } - }) - T(false && "only string roles"); - } catch (e) {} - - try { - secretDb.setSecObj({ - "members" : { - roles : ["super-secret-club", {"top-secret":"awesome"}], - names : ["joe",22] - } - }); - T(false && "only string names"); - } catch (e) {} - - try { - secretDb.setSecObj({ - "members" : { - roles : ["super-secret-club", {"top-secret":"awesome"}], - names : "joe" - } - }); - T(false && "only lists of names"); - } catch (e) {} - } finally { - CouchDB.logout(); - } - }; - - run_on_modified_server( - [{section: "httpd", - key: "authentication_handlers", - value: "{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"}, - {section: "couch_httpd_auth", - key: "authentication_db", value: "test_suite_users"}], - testFun - ); - - // security changes will always commit synchronously - restartServer(); - - run_on_modified_server( - [{section: "httpd", - key: "authentication_handlers", - value: "{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"}, - {section: "couch_httpd_auth", - key: "authentication_db", value: "test_suite_users"}], - testFun2 - ); -} http://git-wip-us.apache.org/repos/asf/couchdb/blob/e2d9c9b1/share/www/script/test/recreate_doc.js ---------------------------------------------------------------------- diff --git a/share/www/script/test/recreate_doc.js b/share/www/script/test/recreate_doc.js deleted file mode 100644 index f972379..0000000 --- a/share/www/script/test/recreate_doc.js +++ /dev/null @@ -1,145 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -couchTests.recreate_doc = function(debug) { - var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"}); - db.deleteDb(); - db.createDb(); - if (debug) debugger; - - // First create a new document with the ID "foo", and delete it again - var doc = {_id: "foo", a: "bar", b: 42}; - var result = db.save(doc); - T(result.ok); - var firstRev = result.rev; - T(db.deleteDoc(doc).ok); - - // Now create a new document with the same ID, save it, and then modify it - for (var i = 0; i < 10; i++) { - doc = {_id: "foo"}; - T(db.save(doc).ok); - doc = db.open("foo"); - doc.a = "baz"; - T(db.save(doc).ok); - T(db.deleteDoc(doc).rev != undefined); - } - - try { - // COUCHDB-292 now attempt to save the document with a prev that's since - // been deleted and this should generate a conflict exception - db.save({_id:"foo", _rev:firstRev, bar:1}); - T("no save conflict 1" && false); // we shouldn't hit here - } catch (e) { - T(e.error == "conflict"); - } - - var binAttDoc = { - _id: "foo", - _rev:firstRev, - _attachments:{ - "foo.txt": { - content_type:"text/plain", - data: "VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHRleHQ=" - } - } - }; - try { - // same as before, but with binary - db.save(binAttDoc); - T("no save conflict 2" && false); // we shouldn't hit here - } catch (e) { - T(e.error == "conflict"); - } - - - try { - // random non-existant prev rev - db.save({_id:"foo", _rev:"1-asfafasdf", bar:1}); - T("no save conflict 3" && false); // we shouldn't hit here - } catch (e) { - T(e.error == "conflict"); - } - - try { - // random non-existant prev rev with bin - binAttDoc._rev = "1-aasasfasdf"; - db.save(binAttDoc); - T("no save conflict 4" && false); // we shouldn't hit here - } catch (e) { - T(e.error == "conflict"); - } - - db.deleteDb(); - db.createDb(); - - // Helper function to create a doc with multiple revisions - // that are compacted away to ?REV_MISSING. - - var createDoc = function(docid) { - var ret = [{_id: docid, count: 0}]; - T(db.save(ret[0]).ok); - for(var i = 0; i < 2; i++) { - ret[ret.length] = { - _id: docid, - _rev: ret[ret.length-1]._rev, - count: ret[ret.length-1].count+1 - }; - T(db.save(ret[ret.length-1]).ok); - } - db.compact(); - while(db.info().compact_running) {} - return ret; - } - - // Helper function to check that there are no duplicates - // in the changes feed and that it has proper update - // sequence ordering. - - var checkChanges = function() { - // Assert that there are no duplicates in _changes. - var req = CouchDB.request("GET", "/test_suite_db/_changes"); - var resp = JSON.parse(req.responseText); - var docids = {}; - var prev_seq = -1; - for(var i = 0; i < resp.results.length; i++) { - row = resp.results[i]; - T(row.seq > prev_seq, "Unordered _changes feed."); - T(docids[row.id] === undefined, "Duplicates in _changes feed."); - prev_seq = row.seq; - docids[row.id] = true; - } - }; - - // COUCHDB-1265 - Check that the changes feed remains proper - // after we try and break the update_seq tree. - - // This first case is the one originally reported and "fixed" - // in COUCHDB-1265. Reinserting an old revision into the - // revision tree causes duplicates in the update_seq tree. - - var revs = createDoc("a"); - T(db.save(revs[1], {new_edits: false}).ok); - T(db.save(revs[revs.length-1]).ok); - checkChanges(); - - // The original fix for COUCHDB-1265 is not entirely correct - // as it didn't consider the possibility that a compaction - // might run after the original tree screw up. - - revs = createDoc("b"); - T(db.save(revs[1], {new_edits: false}).ok); - db.compact(); - while(db.info().compact_running) {} - T(db.save(revs[revs.length-1]).ok); - checkChanges(); - -}; http://git-wip-us.apache.org/repos/asf/couchdb/blob/e2d9c9b1/share/www/script/test/reduce.js ---------------------------------------------------------------------- diff --git a/share/www/script/test/reduce.js b/share/www/script/test/reduce.js deleted file mode 100644 index 36e5cb7..0000000 --- a/share/www/script/test/reduce.js +++ /dev/null @@ -1,414 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); you may not -// use this file except in compliance with the License. You may obtain a copy of -// the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -// License for the specific language governing permissions and limitations under -// the License. - -couchTests.reduce = function(debug) { - var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"}); - db.deleteDb(); - db.createDb(); - if (debug) debugger; - var numDocs = 500; - var docs = makeDocs(1,numDocs + 1); - db.bulkSave(docs); - var summate = function(N) {return (N+1)*N/2;}; - - var map = function (doc) { - emit(doc.integer, doc.integer); - emit(doc.integer, doc.integer); - }; - var reduce = function (keys, values) { return sum(values); }; - var result = db.query(map, reduce); - T(result.rows[0].value == 2*summate(numDocs)); - - result = db.query(map, reduce, {startkey: 4, endkey: 4}); - T(result.rows[0].value == 8); - - result = db.query(map, reduce, {startkey: 4, endkey: 5}); - T(result.rows[0].value == 18); - - result = db.query(map, reduce, {startkey: 4, endkey: 6}); - T(result.rows[0].value == 30); - - result = db.query(map, reduce, {group:true, limit:3}); - T(result.rows[0].value == 2); - T(result.rows[1].value == 4); - T(result.rows[2].value == 6); - - for(var i=1; i