Skip to content

Commit

Permalink
- TresholdsGovernorTest adapted to use of keepCountsFor parameter
Browse files Browse the repository at this point in the history
- doc/Installation.md added keepCountsFor parameter to configurations
  • Loading branch information
metaclass-nl committed Jul 25, 2014
1 parent 8afbbaf commit 1564c07
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
18 changes: 18 additions & 0 deletions doc/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions doc/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand All @@ -39,46 +37,49 @@ 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");

$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 = '')
Expand Down

0 comments on commit 1564c07

Please sign in to comment.