forked from jaredhanson/passport-facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.token.error.test.js
80 lines (67 loc) · 2.42 KB
/
strategy.token.error.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var chai = require('chai')
, FacebookStrategy = require('../lib/strategy');
describe('Strategy', function() {
describe('using token endpoint that responds with non-standard error', function() {
var strategy = new FacebookStrategy({
clientID: 'ABC123',
clientSecret: 'secret'
},
function() {});
// inject a "mock" oauth2 instance
strategy._oauth2.getOAuthAccessToken = function(code, options, callback) {
return callback({ statusCode: 400, data: '{"error":{"message":"Invalid verification code format.","type":"OAuthException","code":100}}' });
}
describe('handling response', function() {
var err;
before(function(done) {
chai.passport(strategy)
.error(function(e) {
err = e;
done();
})
.req(function(req) {
req.query = {};
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA+ALT1';
})
.authenticate();
});
it('should error', function() {
expect(err.constructor.name).to.equal('FacebookTokenError');
expect(err.message).to.equal('Invalid verification code format.');
expect(err.type).to.equal('OAuthException');
expect(err.code).to.equal(100);
});
});
});
describe('using token endpoint that responds with standard error', function() {
var strategy = new FacebookStrategy({
clientID: 'ABC123',
clientSecret: 'secret'
},
function() {});
// inject a "mock" oauth2 instance
strategy._oauth2.getOAuthAccessToken = function(code, options, callback) {
return callback({ statusCode: 400, data: '{"error":"invalid_grant","error_description":"The provided value for the input parameter \'code\' is not valid."} '});
}
describe('handling response', function() {
var err;
before(function(done) {
chai.passport(strategy)
.error(function(e) {
err = e;
done();
})
.req(function(req) {
req.query = {};
req.query.code = 'SplxlOBeZQQYbYS6WxSbIA+ALT1';
})
.authenticate();
});
it('should error', function() {
expect(err.constructor.name).to.equal('TokenError');
expect(err.message).to.equal('The provided value for the input parameter \'code\' is not valid.');
expect(err.code).to.equal('invalid_grant');
});
});
});
});