Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ Strategy.prototype.authenticate = function(req, options) {
options = options || {};
var username = lookup(req.body, this._usernameField) || lookup(req.query, this._usernameField);
var password = lookup(req.body, this._passwordField) || lookup(req.query, this._passwordField);

if (!username || !password) {
return this.fail({ message: options.badRequestMessage || 'Missing credentials' }, 400);
}


var self = this;

function verified(err, user, info) {
Expand Down
52 changes: 22 additions & 30 deletions test/strategy.normal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,37 @@ describe('Strategy', function() {

describe('handling a request without a body', function() {
var strategy = new Strategy(function(username, password, done) {
throw new Error('should not be called');
return done(null, false, { message: 'authentication failed' });
});

var info, status;
var info;

before(function(done) {
chai.passport(strategy)
.fail(function(i, s) {
.fail(function(i) {
info = i;
status = s;
done();
})
.authenticate();
});

it('should fail with info and status', function() {
expect(info).to.be.an.object;
expect(info.message).to.equal('Missing credentials');
expect(status).to.equal(400);
it('should fail', function() {
expect(info).to.be.an('object');
expect(info.message).to.equal('authentication failed');
});
});

describe('handling a request without a body, but no username and password', function() {
describe('handling a request with a body, but no username and password', function() {
var strategy = new Strategy(function(username, password, done) {
throw new Error('should not be called');
return done(null, false, { message: 'authentication failed' });
});

var info, status;
var info;

before(function(done) {
chai.passport(strategy)
.fail(function(i, s) {
info = i;
status = s;
done();
})
.req(function(req) {
Expand All @@ -125,25 +122,23 @@ describe('Strategy', function() {
.authenticate();
});

it('should fail with info and status', function() {
expect(info).to.be.an.object;
expect(info.message).to.equal('Missing credentials');
expect(status).to.equal(400);
it('should fail', function() {
expect(info).to.be.an('object');
expect(info.message).to.equal('authentication failed');
});
});

describe('handling a request without a body, but no password', function() {
var strategy = new Strategy(function(username, password, done) {
throw new Error('should not be called');
return done(null, false, { message: 'authentication failed' });
});

var info, status;
var info;

before(function(done) {
chai.passport(strategy)
.fail(function(i, s) {
info = i;
status = s;
done();
})
.req(function(req) {
Expand All @@ -153,25 +148,23 @@ describe('Strategy', function() {
.authenticate();
});

it('should fail with info and status', function() {
expect(info).to.be.an.object;
expect(info.message).to.equal('Missing credentials');
expect(status).to.equal(400);
it('should fail', function() {
expect(info).to.be.an('object');
expect(info.message).to.equal('authentication failed');
});
});

describe('handling a request without a body, but no username', function() {
var strategy = new Strategy(function(username, password, done) {
throw new Error('should not be called');
return done(null, false, { message: 'authentication failed' });
});

var info, status;
var info;

before(function(done) {
chai.passport(strategy)
.fail(function(i, s) {
info = i;
status = s;
done();
})
.req(function(req) {
Expand All @@ -181,10 +174,9 @@ describe('Strategy', function() {
.authenticate();
});

it('should fail with info and status', function() {
expect(info).to.be.an.object;
expect(info.message).to.equal('Missing credentials');
expect(status).to.equal(400);
it('should fail', function() {
expect(info).to.be.an('object');
expect(info.message).to.equal('authentication failed');
});
});

Expand Down
8 changes: 3 additions & 5 deletions test/strategy.options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ describe('Strategy', function() {

describe('handling a request without a body, but no username and password, with message option to authenticate', function() {
var strategy = new Strategy(function(username, password, done) {
throw new Error('should not be called');
return done(null, false, { message: 'Something is wrong with this request' });
});

var info, status;
var info;

before(function(done) {
chai.passport(strategy)
.fail(function(i, s) {
info = i;
status = s;
done();
})
.req(function(req) {
Expand All @@ -27,10 +26,9 @@ describe('Strategy', function() {
.authenticate({ badRequestMessage: 'Something is wrong with this request' });
});

it('should fail with info and status', function() {
it('should fail', function() {
expect(info).to.be.an.object;
expect(info.message).to.equal('Something is wrong with this request');
expect(status).to.equal(400);
});
});

Expand Down