Skip to content

Added exception for Twitter and OAuth missing options #3676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions spec/OAuth1.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
});
16 changes: 15 additions & 1 deletion spec/TwitterAuth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -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();
}
});
});
4 changes: 4 additions & 0 deletions src/Adapters/Auth/OAuth1Client.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Adapters/Auth/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down