Improve PR quality

This commit is contained in:
Matej Bačo committed 2026-01-05 22:20:20 +01:00
1 parent f9ed0685c9
commit b51d34f8da
5 files changed
+24 -27

No files matched your search

@@ -260,10 +260,6 @@ class TablesDB extends TimeLimit
*/
protected function set(string $key, int $timestamp, int $value): void
{
if (0 == $this->limit) { // No limit no point for counting
return;
}
$timestamp = $this->toDateTime($timestamp);
$response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
@@ -225,9 +225,6 @@ class Database extends TimeLimit
*/
protected function set(string $key, int $timestamp, int $value): void
{
if (0 == $this->limit) { // No limit no point for counting
return;
}
$timestamp = $this->toDateTime($timestamp);
Authorization::skip(function () use ($timestamp, $key, $value) {
-3
View File
@@ -87,9 +87,6 @@ class Redis extends TimeLimit
*/
protected function set(string $key, int $timestamp, int $value): void
{
if (0 == $this->limit) { // No limit no point for counting
return;
}
$key = self::NAMESPACE . '__' . $key . '__' . $timestamp;
$this->redis->multi()
@@ -89,9 +89,6 @@ class RedisCluster extends TimeLimit
*/
protected function set(string $key, int $timestamp, int $value): void
{
if (0 == $this->limit) { // No limit no point for counting
return;
}
$key = self::NAMESPACE . '__' . $key . '__' . $timestamp;
+24 -14
View File
@@ -102,27 +102,37 @@ abstract class Base extends TestCase
*/
public function testReset(): void
{
$adapter = $this->getAdapter('reset-test-{{ip}}', 5, 1);
$adapter->setParam('{{ip}}', '192.168.1.1');
$abuse = new Abuse($adapter);
// Make 3 checks
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
// Reset the count
$abuse->reset();
// Should be able to make 5 checks again
$adapter = $this->getAdapter('reset-test-{{ip}}', 5, 1);
$adapter = $this->getAdapter('reset-test-{{ip}}', 5, 600);
$adapter->setParam('{{ip}}', '192.168.1.1');
$abuse = new Abuse($adapter);
// 5 OK, 6th has limit
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), true);
// Reset the count
$abuse->reset();
// Should be 5 more OK, then 6th limit
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), false);
$this->assertSame($abuse->check(), true);
// TO be sure, lets do bunch of requests with resets
// All should pass successfully
$adapter = $this->getAdapter('reset-test-{{ip}}', 2, 600);
$adapter->setParam('{{ip}}', '192.168.1.2');
$abuse = new Abuse($adapter);
for ($i = 0; $i < 15; $i++) {
$this->assertSame($abuse->check(), false);
$abuse->reset();
}
}
}