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 b395106 commit 3001654
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/http/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,59 @@ describe('http.ServerRequest', function() {
});
});

describe('encountering an error saving existing 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(function() {
cb(new Error('something went wrong'));
});
};
req.session.regenerate = function(cb) {
req.session = { id: '2' };
process.nextTick(cb);
};

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 3001654

Please sign in to comment.