forked from jaredhanson/passport-facebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.profile.error.test.js
105 lines (85 loc) · 3.17 KB
/
strategy.profile.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var FacebookStrategy = require('../lib/strategy');
describe('Strategy#userProfile', function() {
describe('handling API errors', function() {
var strategy = new FacebookStrategy({
clientID: 'ABC123',
clientSecret: 'secret'
},
function() {});
// mock
strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/me') { return callback(new Error('wrong url argument')); }
if (accessToken != 'token') { return callback(new Error('wrong token argument')); }
var body = '{"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190}}';
callback({ statusCode: 401, data: body });
}
var err, profile;
before(function(done) {
strategy.userProfile('token', function(e, p) {
err = e;
profile = p;
done();
});
});
it('should error', function() {
expect(err).to.be.an.instanceOf(Error);
expect(err.constructor.name).to.equal('FacebookGraphAPIError');
expect(err.message).to.equal('Invalid OAuth access token.');
expect(err.type).to.equal('OAuthException');
expect(err.code).to.equal(190);
});
});
describe('handling internal OAuth errors', function() {
var strategy = new FacebookStrategy({
clientID: 'ABC123',
clientSecret: 'secret'
},
function() {});
// mock
strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/me') { return callback(new Error('wrong url argument')); }
if (accessToken != 'token') { return callback(new Error('wrong token argument')); }
var body = '{"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190}}';
callback({ statusCode: 401, x__data: body });
}
var err, profile;
before(function(done) {
strategy.userProfile('token', function(e, p) {
err = e;
profile = p;
done();
});
});
it('should error', function() {
expect(err).to.be.an.instanceOf(Error);
expect(err.constructor.name).to.equal('InternalOAuthError');
expect(err.message).to.equal('Failed to fetch user profile');
});
});
describe('handling malformed responses', function() {
var strategy = new FacebookStrategy({
clientID: 'ABC123',
clientSecret: 'secret'
},
function() {});
// mock
strategy._oauth2.get = function(url, accessToken, callback) {
if (url != 'https://graph.facebook.com/me') { return callback(new Error('wrong url argument')); }
if (accessToken != 'token') { return callback(new Error('wrong token argument')); }
var body = 'Hello, world.';
callback(null, body, undefined);
}
var err, profile;
before(function(done) {
strategy.userProfile('token', function(e, p) {
err = e;
profile = p;
done();
});
});
it('should error', function() {
expect(err).to.be.an.instanceOf(Error);
expect(err.message).to.equal('Failed to parse user profile');
});
});
});