diff --git a/test/http/request.test.js b/test/http/request.test.js index 138788ac..2337b147 100644 --- a/test/http/request.test.js +++ b/test/http/request.test.js @@ -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) {