Skip to content

Commit b4e4cff

Browse files
committed
Fix test to allow setting of authInfo from authorize call.
1 parent da379a0 commit b4e4cff

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/authenticator.middleware.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,55 @@ describe('Authenticator', function() {
245245
expect(request.account.username).to.equal('jaredhanson');
246246
});
247247

248+
it('should set authInfo to empty object', function() {
249+
expect(request.authInfo).to.deep.equal({});
250+
});
251+
});
252+
253+
describe('handling a request with authInfo disabled', function() {
254+
function Strategy() {
255+
}
256+
Strategy.prototype.authenticate = function(req) {
257+
var user = { id: '1', username: 'jaredhanson' };
258+
this.success(user);
259+
};
260+
261+
var passport = new Authenticator();
262+
passport.use('success', new Strategy());
263+
264+
var request, error;
265+
266+
before(function(done) {
267+
chai.connect.use(passport.authorize('success', { authInfo: false }))
268+
.req(function(req) {
269+
request = req;
270+
271+
req.logIn = function(user, options, done) {
272+
this.user = user;
273+
done();
274+
};
275+
})
276+
.next(function(err) {
277+
error = err;
278+
done();
279+
})
280+
.dispatch();
281+
});
282+
283+
it('should not error', function() {
284+
expect(error).to.be.undefined;
285+
});
286+
287+
it('should not set user', function() {
288+
expect(request.user).to.be.undefined;
289+
});
290+
291+
it('should set account', function() {
292+
expect(request.account).to.be.an('object');
293+
expect(request.account.id).to.equal('1');
294+
expect(request.account.username).to.equal('jaredhanson');
295+
});
296+
248297
it('should not set authInfo', function() {
249298
expect(request.authInfo).to.be.undefined;
250299
});

0 commit comments

Comments
 (0)