fix rate-limit.js module failing to block excessive requests

This commit is contained in:
cleverbeagle 2017-07-31 09:30:52 -05:00
parent 6bfe6a3947
commit 031f36759f
2 changed files with 5 additions and 11 deletions

View file

@ -1,4 +1,5 @@
/* eslint-disable consistent-return */ /* eslint-disable consistent-return */
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base'; import { Accounts } from 'meteor/accounts-base';
@ -6,6 +7,7 @@ let action;
const updatePassword = (userId, newPassword) => { const updatePassword = (userId, newPassword) => {
try { try {
throw new Meteor.Error('500', 'Testing failures.');
Accounts.setPassword(userId, newPassword, { logout: false }); Accounts.setPassword(userId, newPassword, { logout: false });
} catch (exception) { } catch (exception) {
action.reject(`[editProfile.updatePassword] ${exception}`); action.reject(`[editProfile.updatePassword] ${exception}`);
@ -31,13 +33,12 @@ const editProfile = ({ userId, profile }, promise) => {
updateUser(userId, profile); updateUser(userId, profile);
if (profile.password) updatePassword(userId, profile.password); if (profile.password) updatePassword(userId, profile.password);
action.resolve();
} catch (exception) { } catch (exception) {
action.reject(`[editProfile.handler] ${exception}`); action.reject(`[editProfile.handler] ${exception}`);
} }
}; };
export default options => export default options =>
new Promise((resolve, reject) => new Promise((resolve, reject) =>
editProfile(options, { resolve, reject })); editProfile(options, { resolve, reject }));

View file

@ -1,18 +1,11 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import { _ } from 'meteor/underscore';
const fetchMethodNames = methods => _.pluck(methods, 'name');
const assignLimits = ({ methods, limit, timeRange }) => {
const methodNames = fetchMethodNames(methods);
export default ({ methods, limit, timeRange }) => {
if (Meteor.isServer) { if (Meteor.isServer) {
DDPRateLimiter.addRule({ DDPRateLimiter.addRule({
name(name) { return _.contains(methodNames, name); }, name(name) { return methods.indexOf(name) > -1; },
connectionId() { return true; }, connectionId() { return true; },
}, limit, timeRange); }, limit, timeRange);
} }
}; };
export default function rateLimit(options) { return assignLimits(options); }