From 7b883097967e0ee2094e8fa449a2003900572eee Mon Sep 17 00:00:00 2001 From: Jared Hanson Date: Tue, 29 Mar 2016 16:08:58 -0700 Subject: [PATCH] Expand test coverage. --- test/oauth2.state.session.test.js | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/oauth2.state.session.test.js b/test/oauth2.state.session.test.js index ae8556c..d93a7e9 100644 --- a/test/oauth2.state.session.test.js +++ b/test/oauth2.state.session.test.js @@ -176,6 +176,48 @@ describe('OAuth2Strategy', function() { }); }); // that was approved + describe('that was approved with other data in the session', function() { + var request + , user + , info; + + before(function(done) { + chai.passport.use(strategy) + .success(function(u, i) { + user = u; + info = i; + done(); + }) + .req(function(req) { + request = req; + + req.query = {}; + req.query.code = 'SplxlOBeZQQYbYS6WxSbIA'; + req.query.state = 'DkbychwKu8kBaJoLE5yeR5NK'; + req.session = {}; + req.session['oauth2:www.example.com'] = {}; + req.session['oauth2:www.example.com']['state'] = 'DkbychwKu8kBaJoLE5yeR5NK'; + req.session['oauth2:www.example.com'].foo = 'bar'; + }) + .authenticate(); + }); + + it('should supply user', function() { + expect(user).to.be.an.object; + expect(user.id).to.equal('1234'); + }); + + it('should supply info', function() { + expect(info).to.be.an.object; + expect(info.message).to.equal('Hello'); + }); + + it('should preserve other data from session', function() { + expect(request.session['oauth2:www.example.com'].state).to.be.undefined; + expect(request.session['oauth2:www.example.com'].foo).to.equal('bar'); + }); + }); // that was approved with other data in the session + describe('that fails due to state being invalid', function() { var request , info, status;