From 2ffacd49268f745a3e854353e4179011dc646c70 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Sat, 12 Mar 2011 17:35:33 +0000 Subject: Merged revision 1080953 from trunk Replicator manager: do basic validation of replication documents Now the default design document of the replicator database validates each replication document added to the database so that necessary fields must be present and have the right type, and optional replication related fields have the correct type as well. Closes COUCHDB-1088. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1080954 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/replicator_db.js | 129 +++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'share/www/script/test') diff --git a/share/www/script/test/replicator_db.js b/share/www/script/test/replicator_db.js index 95a196d7..e8986d6e 100644 --- a/share/www/script/test/replicator_db.js +++ b/share/www/script/test/replicator_db.js @@ -916,6 +916,131 @@ couchTests.replicator_db = function(debug) { } + function rep_doc_field_validation() { + var docs = makeDocs(1, 5); + + populate_db(dbA, docs); + populate_db(dbB, []); + + var repDoc = { + _id: "rep1", + target: dbB.name + }; + + try { + repDb.save(repDoc); + T(false, "should have failed because source field is missing"); + } catch (x) { + TEquals("forbidden", x.error); + } + + repDoc = { + _id: "rep1", + source: 123, + target: dbB.name + }; + + try { + repDb.save(repDoc); + T(false, "should have failed because source field is a number"); + } catch (x) { + TEquals("forbidden", x.error); + } + + repDoc = { + _id: "rep1", + source: dbA.name + }; + + try { + repDb.save(repDoc); + T(false, "should have failed because target field is missing"); + } catch (x) { + TEquals("forbidden", x.error); + } + + repDoc = { + _id: "rep1", + source: dbA.name, + target: null + }; + + try { + repDb.save(repDoc); + T(false, "should have failed because target field is null"); + } catch (x) { + TEquals("forbidden", x.error); + } + + repDoc = { + _id: "rep1", + source: dbA.name, + target: { url: 123 } + }; + + try { + repDb.save(repDoc); + T(false, "should have failed because target.url field is not a string"); + } catch (x) { + TEquals("forbidden", x.error); + } + + repDoc = { + _id: "rep1", + source: dbA.name, + target: { url: dbB.name, auth: null } + }; + + try { + repDb.save(repDoc); + T(false, "should have failed because target.auth field is null"); + } catch (x) { + TEquals("forbidden", x.error); + } + + repDoc = { + _id: "rep1", + source: dbA.name, + target: { url: dbB.name, auth: "foo:bar" } + }; + + try { + repDb.save(repDoc); + T(false, "should have failed because target.auth field is not an object"); + } catch (x) { + TEquals("forbidden", x.error); + } + + repDoc = { + _id: "rep1", + source: dbA.name, + target: dbB.name, + continuous: "true" + }; + + try { + repDb.save(repDoc); + T(false, "should have failed because continuous is not a boolean"); + } catch (x) { + TEquals("forbidden", x.error); + } + + repDoc = { + _id: "rep1", + source: dbA.name, + target: dbB.name, + filter: 123 + }; + + try { + repDb.save(repDoc); + T(false, "should have failed because filter is not a string"); + } catch (x) { + TEquals("forbidden", x.error); + } + } + + // run all the tests var server_config = [ { @@ -983,6 +1108,10 @@ couchTests.replicator_db = function(debug) { restartServer(); run_on_modified_server(server_config, compact_rep_db); + repDb.deleteDb(); + restartServer(); + run_on_modified_server(server_config, rep_doc_field_validation); + /* * Disabled, since error state would be set on the document only after * the exponential backoff retry done by the replicator database listener -- cgit v1.2.3