From 1564c07bcd3dba7411d051e90a475adf938dd227 Mon Sep 17 00:00:00 2001 From: henk Date: Fri, 25 Jul 2014 15:14:13 +0200 Subject: [PATCH] - TresholdsGovernorTest adapted to use of keepCountsFor parameter - doc/Installation.md added keepCountsFor parameter to configurations --- doc/Installation.md | 18 ++++++++++ doc/changelog.txt | 3 ++ .../Tests/Service/TresholdsGovernorTest.php | 33 ++++++++++--------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/doc/Installation.md b/doc/Installation.md index 48ce55e..aa10241 100644 --- a/doc/Installation.md +++ b/doc/Installation.md @@ -202,6 +202,24 @@ Configurations This setting basically says how long this vacation may be and still be allowed to log in because of his user agent. +8. Garbage collection delay + + keepCountsFor + + For how long the requestcounts will be kept before being garbage-collected. Values like "4 days". + + If you use the AuthenticationGuardBundle and have enabled the user interface for user + administrators to look into why a user may have been blocked, this is how long they can + look back in time to see what happened. + + This value must allways be set longer then both blockUsernamesFor and blockIpAddressesFor, + otherwise counters will be deleted before blocking should end and no longer be counted in + for blocking. + + Currently the AuthenticationGuardBundle's user interface shows no information about active releases, but for + future extension this value also acts as a minimum for how long releases will be kept before being + garbage collected, but if allowReleasedUserOnAddressFor (or allowReleasedUserByCookieFor) + is set to a longer duration, the releases will be kept longer (according to the longest one). Notes diff --git a/doc/changelog.txt b/doc/changelog.txt index 43c8898..3db8c0c 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -105,5 +105,8 @@ comitted, pushed - DbalGateway::getReleasesIdWhereDateAndUsernameAndIpAddressAndCookie bug fixed: only first character was returned comitted and pushed --------------------- +- TresholdsGovernorTest adapted to use of keepCountsFor parameter +- doc/Installation.md added keepCountsFor parameter to configurations +------------------- (blocked columns and statistics need tests and documentation, statistics UI need refactoring from UserBundle) diff --git a/src/Metaclass/TresholdsGovernor/Tests/Service/TresholdsGovernorTest.php b/src/Metaclass/TresholdsGovernor/Tests/Service/TresholdsGovernorTest.php index 49ddce7..db689ec 100644 --- a/src/Metaclass/TresholdsGovernor/Tests/Service/TresholdsGovernorTest.php +++ b/src/Metaclass/TresholdsGovernor/Tests/Service/TresholdsGovernorTest.php @@ -18,12 +18,10 @@ class TresholdsGovernorTest extends \PHPUnit_Framework_TestCase function setup() { - $this->governor = new TresholdsGovernor(array()); + $this->governor = new TresholdsGovernor(array()); $this->governor->dtString = '1980-07-01 00:00:00'; $this->governor->counterDurationInSeconds = 300; //5 minutes - $this->governor->blockUsernamesFor = '30 days'; - $this->governor->blockIpAddressesFor = '30 days'; //not very realistic, but should still work - $this->governor->allowReleasedUserOnAddressFor = '30 days'; + $this->governor->allowReleasedUserOnAddressFor = '30 days'; $this->governor->allowReleasedUserByCookieFor = '10 days'; } @@ -39,25 +37,28 @@ function testPackData() { $this->governor->requestCountsManager = new RdbManager(new MockGateway()); $this->governor->releasesManager = new RdbManager(new MockGateway()); - $this->governor->blockUsernamesFor = '1 days'; - $this->governor->blockIpAddressesFor = '3 days'; + $this->governor->keepCountsFor = '3 days'; + $this->governor->blockUsernamesFor = '4 days'; + $this->governor->blockIpAddressesFor = '5 days'; // $this->governor->allowReleasedUserOnAddressFor = '30 days'; // $this->governor->allowReleasedUserByCookieFor = '10 days'; - $this->governor->packData(); $this->assertNull($this->governor->requestCountsManager->gateway->deleteReleasesLimit, "releasesLimit on requestCountsGateway"); $this->assertNull($this->governor->releasesManager->gateway->deleteCountsLimit, "deleteCountsLimit on releasesGateway"); - //3 days befor 1980-07-01 00:00:00 + + $this->governor->packData(); + //3 days before 1980-07-01 00:00:00 $this->assertEquals(new \DateTime('1980-06-28 00:00:00'), $this->governor->requestCountsManager->gateway->deleteCountsLimit, "deleteCountsLimit on requestCountsGateway"); //30 days before 1980-07-01 00:00:00 $this->assertEquals(new \DateTime('1980-06-01 00:00:00'), $this->governor->releasesManager->gateway->deleteReleasesLimit, "deleteReleasesLimit on releasesGateway"); - - $this->governor->blockUsernamesFor = '5 days'; + + $this->governor->keepCountsFor = '5 days'; + $this->governor->blockUsernamesFor = '4 days'; $this->governor->blockIpAddressesFor = '3 days'; $this->governor->allowReleasedUserOnAddressFor = '3 days'; $this->governor->allowReleasedUserByCookieFor = '10 days'; $this->governor->packData(); - //5 days befor 1980-07-01 00:00:00 + //5 days before 1980-07-01 00:00:00 $this->assertEquals(new \DateTime('1980-06-26 00:00:00'), $this->governor->requestCountsManager->gateway->deleteCountsLimit, "deleteCountsLimit on requestCountsGateway"); //10 days before 1980-07-01 00:00:00 $this->assertEquals(new \DateTime('1980-06-21 00:00:00'), $this->governor->releasesManager->gateway->deleteReleasesLimit, "deleteReleasesLimit on releasesGateway"); @@ -65,20 +66,20 @@ function testPackData() $this->governor->allowReleasedUserOnAddressFor = ''; $this->governor->allowReleasedUserByCookieFor = '11 days'; $this->governor->packData(); - //10 days before 1980-07-01 00:00:00 + //11 days before 1980-07-01 00:00:00 $this->assertEquals(new \DateTime('1980-06-20 00:00:00'), $this->governor->releasesManager->gateway->deleteReleasesLimit, "deleteReleasesLimit on releasesGateway"); $this->governor->allowReleasedUserOnAddressFor = '2 days'; $this->governor->allowReleasedUserByCookieFor = ''; $this->governor->packData(); - //2 days before 1980-07-01 00:00:00 - $this->assertEquals(new \DateTime('1980-06-29 00:00:00'), $this->governor->releasesManager->gateway->deleteReleasesLimit, "deleteReleasesLimit on releasesGateway"); + //5 days before 1980-07-01 00:00:00 (becvause of keepCountsFor) + $this->assertEquals(new \DateTime('1980-06-26 00:00:00'), $this->governor->releasesManager->gateway->deleteReleasesLimit, "deleteReleasesLimit on releasesGateway"); $this->governor->allowReleasedUserOnAddressFor = ''; $this->governor->allowReleasedUserByCookieFor = ''; $this->governor->packData(); - //1980-07-01 00:00:00 - $this->assertEquals(new \DateTime('1980-07-01 00:00:00'), $this->governor->releasesManager->gateway->deleteReleasesLimit, "deleteReleasesLimit on releasesGateway"); + //5 days before 1980-07-01 00:00:00 (becvause of keepCountsFor) + $this->assertEquals(new \DateTime('1980-06-26 00:00:00'), $this->governor->releasesManager->gateway->deleteReleasesLimit, "deleteReleasesLimit on releasesGateway"); } function assertNoException($value, $message = '')