Skip to content

Commit

Permalink
Add test for Issue saintedlama#96
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHubinger committed Aug 28, 2015
1 parent 15e8981 commit 3052f2d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
24 changes: 12 additions & 12 deletions test/alternative-query-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var passportLocalMongoose = require('../lib/passport-local-mongoose');
var mongotest = require('./mongotest');

describe('alternative query field', function () {
beforeEach(mongotest.prepareDb('mongodb://localhost/passportlocalmongooseissues'));
beforeEach(mongotest.prepareDb('mongodb://boot2docker/passportlocalmongooseissues'));
afterEach(mongotest.disconnect());

it('should find an existing user by alternative query field', function (done) {
Expand All @@ -21,7 +21,7 @@ describe('alternative query field', function () {
var user = new User({ username : 'hugo', email : email });
user.save(function (err) {
assert.ifError(err);

User.findByUsername(email, function (err, user) {
assert.ifError(err);
assert.ok(user);
Expand All @@ -31,7 +31,7 @@ describe('alternative query field', function () {
});
});
});

it('should authenticate an existing user by alternative query field', function (done) {
this.timeout(5000); // Five seconds - mongo db access needed

Expand All @@ -45,7 +45,7 @@ describe('alternative query field', function () {
var user = new User({ username : 'hugo', email : email });
User.register(user, 'password', function (err) {
assert.ifError(err);

User.authenticate()('[email protected]', 'password', function(err, user, message) {
assert.ifError(err);
assert.ok(user);
Expand All @@ -54,8 +54,8 @@ describe('alternative query field', function () {
done();
});
});
});
});

it('should authenticate an existing user by default username field', function (done) {
this.timeout(5000); // Five seconds - mongo db access needed

Expand All @@ -69,7 +69,7 @@ describe('alternative query field', function () {
var user = new User({ username : 'hugo', email : email });
User.register(user, 'password', function (err) {
assert.ifError(err);

User.authenticate()('hugo', 'password', function(err, user, message) {
assert.ifError(err);
assert.ok(user);
Expand All @@ -78,8 +78,8 @@ describe('alternative query field', function () {
done();
});
});
});
});

it('should not authenticate an existing user by unconfigured alternative query field', function (done) {
this.timeout(5000); // Five seconds - mongo db access needed

Expand All @@ -93,7 +93,7 @@ describe('alternative query field', function () {
var user = new User({ username : 'hugo', email : email });
User.register(user, 'password', function (err) {
assert.ifError(err);

User.authenticate()('[email protected]', 'password', function(err, user, message) {
assert.ifError(err);
assert.ok(!user);
Expand All @@ -102,5 +102,5 @@ describe('alternative query field', function () {
done();
});
});
});
});
});
});
32 changes: 30 additions & 2 deletions test/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var passportLocalMongoose = require('../lib/passport-local-mongoose');
var mongotest = require('./mongotest');

describe('issues', function () {
beforeEach(mongotest.prepareDb('mongodb://localhost/passportlocalmongooseissues'));
beforeEach(mongotest.prepareDb('mongodb://boot2docker/passportlocalmongooseissues'));
afterEach(mongotest.disconnect());

it('should support nested fields - Issue #9', function(done) {
Expand Down Expand Up @@ -169,4 +169,32 @@ describe('issues', function () {
});
});
});
});

it.only('authentication should work with salt/hash field marked as select: false - Issue #96', function(done) {
this.timeout(5000); // Five seconds - mongo db access needed

var UserSchema = new Schema({});

UserSchema.plugin(passportLocalMongoose, { });
var User = mongoose.model('ShouldAuthenticateWithSaltAndHashNotExposed_Issue_96', UserSchema);

User.register({username: 'nicolascage'}, 'password', function (err, user) {
assert.ifError(err);
assert.ok(user);
User.findOne({username: 'nicolascage'}, function(err, user) {
assert.ifError(err);
assert.ok(user);
assert.equal(user.username, 'nicolascage');
user.authenticate('password', function(err, auth, reason) {
console.log(err)
assert.ifError(err);

console.log(reason);
assert.ok(auth);

done();
});
});
});
});
});
27 changes: 15 additions & 12 deletions test/passport-local-mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ describe('passportLocalMongoose', function () {

var user = new DefaultUser();

setPasswordAndAuthenticate(user, 'password', 'nopassword', function (err, result) {
assert.ifError(err);
assert.ok(result === false);
var testUser = DefaultUser.findById(user._id, function(err, user) {

done();
});
setPasswordAndAuthenticate(user, 'password', 'nopassword', function (err, result) {
assert.ifError(err);
assert.ok(result === false);

done();
});
});
});

it('should supply a message when authentication fails', function (done) {
Expand All @@ -196,7 +199,7 @@ describe('passportLocalMongoose', function () {
});

describe('static #authenticate()', function () {
beforeEach(mongotest.prepareDb('mongodb://localhost/passportlocalmongoosetests'));
beforeEach(mongotest.prepareDb('mongodb://boot2docker/passportlocalmongoosetests'));
afterEach(mongotest.disconnect());

it('should yield false with message option for authenticate', function (done) {
Expand Down Expand Up @@ -334,7 +337,7 @@ describe('passportLocalMongoose', function () {
debugger;
expect(err).to.not.exist;
expect(result).to.be.false;

done();
});
});
Expand Down Expand Up @@ -436,7 +439,7 @@ describe('passportLocalMongoose', function () {
});

describe('static #deserializeUser()', function () {
beforeEach(mongotest.prepareDb('mongodb://localhost/passportlocalmongoosetests'));
beforeEach(mongotest.prepareDb('mongodb://boot2docker/passportlocalmongoosetests'));
afterEach(mongotest.disconnect());

it('should define a static deserializeUser function for passport', function () {
Expand Down Expand Up @@ -480,7 +483,7 @@ describe('passportLocalMongoose', function () {
});

describe('static #findByUsername()', function () {
beforeEach(mongotest.prepareDb('mongodb://localhost/passportlocalmongoosetests'));
beforeEach(mongotest.prepareDb('mongodb://boot2docker/passportlocalmongoosetests'));
afterEach(mongotest.disconnect());

it('should define static findByUsername helper function', function () {
Expand Down Expand Up @@ -607,7 +610,7 @@ describe('passportLocalMongoose', function () {
});

describe('static #register()', function () {
beforeEach(mongotest.prepareDb('mongodb://localhost/passportlocalmongoosetests'));
beforeEach(mongotest.prepareDb('mongodb://boot2docker/passportlocalmongoosetests'));
afterEach(mongotest.disconnect());

it('should define static register helper function', function () {
Expand Down Expand Up @@ -673,7 +676,7 @@ describe('passportLocalMongoose', function () {
});
});
});

it('should not authenticate registered user with wrong password', function (done) {
this.timeout(5000); // Five seconds - mongo db access needed

Expand All @@ -693,7 +696,7 @@ describe('passportLocalMongoose', function () {
});
});
});

it('it should add username existing user without username', function (done) {
this.timeout(5000); // Five seconds - mongo db access needed

Expand Down

0 comments on commit 3052f2d

Please sign in to comment.