mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-03-22 13:10:41 +08:00
small unit test refactoring, comment wording
This commit is contained in:
parent
91041d8c59
commit
190a35a53b
|
@ -161,7 +161,7 @@ class TrafficLimiter extends AbstractPersistence
|
|||
}
|
||||
}
|
||||
|
||||
// this hash is used as an array key, hence a shorter algo is used
|
||||
// used as array key, which are limited in length, hence using algo with shorter range
|
||||
$hash = self::getHash('sha256');
|
||||
$now = time();
|
||||
$tl = (int) self::$_store->getValue('traffic_limiter', $hash);
|
||||
|
|
|
@ -45,10 +45,14 @@ class TrafficLimiterTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertTrue(TrafficLimiter::canPass(), 'fourth request has different ip and may pass');
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$this->assertFalse(TrafficLimiter::canPass(), 'fifth request is to fast, may not pass');
|
||||
}
|
||||
|
||||
// exempted IPs configuration
|
||||
public function testTrafficLimitExempted()
|
||||
{
|
||||
TrafficLimiter::setExempted('1.2.3.4,10.10.10.0/24,2001:1620:2057::/48');
|
||||
$this->assertFalse(TrafficLimiter::canPass(), 'still too fast and not exempted');
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
$this->assertTrue(TrafficLimiter::canPass(), 'first request may pass');
|
||||
$this->assertFalse(TrafficLimiter::canPass(), 'not exempted');
|
||||
$_SERVER['REMOTE_ADDR'] = '10.10.10.10';
|
||||
$this->assertTrue(TrafficLimiter::canPass(), 'IPv4 in exempted range');
|
||||
$this->assertTrue(TrafficLimiter::canPass(), 'request is to fast, but IPv4 in exempted range');
|
||||
|
@ -56,6 +60,7 @@ class TrafficLimiterTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertTrue(TrafficLimiter::canPass(), 'IPv6 in exempted range');
|
||||
$this->assertTrue(TrafficLimiter::canPass(), 'request is to fast, but IPv6 in exempted range');
|
||||
TrafficLimiter::setExempted('127.*,foobar');
|
||||
$this->assertTrue(TrafficLimiter::canPass(), 'first cached request may pass');
|
||||
$this->assertFalse(TrafficLimiter::canPass(), 'request is to fast, invalid range');
|
||||
$_SERVER['REMOTE_ADDR'] = 'foobar';
|
||||
$this->assertTrue(TrafficLimiter::canPass(), 'non-IP address');
|
||||
|
|
Loading…
Reference in New Issue
Block a user