Fixed getLastRateLimitEvent mixup and updated DDPRateLimiter tests to reflect that.

This commit is contained in:
Anubhav Jain
2015-07-21 16:50:48 -07:00
parent ba77b0f6cc
commit ce84258bfd
3 changed files with 15 additions and 40 deletions

View File

@@ -6,7 +6,18 @@ Meteor.methods({
var connection = this.connection;
connection.lastRateLimitEvent = connection.lastRateLimitEvent || {};
connection.lastMethodName = connection.lastMethodName || '';
// XXX In Javascript v8 engine, we are currently guaranteed the ordering of
// the keys in objects as they are listed. This may change in future
// iterations of v8 for performance reasons and will potentially break this
// test.
this.ruleId = DDPRateLimiter.addRule({
name: function (name) {
connection.lastMethodName = name;
if (name !== 'getLastRateLimitEvent') {
connection.lastRateLimitEvent.name = name;
}
return name !== "a-method-that-is-not-rate-limited";
},
userId: function (userId) {
connection.lastRateLimitEvent.userId = userId;
return true;
@@ -19,13 +30,6 @@ Meteor.methods({
}
return true;
},
name: function (name) {
if (name !== 'getLastRateLimitEvent') {
connection.lastRateLimitEvent.name = name;
}
connection.lastMethodName = name;
return name !== "a-method-that-is-not-rate-limited";
},
clientAddress: function (clientAddress) {
connection.lastRateLimitEvent.clientAddress = clientAddress
return true;
@@ -54,36 +58,6 @@ Meteor.methods({
},
'a-method-that-is-not-rate-limited': function () {
return "not-rate-limited";
},
addSubscriptionRuleToDDPRateLimiter: function () {
var connection = this.connection;
connection.lastRateLimitEvent = connection.lastRateLimitEvent || {};
connection.lastMethodName = connection.lastMethodName || '';
this.ruleId = DDPRateLimiter.addRule({
userId: function (userId) {
connection.lastRateLimitEvent.userId = userId;
return true;
},
name: function (name) {
connection.lastMethodName = name;
// Special check to return proper name since 'getLastRateLimitEvent'
// is another method call
if (name !== 'getLastRateLimitEvent')
connection.lastRateLimitEvent.name = name;
return true;
},
type: function (type) {
if (connection.lastMethodName !== 'getLastRateLimitEvent')
connection.lastRateLimitEvent.type = type;
return type === 'subscription';
},
clientAddress: function (clientAddress) {
connection.lastRateLimitEvent.clientAddress = clientAddress;
return true;
},
connectionId: this.connection.id
}, RATE_LIMIT_NUM_CALLS, RATE_LIMIT_INTERVAL_TIME_MS);
return this.ruleId;
}
});

View File

@@ -74,7 +74,7 @@ testAsyncMulti("ddp rate limiter - matchers get passed correct arguments", [
testAsyncMulti("ddp rate limiter - we can return with type 'subscription'", [
function (test, expect) {
var self = this;
Meteor.call("addSubscriptionRuleToDDPRateLimiter", expect(
Meteor.call("addRuleToDDPRateLimiter", expect(
function(error, result) {
self.ruleId = result;
}));
@@ -101,7 +101,7 @@ testAsyncMulti("ddp rate limiter - we can return with type 'subscription'", [
testAsyncMulti("ddp rate limiter - rate limits to subscriptions", [
function (test, expect) {
var self = this;
Meteor.call("addSubscriptionRuleToDDPRateLimiter", expect(
Meteor.call("addRuleToDDPRateLimiter", expect(
function(error, result) {
self.ruleId = result;
})

View File

@@ -20,10 +20,11 @@ Package.onUse(function(api) {
Package.onTest(function(api) {
api.use('underscore');
api.use('ddp-rate-limiter');
api.use(['accounts-password', 'tinytest', 'test-helpers', 'tracker',
'accounts-base', 'random', 'email', 'underscore', 'check',
'ddp', 'ecmascript', 'es5-shim']);
api.use('ddp-rate-limiter');
api.addFiles('ddp-rate-limiter-tests-common.js');
api.addFiles('ddp-rate-limiter-test-service.js', 'server');
api.addFiles('ddp-rate-limiter-tests.js', 'client');