Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed May 19, 2022
1 parent 3001654 commit 80cc4e3
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/http/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,58 @@ describe('http.ServerRequest', function() {
});
});

describe('encountering an error regenerating session', function() {
var passport = new Passport();

var req = new Object();
req.logout = request.logout;
req.isAuthenticated = request.isAuthenticated;
req.isUnauthenticated = request.isUnauthenticated;
req.user = { id: '1', username: 'root' };
req._passport = {};
req._passport.instance = passport;
req._sessionManager = passport._sm;
req.session = { id: '1' };
req.session['passport'] = {};
req.session['passport'].user = '1';
req.session.save = function(cb) {
expect(req.session['passport'].user).to.be.undefined;
process.nextTick(cb);
};
req.session.regenerate = function(cb) {
process.nextTick(function() {
cb(new Error('something went wrong'));
});
};

var error;

before(function(done) {
req.logout(function(err) {
error = err;
done();
});
});

it('should error', function() {
expect(error).to.be.an.instanceOf(Error);
expect(error.message).to.equal('something went wrong');
});

it('should not be authenticated', function() {
expect(req.isAuthenticated()).to.be.false;
expect(req.isUnauthenticated()).to.be.true;
});

it('should clear user', function() {
expect(req.user).to.be.null;
});

it('should clear serialized user', function() {
expect(req.session['passport'].user).to.be.undefined;
});
});

describe('existing session, but not passing a callback argument', function() {
var passport = new Passport();
passport.serializeUser(function(user, done) {
Expand Down

0 comments on commit 80cc4e3

Please sign in to comment.