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