Skip to content

Commit

Permalink
Fix test to allow setting of authInfo with assignProperty.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Nov 27, 2023
1 parent b4e4cff commit 0f2f81c
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/middleware/authenticate.success.test.js
Expand Up @@ -98,6 +98,55 @@ describe('middleware/authenticate', function() {
expect(request.account.username).to.equal('jaredhanson');
});

it('should set authInfo to empty object', function() {
expect(request.authInfo).to.deep.equal({});
});
});

describe('success that assigns a specific property with authInfo disabled', function() {
function Strategy() {
}
Strategy.prototype.authenticate = function(req) {
var user = { id: '1', username: 'jaredhanson' };
this.success(user);
};

var passport = new Passport();
passport.use('success', new Strategy());

var request, error;

before(function(done) {
chai.connect.use(authenticate(passport, 'success', { assignProperty: 'account', authInfo: false }))
.req(function(req) {
request = req;

req.logIn = function(user, options, done) {
this.user = user;
done();
};
})
.next(function(err) {
error = err;
done();
})
.dispatch();
});

it('should not error', function() {
expect(error).to.be.undefined;
});

it('should not set user', function() {
expect(request.user).to.be.undefined;
});

it('should set account', function() {
expect(request.account).to.be.an('object');
expect(request.account.id).to.equal('1');
expect(request.account.username).to.equal('jaredhanson');
});

it('should not set authInfo', function() {
expect(request.authInfo).to.be.undefined;
});
Expand Down

0 comments on commit 0f2f81c

Please sign in to comment.