pouchdb-admins
PouchDB plugin to simulate CouchDB’s admin accounts
pouchdb-admins
mimics how CouchDB stores a map of admin accounts in its configuration.
Example
var PouchDB = PouchDB var db = 'my-users' var admins = db admins admins adminsadminsadminsadmins
API
Factory
db
Argument | Type | Description | Required |
---|---|---|---|
options.secret |
String |
Server secret, like CouchDB’s couch_httpd_auth.secret
|
Yes |
options.admins |
Object | Map of existing admin accounts | No |
options.sessionTimeout |
Number |
Default timeout for sessions in milliseconds, used in
.calculateSessionId
|
No |
Returns admins
API.
Throws
TypeError |
options.secret is not a String |
---|
Example
var admins = db
admins.get()
Looks up admin account by username
admins
Argument | Type | Description | Required |
---|---|---|---|
username |
String | - | Yes |
Resolves without doc for admin as if it would be stored in CouchDB’s _users
but without a _rev
property.
id: 'org.couchdb.user:kim' type: 'user' name: 'kim' password_scheme: 'pbkdf2' derived_key: 'e079757b4cb58ae17467c8befe725778ce97e422' salt: '0aef36ccafa33f3e81ae897baf23f85c' iterations: 10 roles: '_admin'
Rejects with
TypeError |
username is not a String |
---|---|
not_found |
admin not found |
Example
admins
Session validation example
var isValidSessionId = admins
admins.set()
Adds or updates admin password
admins
Argument | Type | Description | Required |
---|---|---|---|
username |
String | - | Yes |
password |
String | - | Yes |
Resolves without argument. Rejects with
TypeError |
username is not a String |
---|---|
TypeError |
password is not a String |
Example
admins
admins.validatePassword
Validates password of admin account
admins
Argument | Type | Description | Required |
---|---|---|---|
username |
String | - | Yes |
password |
String | - | Yes |
Resolves without argument. Rejects with
TypeError |
username is not a String |
---|---|
TypeError |
password is not a String |
not_found |
missing |
unauthorized |
Name or password is incorrect |
Example
admins
calculateSessionId()
tbd
validateSession()
tbd
Events
admins
is an event emitter and exposes
all methods .on
, once
, .removeListener
etc.
Event | Description | Argument |
---|---|---|
change |
triggered for any add , update and remove event
|
adminsMap of all admin accounts with hashed password
|
add |
New admin account created |
username of new admin account
|
update |
Existing admin account updated |
username of updated admin account
|
remove |
New admin account created |
username of removed admin account
|
How it works
Here an excerpt of a couch.ini
that stores a map of two admin accounts with
their hashed passwords. The format is -{password scheme}-{derived key},{salt},{iterations}
.
[admins]admin=-pbkdf2-e079757b4cb58ae17467c8befe725778ce97e422,0aef36ccafa33f3e81ae897baf23f85c,10anotheradmin=-pbkdf2-67c8befe725778ce97e422e079757b4cb58ae174,7baf23f85c0aef36ccafa33f3e81ae89,10
Testing
Local setup
git clone git@github.com:hoodiehq/pouchdb-admins.git
cd pouchdb-admins
npm install
Run all tests and code style checks
npm test
Run all tests on file change
npm run test:watch
Run tests from single file
node tests/integration/constructor-test.js
# PROTIP™: pipe output through https://www.npmjs.com/package/tape#pretty-reporters