Skip to content

Commit

Permalink
Invalidate leaky bucket settings with tokenlimit == threshold (caus…
Browse files Browse the repository at this point in the history
…es division by 0)
  • Loading branch information
Feijs committed Sep 5, 2016
1 parent d045a36 commit 5acc059
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/Throttle/Settings/LeakyBucketSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public function merge(ThrottleSettingsInterface $settings)
*/
public function isValid()
{
return null !== $this->tokenLimit && null !== $this->timeLimit && 0 !== $this->timeLimit;
return
null !== $this->tokenLimit &&
null !== $this->timeLimit &&
0 !== $this->timeLimit &&
$this->tokenLimit !== $this->threshold;
}

/**
Expand Down
15 changes: 8 additions & 7 deletions tests/Throttle/Settings/LeakyBucketSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function testInvalidMerge()
/**
* @dataProvider inputProvider
*/
public function testIsValid($tokenLimit, $timeLimit, $result)
public function testIsValid($tokenLimit, $timeLimit, $threshold, $result)
{
self::assertEquals($result, (new LeakyBucketSettings($tokenLimit, $timeLimit))->isValid());
self::assertEquals($result, (new LeakyBucketSettings($tokenLimit, $timeLimit, $threshold))->isValid());
}

/**
Expand All @@ -50,11 +50,12 @@ public function testIsValid($tokenLimit, $timeLimit, $result)
public function inputProvider()
{
return [
[null, null, false],
[null, 600, false],
[3, null, false],
[3, 0, false],
[3, 600, true],
[null, null, null, false],
[null, 600, null, false],
[3, null, null, false],
[3, 0, null, false],
[3, 600, 3, false],
[30, 600, 15, true],
];
}
}

0 comments on commit 5acc059

Please sign in to comment.