Files
passport-local/test/strategy.fields.test.js
2014-03-08 10:45:41 -08:00

86 lines
2.3 KiB
JavaScript

/* global describe, it, expect, before */
/* jshint expr: true */
var chai = require('chai')
, Strategy = require('../lib/strategy');
describe('Strategy', function() {
describe('handling a request with valid credentials in body using custom field names', function() {
var strategy = new Strategy({ usernameField: 'userid', passwordField: 'passwd' }, function(username, password, done) {
if (username == 'johndoe' && password == 'secret') {
return done(null, { id: '1234' }, { scope: 'read' });
}
return done(null, false);
});
var user
, info;
before(function(done) {
chai.passport(strategy)
.success(function(u, i) {
user = u;
info = i;
done();
})
.req(function(req) {
req.body = {};
req.body.userid = 'johndoe';
req.body.passwd = 'secret';
})
.authenticate();
});
it('should supply user', function() {
expect(user).to.be.an.object;
expect(user.id).to.equal('1234');
});
it('should supply info', function() {
expect(info).to.be.an.object;
expect(info.scope).to.equal('read');
});
});
describe('handling a request with valid credentials in body using custom field names with object notation', function() {
var strategy = new Strategy({ usernameField: 'user[username]', passwordField: 'user[password]' }, function(username, password, done) {
if (username == 'johndoe' && password == 'secret') {
return done(null, { id: '1234' }, { scope: 'read' });
}
return done(null, false);
});
var user
, info;
before(function(done) {
chai.passport(strategy)
.success(function(u, i) {
user = u;
info = i;
done();
})
.req(function(req) {
req.body = {};
req.body.user = {};
req.body.user.username = 'johndoe';
req.body.user.password = 'secret';
})
.authenticate();
});
it('should supply user', function() {
expect(user).to.be.an.object;
expect(user.id).to.equal('1234');
});
it('should supply info', function() {
expect(info).to.be.an.object;
expect(info.scope).to.equal('read');
});
});
});