fix: tests

This commit is contained in:
Christy Jacob committed 2024-12-18 11:36:01 +05:30
1 parent 76fc3da33b
commit 2663547e42
8 files changed
+42 -12

No files matched your search

+9
View File
@@ -10,6 +10,15 @@ services:
ports:
- "9307:3306"
adminer:
image: adminer
container_name: abuse-adminer
restart: always
ports:
- 9506:8080
networks:
- abuse
redis:
image: redis:6.0-alpine
container_name: redis
+2 -2
View File
@@ -53,11 +53,11 @@ abstract class Base extends TestCase
public function testCleanup(): void
{
// Check that there is only one log
// Check that there are 3 logs
$logs = $this->abuse->getLogs(0, 10);
$this->assertEquals(3, \count($logs));
sleep(5);
sleep(2);
// Delete the log
$status = $this->abuse->cleanup($this->getCleanupDateTime());
@@ -1,6 +1,6 @@
<?php
namespace Abuse\Bench\Database;
namespace Abuse\Bench;
use PDO;
use Utopia\Abuse\Abuse;
@@ -13,7 +13,7 @@ use Utopia\Database\Database;
use Utopia\Exception;
use Utopia\Tests\Bench\Base;
class TimeLimitBench extends Base
class DatabaseBench extends Base
{
protected Database $db;
@@ -1,13 +1,13 @@
<?php
namespace Abuse\Bench\Redis;
namespace Abuse\Bench;
use Redis as Client;
use Utopia\Abuse\Abuse;
use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimit;
use Utopia\Tests\Bench\Base;
final class TimeLimitBench extends Base
final class RedisBench extends Base
{
protected Client $redis;
+24
View File
@@ -0,0 +1,24 @@
<?php
namespace Abuse\Bench;
use RedisCluster as Client;
use Utopia\Abuse\Abuse;
use Utopia\Abuse\Adapters\TimeLimit\RedisCluster as TimeLimit;
use Utopia\Abuse\Adapters\TimeLimit\RedisCluster;
use Utopia\Tests\Bench\Base;
final class RedisClusterBench extends Base
{
protected Client $redis;
/**
* @throws \Exception
*/
public function setUp(): void
{
$this->redis = new Client(null, ['redis-cluster-0:6379', 'redis-cluster-1:6379', 'redis-cluster-2:6379', 'redis-cluster-3:6379']);
$this->adapter = new RedisCluster('login-attempt-from-{{ip}}', 3, 60 * 5, $this->redis);
$this->abuse = new Abuse($this->adapter);
}
}
+1 -2
View File
@@ -45,7 +45,6 @@ class DatabaseTest extends Base
$adapter->setParam('{{ip}}', '127.0.0.1');
$this->abuse = new Abuse($adapter);
$this->abuse->cleanup($this->getCleanupDateTime());
}
public function getAdapter(string $key, int $limit, int $seconds): Adapter
@@ -55,6 +54,6 @@ class DatabaseTest extends Base
public function getCleanupDateTime(): string
{
return DateTime::addSeconds(new \DateTime(), -1);
return DateTime::format(new \DateTime());
}
}
+1 -2
View File
@@ -23,7 +23,6 @@ class RedisClusterTest extends Base
$adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 1, $this->redis);
$adapter->setParam('{{ip}}', '127.0.0.1');
$this->abuse = new Abuse($adapter);
$this->abuse->cleanup($this->getCleanupDateTime());
}
public function getAdapter(string $key, int $limit, int $seconds): Adapter
@@ -33,7 +32,7 @@ class RedisClusterTest extends Base
public function getCleanupDateTime(): string
{
$interval = DateInterval::createFromDateString(1 . ' seconds');
$interval = DateInterval::createFromDateString('now');
return strval((new \DateTime())->sub($interval)->getTimestamp());
}
}
+1 -2
View File
@@ -24,7 +24,6 @@ class RedisTest extends Base
$adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 1, $this->redis);
$adapter->setParam('{{ip}}', '127.0.0.1');
$this->abuse = new Abuse($adapter);
$this->abuse->cleanup($this->getCleanupDateTime());
}
public function getAdapter(string $key, int $limit, int $seconds): Adapter
@@ -34,7 +33,7 @@ class RedisTest extends Base
public function getCleanupDateTime(): string
{
$interval = DateInterval::createFromDateString(1 . ' seconds');
$interval = DateInterval::createFromDateString('now');
return strval((new \DateTime())->sub($interval)->getTimestamp());
}
}