Skip to content

Commit e01b417

Browse files
Benjamin Wilson Friedmanflovilmart
Benjamin Wilson Friedman
authored andcommitted
Added exception for Twitter and OAuth missing options (#3676)
* Added exception for Twitter and OAuth missing configuration information * Updated error codes to INTERNAL_SERVER_ERROR, code 1
1 parent a54f4d4 commit e01b417

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

spec/OAuth1.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,14 @@ describe('OAuth', function() {
133133
done();
134134
})
135135
});
136+
137+
it("Should fail with missing options", (done) => {
138+
var options = undefined;
139+
try {
140+
new OAuth(options);
141+
} catch (error) {
142+
jequal(error.message, 'No options passed to OAuth');
143+
done();
144+
}
145+
});
136146
});

spec/TwitterAuth.spec.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Twitter Auth', () => {
99
consumer_key: 'hello'
1010
}, {
1111
consumer_key: 'world'
12-
}]).consumer_key).toEqual('hello')
12+
}]).consumer_key).toEqual('hello');
1313

1414
// Multiple options, consumer_key not found
1515
expect(function(){
@@ -47,4 +47,18 @@ describe('Twitter Auth', () => {
4747
consumer_key: 'hello'
4848
}).consumer_key).toEqual('hello');
4949
});
50+
51+
it("Should fail with missing options", (done) => {
52+
try {
53+
twitter.validateAuthData({
54+
consumer_key: 'key',
55+
consumer_secret: 'secret',
56+
auth_token: 'token',
57+
auth_token_secret: 'secret'
58+
}, undefined);
59+
} catch (error) {
60+
jequal(error.message, 'Twitter auth configuration missing');
61+
done();
62+
}
63+
});
5064
});

src/Adapters/Auth/OAuth1Client.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
var https = require('https'),
22
crypto = require('crypto');
3+
var Parse = require('parse/node').Parse;
34

45
var OAuth = function(options) {
6+
if(!options) {
7+
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'No options passed to OAuth');
8+
}
59
this.consumer_key = options.consumer_key;
610
this.consumer_secret = options.consumer_secret;
711
this.auth_token = options.auth_token;

src/Adapters/Auth/twitter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ var logger = require('../../logger').default;
55

66
// Returns a promise that fulfills iff this user id is valid.
77
function validateAuthData(authData, options) {
8+
if(!options) {
9+
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Twitter auth configuration missing');
10+
}
811
options = handleMultipleConfigurations(authData, options);
912
var client = new OAuth(options);
1013
client.host = "api.twitter.com";

0 commit comments

Comments
 (0)