diff --git a/lib/options.js b/lib/options.js index be62d4a..1c8db3a 100644 --- a/lib/options.js +++ b/lib/options.js @@ -21,6 +21,8 @@ exports.canonical = function(opts) { assert.ok(match, 'Invalid rate: ' + opts.rate); canon.limit = parseInt(match[1], 10); canon.window = moment.duration(1, match[2]) / 1000; + assert.notEqual(canon.limit, 0, 'Invalid rate limit: ' + opts.rate); + assert.notEqual(canon.window, 0, 'Invalid rate window: ' + opts.rate); } // Limit + window diff --git a/test/options.spec.js b/test/options.spec.js index 40aa193..7ad9639 100644 --- a/test/options.spec.js +++ b/test/options.spec.js @@ -95,14 +95,34 @@ describe('Options', function() { assertRate('5000/d', 5000, 86400); }); - it('has to be a valid rate', function() { + it('has to be a valid format', function() { (function() { var opts = options.canonical({ redis: {}, key: 'ip', - rate: '50 things' + rate: 'foobar' }); - }).should.throw('Invalid rate: 50 things'); + }).should.throw('Invalid rate: foobar'); + }); + + it('has to be a valid limit', function() { + (function() { + var opts = options.canonical({ + redis: {}, + key: 'ip', + rate: '0/hour' + }); + }).should.throw('Invalid rate limit: 0/hour'); + }); + + it('has to be a valid unit', function() { + (function() { + var opts = options.canonical({ + redis: {}, + key: 'ip', + rate: '50/century' + }); + }).should.throw('Invalid rate window: 50/century'); }); });