couch-login
Advanced tools
Comparing version 0.1.12 to 0.1.13
@@ -6,2 +6,3 @@ var request = require('request') | ||
, BASIC = {} | ||
, assert = require('assert') | ||
@@ -67,2 +68,3 @@ module.exports = CouchLogin | ||
function decorate (req, res) { | ||
assert(this instanceof CouchLogin) | ||
req.couch = res.couch = this | ||
@@ -91,2 +93,3 @@ | ||
function anon () { | ||
assert(this instanceof CouchLogin) | ||
return new CouchLogin(this.couch, NaN) | ||
@@ -96,2 +99,3 @@ } | ||
function makeReq (meth, body, f) { return function madeReq (p, d, cb) { | ||
assert(this instanceof CouchLogin) | ||
f = f || (this.token !== this.token) | ||
@@ -136,2 +140,5 @@ if (!f && !valid(this.token)) { | ||
// we're handling cookies, don't do it for us. | ||
req.jar = false | ||
request(req, function (er, res, data) { | ||
@@ -141,3 +148,3 @@ // update cookie. | ||
addToken.call(this, res) | ||
return cb(er, res, data) | ||
return cb.call(this, er, res, data) | ||
}.bind(this)) | ||
@@ -147,6 +154,8 @@ }} | ||
function login (auth, cb) { | ||
assert(this instanceof CouchLogin) | ||
if (this.token === BASIC) { | ||
this.auth = new Buffer(auth.name + ':' + auth.password).toString('base64') | ||
this.name = auth.name | ||
return process.nextTick(cb, null, { statusCode: 200 }, { ok: true }) | ||
cb = cb.bind(this, null, { statusCode: 200 }, { ok: true }) | ||
return process.nextTick(cb) | ||
} | ||
@@ -160,6 +169,7 @@ var a = { name: auth.name, password: auth.password } | ||
cb(er, cr, data) | ||
}) | ||
}.bind(this)) | ||
} | ||
function changePass (auth, cb) { | ||
assert(this instanceof CouchLogin) | ||
if (!auth.name || !auth.password) return cb(new Error('invalid auth')) | ||
@@ -207,2 +217,3 @@ | ||
function deleteAccount (name, cb) { | ||
assert(this instanceof CouchLogin) | ||
var u = '/_users/org.couchdb.user:' + name | ||
@@ -228,5 +239,7 @@ this.get(u, thenPut.bind(this)) | ||
function signup (auth, cb) { | ||
if (this.token && this.token !== BASIC) | ||
assert(this instanceof CouchLogin) | ||
if (this.token && this.token !== BASIC) { | ||
return this.logout(function (er, res, data) { | ||
if (er || res.statusCode !== 200) { | ||
if (er || res && res.statusCode !== 200) { | ||
return cb(er, res, data) | ||
@@ -241,2 +254,3 @@ } | ||
}.bind(this)) | ||
} | ||
@@ -276,2 +290,3 @@ // make a new user record. | ||
function addToken (res) { | ||
assert(this instanceof CouchLogin) | ||
// not doing the whole login session cookie thing. | ||
@@ -324,5 +339,7 @@ if (this.token === BASIC) | ||
function logout (cb) { | ||
assert(this instanceof CouchLogin) | ||
if (!this.token && this.tokenGet) { | ||
return this.tokenGet(function (er, tok) { | ||
if (er || !tok) return cb() | ||
if (er || !tok) | ||
return cb(null, { statusCode: 200 }, {}) | ||
this.token = tok | ||
@@ -336,3 +353,3 @@ this.logout(cb) | ||
if (this.tokenDel) this.tokenDel() | ||
return process.nextTick(cb) | ||
return process.nextTick(cb.bind(this, null, { statusCode: 200 }, {})) | ||
} | ||
@@ -350,3 +367,4 @@ | ||
this.token = null | ||
if (this.tokenDel) this.tokenDel() | ||
if (this.tokenDel) | ||
this.tokenDel() | ||
cb(er, res, data) | ||
@@ -353,0 +371,0 @@ }.bind(this)) |
@@ -5,3 +5,3 @@ { | ||
"description": "A module for doing logged-in requests to a couchdb server", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
var tap = require('tap') | ||
, CouchLogin = require('../couch-login.js') | ||
// Yeah, go ahead and abuse my staging server, whatevs. | ||
var auth = { name: 'testuser', password: 'test' } | ||
, newAuth = { name: 'testuser', password: 'asdfasdf' } | ||
, couch = new CouchLogin('https://isaacs-staging.iriscouch.com/') | ||
, couch = new CouchLogin('http://localhost:15985/') | ||
, u = '/_users/org.couchdb.user:' + auth.name | ||
@@ -10,0 +8,0 @@ , userRecordMarker |
@@ -6,7 +6,5 @@ // Should be able to use this module to log into the registry, as well. | ||
// Yeah, go ahead and abuse my staging server, whatevs. | ||
var auth = { name: 'testuser', password: 'test' } | ||
, newAuth = { name: 'testuser', password: 'asdfasdf' } | ||
, couch = new CouchLogin('https://staging.npmjs.org/') | ||
, couch = new CouchLogin('http://127.0.0.1:15985/') | ||
, u = '/_users/org.couchdb.user:' + auth.name | ||
@@ -208,3 +206,3 @@ , userRecordMarker | ||
t.equal(data.testingCouchLogin, undefined) | ||
t.equal(data.mustChangePass, false) | ||
t.notOk(data.mustChangePass) | ||
userRecord = data | ||
@@ -211,0 +209,0 @@ t.end() |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
69888
13
0
1007
2
1