Skip to content

Commit ac6e390

Browse files
committed
Test cases for meta argument on redirect.
1 parent 12354c1 commit ac6e390

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

lib/strategy.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ OAuth2Strategy.prototype.authenticate = function(req, options) {
229229
} else { // arity == 2
230230
this._stateStore.store(req, stored);
231231
}
232-
233-
234232
} catch (ex) {
235233
return this.error(ex);
236234
}

test/oauth2.state.custom.test.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ describe('OAuth2Strategy', function() {
1212
function CustomStore() {
1313
}
1414

15-
CustomStore.prototype.store = function(req, cb) {
15+
CustomStore.prototype.store = function(req, meta, cb) {
16+
if (req.url === '/error') { return cb(new Error('something went wrong storing state')); }
17+
if (req.url === '/exception') { throw new Error('something went horribly wrong storing state'); }
18+
1619
if (req.url !== '/me') { return cb(new Error('incorrect req argument')); }
20+
if (meta.authorizationURL !== 'https://www.example.com/oauth2/authorize') { return cb(new Error('incorrect meta.authorizationURL argument')); }
21+
if (meta.tokenURL !== 'https://www.example.com/oauth2/token') { return cb(new Error('incorrect meta.tokenURL argument')); }
22+
if (meta.clientID !== 'ABC123') { return callback(new Error('incorrect meta.clientID argument')); }
1723

1824
req.customStoreStoreCalled = req.customStoreStoreCalled ? req.customStoreStoreCalled++ : 1;
1925
return cb(null, 'foos7473');
@@ -60,6 +66,50 @@ describe('OAuth2Strategy', function() {
6066
});
6167
}); // that redirects to service provider
6268

69+
describe('that errors due to custom store supplying error', function() {
70+
var request, err;
71+
72+
before(function(done) {
73+
chai.passport.use(strategy)
74+
.error(function(e) {
75+
err = e;
76+
done();
77+
})
78+
.req(function(req) {
79+
request = req;
80+
req.url = '/error';
81+
})
82+
.authenticate();
83+
});
84+
85+
it('should error', function() {
86+
expect(err).to.be.an.instanceof(Error);
87+
expect(err.message).to.equal('something went wrong storing state');
88+
});
89+
}); // that errors due to custom store supplying error
90+
91+
describe('that errors due to custom store throwing error', function() {
92+
var request, err;
93+
94+
before(function(done) {
95+
chai.passport.use(strategy)
96+
.error(function(e) {
97+
err = e;
98+
done();
99+
})
100+
.req(function(req) {
101+
request = req;
102+
req.url = '/exception';
103+
})
104+
.authenticate();
105+
});
106+
107+
it('should error', function() {
108+
expect(err).to.be.an.instanceof(Error);
109+
expect(err.message).to.equal('something went horribly wrong storing state');
110+
});
111+
}); // that errors due to custom store throwing error
112+
63113
}); // issuing authorization request
64114

65115
}); // with custom state store that accepts meta argument

0 commit comments

Comments
 (0)