From 0b2c4d2dbfe962dc23a05b6d36b9354c36bb6b45 Mon Sep 17 00:00:00 2001 From: Hugh Willson Date: Wed, 26 Oct 2016 09:29:11 -0400 Subject: [PATCH 1/3] Preventing undefined callback from being passed into the forgotPassword Method, which in turn prevents unnecessary audit-argument-checks warnings. --- packages/accounts-password/password_client.js | 6 ++- packages/accounts-password/password_tests.js | 39 ++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/packages/accounts-password/password_client.js b/packages/accounts-password/password_client.js index bc1478507f..1a5bcd468c 100644 --- a/packages/accounts-password/password_client.js +++ b/packages/accounts-password/password_client.js @@ -220,7 +220,11 @@ Accounts.forgotPassword = function(options, callback) { if (!options.email) { return reportError(new Meteor.Error(400, "Must pass options.email"), callback); } - Accounts.connection.call("forgotPassword", options, callback); + if (callback) { + Accounts.connection.call("forgotPassword", options, callback); + } else { + Accounts.connection.call("forgotPassword", options); + } }; // Resets a password based on a token originally created by diff --git a/packages/accounts-password/password_tests.js b/packages/accounts-password/password_tests.js index 1d9467d6b5..ceb980c920 100644 --- a/packages/accounts-password/password_tests.js +++ b/packages/accounts-password/password_tests.js @@ -2,7 +2,7 @@ Accounts._noConnectionCloseDelayForTest = true; if (Meteor.isServer) { Accounts.removeDefaultRateLimit(); - + Meteor.methods({ getResetToken: function () { var token = Meteor.users.findOne(this.userId).services.password.reset; @@ -557,8 +557,8 @@ if (Meteor.isClient) (function () { }, 10 * 1000, 100); } ]); - - + + testAsyncMulti("passwords - forgotPassword client return error when empty email", [ function (test, expect) { // setup @@ -578,7 +578,36 @@ if (Meteor.isClient) (function () { }, /Must pass options\.email/); }, ]); - + + Tinytest.add( + 'passwords - forgotPassword only passes callback value to forgotPassword ' + + 'Method if callback is defined', + function (test) { + let methodCallArgumentCount = 0; + const originalMethodCall = Accounts.connection.call; + const stubMethodCall = (...args) => { + methodCallArgumentCount = args.length; + } + Accounts.connection.call = stubMethodCall; + + Accounts.forgotPassword({ email: 'test@meteor.com' }); + test.equal( + methodCallArgumentCount, + 2, + 'Method call should have 2 arguments since no callback is passed in' + ); + + Accounts.forgotPassword({ email: 'test@meteor.com' }, () => {}); + test.equal( + methodCallArgumentCount, + 3, + 'Method call should have 3 arguments since a callback is passed in' + ); + + Accounts.connection.call = originalMethodCall; + } + ); + testAsyncMulti("passwords - verifyEmail client return error when empty token", [ function (test, expect) { // setup @@ -598,7 +627,7 @@ if (Meteor.isClient) (function () { }, /Need to pass token/); }, ]); - + testAsyncMulti("passwords - resetPassword errors", [ function (test, expect) { // setup From 2afc4bfd535ae197663354f391b9d574a0701ecd Mon Sep 17 00:00:00 2001 From: Hugh Willson Date: Wed, 26 Oct 2016 11:59:44 -0400 Subject: [PATCH 2/3] Minor formatting adjustment to force CI rebuild. --- packages/accounts-password/password_client.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/accounts-password/password_client.js b/packages/accounts-password/password_client.js index 1a5bcd468c..28e2787c4f 100644 --- a/packages/accounts-password/password_client.js +++ b/packages/accounts-password/password_client.js @@ -220,6 +220,7 @@ Accounts.forgotPassword = function(options, callback) { if (!options.email) { return reportError(new Meteor.Error(400, "Must pass options.email"), callback); } + if (callback) { Accounts.connection.call("forgotPassword", options, callback); } else { From 73541c38387f8888cf37c1eb1b071c37fb057097 Mon Sep 17 00:00:00 2001 From: Hugh Willson Date: Tue, 1 Nov 2016 10:04:50 -0400 Subject: [PATCH 3/3] Updated test description to include the issue # being resolved (#5676). --- packages/accounts-password/password_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/accounts-password/password_tests.js b/packages/accounts-password/password_tests.js index ceb980c920..3a3e564f21 100644 --- a/packages/accounts-password/password_tests.js +++ b/packages/accounts-password/password_tests.js @@ -581,7 +581,7 @@ if (Meteor.isClient) (function () { Tinytest.add( 'passwords - forgotPassword only passes callback value to forgotPassword ' - + 'Method if callback is defined', + + 'Method if callback is defined (to address issue #5676)', function (test) { let methodCallArgumentCount = 0; const originalMethodCall = Accounts.connection.call;