Skip to content

Commit

Permalink
Merge pull request #365 from hoodiehq/test-refactor
Browse files Browse the repository at this point in the history
Test refactor
  • Loading branch information
boennemann committed Aug 5, 2015
2 parents a9c1c31 + d992555 commit d1dfc90
Show file tree
Hide file tree
Showing 47 changed files with 1,726 additions and 387 deletions.
2 changes: 1 addition & 1 deletion lib/core/plugins.js
Expand Up @@ -8,7 +8,7 @@ var path = require('path')
var async = require('async')
var clc = require('cli-color')

var plugins_manager = require('hoodie-plugins-manager/lib/index')
var plugins_manager = require('../plugins/manager')
var configStore = require('./config_store')

/**
Expand Down
62 changes: 62 additions & 0 deletions lib/plugins/manager/account_manager.js
@@ -0,0 +1,62 @@
var events = require('events')

var couchr = require('couchr')

exports.start = function (manager, callback) {
var am = {}

var ev = new events.EventEmitter()
am.emit = function () {
ev.emit.apply(ev, arguments)
}
am.on = function () {
ev.on.apply(ev, arguments)
}

var user_db = manager._resolve('_users')
var feed = couchr.changes(user_db, {include_docs: true})

feed.on('change', function (change) {
am.emit('change', change)
})

am.stop = function (callback) {
feed.once('error', function (err) {
// ignore connection errors during stopping of feed
if (err.code !== 'ECONNREFUSED' &&
err.code !== 'ECONNRESET') {
throw err
}
})
feed.once('stop', callback)
feed.stop()
}

// CouchDB 1.4.0 has a introduced the requirement that user fields be explicitly declared public for them to be
// returned. In the case of admins, this filtering should not be applied, but there's a bug.
// BUG: https://issues.apache.org/jira/browse/COUCHDB-1888
var couchRoot = manager._resolve('')

couchr.get(couchRoot, function (err, result) {
if (err) {
return callback(err, null)
}

if (result.version === '1.4.0') {
var config_db = manager._resolve('_config')

var publicFields = [
'_id', '_rev', 'name', 'password_sha', 'password_scheme', 'iterations',
'name', 'roles', 'derived_key', 'salt', 'database', 'hoodieId',
'updatedAt', 'signedUpAt', 'type'
]

couchr.put(config_db + '/couch_httpd_auth/public_fields', JSON.stringify(publicFields.join(',')), function () {
callback(null, am)
})
} else {
callback(null, am)
}
})

}

0 comments on commit d1dfc90

Please sign in to comment.