Permalink
Browse files

Do not crash processing ddocs for unauthorized dbs

  • Loading branch information...
1 parent 0840bf3 commit 08a8fbee15efafa6be2eb9de59e5ae095eb54163 @jhs committed Feb 21, 2011
Showing with 6 additions and 3 deletions.
  1. +6 −3 audit_couchdb.js
View
@@ -18,7 +18,7 @@ function CouchAudit(url) {
var ddocs_in_db = {};
self.on('database_ok', function(url, info, security) {
self.log.debug("Tracking ddocs in database: " + url);
- ddocs_in_db[url] = {};
+ ddocs_in_db[url] = [];
if("readers" in security) {
// TODO
@@ -28,11 +28,14 @@ function CouchAudit(url) {
})
self.on('database_unauthorized', function(url) {
+ ddocs_in_db[url] = null;
this.low("Database is unauthorized: " + url);
})
self.on('database_done', function(url) {
- var ddocs = Object.keys(ddocs_in_db[url]).map(function(k) { return ddocs_in_db[url][k] });
+ var ddocs = ddocs_in_db[url];
+ if(ddocs === null) // DB was unauthorized.
+ return;
var validator_count = ddocs.reduce(function(sum, ddoc) { return sum + (ddoc.validate_doc_update ? 1 : 0) }, 0);
if(validator_count < 1)
@@ -43,7 +46,7 @@ function CouchAudit(url) {
self.on('ddoc', function(db_url, ddoc, info) {
var ddoc_url = lib.join(db_url, ddoc._id);
- ddocs_in_db[db_url][ddoc._id] = ddoc;
+ ddocs_in_db[db_url].push(ddoc);
if(ddoc.language !== info.view_index.language)
throw new Error("Different languages in ddoc vs. index info: " + JSON.stringify(info) + " vs. language = " + JSON.stringify(ddoc.language));

0 comments on commit 08a8fbe

Please sign in to comment.