Skip to content

Commit 32b1ecf

Browse files
committed
Test case for custom store and redirect.
1 parent 4b879ab commit 32b1ecf

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/oauth2.state.custom.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var OAuth2Strategy = require('../lib/strategy')
2+
, AuthorizationError = require('../lib/errors/authorizationerror')
3+
, TokenError = require('../lib/errors/tokenerror')
4+
, InternalOAuthError = require('../lib/errors/internaloautherror')
5+
, chai = require('chai')
6+
, uri = require('url');
7+
8+
9+
describe('OAuth2Strategy', function() {
10+
11+
describe('with custom state store that accepts meta argument', function() {
12+
function CustomStore() {
13+
}
14+
15+
CustomStore.prototype.store = function(req, cb) {
16+
if (req.url !== '/me') { return cb(new Error('incorrect req argument')); }
17+
18+
req.customStoreStoreCalled = req.customStoreStoreCalled ? req.customStoreStoreCalled++ : 1;
19+
return cb(null, 'foos7473');
20+
};
21+
22+
CustomStore.prototype.verify = function(req, state, meta, cb) {
23+
};
24+
25+
26+
describe('issuing authorization request', function() {
27+
var strategy = new OAuth2Strategy({
28+
authorizationURL: 'https://www.example.com/oauth2/authorize',
29+
tokenURL: 'https://www.example.com/oauth2/token',
30+
clientID: 'ABC123',
31+
clientSecret: 'secret',
32+
callbackURL: 'https://www.example.net/auth/example/callback',
33+
store: new CustomStore()
34+
},
35+
function(accessToken, refreshToken, profile, done) {});
36+
37+
38+
describe('that redirects to service provider', function() {
39+
var request, url;
40+
41+
before(function(done) {
42+
chai.passport.use(strategy)
43+
.redirect(function(u) {
44+
url = u;
45+
done();
46+
})
47+
.req(function(req) {
48+
request = req;
49+
req.url = '/me';
50+
})
51+
.authenticate();
52+
});
53+
54+
it('should be redirected', function() {
55+
expect(url).to.equal('https://www.example.com/oauth2/authorize?response_type=code&redirect_uri=https%3A%2F%2Fwww.example.net%2Fauth%2Fexample%2Fcallback&state=foos7473&client_id=ABC123');
56+
});
57+
58+
it('should store request token in custom store', function() {
59+
expect(request.customStoreStoreCalled).to.equal(1);
60+
});
61+
}); // that redirects to service provider
62+
63+
}); // issuing authorization request
64+
65+
}); // with custom state store that accepts meta argument
66+
67+
});

0 commit comments

Comments
 (0)