Skip to content

Commit 47b10a0

Browse files
committed
Expand test coverage.
1 parent 7be73ea commit 47b10a0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/oauth2.state.session.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,41 @@ describe('OAuth2Strategy', function() {
5151
});
5252
}); // that redirects to service provider
5353

54+
describe('that redirects to service provider with other data in session', function() {
55+
var request, url;
56+
57+
before(function(done) {
58+
chai.passport.use(strategy)
59+
.redirect(function(u) {
60+
url = u;
61+
done();
62+
})
63+
.req(function(req) {
64+
request = req;
65+
req.session = {};
66+
req.session['oauth2:www.example.com'] = {};
67+
req.session['oauth2:www.example.com'].foo = 'bar';
68+
})
69+
.authenticate();
70+
});
71+
72+
it('should be redirected', function() {
73+
var u = uri.parse(url, true);
74+
expect(u.query.state).to.have.length(24);
75+
});
76+
77+
it('should save state in session', function() {
78+
var u = uri.parse(url, true);
79+
80+
expect(request.session['oauth2:www.example.com'].state).to.have.length(24);
81+
expect(request.session['oauth2:www.example.com'].state).to.equal(u.query.state);
82+
});
83+
84+
it('should preserve other data in session', function() {
85+
expect(request.session['oauth2:www.example.com'].foo).to.equal('bar');
86+
});
87+
}); // that redirects to service provider with other data in session
88+
5489
describe('that errors due to lack of session support in app', function() {
5590
var request, err;
5691

0 commit comments

Comments
 (0)