Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Forbes Lindesay
committed
Aug 17, 2012
1 parent
bf73fb4
commit 377e634
Showing
6 changed files
with
142 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- 0.6 | ||
- 0.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
{ | ||
"name": "connect-roles", | ||
"description": "Provides dynamic roles based authentication for node.js connect and express servers.", | ||
"version": "0.1.7", | ||
"homepage": "http://documentup.com/ForbesLindesay/connect-roles", | ||
"repository": { | ||
"type":"git", | ||
"url": "git://github.com/ForbesLindesay/connect-roles.git" | ||
}, | ||
"main": "./index" | ||
"name": "connect-roles", | ||
"description": "Provides dynamic roles based authentication for node.js connect and express servers.", | ||
"version": "0.1.7", | ||
"homepage": "http://documentup.com/ForbesLindesay/connect-roles", | ||
"repository": { | ||
"type":"git", | ||
"url": "git://github.com/ForbesLindesay/connect-roles.git" | ||
}, | ||
"main": "./index", | ||
"devDependencies": { | ||
"should": "*", | ||
"mocha": "*" | ||
}, | ||
"scripts": { | ||
"prepublish": "mocha", | ||
"test": "mocha -R spec" | ||
}, | ||
"author": "ForbesLindesay", | ||
"license": "BSD", | ||
"keywords": [ | ||
"roles", | ||
"authorization", | ||
"authentication", | ||
"security", | ||
"connect", | ||
"express", | ||
"passport", | ||
"everyauth" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
var roles = require('../'); | ||
var assert = require('should'); | ||
|
||
describe('middleware', function () { | ||
describe('when there is a user', function () { | ||
it('adds methods', function (done) { | ||
var req = {user: { id: 'Forbes' }}; | ||
var res = {}; | ||
roles(req, res, function (err) { | ||
if (err) return done(err); | ||
req.user.isAuthenticated.should.equal(true); | ||
req.user.can.should.be.a('function'); | ||
req.user.is.should.be.a('function'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('when there is no user', function () { | ||
it('adds methods and the anonymous user', function (done) { | ||
var req = {}; | ||
var res = {}; | ||
roles(req, res, function (err) { | ||
if (err) return done(err); | ||
req.user.isAuthenticated.should.equal(false); | ||
req.user.can.should.be.a('function'); | ||
req.user.is.should.be.a('function'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
function notCalled(name) { | ||
return function notCalled() { | ||
throw new Error('The function ' + name + ' should not be called here.'); | ||
} | ||
} | ||
describe('isAuthenticated route middleware', function () { | ||
describe('when there is a user', function () { | ||
before(function () { | ||
roles.setFailureHandler(notCalled('Failure Handler')); | ||
}); | ||
it('passes the test', function (done) { | ||
var req = {user: { isAuthenticated: true }}; | ||
var res = {send: notCalled('send')}; | ||
roles.isAuthenticated(req, res, function (err) { | ||
if (err) return done(err); | ||
done(); | ||
}); | ||
}); | ||
after(function () { | ||
roles.setFailureHandler(function failureHandler(req, res, action) { | ||
res.send(403); | ||
}); | ||
}); | ||
}); | ||
describe('when there is a user but they aren\'t authenticated.', function () { | ||
it('fails the test', function (done) { | ||
var req = {user: { id: 'Forbes' }}; | ||
var res = {send: send}; | ||
function send(code) { | ||
code.should.equal(403); | ||
done(); | ||
} | ||
roles.isAuthenticated(req, res, notCalled('next')); | ||
}); | ||
}); | ||
describe('when there is no user', function () { | ||
it('adds methods and the anonymous user', function (done) { | ||
var req = {}; | ||
var res = {}; | ||
roles(req, res, function (err) { | ||
if (err) return done(err); | ||
req.user.isAuthenticated.should.equal(false); | ||
req.user.can.should.be.a('function'); | ||
req.user.is.should.be.a('function'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |