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
This commit is contained in:
committed by
Florent Vilmart
parent
a54f4d43fa
commit
e01b417d3f
@@ -133,4 +133,14 @@ describe('OAuth', function() {
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
it("Should fail with missing options", (done) => {
|
||||
var options = undefined;
|
||||
try {
|
||||
new OAuth(options);
|
||||
} catch (error) {
|
||||
jequal(error.message, 'No options passed to OAuth');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('Twitter Auth', () => {
|
||||
consumer_key: 'hello'
|
||||
}, {
|
||||
consumer_key: 'world'
|
||||
}]).consumer_key).toEqual('hello')
|
||||
}]).consumer_key).toEqual('hello');
|
||||
|
||||
// Multiple options, consumer_key not found
|
||||
expect(function(){
|
||||
@@ -47,4 +47,18 @@ describe('Twitter Auth', () => {
|
||||
consumer_key: 'hello'
|
||||
}).consumer_key).toEqual('hello');
|
||||
});
|
||||
|
||||
it("Should fail with missing options", (done) => {
|
||||
try {
|
||||
twitter.validateAuthData({
|
||||
consumer_key: 'key',
|
||||
consumer_secret: 'secret',
|
||||
auth_token: 'token',
|
||||
auth_token_secret: 'secret'
|
||||
}, undefined);
|
||||
} catch (error) {
|
||||
jequal(error.message, 'Twitter auth configuration missing');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
var https = require('https'),
|
||||
crypto = require('crypto');
|
||||
var Parse = require('parse/node').Parse;
|
||||
|
||||
var OAuth = function(options) {
|
||||
if(!options) {
|
||||
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'No options passed to OAuth');
|
||||
}
|
||||
this.consumer_key = options.consumer_key;
|
||||
this.consumer_secret = options.consumer_secret;
|
||||
this.auth_token = options.auth_token;
|
||||
|
||||
@@ -5,6 +5,9 @@ var logger = require('../../logger').default;
|
||||
|
||||
// Returns a promise that fulfills iff this user id is valid.
|
||||
function validateAuthData(authData, options) {
|
||||
if(!options) {
|
||||
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Twitter auth configuration missing');
|
||||
}
|
||||
options = handleMultipleConfigurations(authData, options);
|
||||
var client = new OAuth(options);
|
||||
client.host = "api.twitter.com";
|
||||
|
||||
Reference in New Issue
Block a user