Skip to content

Commit

Permalink
test(*): Add some delay to make the test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
julienloizelet committed Oct 18, 2024
1 parent 6ba2a18 commit 0b4c021
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 0 additions & 7 deletions tests/Integration/AbstractBouncerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1252,22 +1252,15 @@ public function testCanVerifyIpInStreamMode(): void
$bouncer->getRemediationForIp(TestHelpers::NEWLY_BAD_IP),
'Preload the bypass remediation to prepare the next tests'
);

// Add and remove decision
$this->logger->info('DEBUG', ['message' => 'Start SecondState test']);
$this->watcherClient->setSecondState();

// Pull updates
$bouncer->refreshBlocklistCache();

$this->logger->info('DEBUG', ['message' => 'Will check 3.4.5.6']);
$this->assertEquals(
'ban',
$bouncer->getRemediationForIp(TestHelpers::NEWLY_BAD_IP),
'The new decision should now be added, so the previously clean IP should now be bad'
);

$this->logger->info('DEBUG', ['message' => 'Will check 1.2.3.4']);
$this->assertEquals(
'bypass',
$bouncer->getRemediationForIp(TestHelpers::BAD_IP),
Expand Down
4 changes: 4 additions & 0 deletions tests/Integration/WatcherClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,20 @@ private function manageRequest(
public function setInitialState(): void
{
$this->deleteAllDecisions();
sleep(1);
$now = new \DateTime();
$this->addDecision($now, '12h', '+12 hours', TestHelpers::BAD_IP, 'captcha');
$this->addDecision($now, '24h', self::HOURS24, TestHelpers::BAD_IP . '/' . TestHelpers::IP_RANGE, 'ban');
$this->addDecision($now, '24h', '+24 hours', TestHelpers::JAPAN, 'captcha', Constants::SCOPE_COUNTRY);
sleep(1);
}

/** Set the second watcher state */
public function setSecondState(): void
{
$this->logger->info('', ['message' => 'Set "second" state']);
$this->deleteAllDecisions();
sleep(1);
$now = new \DateTime();
$this->addDecision($now, '36h', '+36 hours', TestHelpers::NEWLY_BAD_IP, 'ban');
$this->addDecision(
Expand All @@ -89,6 +92,7 @@ public function setSecondState(): void
$this->addDecision($now, '24h', self::HOURS24, TestHelpers::JAPAN, 'captcha', Constants::SCOPE_COUNTRY);
$this->addDecision($now, '24h', self::HOURS24, TestHelpers::IP_JAPAN, 'ban');
$this->addDecision($now, '24h', self::HOURS24, TestHelpers::IP_FRANCE, 'ban');
sleep(1);
}

public function setSimpleDecision(string $type = 'ban'): void
Expand Down

0 comments on commit 0b4c021

Please sign in to comment.