From e6c581ba49f8edfd585f46907388257b1d8861c3 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 28 Mar 2017 13:45:51 -0700 Subject: [PATCH 1/2] Added exception for Twitter and OAuth missing configuration information --- spec/OAuth1.spec.js | 10 ++++++++++ spec/TwitterAuth.spec.js | 16 +++++++++++++++- src/Adapters/Auth/OAuth1Client.js | 4 ++++ src/Adapters/Auth/twitter.js | 3 +++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/spec/OAuth1.spec.js b/spec/OAuth1.spec.js index 15e55d3bc7..5c64f7e368 100644 --- a/spec/OAuth1.spec.js +++ b/spec/OAuth1.spec.js @@ -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(); + } + }); }); diff --git a/spec/TwitterAuth.spec.js b/spec/TwitterAuth.spec.js index 8cec73e494..d98297f745 100644 --- a/spec/TwitterAuth.spec.js +++ b/spec/TwitterAuth.spec.js @@ -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(); + } + }); }); diff --git a/src/Adapters/Auth/OAuth1Client.js b/src/Adapters/Auth/OAuth1Client.js index 2fb2057308..4fbd50bc66 100644 --- a/src/Adapters/Auth/OAuth1Client.js +++ b/src/Adapters/Auth/OAuth1Client.js @@ -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.OBJECT_NOT_FOUND, 'No options passed to OAuth'); + } this.consumer_key = options.consumer_key; this.consumer_secret = options.consumer_secret; this.auth_token = options.auth_token; diff --git a/src/Adapters/Auth/twitter.js b/src/Adapters/Auth/twitter.js index 81f7f135c6..07c9e07537 100644 --- a/src/Adapters/Auth/twitter.js +++ b/src/Adapters/Auth/twitter.js @@ -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.OBJECT_NOT_FOUND, 'Twitter auth configuration missing'); + } options = handleMultipleConfigurations(authData, options); var client = new OAuth(options); client.host = "api.twitter.com"; From 5e39b91df744b96f4371064aee652136e56f0779 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 28 Mar 2017 14:39:04 -0700 Subject: [PATCH 2/2] Updated error codes to INTERNAL_SERVER_ERROR, code 1 --- src/Adapters/Auth/OAuth1Client.js | 2 +- src/Adapters/Auth/twitter.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapters/Auth/OAuth1Client.js b/src/Adapters/Auth/OAuth1Client.js index 4fbd50bc66..6776b51010 100644 --- a/src/Adapters/Auth/OAuth1Client.js +++ b/src/Adapters/Auth/OAuth1Client.js @@ -4,7 +4,7 @@ var Parse = require('parse/node').Parse; var OAuth = function(options) { if(!options) { - throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'No options passed to OAuth'); + 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; diff --git a/src/Adapters/Auth/twitter.js b/src/Adapters/Auth/twitter.js index 07c9e07537..ee8517819e 100644 --- a/src/Adapters/Auth/twitter.js +++ b/src/Adapters/Auth/twitter.js @@ -6,7 +6,7 @@ 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.OBJECT_NOT_FOUND, 'Twitter auth configuration missing'); + throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'Twitter auth configuration missing'); } options = handleMultipleConfigurations(authData, options); var client = new OAuth(options);