From 55b34b581c957fc98f912943d94dcdc7079f191e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 8 Mar 2024 11:27:58 +0000 Subject: [PATCH 01/48] Introduce auth instance --- composer.json | 2 +- composer.lock | 78 ++++++++++++++++++-------------- src/Abuse/Adapters/TimeLimit.php | 15 +++--- 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index 29d77f51d5..dc3e6c0cb1 100755 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": ">=8.0", "ext-pdo": "*", "ext-curl": "*", - "utopia-php/database": "0.49.*" + "utopia-php/database": "dev-feat-framework-v2 as 0.49.99" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index 4179b93ab4..9c8ec72f89 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f78eeda391d225f378154fe10e288486", + "content-hash": "1b7e75223ec175933d427857707d8c4c", "packages": [ { "name": "jean85/pretty-package-versions", - "version": "2.0.5", + "version": "2.0.6", "source": { "type": "git", "url": "https://github.com/Jean85/pretty-package-versions.git", - "reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af" + "reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/ae547e455a3d8babd07b96966b17d7fd21d9c6af", - "reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af", + "url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/f9fdd29ad8e6d024f52678b570e5593759b550b4", + "reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4", "shasum": "" }, "require": { @@ -25,9 +25,9 @@ "php": "^7.1|^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.17", + "friendsofphp/php-cs-fixer": "^3.2", "jean85/composer-provided-replaced-stub-package": "^1.0", - "phpstan/phpstan": "^0.12.66", + "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^7.5|^8.5|^9.4", "vimeo/psalm": "^4.3" }, @@ -61,9 +61,9 @@ ], "support": { "issues": "https://github.com/Jean85/pretty-package-versions/issues", - "source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.5" + "source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.6" }, - "time": "2021-10-08T21:21:46+00:00" + "time": "2024-03-08T09:58:59+00:00" }, { "name": "mongodb/mongodb", @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "0.49.1", + "version": "dev-feat-framework-v2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "4199fe8f00f4e181c7782c4a6862845d591c1f03" + "reference": "bdd9140e40c77faadb0cf2f5050b466c34eef673" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/4199fe8f00f4e181c7782c4a6862845d591c1f03", - "reference": "4199fe8f00f4e181c7782c4a6862845d591c1f03", + "url": "https://api.github.com/repos/utopia-php/database/zipball/bdd9140e40c77faadb0cf2f5050b466c34eef673", + "reference": "bdd9140e40c77faadb0cf2f5050b466c34eef673", "shasum": "" }, "require": { @@ -284,7 +284,7 @@ "php": ">=8.0", "utopia-php/cache": "0.9.*", "utopia-php/fetch": "0.1.*", - "utopia-php/framework": "0.33.*", + "utopia-php/framework": "0.34.*", "utopia-php/mongo": "0.3.*" }, "require-dev": { @@ -295,7 +295,7 @@ "phpunit/phpunit": "^9.4", "rregeer/phpunit-coverage-check": "^0.3.1", "swoole/ide-helper": "4.8.0", - "utopia-php/cli": "^0.14.0" + "utopia-php/cli": "0.17.*" }, "type": "library", "autoload": { @@ -317,9 +317,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.49.1" + "source": "https://github.com/utopia-php/database/tree/feat-framework-v2" }, - "time": "2024-03-06T11:35:53+00:00" + "time": "2024-03-07T16:55:44+00:00" }, { "name": "utopia-php/fetch", @@ -362,48 +362,51 @@ }, { "name": "utopia-php/framework", - "version": "0.33.2", + "version": "0.34.2", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "b1423ca3e3b61c6c4c2e619d2cb80672809a19f3" + "reference": "fd126c02b78cc80678c9638f7b335dfb4a841b78" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/b1423ca3e3b61c6c4c2e619d2cb80672809a19f3", - "reference": "b1423ca3e3b61c6c4c2e619d2cb80672809a19f3", + "url": "https://api.github.com/repos/utopia-php/http/zipball/fd126c02b78cc80678c9638f7b335dfb4a841b78", + "reference": "fd126c02b78cc80678c9638f7b335dfb4a841b78", "shasum": "" }, "require": { + "ext-swoole": "*", "php": ">=8.0" }, "require-dev": { "laravel/pint": "^1.2", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25" + "phpunit/phpunit": "^9.5.25", + "swoole/ide-helper": "4.8.3" }, "type": "library", "autoload": { "psr-4": { - "Utopia\\": "src/" + "Utopia\\Http\\": "src/Http" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "A simple, light and advanced PHP framework", + "description": "A simple, light and advanced PHP HTTP framework", "keywords": [ "framework", + "http", "php", "upf" ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.2" + "source": "https://github.com/utopia-php/http/tree/0.34.2" }, - "time": "2024-01-31T10:35:59+00:00" + "time": "2024-02-20T11:36:56+00:00" }, { "name": "utopia-php/mongo", @@ -840,16 +843,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.59", + "version": "1.10.60", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e607609388d3a6d418a50a49f7940e8086798281" + "reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e607609388d3a6d418a50a49f7940e8086798281", - "reference": "e607609388d3a6d418a50a49f7940e8086798281", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/95dcea7d6c628a3f2f56d091d8a0219485a86bbe", + "reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe", "shasum": "" }, "require": { @@ -898,7 +901,7 @@ "type": "tidelift" } ], - "time": "2024-02-20T13:59:13+00:00" + "time": "2024-03-07T13:30:19+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2337,9 +2340,18 @@ "time": "2024-03-03T12:36:25+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-feat-framework-v2", + "alias": "0.49.99", + "alias_normalized": "0.49.99.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Abuse/Adapters/TimeLimit.php b/src/Abuse/Adapters/TimeLimit.php index 038f32c0db..4ce97ca9ab 100644 --- a/src/Abuse/Adapters/TimeLimit.php +++ b/src/Abuse/Adapters/TimeLimit.php @@ -48,14 +48,17 @@ class TimeLimit implements Adapter */ protected array $params = []; + protected Authorization $auth; + /** * @param string $key * @param int $seconds * @param int $limit * @param Database $db */ - public function __construct(string $key, int $limit, int $seconds, Database $db) + public function __construct(string $key, int $limit, int $seconds, Database $db, Authorization $auth) { + $this->auth = $auth; $this->key = $key; $time = (int) \date('U', (int) (\floor(\time() / $seconds)) * $seconds); // todo: any good Idea without time()? $this->time = DateTime::format((new \DateTime())->setTimestamp($time)); @@ -70,7 +73,7 @@ class TimeLimit implements Adapter public function setup(): void { if (! $this->db->exists($this->db->getDatabase())) { - throw new Exception('You need to create database before running timelimit setup'); + throw new \Exception('You need to create database before running timelimit setup'); } $attributes = [ @@ -191,7 +194,7 @@ class TimeLimit implements Adapter } /** @var array $result */ - $result = Authorization::skip(function () use ($key, $datetime) { + $result = $this->auth->skip(function () use ($key, $datetime) { return $this->db->find(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -223,7 +226,7 @@ class TimeLimit implements Adapter return; } - Authorization::skip(function () use ($datetime, $key) { + $this->auth->skip(function () use ($datetime, $key) { $data = $this->db->findOne(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -280,7 +283,7 @@ class TimeLimit implements Adapter public function getLogs(?int $offset = null, ?int $limit = 25): array { /** @var array $results */ - $results = Authorization::skip(function () use ($offset, $limit) { + $results = $this->auth->skip(function () use ($offset, $limit) { $queries = []; $queries[] = Query::orderDesc(''); @@ -307,7 +310,7 @@ class TimeLimit implements Adapter */ public function cleanup(string $datetime): bool { - Authorization::skip(function () use ($datetime) { + $this->auth->skip(function () use ($datetime) { do { $documents = $this->db->find(TimeLimit::COLLECTION, [ Query::lessThan('time', $datetime), From 36113abc0d4f98556b09cfba2af479b806672206 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 17 Apr 2024 16:38:33 +0300 Subject: [PATCH 02/48] composer.lock --- composer.lock | 53 +++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/composer.lock b/composer.lock index 9c8ec72f89..c0917024dc 100644 --- a/composer.lock +++ b/composer.lock @@ -216,16 +216,16 @@ }, { "name": "utopia-php/cache", - "version": "0.9.0", + "version": "0.9.1", "source": { "type": "git", "url": "https://github.com/utopia-php/cache.git", - "reference": "4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e" + "reference": "552b4c554bb14d0c529631ce304cdf4a2b9d06a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cache/zipball/4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e", - "reference": "4fc7b4789b5f0ce74835c1ecfec4f3afe6f0e34e", + "url": "https://api.github.com/repos/utopia-php/cache/zipball/552b4c554bb14d0c529631ce304cdf4a2b9d06a6", + "reference": "552b4c554bb14d0c529631ce304cdf4a2b9d06a6", "shasum": "" }, "require": { @@ -260,9 +260,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cache/issues", - "source": "https://github.com/utopia-php/cache/tree/0.9.0" + "source": "https://github.com/utopia-php/cache/tree/0.9.1" }, - "time": "2024-01-07T18:11:23+00:00" + "time": "2024-03-19T17:07:20+00:00" }, { "name": "utopia-php/database", @@ -843,16 +843,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.60", + "version": "1.10.67", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe" + "reference": "16ddbe776f10da6a95ebd25de7c1dbed397dc493" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/95dcea7d6c628a3f2f56d091d8a0219485a86bbe", - "reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/16ddbe776f10da6a95ebd25de7c1dbed397dc493", + "reference": "16ddbe776f10da6a95ebd25de7c1dbed397dc493", "shasum": "" }, "require": { @@ -895,13 +895,9 @@ { "url": "https://github.com/phpstan", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" } ], - "time": "2024-03-07T13:30:19+00:00" + "time": "2024-04-16T07:22:02+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1224,16 +1220,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.17", + "version": "9.6.19", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "1a156980d78a6666721b7e8e8502fe210b587fcd" + "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1a156980d78a6666721b7e8e8502fe210b587fcd", - "reference": "1a156980d78a6666721b7e8e8502fe210b587fcd", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1a54a473501ef4cdeaae4e06891674114d79db8", + "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8", "shasum": "" }, "require": { @@ -1307,7 +1303,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.17" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.19" }, "funding": [ { @@ -1323,7 +1319,7 @@ "type": "tidelift" } ], - "time": "2024-02-23T13:14:51+00:00" + "time": "2024-04-05T04:35:58+00:00" }, { "name": "sebastian/cli-parser", @@ -2127,16 +2123,16 @@ }, { "name": "sebastian/resource-operations", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e", + "reference": "05d5692a7993ecccd56a03e40cd7e5b09b1d404e", "shasum": "" }, "require": { @@ -2148,7 +2144,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-main": "3.0-dev" } }, "autoload": { @@ -2169,8 +2165,7 @@ "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { - "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.4" }, "funding": [ { @@ -2178,7 +2173,7 @@ "type": "github" } ], - "time": "2020-09-28T06:45:17+00:00" + "time": "2024-03-14T16:00:52+00:00" }, { "name": "sebastian/type", From 46f3177ce2f91a8c8468e42e18e0d3c16febb79d Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 17 Apr 2024 18:55:23 +0300 Subject: [PATCH 03/48] composer.lock --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index c0917024dc..54a78c576e 100644 --- a/composer.lock +++ b/composer.lock @@ -270,12 +270,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "bdd9140e40c77faadb0cf2f5050b466c34eef673" + "reference": "0645d8550cbcdb921d072b05f05b0f979442d94f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/bdd9140e40c77faadb0cf2f5050b466c34eef673", - "reference": "bdd9140e40c77faadb0cf2f5050b466c34eef673", + "url": "https://api.github.com/repos/utopia-php/database/zipball/0645d8550cbcdb921d072b05f05b0f979442d94f", + "reference": "0645d8550cbcdb921d072b05f05b0f979442d94f", "shasum": "" }, "require": { @@ -319,7 +319,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/feat-framework-v2" }, - "time": "2024-03-07T16:55:44+00:00" + "time": "2024-04-17T14:28:28+00:00" }, { "name": "utopia-php/fetch", From 88f74c0726938769ea1ff82c77bd1213816c7c04 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 17 Apr 2024 19:32:58 +0300 Subject: [PATCH 04/48] auth test --- src/Abuse/Adapters/TimeLimit.php | 28 ++++++++++++++++++---------- tests/Abuse/AbuseTest.php | 6 ++++-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Abuse/Adapters/TimeLimit.php b/src/Abuse/Adapters/TimeLimit.php index 4ce97ca9ab..36d647806f 100644 --- a/src/Abuse/Adapters/TimeLimit.php +++ b/src/Abuse/Adapters/TimeLimit.php @@ -7,12 +7,12 @@ use Utopia\Abuse\Adapter; use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; +use Utopia\Database\Exception; use Utopia\Database\Exception\Authorization as AuthorizationException; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Structure; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; -use Utopia\Exception; class TimeLimit implements Adapter { @@ -51,10 +51,11 @@ class TimeLimit implements Adapter protected Authorization $auth; /** - * @param string $key - * @param int $seconds - * @param int $limit - * @param Database $db + * @param string $key + * @param int $limit + * @param int $seconds + * @param Database $db + * @param Authorization $auth */ public function __construct(string $key, int $limit, int $seconds, Database $db, Authorization $auth) { @@ -68,12 +69,12 @@ class TimeLimit implements Adapter /** * @throws Duplicate - * @throws Exception|\Exception + * @throws Exception */ public function setup(): void { if (! $this->db->exists($this->db->getDatabase())) { - throw new \Exception('You need to create database before running timelimit setup'); + throw new Exception('You need to create database before running timelimit setup'); } $attributes = [ @@ -194,6 +195,14 @@ class TimeLimit implements Adapter } /** @var array $result */ + + /** + * todo: why we are using + * $this->auth->skip + * and not ? + * $this->db->getAuthorization()->skip + */ + $result = $this->auth->skip(function () use ($key, $datetime) { return $this->db->find(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), @@ -250,7 +259,7 @@ class TimeLimit implements Adapter Query::equal('time', [$datetime]), ]); - if ($data !== false && $data instanceof Document) { + if ($data instanceof Document) { $count = $data->getAttribute('count', 0); if (\is_numeric($count)) { $this->count = intval($count); @@ -261,7 +270,6 @@ class TimeLimit implements Adapter } } } else { - /** @var Document $data */ $this->db->increaseDocumentAttribute(TimeLimit::COLLECTION, $data->getId(), 'count'); } }); @@ -332,7 +340,7 @@ class TimeLimit implements Adapter * * @return bool * - * @throws \Exception|Throwable + * @throws Throwable */ public function check(): bool { diff --git a/tests/Abuse/AbuseTest.php b/tests/Abuse/AbuseTest.php index 755b6e6d67..7f02ab90e9 100755 --- a/tests/Abuse/AbuseTest.php +++ b/tests/Abuse/AbuseTest.php @@ -12,7 +12,8 @@ use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Adapter\MySQL; use Utopia\Database\Database; use Utopia\Database\DateTime; -use Utopia\Exception; +use Utopia\Database\Exception; +use Utopia\Database\Validator\Authorization; class AbuseTest extends TestCase { @@ -39,9 +40,10 @@ class AbuseTest extends TestCase $db = new Database(new MySQL($pdo), new Cache(new NoCache())); $db->setDatabase('utopiaTests'); $db->setNamespace('namespace'); + $db->setAuthorization(new Authorization()); $this->db = $db; - $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db); + $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db, new Authorization()); if (! $db->exists('utopiaTests')) { $db->create(); $adapter->setup(); From 7cd611bbf82115dd53805b36424a8c0b96c1f13d Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 17 Apr 2024 19:43:34 +0300 Subject: [PATCH 05/48] Question --- src/Abuse/Adapters/TimeLimit.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Abuse/Adapters/TimeLimit.php b/src/Abuse/Adapters/TimeLimit.php index 36d647806f..63ef629430 100644 --- a/src/Abuse/Adapters/TimeLimit.php +++ b/src/Abuse/Adapters/TimeLimit.php @@ -201,6 +201,7 @@ class TimeLimit implements Adapter * $this->auth->skip * and not ? * $this->db->getAuthorization()->skip + * are they different objects? */ $result = $this->auth->skip(function () use ($key, $datetime) { From a58454e367a827285415092e7e393559025f3faf Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 17 Apr 2024 20:05:33 +0300 Subject: [PATCH 06/48] Add objects --- tests/Abuse/AbuseTest.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/Abuse/AbuseTest.php b/tests/Abuse/AbuseTest.php index 7f02ab90e9..0f5c384cb2 100755 --- a/tests/Abuse/AbuseTest.php +++ b/tests/Abuse/AbuseTest.php @@ -22,6 +22,7 @@ class AbuseTest extends TestCase protected Abuse $abuseIp; protected Database $db; + protected Authorization $authorization; /** * @throws Exception @@ -40,10 +41,13 @@ class AbuseTest extends TestCase $db = new Database(new MySQL($pdo), new Cache(new NoCache())); $db->setDatabase('utopiaTests'); $db->setNamespace('namespace'); - $db->setAuthorization(new Authorization()); + + $this->authorization = new Authorization(); + $db->setAuthorization($this->authorization); $this->db = $db; - $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db, new Authorization()); + // todo do I need to pass a new $auth ? or can I use the one from DB? + $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db, $this->authorization); if (! $db->exists('utopiaTests')) { $db->create(); $adapter->setup(); @@ -63,7 +67,7 @@ class AbuseTest extends TestCase $key = '{{ip}}'; $value = '0.0.0.10'; - $adapter = new TimeLimit($key, 1, 1, $this->db); + $adapter = new TimeLimit($key, 1, 1, $this->db, new Authorization()); $adapter->setParam($key, $value); $this->abuseIp = new Abuse($adapter); $this->assertEquals($this->abuseIp->check(), false); @@ -71,7 +75,7 @@ class AbuseTest extends TestCase sleep(1); - $adapter = new TimeLimit($key, 1, 1, $this->db); + $adapter = new TimeLimit($key, 1, 1, $this->db, new Authorization()); $adapter->setParam($key, $value); $this->abuseIp = new Abuse($adapter); From db3dbb5603c62e1e8f87480e77f9b66553bed43a Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 17 Apr 2024 20:08:09 +0300 Subject: [PATCH 07/48] Question --- tests/Abuse/AbuseTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Abuse/AbuseTest.php b/tests/Abuse/AbuseTest.php index 0f5c384cb2..31f149dce3 100755 --- a/tests/Abuse/AbuseTest.php +++ b/tests/Abuse/AbuseTest.php @@ -22,7 +22,6 @@ class AbuseTest extends TestCase protected Abuse $abuseIp; protected Database $db; - protected Authorization $authorization; /** * @throws Exception @@ -42,12 +41,12 @@ class AbuseTest extends TestCase $db->setDatabase('utopiaTests'); $db->setNamespace('namespace'); - $this->authorization = new Authorization(); - $db->setAuthorization($this->authorization); + $auth = new Authorization(); + $db->setAuthorization($auth); $this->db = $db; - // todo do I need to pass a new $auth ? or can I use the one from DB? - $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db, $this->authorization); + // todo: Should I create a new Authorization() or can I use $auth from the db? + $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db, $auth); if (! $db->exists('utopiaTests')) { $db->create(); $adapter->setup(); From 70a3a0a9aa6dfea5562be88d0f2e16a92e4e95ac Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Apr 2024 16:07:17 +0300 Subject: [PATCH 08/48] Use db auth --- composer.lock | 8 ++++---- src/Abuse/Adapters/TimeLimit.php | 22 +++++----------------- tests/Abuse/AbuseTest.php | 4 ++-- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/composer.lock b/composer.lock index 54a78c576e..db03c55975 100644 --- a/composer.lock +++ b/composer.lock @@ -270,12 +270,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "0645d8550cbcdb921d072b05f05b0f979442d94f" + "reference": "6b8264a4e269d679182fc376179281b7108a4242" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/0645d8550cbcdb921d072b05f05b0f979442d94f", - "reference": "0645d8550cbcdb921d072b05f05b0f979442d94f", + "url": "https://api.github.com/repos/utopia-php/database/zipball/6b8264a4e269d679182fc376179281b7108a4242", + "reference": "6b8264a4e269d679182fc376179281b7108a4242", "shasum": "" }, "require": { @@ -319,7 +319,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/feat-framework-v2" }, - "time": "2024-04-17T14:28:28+00:00" + "time": "2024-04-18T12:50:22+00:00" }, { "name": "utopia-php/fetch", diff --git a/src/Abuse/Adapters/TimeLimit.php b/src/Abuse/Adapters/TimeLimit.php index 63ef629430..b01d4b7853 100644 --- a/src/Abuse/Adapters/TimeLimit.php +++ b/src/Abuse/Adapters/TimeLimit.php @@ -48,18 +48,14 @@ class TimeLimit implements Adapter */ protected array $params = []; - protected Authorization $auth; - /** * @param string $key * @param int $limit * @param int $seconds * @param Database $db - * @param Authorization $auth */ - public function __construct(string $key, int $limit, int $seconds, Database $db, Authorization $auth) + public function __construct(string $key, int $limit, int $seconds, Database $db) { - $this->auth = $auth; $this->key = $key; $time = (int) \date('U', (int) (\floor(\time() / $seconds)) * $seconds); // todo: any good Idea without time()? $this->time = DateTime::format((new \DateTime())->setTimestamp($time)); @@ -196,15 +192,7 @@ class TimeLimit implements Adapter /** @var array $result */ - /** - * todo: why we are using - * $this->auth->skip - * and not ? - * $this->db->getAuthorization()->skip - * are they different objects? - */ - - $result = $this->auth->skip(function () use ($key, $datetime) { + $result = $this->db->getAuthorization()->skip(function () use ($key, $datetime) { return $this->db->find(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -236,7 +224,7 @@ class TimeLimit implements Adapter return; } - $this->auth->skip(function () use ($datetime, $key) { + $this->db->getAuthorization()->skip(function () use ($datetime, $key) { $data = $this->db->findOne(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -292,7 +280,7 @@ class TimeLimit implements Adapter public function getLogs(?int $offset = null, ?int $limit = 25): array { /** @var array $results */ - $results = $this->auth->skip(function () use ($offset, $limit) { + $results = $this->db->getAuthorization()->skip(function () use ($offset, $limit) { $queries = []; $queries[] = Query::orderDesc(''); @@ -319,7 +307,7 @@ class TimeLimit implements Adapter */ public function cleanup(string $datetime): bool { - $this->auth->skip(function () use ($datetime) { + $this->db->getAuthorization()->skip(function () use ($datetime) { do { $documents = $this->db->find(TimeLimit::COLLECTION, [ Query::lessThan('time', $datetime), diff --git a/tests/Abuse/AbuseTest.php b/tests/Abuse/AbuseTest.php index 31f149dce3..0497311e5e 100755 --- a/tests/Abuse/AbuseTest.php +++ b/tests/Abuse/AbuseTest.php @@ -66,7 +66,7 @@ class AbuseTest extends TestCase $key = '{{ip}}'; $value = '0.0.0.10'; - $adapter = new TimeLimit($key, 1, 1, $this->db, new Authorization()); + $adapter = new TimeLimit($key, 1, 1, $this->db); $adapter->setParam($key, $value); $this->abuseIp = new Abuse($adapter); $this->assertEquals($this->abuseIp->check(), false); @@ -74,7 +74,7 @@ class AbuseTest extends TestCase sleep(1); - $adapter = new TimeLimit($key, 1, 1, $this->db, new Authorization()); + $adapter = new TimeLimit($key, 1, 1, $this->db); $adapter->setParam($key, $value); $this->abuseIp = new Abuse($adapter); From 56e67231ed156a27fcd605eb2a4a890ee2342fa1 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Apr 2024 17:38:55 +0300 Subject: [PATCH 09/48] setAuthorization --- tests/Abuse/AbuseTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/Abuse/AbuseTest.php b/tests/Abuse/AbuseTest.php index 0497311e5e..2247a15ca0 100755 --- a/tests/Abuse/AbuseTest.php +++ b/tests/Abuse/AbuseTest.php @@ -40,13 +40,10 @@ class AbuseTest extends TestCase $db = new Database(new MySQL($pdo), new Cache(new NoCache())); $db->setDatabase('utopiaTests'); $db->setNamespace('namespace'); - - $auth = new Authorization(); - $db->setAuthorization($auth); + $db->setAuthorization(new Authorization()); $this->db = $db; - // todo: Should I create a new Authorization() or can I use $auth from the db? - $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db, $auth); + $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db); if (! $db->exists('utopiaTests')) { $db->create(); $adapter->setup(); From fffd9c0a4d1f0d0b8f5730a5523c91c75977a0dc Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Apr 2024 17:55:04 +0300 Subject: [PATCH 10/48] remove setAuthorization --- tests/Abuse/AbuseTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Abuse/AbuseTest.php b/tests/Abuse/AbuseTest.php index 2247a15ca0..26fbd3d47a 100755 --- a/tests/Abuse/AbuseTest.php +++ b/tests/Abuse/AbuseTest.php @@ -40,7 +40,6 @@ class AbuseTest extends TestCase $db = new Database(new MySQL($pdo), new Cache(new NoCache())); $db->setDatabase('utopiaTests'); $db->setNamespace('namespace'); - $db->setAuthorization(new Authorization()); $this->db = $db; $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db); From a2292d71da901ea13129d56f89876626ba92adf0 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Apr 2024 20:04:17 +0300 Subject: [PATCH 11/48] Formatting --- src/Abuse/Adapters/TimeLimit.php | 1 - tests/Abuse/AbuseTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Abuse/Adapters/TimeLimit.php b/src/Abuse/Adapters/TimeLimit.php index b01d4b7853..1308f09f62 100644 --- a/src/Abuse/Adapters/TimeLimit.php +++ b/src/Abuse/Adapters/TimeLimit.php @@ -12,7 +12,6 @@ use Utopia\Database\Exception\Authorization as AuthorizationException; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Structure; use Utopia\Database\Query; -use Utopia\Database\Validator\Authorization; class TimeLimit implements Adapter { diff --git a/tests/Abuse/AbuseTest.php b/tests/Abuse/AbuseTest.php index 26fbd3d47a..5f6048de40 100755 --- a/tests/Abuse/AbuseTest.php +++ b/tests/Abuse/AbuseTest.php @@ -13,7 +13,6 @@ use Utopia\Database\Adapter\MySQL; use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Exception; -use Utopia\Database\Validator\Authorization; class AbuseTest extends TestCase { From b3105b361311d601069697c7691517d70f1bd32d Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Fri, 19 Jul 2024 12:13:52 -0400 Subject: [PATCH 12/48] chore: merge --- composer.lock | 170 +++++++++++++++------------- src/Abuse/Adapters/Database.php | 77 ++++++++++++- tests/Abuse/Bench/DatabaseBench.php | 2 +- tests/Abuse/DatabaseTest.php | 2 +- tests/Abuse/RedisTest.php | 2 +- 5 files changed, 166 insertions(+), 87 deletions(-) diff --git a/composer.lock b/composer.lock index e2fb9e98a5..d6512ad546 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1e53afffe12ae95f750f420f449e4c19", + "content-hash": "9a0fc06bf721ea900f18ce30dc40b628", "packages": [ { "name": "jean85/pretty-package-versions", @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "0.50.0", + "version": "dev-feat-framework-v2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "ce3eaccb2f3bbd34b2b97419836fec633b26b8f7" + "reference": "5b0d6ba40141dd9d4983d3aac018782f8ecdfc8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/ce3eaccb2f3bbd34b2b97419836fec633b26b8f7", - "reference": "ce3eaccb2f3bbd34b2b97419836fec633b26b8f7", + "url": "https://api.github.com/repos/utopia-php/database/zipball/5b0d6ba40141dd9d4983d3aac018782f8ecdfc8a", + "reference": "5b0d6ba40141dd9d4983d3aac018782f8ecdfc8a", "shasum": "" }, "require": { @@ -283,7 +283,7 @@ "ext-pdo": "*", "php": ">=8.0", "utopia-php/cache": "0.10.*", - "utopia-php/framework": "0.33.*", + "utopia-php/framework": "0.34.*", "utopia-php/mongo": "0.3.*" }, "require-dev": { @@ -294,7 +294,7 @@ "phpunit/phpunit": "^9.4", "rregeer/phpunit-coverage-check": "^0.3.1", "swoole/ide-helper": "4.8.0", - "utopia-php/cli": "^0.14.0" + "utopia-php/cli": "0.17.*" }, "type": "library", "autoload": { @@ -316,54 +316,58 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.50.0" + "source": "https://github.com/utopia-php/database/tree/feat-framework-v2" }, - "time": "2024-06-21T03:21:42+00:00" + "time": "2024-06-06T00:07:47+00:00" }, { "name": "utopia-php/framework", - "version": "0.33.6", + "version": "0.34.3", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "8fe57da0cecd57e3b17cd395b4a666a24f4c07a6" + "reference": "e3bbca07c1df4e908ea9d3ce4f59367a7696b66b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/8fe57da0cecd57e3b17cd395b4a666a24f4c07a6", - "reference": "8fe57da0cecd57e3b17cd395b4a666a24f4c07a6", + "url": "https://api.github.com/repos/utopia-php/http/zipball/e3bbca07c1df4e908ea9d3ce4f59367a7696b66b", + "reference": "e3bbca07c1df4e908ea9d3ce4f59367a7696b66b", "shasum": "" }, "require": { + "ext-swoole": "*", "php": ">=8.0" }, "require-dev": { "laravel/pint": "^1.2", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25" + "phpunit/phpunit": "^9.5.25", + "swoole/ide-helper": "4.8.3" }, "type": "library", "autoload": { "psr-4": { - "Utopia\\": "src/" + "Utopia\\": "src/", + "Tests\\E2E\\": "tests/e2e" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "description": "A simple, light and advanced PHP framework", + "description": "A simple, light and advanced PHP HTTP framework", "keywords": [ "framework", + "http", "php", "upf" ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.6" + "source": "https://github.com/utopia-php/http/tree/0.34.3" }, - "time": "2024-03-21T18:10:57+00:00" + "time": "2024-07-02T15:08:46+00:00" }, { "name": "utopia-php/mongo", @@ -778,16 +782,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.0.2", + "version": "v5.1.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", - "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", "shasum": "" }, "require": { @@ -798,7 +802,7 @@ }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^9.0" }, "bin": [ "bin/php-parse" @@ -830,9 +834,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" }, - "time": "2024-03-05T20:51:40+00:00" + "time": "2024-07-01T20:03:41+00:00" }, { "name": "phar-io/manifest", @@ -1056,16 +1060,16 @@ }, { "name": "phpbench/phpbench", - "version": "1.2.15", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/phpbench/phpbench.git", - "reference": "f7000319695cfad04a57fc64bf7ef7abdf4c437c" + "reference": "a3e1ef08d9d7736d43a7fbd444893d6a073c0ca0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpbench/phpbench/zipball/f7000319695cfad04a57fc64bf7ef7abdf4c437c", - "reference": "f7000319695cfad04a57fc64bf7ef7abdf4c437c", + "url": "https://api.github.com/repos/phpbench/phpbench/zipball/a3e1ef08d9d7736d43a7fbd444893d6a073c0ca0", + "reference": "a3e1ef08d9d7736d43a7fbd444893d6a073c0ca0", "shasum": "" }, "require": { @@ -1077,29 +1081,30 @@ "ext-spl": "*", "ext-tokenizer": "*", "php": "^8.1", - "phpbench/container": "^2.1", + "phpbench/container": "^2.2", "phpbench/dom": "~0.3.3", "psr/log": "^1.1 || ^2.0 || ^3.0", "seld/jsonlint": "^1.1", - "symfony/console": "^4.2 || ^5.0 || ^6.0 || ^7.0", - "symfony/filesystem": "^4.2 || ^5.0 || ^6.0 || ^7.0", - "symfony/finder": "^4.2 || ^5.0 || ^6.0 || ^7.0", - "symfony/options-resolver": "^4.2 || ^5.0 || ^6.0 || ^7.0", - "symfony/process": "^4.2 || ^5.0 || ^6.0 || ^7.0", + "symfony/console": "^6.1 || ^7.0", + "symfony/filesystem": "^6.1 || ^7.0", + "symfony/finder": "^6.1 || ^7.0", + "symfony/options-resolver": "^6.1 || ^7.0", + "symfony/process": "^6.1 || ^7.0", "webmozart/glob": "^4.6" }, "require-dev": { "dantleech/invoke": "^2.0", + "ergebnis/composer-normalize": "^2.39", "friendsofphp/php-cs-fixer": "^3.0", "jangregor/phpstan-prophecy": "^1.0", "phpspec/prophecy": "dev-master", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.0", "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^10.0", - "rector/rector": "^0.18.10", - "symfony/error-handler": "^5.2 || ^6.0 || ^7.0", - "symfony/var-dumper": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^10.4", + "rector/rector": "^0.18.11 || ^1.0.0", + "symfony/error-handler": "^6.1 || ^7.0", + "symfony/var-dumper": "^6.1 || ^7.0" }, "suggest": { "ext-xdebug": "For Xdebug profiling extension." @@ -1142,7 +1147,7 @@ ], "support": { "issues": "https://github.com/phpbench/phpbench/issues", - "source": "https://github.com/phpbench/phpbench/tree/1.2.15" + "source": "https://github.com/phpbench/phpbench/tree/1.3.1" }, "funding": [ { @@ -1150,20 +1155,20 @@ "type": "github" } ], - "time": "2023-11-29T12:21:11+00:00" + "time": "2024-06-30T11:04:37+00:00" }, { "name": "phpstan/phpstan", - "version": "1.11.5", + "version": "1.11.7", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "490f0ae1c92b082f154681d7849aee776a7c1443" + "reference": "52d2bbfdcae7f895915629e4694e9497d0f8e28d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/490f0ae1c92b082f154681d7849aee776a7c1443", - "reference": "490f0ae1c92b082f154681d7849aee776a7c1443", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/52d2bbfdcae7f895915629e4694e9497d0f8e28d", + "reference": "52d2bbfdcae7f895915629e4694e9497d0f8e28d", "shasum": "" }, "require": { @@ -1208,7 +1213,7 @@ "type": "github" } ], - "time": "2024-06-17T15:10:54+00:00" + "time": "2024-07-06T11:17:41+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1531,45 +1536,45 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.19", + "version": "9.6.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8" + "reference": "49d7820565836236411f5dc002d16dd689cde42f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a1a54a473501ef4cdeaae4e06891674114d79db8", - "reference": "a1a54a473501ef4cdeaae4e06891674114d79db8", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/49d7820565836236411f5dc002d16dd689cde42f", + "reference": "49d7820565836236411f5dc002d16dd689cde42f", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1 || ^2", + "doctrine/instantiator": "^1.5.0 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.3", - "phar-io/version": "^3.0.2", + "myclabs/deep-copy": "^1.12.0", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.28", - "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-code-coverage": "^9.2.31", + "phpunit/php-file-iterator": "^3.0.6", "phpunit/php-invoker": "^3.1.1", - "phpunit/php-text-template": "^2.0.3", - "phpunit/php-timer": "^5.0.2", - "sebastian/cli-parser": "^1.0.1", - "sebastian/code-unit": "^1.0.6", + "phpunit/php-text-template": "^2.0.4", + "phpunit/php-timer": "^5.0.3", + "sebastian/cli-parser": "^1.0.2", + "sebastian/code-unit": "^1.0.8", "sebastian/comparator": "^4.0.8", - "sebastian/diff": "^4.0.3", - "sebastian/environment": "^5.1.3", - "sebastian/exporter": "^4.0.5", - "sebastian/global-state": "^5.0.1", - "sebastian/object-enumerator": "^4.0.3", - "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^3.2", + "sebastian/diff": "^4.0.6", + "sebastian/environment": "^5.1.5", + "sebastian/exporter": "^4.0.6", + "sebastian/global-state": "^5.0.7", + "sebastian/object-enumerator": "^4.0.4", + "sebastian/resource-operations": "^3.0.4", + "sebastian/type": "^3.2.1", "sebastian/version": "^3.0.2" }, "suggest": { @@ -1614,7 +1619,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.19" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.20" }, "funding": [ { @@ -1630,7 +1635,7 @@ "type": "tidelift" } ], - "time": "2024-04-05T04:35:58+00:00" + "time": "2024-07-10T11:45:39+00:00" }, { "name": "psr/cache", @@ -2749,23 +2754,23 @@ }, { "name": "seld/jsonlint", - "version": "1.10.2", + "version": "1.11.0", "source": { "type": "git", "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "9bb7db07b5d66d90f6ebf542f09fc67d800e5259" + "reference": "1748aaf847fc731cfad7725aec413ee46f0cc3a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/9bb7db07b5d66d90f6ebf542f09fc67d800e5259", - "reference": "9bb7db07b5d66d90f6ebf542f09fc67d800e5259", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/1748aaf847fc731cfad7725aec413ee46f0cc3a2", + "reference": "1748aaf847fc731cfad7725aec413ee46f0cc3a2", "shasum": "" }, "require": { "php": "^5.3 || ^7.0 || ^8.0" }, "require-dev": { - "phpstan/phpstan": "^1.5", + "phpstan/phpstan": "^1.11", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0 || ^8.5.13" }, "bin": [ @@ -2797,7 +2802,7 @@ ], "support": { "issues": "https://github.com/Seldaek/jsonlint/issues", - "source": "https://github.com/Seldaek/jsonlint/tree/1.10.2" + "source": "https://github.com/Seldaek/jsonlint/tree/1.11.0" }, "funding": [ { @@ -2809,7 +2814,7 @@ "type": "tidelift" } ], - "time": "2024-02-07T12:57:50+00:00" + "time": "2024-07-11T14:55:45+00:00" }, { "name": "symfony/console", @@ -3817,9 +3822,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-feat-framework-v2", + "alias": "0.49.99", + "alias_normalized": "0.49.99.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Abuse/Adapters/Database.php b/src/Abuse/Adapters/Database.php index 534ee49904..b4c8a8be14 100644 --- a/src/Abuse/Adapters/Database.php +++ b/src/Abuse/Adapters/Database.php @@ -9,8 +9,7 @@ use Utopia\Database\Exception\Authorization as AuthorizationException; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Structure; use Utopia\Database\Query; -use Utopia\Database\Validator\Authorization; -use Utopia\Exception; +use Utopia\Http\Exception; class Database extends TimeLimit { @@ -127,7 +126,7 @@ class Database extends TimeLimit } /** @var array $result */ - $result = Authorization::skip(function () use ($key, $datetime) { + $result = $this->db->getAuthorization()->skip(function () use ($key, $datetime) { return $this->db->find(Database::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -159,7 +158,7 @@ class Database extends TimeLimit return; } - Authorization::skip(function () use ($datetime, $key) { + $this->db->getAuthorization()->skip(function () use ($datetime, $key) { $data = $this->db->findOne(Database::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -216,7 +215,7 @@ class Database extends TimeLimit public function getLogs(?int $offset = null, ?int $limit = 25): array { /** @var array $results */ - $results = Authorization::skip(function () use ($offset, $limit) { + $results = $this->db->getAuthorization()->skip(function () use ($offset, $limit) { $queries = []; $queries[] = Query::orderDesc(''); @@ -243,7 +242,7 @@ class Database extends TimeLimit */ public function cleanup(string $datetime): bool { - Authorization::skip(function () use ($datetime) { + $this->db->getAuthorization()->skip(function () use ($datetime) { do { $documents = $this->db->find(Database::COLLECTION, [ Query::lessThan('time', $datetime), @@ -257,4 +256,70 @@ class Database extends TimeLimit return true; } + + /** + * Check + * + * Checks if number of counts is bigger or smaller than current limit. limit 0 is equal to unlimited + * + * @return bool + * + * @throws \Throwable + */ + public function check(): bool + { + if (0 == $this->limit) { + return false; + } + + $key = $this->parseKey(); + + if ($this->limit > $this->count($key, $this->time)) { + $this->hit($key, $this->time); + + return false; + } + + return true; + } + + /** + * Remaining + * + * Returns the number of current remaining counts + * + * @return int + * + * @throws \Exception + */ + public function remaining(): int + { + $left = $this->limit - ($this->count($this->parseKey(), $this->time) + 1); // Add one because we need to say how many left not how many done + + return (0 > $left) ? 0 : $left; + } + + /** + * Limit + * + * Return the limit integer + * + * @return int + */ + public function limit(): int + { + return $this->limit; + } + + /** + * Time + * + * Return the Datetime + * + * @return string + */ + public function time(): string + { + return $this->time; + } } diff --git a/tests/Abuse/Bench/DatabaseBench.php b/tests/Abuse/Bench/DatabaseBench.php index fcba9517fd..833d25396c 100644 --- a/tests/Abuse/Bench/DatabaseBench.php +++ b/tests/Abuse/Bench/DatabaseBench.php @@ -10,7 +10,7 @@ use Utopia\Cache\Cache; use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Adapter\MySQL; use Utopia\Database\Database; -use Utopia\Exception; +use Utopia\Http\Exception; class DatabaseBench extends Base { diff --git a/tests/Abuse/DatabaseTest.php b/tests/Abuse/DatabaseTest.php index 5927d0f72f..7def059f89 100755 --- a/tests/Abuse/DatabaseTest.php +++ b/tests/Abuse/DatabaseTest.php @@ -12,7 +12,7 @@ use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Adapter\MySQL; use Utopia\Database\Database; use Utopia\Database\DateTime; -use Utopia\Exception; +use Utopia\Http\Exception; class DatabaseTest extends Base { diff --git a/tests/Abuse/RedisTest.php b/tests/Abuse/RedisTest.php index b29b568085..4f938635dc 100644 --- a/tests/Abuse/RedisTest.php +++ b/tests/Abuse/RedisTest.php @@ -7,7 +7,7 @@ use Utopia\Abuse\Adapter; use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapters\Redis; use Redis as Client; -use Utopia\Exception; +use Utopia\Http\Exception; class RedisTest extends Base { From 4f49bbba8235dc2ed8220482e1e1b46f1e4598df Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:35:18 -0400 Subject: [PATCH 13/48] chore: updating to latest database --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 593015fe28..1a9f23284d 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-pdo": "*", "ext-curl": "*", "ext-redis": "*", - "utopia-php/database": "dev-feat-framework-v2 as 0.49.99" + "utopia-php/database": "0.51.*" }, "require-dev": { "phpunit/phpunit": "^9.4", From 7ff88da05716acb20a2ca479635a677c40e8ca1c Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:49:58 -0400 Subject: [PATCH 14/48] chore: updating to the latest database --- composer.json | 4 +- composer.lock | 213 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 155 insertions(+), 62 deletions(-) diff --git a/composer.json b/composer.json index 1a9f23284d..8842ebb964 100755 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "keywords": ["php","framework", "upf", "utopia", "abuse"], "license": "MIT", - "minimum-stability": "stable", + "minimum-stability": "RC", "autoload": { "psr-4": {"Utopia\\Abuse\\": "src/Abuse"} }, @@ -22,7 +22,7 @@ "ext-pdo": "*", "ext-curl": "*", "ext-redis": "*", - "utopia-php/database": "0.51.*" + "utopia-php/database": "1.0.*" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index d6512ad546..26b23d6fb6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9a0fc06bf721ea900f18ce30dc40b628", + "content-hash": "e6a6611ef5abc949f69ba822126ffd75", "packages": [ { "name": "jean85/pretty-package-versions", @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "dev-feat-framework-v2", + "version": "1.0.0-RC1", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "5b0d6ba40141dd9d4983d3aac018782f8ecdfc8a" + "reference": "36720e88125e3c16fb770bf2422a757fcec68050" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/5b0d6ba40141dd9d4983d3aac018782f8ecdfc8a", - "reference": "5b0d6ba40141dd9d4983d3aac018782f8ecdfc8a", + "url": "https://api.github.com/repos/utopia-php/database/zipball/36720e88125e3c16fb770bf2422a757fcec68050", + "reference": "36720e88125e3c16fb770bf2422a757fcec68050", "shasum": "" }, "require": { @@ -283,7 +283,7 @@ "ext-pdo": "*", "php": ">=8.0", "utopia-php/cache": "0.10.*", - "utopia-php/framework": "0.34.*", + "utopia-php/framework": "1.0.*", "utopia-php/mongo": "0.3.*" }, "require-dev": { @@ -294,7 +294,7 @@ "phpunit/phpunit": "^9.4", "rregeer/phpunit-coverage-check": "^0.3.1", "swoole/ide-helper": "4.8.0", - "utopia-php/cli": "0.17.*" + "utopia-php/cli": "1.0.*" }, "type": "library", "autoload": { @@ -316,27 +316,26 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/feat-framework-v2" + "source": "https://github.com/utopia-php/database/tree/1.0.0-RC1" }, - "time": "2024-06-06T00:07:47+00:00" + "time": "2024-08-09T17:41:07+00:00" }, { - "name": "utopia-php/framework", - "version": "0.34.3", + "name": "utopia-php/di", + "version": "0.1.0", "source": { "type": "git", - "url": "https://github.com/utopia-php/http.git", - "reference": "e3bbca07c1df4e908ea9d3ce4f59367a7696b66b" + "url": "https://github.com/utopia-php/di.git", + "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/e3bbca07c1df4e908ea9d3ce4f59367a7696b66b", - "reference": "e3bbca07c1df4e908ea9d3ce4f59367a7696b66b", + "url": "https://api.github.com/repos/utopia-php/di/zipball/22490c95f7ac3898ed1c33f1b1b5dd577305ee31", + "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31", "shasum": "" }, "require": { - "ext-swoole": "*", - "php": ">=8.0" + "php": ">=8.2" }, "require-dev": { "laravel/pint": "^1.2", @@ -356,6 +355,56 @@ "license": [ "MIT" ], + "description": "A simple and lite library for managing dependency injections", + "keywords": [ + "framework", + "http", + "php", + "upf" + ], + "support": { + "issues": "https://github.com/utopia-php/di/issues", + "source": "https://github.com/utopia-php/di/tree/0.1.0" + }, + "time": "2024-08-08T14:35:19+00:00" + }, + { + "name": "utopia-php/framework", + "version": "1.0.0-RC2", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/http.git", + "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/http/zipball/d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", + "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", + "shasum": "" + }, + "require": { + "ext-swoole": "*", + "php": ">=8.0", + "utopia-php/servers": "0.1.* " + }, + "require-dev": { + "ext-xdebug": "*", + "laravel/pint": "^1.2", + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.5.25", + "swoole/ide-helper": "4.8.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], "description": "A simple, light and advanced PHP HTTP framework", "keywords": [ "framework", @@ -365,9 +414,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.34.3" + "source": "https://github.com/utopia-php/http/tree/1.0.0-RC2" }, - "time": "2024-07-02T15:08:46+00:00" + "time": "2024-08-08T14:46:41+00:00" }, { "name": "utopia-php/mongo", @@ -428,6 +477,59 @@ "source": "https://github.com/utopia-php/mongo/tree/0.3.1" }, "time": "2023-09-01T17:25:28+00:00" + }, + { + "name": "utopia-php/servers", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/servers.git", + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", + "shasum": "" + }, + "require": { + "php": ">=8.0", + "utopia-php/di": "0.1.*" + }, + "require-dev": { + "laravel/pint": "^0.2.3", + "phpstan/phpstan": "^1.8", + "phpunit/phpunit": "^9.5.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\Servers\\": "src/Servers" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Team Appwrite", + "email": "team@appwrite.io" + } + ], + "description": "A base library for building Utopia style servers.", + "keywords": [ + "framework", + "php", + "servers", + "upf", + "utopia" + ], + "support": { + "issues": "https://github.com/utopia-php/servers/issues", + "source": "https://github.com/utopia-php/servers/tree/0.1.0" + }, + "time": "2024-08-08T14:31:39+00:00" } ], "packages-dev": [ @@ -1159,16 +1261,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.11.7", + "version": "1.11.10", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "52d2bbfdcae7f895915629e4694e9497d0f8e28d" + "reference": "640410b32995914bde3eed26fa89552f9c2c082f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/52d2bbfdcae7f895915629e4694e9497d0f8e28d", - "reference": "52d2bbfdcae7f895915629e4694e9497d0f8e28d", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/640410b32995914bde3eed26fa89552f9c2c082f", + "reference": "640410b32995914bde3eed26fa89552f9c2c082f", "shasum": "" }, "require": { @@ -1213,7 +1315,7 @@ "type": "github" } ], - "time": "2024-07-06T11:17:41+00:00" + "time": "2024-08-08T09:02:50+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2818,16 +2920,16 @@ }, { "name": "symfony/console", - "version": "v7.1.2", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "0aa29ca177f432ab68533432db0de059f39c92ae" + "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/0aa29ca177f432ab68533432db0de059f39c92ae", - "reference": "0aa29ca177f432ab68533432db0de059f39c92ae", + "url": "https://api.github.com/repos/symfony/console/zipball/cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", + "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", "shasum": "" }, "require": { @@ -2891,7 +2993,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.2" + "source": "https://github.com/symfony/console/tree/v7.1.3" }, "funding": [ { @@ -2907,7 +3009,7 @@ "type": "tidelift" } ], - "time": "2024-06-28T10:03:55+00:00" + "time": "2024-07-26T12:41:01+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3044,16 +3146,16 @@ }, { "name": "symfony/finder", - "version": "v7.1.1", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "fbb0ba67688b780efbc886c1a0a0948dcf7205d6" + "reference": "717c6329886f32dc65e27461f80f2a465412fdca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/fbb0ba67688b780efbc886c1a0a0948dcf7205d6", - "reference": "fbb0ba67688b780efbc886c1a0a0948dcf7205d6", + "url": "https://api.github.com/repos/symfony/finder/zipball/717c6329886f32dc65e27461f80f2a465412fdca", + "reference": "717c6329886f32dc65e27461f80f2a465412fdca", "shasum": "" }, "require": { @@ -3088,7 +3190,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.1.1" + "source": "https://github.com/symfony/finder/tree/v7.1.3" }, "funding": [ { @@ -3104,7 +3206,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-07-24T07:08:44+00:00" }, { "name": "symfony/options-resolver", @@ -3493,16 +3595,16 @@ }, { "name": "symfony/process", - "version": "v7.1.1", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "febf90124323a093c7ee06fdb30e765ca3c20028" + "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/febf90124323a093c7ee06fdb30e765ca3c20028", - "reference": "febf90124323a093c7ee06fdb30e765ca3c20028", + "url": "https://api.github.com/repos/symfony/process/zipball/7f2f542c668ad6c313dc4a5e9c3321f733197eca", + "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca", "shasum": "" }, "require": { @@ -3534,7 +3636,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.1.1" + "source": "https://github.com/symfony/process/tree/v7.1.3" }, "funding": [ { @@ -3550,7 +3652,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-07-26T12:44:47+00:00" }, { "name": "symfony/service-contracts", @@ -3637,16 +3739,16 @@ }, { "name": "symfony/string", - "version": "v7.1.2", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "14221089ac66cf82e3cf3d1c1da65de305587ff8" + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/14221089ac66cf82e3cf3d1c1da65de305587ff8", - "reference": "14221089ac66cf82e3cf3d1c1da65de305587ff8", + "url": "https://api.github.com/repos/symfony/string/zipball/ea272a882be7f20cad58d5d78c215001617b7f07", + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07", "shasum": "" }, "require": { @@ -3704,7 +3806,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.2" + "source": "https://github.com/symfony/string/tree/v7.1.3" }, "funding": [ { @@ -3720,7 +3822,7 @@ "type": "tidelift" } ], - "time": "2024-06-28T09:27:18+00:00" + "time": "2024-07-22T10:25:37+00:00" }, { "name": "theseer/tokenizer", @@ -3822,18 +3924,9 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [ - { - "package": "utopia-php/database", - "version": "dev-feat-framework-v2", - "alias": "0.49.99", - "alias_normalized": "0.49.99.0" - } - ], - "minimum-stability": "stable", - "stability-flags": { - "utopia-php/database": 20 - }, + "aliases": [], + "minimum-stability": "RC", + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { From 0059ae5daec97edd85276bb5c7eb501484b79ad5 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:14:29 -0400 Subject: [PATCH 15/48] chore: merge, lint --- composer.lock | 194 +++++++++++++++++----- src/Abuse/Adapters/Database/TimeLimit.php | 4 +- 2 files changed, 152 insertions(+), 46 deletions(-) diff --git a/composer.lock b/composer.lock index 152575410f..03a120a02e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6522b9fb8652f6801bd7c5664430c672", + "content-hash": "e6a6611ef5abc949f69ba822126ffd75", "packages": [ { "name": "jean85/pretty-package-versions", @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.0", + "version": "1.0.0-RC2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "2e116d544b14e8b2edfcb5b793d214136ff64f42" + "reference": "d70eb76c7cf5ee596752209a4d57e4d08fe8a986" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/2e116d544b14e8b2edfcb5b793d214136ff64f42", - "reference": "2e116d544b14e8b2edfcb5b793d214136ff64f42", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d70eb76c7cf5ee596752209a4d57e4d08fe8a986", + "reference": "d70eb76c7cf5ee596752209a4d57e4d08fe8a986", "shasum": "" }, "require": { @@ -283,7 +283,7 @@ "ext-pdo": "*", "php": ">=8.0", "utopia-php/cache": "0.10.*", - "utopia-php/framework": "0.33.*", + "utopia-php/framework": "1.0.*", "utopia-php/mongo": "0.3.*" }, "require-dev": { @@ -294,7 +294,7 @@ "phpunit/phpunit": "9.6.*", "rregeer/phpunit-coverage-check": "0.3.*", "swoole/ide-helper": "5.1.3", - "utopia-php/cli": "0.14.*" + "utopia-php/cli": "1.0.*" }, "type": "library", "autoload": { @@ -316,32 +316,84 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.0" + "source": "https://github.com/utopia-php/database/tree/1.0.0-RC2" }, - "time": "2024-08-30T04:32:56+00:00" + "time": "2024-09-04T17:58:16+00:00" }, { - "name": "utopia-php/framework", - "version": "0.33.8", + "name": "utopia-php/di", + "version": "0.1.0", "source": { "type": "git", - "url": "https://github.com/utopia-php/http.git", - "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5" + "url": "https://github.com/utopia-php/di.git", + "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/a7f577540a25cb90896fef2b64767bf8d700f3c5", - "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5", + "url": "https://api.github.com/repos/utopia-php/di/zipball/22490c95f7ac3898ed1c33f1b1b5dd577305ee31", + "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31", "shasum": "" }, "require": { - "php": ">=8.0" + "php": ">=8.2" }, "require-dev": { "laravel/pint": "^1.2", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25" + "phpunit/phpunit": "^9.5.25", + "swoole/ide-helper": "4.8.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\": "src/", + "Tests\\E2E\\": "tests/e2e" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A simple and lite library for managing dependency injections", + "keywords": [ + "framework", + "http", + "php", + "upf" + ], + "support": { + "issues": "https://github.com/utopia-php/di/issues", + "source": "https://github.com/utopia-php/di/tree/0.1.0" + }, + "time": "2024-08-08T14:35:19+00:00" + }, + { + "name": "utopia-php/framework", + "version": "1.0.0-RC2", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/http.git", + "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/http/zipball/d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", + "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", + "shasum": "" + }, + "require": { + "ext-swoole": "*", + "php": ">=8.0", + "utopia-php/servers": "0.1.* " + }, + "require-dev": { + "ext-xdebug": "*", + "laravel/pint": "^1.2", + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.5.25", + "swoole/ide-helper": "4.8.3" }, "type": "library", "autoload": { @@ -353,17 +405,18 @@ "license": [ "MIT" ], - "description": "A simple, light and advanced PHP framework", + "description": "A simple, light and advanced PHP HTTP framework", "keywords": [ "framework", + "http", "php", "upf" ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.8" + "source": "https://github.com/utopia-php/http/tree/1.0.0-RC2" }, - "time": "2024-08-15T14:10:09+00:00" + "time": "2024-08-08T14:46:41+00:00" }, { "name": "utopia-php/mongo", @@ -424,6 +477,59 @@ "source": "https://github.com/utopia-php/mongo/tree/0.3.1" }, "time": "2023-09-01T17:25:28+00:00" + }, + { + "name": "utopia-php/servers", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/servers.git", + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", + "shasum": "" + }, + "require": { + "php": ">=8.0", + "utopia-php/di": "0.1.*" + }, + "require-dev": { + "laravel/pint": "^0.2.3", + "phpstan/phpstan": "^1.8", + "phpunit/phpunit": "^9.5.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\Servers\\": "src/Servers" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Team Appwrite", + "email": "team@appwrite.io" + } + ], + "description": "A base library for building Utopia style servers.", + "keywords": [ + "framework", + "php", + "servers", + "upf", + "utopia" + ], + "support": { + "issues": "https://github.com/utopia-php/servers/issues", + "source": "https://github.com/utopia-php/servers/tree/0.1.0" + }, + "time": "2024-08-08T14:31:39+00:00" } ], "packages-dev": [ @@ -1155,16 +1261,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.0", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "384af967d35b2162f69526c7276acadce534d0e1" + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", - "reference": "384af967d35b2162f69526c7276acadce534d0e1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", "shasum": "" }, "require": { @@ -1209,7 +1315,7 @@ "type": "github" } ], - "time": "2024-08-27T09:18:05+00:00" + "time": "2024-09-03T19:55:22+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2814,16 +2920,16 @@ }, { "name": "symfony/console", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9" + "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", - "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", + "url": "https://api.github.com/repos/symfony/console/zipball/1eed7af6961d763e7832e874d7f9b21c3ea9c111", + "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111", "shasum": "" }, "require": { @@ -2887,7 +2993,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.3" + "source": "https://github.com/symfony/console/tree/v7.1.4" }, "funding": [ { @@ -2903,7 +3009,7 @@ "type": "tidelift" } ], - "time": "2024-07-26T12:41:01+00:00" + "time": "2024-08-15T22:48:53+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3040,16 +3146,16 @@ }, { "name": "symfony/finder", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "717c6329886f32dc65e27461f80f2a465412fdca" + "reference": "d95bbf319f7d052082fb7af147e0f835a695e823" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/717c6329886f32dc65e27461f80f2a465412fdca", - "reference": "717c6329886f32dc65e27461f80f2a465412fdca", + "url": "https://api.github.com/repos/symfony/finder/zipball/d95bbf319f7d052082fb7af147e0f835a695e823", + "reference": "d95bbf319f7d052082fb7af147e0f835a695e823", "shasum": "" }, "require": { @@ -3084,7 +3190,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.1.3" + "source": "https://github.com/symfony/finder/tree/v7.1.4" }, "funding": [ { @@ -3100,7 +3206,7 @@ "type": "tidelift" } ], - "time": "2024-07-24T07:08:44+00:00" + "time": "2024-08-13T14:28:19+00:00" }, { "name": "symfony/options-resolver", @@ -3633,16 +3739,16 @@ }, { "name": "symfony/string", - "version": "v7.1.3", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "ea272a882be7f20cad58d5d78c215001617b7f07" + "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/ea272a882be7f20cad58d5d78c215001617b7f07", - "reference": "ea272a882be7f20cad58d5d78c215001617b7f07", + "url": "https://api.github.com/repos/symfony/string/zipball/6cd670a6d968eaeb1c77c2e76091c45c56bc367b", + "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b", "shasum": "" }, "require": { @@ -3700,7 +3806,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.3" + "source": "https://github.com/symfony/string/tree/v7.1.4" }, "funding": [ { @@ -3716,7 +3822,7 @@ "type": "tidelift" } ], - "time": "2024-07-22T10:25:37+00:00" + "time": "2024-08-12T09:59:40+00:00" }, { "name": "theseer/tokenizer", @@ -3819,7 +3925,7 @@ } ], "aliases": [], - "minimum-stability": "stable", + "minimum-stability": "RC", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Abuse/Adapters/Database/TimeLimit.php b/src/Abuse/Adapters/Database/TimeLimit.php index e5940936f0..2527442cfb 100644 --- a/src/Abuse/Adapters/Database/TimeLimit.php +++ b/src/Abuse/Adapters/Database/TimeLimit.php @@ -128,7 +128,7 @@ class TimeLimit extends TimeLimitAdapter /** @var array $result */ $result = $this->db->getAuthorization()->skip(function () use ($key, $datetime) { - return $this->db->find(Database::COLLECTION, [ + return $this->db->find(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), ]); @@ -160,7 +160,7 @@ class TimeLimit extends TimeLimitAdapter } $this->db->getAuthorization()->skip(function () use ($datetime, $key) { - $data = $this->db->findOne(Database::COLLECTION, [ + $data = $this->db->findOne(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), ]); From 40080354a1b3c972b1680dfe27e6dbeb6556c0da Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:05:55 -0400 Subject: [PATCH 16/48] chore: updating to latest database --- composer.json | 2 +- composer.lock | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index 8842ebb964..ce4baf2f2b 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-pdo": "*", "ext-curl": "*", "ext-redis": "*", - "utopia-php/database": "1.0.*" + "utopia-php/database": "0.54.*" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index 03a120a02e..8ab1de626e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e6a6611ef5abc949f69ba822126ffd75", + "content-hash": "7601e6576cde00888812fb6e2e732dbe", "packages": [ { "name": "jean85/pretty-package-versions", @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "1.0.0-RC2", + "version": "0.54.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "d70eb76c7cf5ee596752209a4d57e4d08fe8a986" + "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/d70eb76c7cf5ee596752209a4d57e4d08fe8a986", - "reference": "d70eb76c7cf5ee596752209a4d57e4d08fe8a986", + "url": "https://api.github.com/repos/utopia-php/database/zipball/1e97fc8b212a8daf9b9a68244677ed34c9db143e", + "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e", "shasum": "" }, "require": { @@ -294,7 +294,7 @@ "phpunit/phpunit": "9.6.*", "rregeer/phpunit-coverage-check": "0.3.*", "swoole/ide-helper": "5.1.3", - "utopia-php/cli": "1.0.*" + "utopia-php/cli": "0.19.*" }, "type": "library", "autoload": { @@ -316,9 +316,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/1.0.0-RC2" + "source": "https://github.com/utopia-php/database/tree/0.54.0" }, - "time": "2024-09-04T17:58:16+00:00" + "time": "2024-09-05T16:00:42+00:00" }, { "name": "utopia-php/di", @@ -370,22 +370,22 @@ }, { "name": "utopia-php/framework", - "version": "1.0.0-RC2", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7" + "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", - "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", + "url": "https://api.github.com/repos/utopia-php/http/zipball/cc880ec41f7f163d4f9956fec26cc6be51b412cf", + "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf", "shasum": "" }, "require": { "ext-swoole": "*", "php": ">=8.0", - "utopia-php/servers": "0.1.* " + "utopia-php/servers": "0.1.*" }, "require-dev": { "ext-xdebug": "*", @@ -414,9 +414,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/1.0.0-RC2" + "source": "https://github.com/utopia-php/http/tree/1.0.0" }, - "time": "2024-08-08T14:46:41+00:00" + "time": "2024-09-05T15:38:08+00:00" }, { "name": "utopia-php/mongo", @@ -535,16 +535,16 @@ "packages-dev": [ { "name": "doctrine/annotations", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f" + "reference": "901c2ee5d26eb64ff43c47976e114bf00843acf7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f", - "reference": "e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/901c2ee5d26eb64ff43c47976e114bf00843acf7", + "reference": "901c2ee5d26eb64ff43c47976e114bf00843acf7", "shasum": "" }, "require": { @@ -556,10 +556,10 @@ "require-dev": { "doctrine/cache": "^2.0", "doctrine/coding-standard": "^10", - "phpstan/phpstan": "^1.8.0", + "phpstan/phpstan": "^1.10.28", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "symfony/cache": "^5.4 || ^6", - "vimeo/psalm": "^4.10" + "symfony/cache": "^5.4 || ^6.4 || ^7", + "vimeo/psalm": "^4.30 || ^5.14" }, "suggest": { "php": "PHP 8.0 or higher comes with attributes, a native replacement for annotations" @@ -605,9 +605,9 @@ ], "support": { "issues": "https://github.com/doctrine/annotations/issues", - "source": "https://github.com/doctrine/annotations/tree/2.0.1" + "source": "https://github.com/doctrine/annotations/tree/2.0.2" }, - "time": "2023-02-02T22:02:53+00:00" + "time": "2024-09-05T10:17:24+00:00" }, { "name": "doctrine/instantiator", From 6f0a7dc02a167c67fd3d8bfc298f9ff9b000a7c4 Mon Sep 17 00:00:00 2001 From: Binyamin Yawitz <316103+byawitz@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:08:08 -0400 Subject: [PATCH 17/48] chore: changing to stable --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ce4baf2f2b..823856bc1b 100755 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "keywords": ["php","framework", "upf", "utopia", "abuse"], "license": "MIT", - "minimum-stability": "RC", + "minimum-stability": "stable", "autoload": { "psr-4": {"Utopia\\Abuse\\": "src/Abuse"} }, From 1c7d4680b5d9a385a88c6b2f5622b3d4b3611bea Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Tue, 17 Sep 2024 18:20:53 +0900 Subject: [PATCH 18/48] Chore: findOne now returns empty documents instead of false on miss --- src/Abuse/Adapters/Database/TimeLimit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Abuse/Adapters/Database/TimeLimit.php b/src/Abuse/Adapters/Database/TimeLimit.php index 2527442cfb..0f1e779295 100644 --- a/src/Abuse/Adapters/Database/TimeLimit.php +++ b/src/Abuse/Adapters/Database/TimeLimit.php @@ -165,7 +165,7 @@ class TimeLimit extends TimeLimitAdapter Query::equal('time', [$datetime]), ]); - if ($data === false) { + if ($data->isEmpty()) { $data = [ '$permissions' => [], 'key' => $key, @@ -183,7 +183,7 @@ class TimeLimit extends TimeLimitAdapter Query::equal('time', [$datetime]), ]); - if ($data !== false && $data instanceof Document) { + if (!$data->isEmpty()) { $count = $data->getAttribute('count', 0); if (\is_numeric($count)) { $this->count = intval($count); From 4198352039d096c258d01e8e1442126069eba48c Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 18 Sep 2024 13:15:57 +0900 Subject: [PATCH 19/48] Chore: Update Database Library --- composer.json | 2 +- composer.lock | 144 +++++++++++++++++++++++++------------------------- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/composer.json b/composer.json index 823856bc1b..79685c2ffa 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-pdo": "*", "ext-curl": "*", "ext-redis": "*", - "utopia-php/database": "0.54.*" + "utopia-php/database": "0.55.*" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index 8ab1de626e..055b1ecad7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7601e6576cde00888812fb6e2e732dbe", + "content-hash": "4ae74a41329275b52e4722de01c60285", "packages": [ { "name": "jean85/pretty-package-versions", @@ -136,20 +136,20 @@ }, { "name": "symfony/polyfill-php80", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "77fa7995ac1b21ab60769b7323d600a991a90433" + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/77fa7995ac1b21ab60769b7323d600a991a90433", - "reference": "77fa7995ac1b21ab60769b7323d600a991a90433", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "type": "library", "extra": { @@ -196,7 +196,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" }, "funding": [ { @@ -212,7 +212,7 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "utopia-php/cache", @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "0.54.0", + "version": "0.55", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e" + "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/1e97fc8b212a8daf9b9a68244677ed34c9db143e", - "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e", + "url": "https://api.github.com/repos/utopia-php/database/zipball/0ad2eb1c163196cd79253c59f1896c5b03d6ba91", + "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91", "shasum": "" }, "require": { @@ -316,9 +316,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.54.0" + "source": "https://github.com/utopia-php/database/tree/0.55" }, - "time": "2024-09-05T16:00:42+00:00" + "time": "2024-09-18T04:00:12+00:00" }, { "name": "utopia-php/di", @@ -370,16 +370,16 @@ }, { "name": "utopia-php/framework", - "version": "1.0.0", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf" + "reference": "fc63ec61c720190a5ea5bb484c615145850951e6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/cc880ec41f7f163d4f9956fec26cc6be51b412cf", - "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf", + "url": "https://api.github.com/repos/utopia-php/http/zipball/fc63ec61c720190a5ea5bb484c615145850951e6", + "reference": "fc63ec61c720190a5ea5bb484c615145850951e6", "shasum": "" }, "require": { @@ -414,9 +414,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/1.0.0" + "source": "https://github.com/utopia-php/http/tree/1.0.2" }, - "time": "2024-09-05T15:38:08+00:00" + "time": "2024-09-10T09:04:19+00:00" }, { "name": "utopia-php/mongo", @@ -480,16 +480,16 @@ }, { "name": "utopia-php/servers", - "version": "0.1.0", + "version": "0.1.1", "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c" + "reference": "fd5c8d32778f265256c1936372a071b944f5ba8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", - "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/fd5c8d32778f265256c1936372a071b944f5ba8a", + "reference": "fd5c8d32778f265256c1936372a071b944f5ba8a", "shasum": "" }, "require": { @@ -527,9 +527,9 @@ ], "support": { "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/0.1.0" + "source": "https://github.com/utopia-php/servers/tree/0.1.1" }, - "time": "2024-08-08T14:31:39+00:00" + "time": "2024-09-06T02:25:56+00:00" } ], "packages-dev": [ @@ -884,16 +884,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.1.0", + "version": "v5.2.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" + "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", - "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", + "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", "shasum": "" }, "require": { @@ -936,9 +936,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.2.0" }, - "time": "2024-07-01T20:03:41+00:00" + "time": "2024-09-15T16:40:33+00:00" }, { "name": "phar-io/manifest", @@ -1261,16 +1261,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.1", + "version": "1.12.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" + "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0fcbf194ab63d8159bb70d9aa3e1350051632009", + "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009", "shasum": "" }, "require": { @@ -1315,7 +1315,7 @@ "type": "github" } ], - "time": "2024-09-03T19:55:22+00:00" + "time": "2024-09-09T08:10:35+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1843,16 +1843,16 @@ }, { "name": "psr/log", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "79dff0b268932c640297f5208d6298f71855c03e" + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/79dff0b268932c640297f5208d6298f71855c03e", - "reference": "79dff0b268932c640297f5208d6298f71855c03e", + "url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", + "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", "shasum": "" }, "require": { @@ -1887,9 +1887,9 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/3.0.1" + "source": "https://github.com/php-fig/log/tree/3.0.2" }, - "time": "2024-08-21T13:31:24+00:00" + "time": "2024-09-11T13:17:53+00:00" }, { "name": "sebastian/cli-parser", @@ -3277,20 +3277,20 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "0424dff1c58f028c451efff2045f5d92410bd540" + "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540", - "reference": "0424dff1c58f028c451efff2045f5d92410bd540", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638", + "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "provide": { "ext-ctype": "*" @@ -3336,7 +3336,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" }, "funding": [ { @@ -3352,24 +3352,24 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a" + "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/64647a7c30b2283f5d49b874d84a18fc22054b7a", - "reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", + "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "suggest": { "ext-intl": "For best performance" @@ -3414,7 +3414,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.31.0" }, "funding": [ { @@ -3430,24 +3430,24 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb" + "reference": "3833d7255cc303546435cb650316bff708a1c75c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/a95281b0be0d9ab48050ebd988b967875cdb9fdb", - "reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c", + "reference": "3833d7255cc303546435cb650316bff708a1c75c", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "suggest": { "ext-intl": "For best performance" @@ -3495,7 +3495,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.31.0" }, "funding": [ { @@ -3511,24 +3511,24 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c" + "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c", - "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341", + "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "provide": { "ext-mbstring": "*" @@ -3575,7 +3575,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0" }, "funding": [ { @@ -3591,7 +3591,7 @@ "type": "tidelift" } ], - "time": "2024-06-19T12:30:46+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/process", @@ -3925,7 +3925,7 @@ } ], "aliases": [], - "minimum-stability": "RC", + "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, From b76dd683c3e2877251aca4b38fd9c015911066fe Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 7 Oct 2024 19:07:20 +0000 Subject: [PATCH 20/48] chore: update db library --- composer.lock | 96 +++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/composer.lock b/composer.lock index 055b1ecad7..82030d2556 100644 --- a/composer.lock +++ b/composer.lock @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "0.55", + "version": "0.55.1", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91" + "reference": "6f44079999491feb0ef85686f6b2ac7ef54db828" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/0ad2eb1c163196cd79253c59f1896c5b03d6ba91", - "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91", + "url": "https://api.github.com/repos/utopia-php/database/zipball/6f44079999491feb0ef85686f6b2ac7ef54db828", + "reference": "6f44079999491feb0ef85686f6b2ac7ef54db828", "shasum": "" }, "require": { @@ -316,9 +316,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.55" + "source": "https://github.com/utopia-php/database/tree/0.55.1" }, - "time": "2024-09-18T04:00:12+00:00" + "time": "2024-10-07T18:52:26+00:00" }, { "name": "utopia-php/di", @@ -884,16 +884,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.2.0", + "version": "v5.3.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb" + "reference": "3abf7425cd284141dc5d8d14a9ee444de3345d1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", - "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/3abf7425cd284141dc5d8d14a9ee444de3345d1a", + "reference": "3abf7425cd284141dc5d8d14a9ee444de3345d1a", "shasum": "" }, "require": { @@ -936,9 +936,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.2.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.3.0" }, - "time": "2024-09-15T16:40:33+00:00" + "time": "2024-09-29T13:56:26+00:00" }, { "name": "phar-io/manifest", @@ -1261,16 +1261,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.3", + "version": "1.12.6", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009" + "reference": "dc4d2f145a88ea7141ae698effd64d9df46527ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0fcbf194ab63d8159bb70d9aa3e1350051632009", - "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc4d2f145a88ea7141ae698effd64d9df46527ae", + "reference": "dc4d2f145a88ea7141ae698effd64d9df46527ae", "shasum": "" }, "require": { @@ -1315,7 +1315,7 @@ "type": "github" } ], - "time": "2024-09-09T08:10:35+00:00" + "time": "2024-10-06T15:03:59+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1638,16 +1638,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.20", + "version": "9.6.21", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "49d7820565836236411f5dc002d16dd689cde42f" + "reference": "de6abf3b6f8dd955fac3caad3af7a9504e8c2ffa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/49d7820565836236411f5dc002d16dd689cde42f", - "reference": "49d7820565836236411f5dc002d16dd689cde42f", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/de6abf3b6f8dd955fac3caad3af7a9504e8c2ffa", + "reference": "de6abf3b6f8dd955fac3caad3af7a9504e8c2ffa", "shasum": "" }, "require": { @@ -1662,7 +1662,7 @@ "phar-io/manifest": "^2.0.4", "phar-io/version": "^3.2.1", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.31", + "phpunit/php-code-coverage": "^9.2.32", "phpunit/php-file-iterator": "^3.0.6", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.4", @@ -1721,7 +1721,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.20" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.21" }, "funding": [ { @@ -1737,7 +1737,7 @@ "type": "tidelift" } ], - "time": "2024-07-10T11:45:39+00:00" + "time": "2024-09-19T10:50:18+00:00" }, { "name": "psr/cache", @@ -2920,16 +2920,16 @@ }, { "name": "symfony/console", - "version": "v7.1.4", + "version": "v7.1.5", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111" + "reference": "0fa539d12b3ccf068a722bbbffa07ca7079af9ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/1eed7af6961d763e7832e874d7f9b21c3ea9c111", - "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111", + "url": "https://api.github.com/repos/symfony/console/zipball/0fa539d12b3ccf068a722bbbffa07ca7079af9ee", + "reference": "0fa539d12b3ccf068a722bbbffa07ca7079af9ee", "shasum": "" }, "require": { @@ -2993,7 +2993,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.4" + "source": "https://github.com/symfony/console/tree/v7.1.5" }, "funding": [ { @@ -3009,7 +3009,7 @@ "type": "tidelift" } ], - "time": "2024-08-15T22:48:53+00:00" + "time": "2024-09-20T08:28:38+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3080,16 +3080,16 @@ }, { "name": "symfony/filesystem", - "version": "v7.1.2", + "version": "v7.1.5", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "92a91985250c251de9b947a14bb2c9390b1a562c" + "reference": "61fe0566189bf32e8cfee78335d8776f64a66f5a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/92a91985250c251de9b947a14bb2c9390b1a562c", - "reference": "92a91985250c251de9b947a14bb2c9390b1a562c", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/61fe0566189bf32e8cfee78335d8776f64a66f5a", + "reference": "61fe0566189bf32e8cfee78335d8776f64a66f5a", "shasum": "" }, "require": { @@ -3126,7 +3126,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v7.1.2" + "source": "https://github.com/symfony/filesystem/tree/v7.1.5" }, "funding": [ { @@ -3142,7 +3142,7 @@ "type": "tidelift" } ], - "time": "2024-06-28T10:03:55+00:00" + "time": "2024-09-17T09:16:35+00:00" }, { "name": "symfony/finder", @@ -3595,16 +3595,16 @@ }, { "name": "symfony/process", - "version": "v7.1.3", + "version": "v7.1.5", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca" + "reference": "5c03ee6369281177f07f7c68252a280beccba847" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/7f2f542c668ad6c313dc4a5e9c3321f733197eca", - "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca", + "url": "https://api.github.com/repos/symfony/process/zipball/5c03ee6369281177f07f7c68252a280beccba847", + "reference": "5c03ee6369281177f07f7c68252a280beccba847", "shasum": "" }, "require": { @@ -3636,7 +3636,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.1.3" + "source": "https://github.com/symfony/process/tree/v7.1.5" }, "funding": [ { @@ -3652,7 +3652,7 @@ "type": "tidelift" } ], - "time": "2024-07-26T12:44:47+00:00" + "time": "2024-09-19T21:48:23+00:00" }, { "name": "symfony/service-contracts", @@ -3739,16 +3739,16 @@ }, { "name": "symfony/string", - "version": "v7.1.4", + "version": "v7.1.5", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b" + "reference": "d66f9c343fa894ec2037cc928381df90a7ad4306" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/6cd670a6d968eaeb1c77c2e76091c45c56bc367b", - "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b", + "url": "https://api.github.com/repos/symfony/string/zipball/d66f9c343fa894ec2037cc928381df90a7ad4306", + "reference": "d66f9c343fa894ec2037cc928381df90a7ad4306", "shasum": "" }, "require": { @@ -3806,7 +3806,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.4" + "source": "https://github.com/symfony/string/tree/v7.1.5" }, "funding": [ { @@ -3822,7 +3822,7 @@ "type": "tidelift" } ], - "time": "2024-08-12T09:59:40+00:00" + "time": "2024-09-20T08:28:38+00:00" }, { "name": "theseer/tokenizer", From 572c41680a6c2ef9530e468d9a9fffe66a3dceb2 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 17 Dec 2024 20:34:51 +0530 Subject: [PATCH 21/48] feat: add support for redis cluster --- composer.lock | 6 +- docker-compose.yml | 48 ++++++ phpunit.xml | 2 +- src/Abuse/Adapter.php | 4 +- src/Abuse/Adapters/TimeLimit.php | 2 - .../TimeLimit.php => TimeLimit/Database.php} | 28 ++-- .../TimeLimit.php => TimeLimit/Redis.php} | 15 +- src/Abuse/Adapters/TimeLimit/RedisCluster.php | 153 ++++++++++++++++++ tests/Abuse/Base.php | 2 +- tests/Abuse/DatabaseTest.php | 7 +- tests/Abuse/RedisClusterTest.php | 39 +++++ tests/Abuse/RedisTest.php | 7 +- 12 files changed, 276 insertions(+), 37 deletions(-) rename src/Abuse/Adapters/{Database/TimeLimit.php => TimeLimit/Database.php} (87%) rename src/Abuse/Adapters/{Redis/TimeLimit.php => TimeLimit/Redis.php} (90%) create mode 100644 src/Abuse/Adapters/TimeLimit/RedisCluster.php create mode 100644 tests/Abuse/RedisClusterTest.php diff --git a/composer.lock b/composer.lock index f8481d3db8..1769d6c2fb 100644 --- a/composer.lock +++ b/composer.lock @@ -758,13 +758,13 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.0.x-dev" - }, "spi": { "OpenTelemetry\\API\\Instrumentation\\AutoInstrumentation\\HookManagerInterface": [ "OpenTelemetry\\API\\Instrumentation\\AutoInstrumentation\\ExtensionHookManager" ] + }, + "branch-alias": { + "dev-main": "1.0.x-dev" } }, "autoload": { diff --git a/docker-compose.yml b/docker-compose.yml index 3e2b3faa35..0599ca8545 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,5 +30,53 @@ services: - ./src:/code/src - ./tests:/code/tests + redis-insight: + image: redis/redisinsight:latest + restart: unless-stopped + networks: + - abuse + environment: + - REDIS_HOSTS=redis-cluster-0:6379 + ports: + - "8081:5540" + + redis-cluster-0: + image: docker.io/bitnami/redis-cluster:7.4 + environment: + - ALLOW_EMPTY_PASSWORD=yes + - REDIS_NODES=redis-cluster-0 redis-cluster-1 redis-cluster-2 redis-cluster-3 + - REDIS_CLUSTER_CREATOR=yes + - REDIS_CLUSTER_REPLICAS=0 + networks: + - abuse + depends_on: + - redis-cluster-1 + - redis-cluster-2 + - redis-cluster-3 + + redis-cluster-1: + image: docker.io/bitnami/redis-cluster:7.4 + environment: + - ALLOW_EMPTY_PASSWORD=yes + - REDIS_NODES=redis-cluster-0 redis-cluster-1 redis-cluster-2 redis-cluster-3 + networks: + - abuse + + redis-cluster-2: + image: docker.io/bitnami/redis-cluster:7.4 + environment: + - ALLOW_EMPTY_PASSWORD=yes + - REDIS_NODES=redis-cluster-0 redis-cluster-1 redis-cluster-2 redis-cluster-3 + networks: + - abuse + + redis-cluster-3: + image: docker.io/bitnami/redis-cluster:7.4 + environment: + - ALLOW_EMPTY_PASSWORD=yes + - REDIS_NODES=redis-cluster-0 redis-cluster-1 redis-cluster-2 redis-cluster-3 + networks: + - abuse + networks: abuse: \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index ec39a7edea..10d408caa0 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/src/Abuse/Adapter.php b/src/Abuse/Adapter.php index 4af27dc40a..d78a06f9e2 100644 --- a/src/Abuse/Adapter.php +++ b/src/Abuse/Adapter.php @@ -70,11 +70,11 @@ abstract class Adapter * * Return logs with an offset and limit * - * @param int|null $offset + * @param int $offset * @param int|null $limit * @return array */ - abstract public function getLogs(?int $offset = null, ?int $limit = 25): array; + abstract public function getLogs(int $offset = 0, ?int $limit = 25): array; /** * Delete all logs older than $datetime diff --git a/src/Abuse/Adapters/TimeLimit.php b/src/Abuse/Adapters/TimeLimit.php index 8040dc3b9a..dcafee0835 100644 --- a/src/Abuse/Adapters/TimeLimit.php +++ b/src/Abuse/Adapters/TimeLimit.php @@ -37,8 +37,6 @@ abstract class TimeLimit extends Adapter abstract protected function hit(string $key, string $datetime): void; - - /** * Check * diff --git a/src/Abuse/Adapters/Database/TimeLimit.php b/src/Abuse/Adapters/TimeLimit/Database.php similarity index 87% rename from src/Abuse/Adapters/Database/TimeLimit.php rename to src/Abuse/Adapters/TimeLimit/Database.php index 47f7e899b7..a7ba5662c2 100644 --- a/src/Abuse/Adapters/Database/TimeLimit.php +++ b/src/Abuse/Adapters/TimeLimit/Database.php @@ -1,8 +1,8 @@ db->createCollection( - TimeLimit::COLLECTION, + self::COLLECTION, $attributes, $indexes ); @@ -138,7 +138,7 @@ class TimeLimit extends TimeLimitAdapter /** @var array $result */ $result = Authorization::skip(function () use ($key, $datetime) { - return $this->db->find(TimeLimit::COLLECTION, [ + return $this->db->find(self::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), ]); @@ -170,7 +170,7 @@ class TimeLimit extends TimeLimitAdapter } Authorization::skip(function () use ($datetime, $key) { - $data = $this->db->findOne(TimeLimit::COLLECTION, [ + $data = $this->db->findOne(self::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), ]); @@ -181,14 +181,14 @@ class TimeLimit extends TimeLimitAdapter 'key' => $key, 'time' => $datetime, 'count' => 1, - '$collection' => TimeLimit::COLLECTION, + '$collection' => self::COLLECTION, ]; try { - $this->db->createDocument(TimeLimit::COLLECTION, new Document($data)); + $this->db->createDocument(self::COLLECTION, new Document($data)); } catch (Duplicate $e) { // Duplicate in case of race condition - $data = $this->db->findOne(TimeLimit::COLLECTION, [ + $data = $this->db->findOne(self::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), ]); @@ -198,14 +198,14 @@ class TimeLimit extends TimeLimitAdapter if (\is_numeric($count)) { $this->count = intval($count); } - $this->db->increaseDocumentAttribute(TimeLimit::COLLECTION, $data->getId(), 'count'); + $this->db->increaseDocumentAttribute(self::COLLECTION, $data->getId(), 'count'); } else { throw new \Exception('Document Not Found'); } } } else { /** @var Document $data */ - $this->db->increaseDocumentAttribute(TimeLimit::COLLECTION, $data->getId(), 'count'); + $this->db->increaseDocumentAttribute(self::COLLECTION, $data->getId(), 'count'); } }); @@ -237,7 +237,7 @@ class TimeLimit extends TimeLimitAdapter $queries[] = Query::limit($limit); } - return $this->db->find(TimeLimit::COLLECTION, $queries); + return $this->db->find(self::COLLECTION, $queries); }); return $results; @@ -255,12 +255,12 @@ class TimeLimit extends TimeLimitAdapter { Authorization::skip(function () use ($datetime) { do { - $documents = $this->db->find(TimeLimit::COLLECTION, [ + $documents = $this->db->find(self::COLLECTION, [ Query::lessThan('time', $datetime), ]); foreach ($documents as $document) { - $this->db->deleteDocument(TimeLimit::COLLECTION, $document->getId()); + $this->db->deleteDocument(self::COLLECTION, $document->getId()); } } while (! empty($documents)); }); diff --git a/src/Abuse/Adapters/Redis/TimeLimit.php b/src/Abuse/Adapters/TimeLimit/Redis.php similarity index 90% rename from src/Abuse/Adapters/Redis/TimeLimit.php rename to src/Abuse/Adapters/TimeLimit/Redis.php index f2349212b3..1fbef43597 100644 --- a/src/Abuse/Adapters/Redis/TimeLimit.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -1,11 +1,11 @@ */ - public function getLogs(?int $offset = null, ?int $limit = 25): array + public function getLogs(int $offset = 0, ?int $limit = 25): array { // TODO limit potential is SCAN but needs cursor no offset - $cursor = null; - $keys = $this->redis->scan($cursor, self::NAMESPACE . '__*', $limit); + $keys = $this->redis->scan($offset, self::NAMESPACE . '__*', $limit); if (!$keys) { return []; } @@ -110,7 +109,7 @@ class TimeLimit extends TimeLimitAdapter { $iterator = null; while ($iterator !== 0) { - $keys = $this->redis->scan($iterator, self::NAMESPACE . '__*__*', 1000); + $keys = $this->redis->scan($iterator, self::NAMESPACE . '__*__*', 10); $keys = $this->filterKeys($keys ? $keys : [], (int) $datetime); $this->redis->del($keys); } diff --git a/src/Abuse/Adapters/TimeLimit/RedisCluster.php b/src/Abuse/Adapters/TimeLimit/RedisCluster.php new file mode 100644 index 0000000000..426dc22fd5 --- /dev/null +++ b/src/Abuse/Adapters/TimeLimit/RedisCluster.php @@ -0,0 +1,153 @@ +redis = $redis; + $this->key = $key; + $time = (int) \date('U', (int) (\floor(\time() / $seconds)) * $seconds); + $this->time = strval($time); + $this->limit = $limit; + } + + /** + * Undocumented function + * + * @param string $key + * @param string $datetime + * @return integer + */ + protected function count(string $key, string $datetime): int + { + if (0 == $this->limit) { // No limit no point for counting + return 0; + } + + if (! \is_null($this->count)) { // Get fetched result + return $this->count; + } + + /** @var string $count */ + $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime); + if (!$count) { + $this->count = 0; + } else { + $this->count = intval($count); + } + + return $this->count; + } + + /** + * @param string $key + * @param string $datetime + * @return void + * + */ + protected function hit(string $key, string $datetime): void + { + if (0 == $this->limit) { // No limit no point for counting + return; + } + + /** @var string $count */ + $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime); + if (!$count) { + $this->count = 0; + } else { + $this->count = intval($count); + } + + $this->redis->incr(self::NAMESPACE . '__'. $key .'__'. $datetime); + $this->count++; + } + + /** + * Get abuse logs + * + * Return logs with an offset and limit + * + * @param int $offset + * @param int|null $limit + * @return array + */ + public function getLogs(int $offset = 0, ?int $limit = 25): array + { + // TODO limit potential is SCAN but needs cursor no offset + $cursor = null; + $keys = $this->scan($cursor, self::NAMESPACE . '__*', $limit); + if (!$keys) { + return []; + } + + $logs = []; + foreach ($keys as $key) { + $logs[$key] = $this->redis->get($key); + } + return $logs; + } + + /** + * Delete all logs older than $datetime + * + * @param string $datetime + * @return bool + */ + public function cleanup(string $datetime): bool + { + $iterator = null; + $keys = $this->scan($iterator, self::NAMESPACE . '__*__*', 1000); + $keys = $this->filterKeys($keys ? $keys : [], (int) $datetime); + $this->redis->del($keys); + return true; + } + + /** + * Filter keys + * + * @param array $keys + * @param integer $timestamp + * @return array + */ + protected function filterKeys(array $keys, int $timestamp): array + { + $filteredKeys = []; + foreach ($keys as $key) { + $parts = explode('__', $key); + $keyTimestamp = (int)end($parts); // Assuming the last part is always the timestamp + if ($keyTimestamp < $timestamp) { + $filteredKeys[] = $key; + } + } + return $filteredKeys; + } + + protected function scan(&$testing, string $pattern, int $count): array|bool + { + $matches = []; + foreach ($this->redis->_masters() as $master) { + $cursor = null; + do { + $keys = $this->redis->scan($cursor, $master, $pattern, $count); + if ($keys !== false) { + $matches = array_merge($matches, $keys); + } + } while ($cursor > 0); + } + + return empty($matches) ? false : $matches; + } +} diff --git a/tests/Abuse/Base.php b/tests/Abuse/Base.php index 1b88f411f6..1eb9f0b7d3 100644 --- a/tests/Abuse/Base.php +++ b/tests/Abuse/Base.php @@ -63,7 +63,7 @@ abstract class Base extends TestCase $status = $this->abuse->cleanup($this->getCleanupDateTime()); $this->assertEquals($status, true); - // Check that there are no logs in the DB + // // Check that there are no logs in the DB $logs = $this->abuse->getLogs(0, 10); $this->assertEquals(0, \count($logs)); } diff --git a/tests/Abuse/DatabaseTest.php b/tests/Abuse/DatabaseTest.php index b3820e6aa4..3890da5fa4 100755 --- a/tests/Abuse/DatabaseTest.php +++ b/tests/Abuse/DatabaseTest.php @@ -5,7 +5,7 @@ namespace Utopia\Tests; use PDO; use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapter; -use Utopia\Abuse\Adapters\Database\TimeLimit as AdaptersDatabase; +use Utopia\Abuse\Adapters\TimeLimit\Database as TimeLimitDatabase; use Utopia\Cache\Adapter\None as NoCache; use Utopia\Cache\Cache; use Utopia\Database\Adapter\MariaDB; @@ -37,7 +37,7 @@ class DatabaseTest extends Base $db->setNamespace('namespace'); $this->db = $db; - $adapter = new AdaptersDatabase('login-attempt-from-{{ip}}', 3, 60 * 5, $db); + $adapter = new TimeLimitDatabase('login-attempt-from-{{ip}}', 3, 60 * 5, $db); if (! $db->exists('utopiaTests')) { $db->create(); $adapter->setup(); @@ -45,11 +45,12 @@ 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 { - return new AdaptersDatabase($key, $limit, $seconds, $this->db); + return new TimeLimitDatabase($key, $limit, $seconds, $this->db); } public function getCleanupDateTime(): string diff --git a/tests/Abuse/RedisClusterTest.php b/tests/Abuse/RedisClusterTest.php new file mode 100644 index 0000000000..9287670479 --- /dev/null +++ b/tests/Abuse/RedisClusterTest.php @@ -0,0 +1,39 @@ +redis = new RedisCluster(null, ['redis-cluster-0:6379', 'redis-cluster-1:6379', 'redis-cluster-2:6379', 'redis-cluster-3:6379']); + $adapter = new TimeLimitRedisCluster('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 + { + return new TimeLimitRedisCluster($key, $limit, $seconds, $this->redis); + } + + public function getCleanupDateTime(): string + { + $interval = DateInterval::createFromDateString(1 . ' seconds'); + return strval((new \DateTime())->sub($interval)->getTimestamp()); + } +} diff --git a/tests/Abuse/RedisTest.php b/tests/Abuse/RedisTest.php index 517ee94777..b39bc953c8 100644 --- a/tests/Abuse/RedisTest.php +++ b/tests/Abuse/RedisTest.php @@ -6,7 +6,7 @@ use DateInterval; use Redis as Client; use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapter; -use Utopia\Abuse\Adapters\Redis\TimeLimit; +use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimitRedis; use Utopia\Exception; class RedisTest extends Base @@ -21,14 +21,15 @@ class RedisTest extends Base { $this->redis = new Client(); $this->redis->connect('redis', 6379); - $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $this->redis); + $adapter = new TimeLimitRedis('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 { - return new TimeLimit($key, $limit, $seconds, $this->redis); + return new TimeLimitRedis($key, $limit, $seconds, $this->redis); } public function getCleanupDateTime(): string From 3b78c863cc8590f24b064eb56e8aa519f31a65e0 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 17 Dec 2024 20:38:02 +0530 Subject: [PATCH 22/48] feat: cleanup --- src/Abuse/Adapters/TimeLimit/Redis.php | 7 ++++--- tests/Abuse/Base.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index 1fbef43597..11cbd4747c 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -80,13 +80,14 @@ class Redis extends TimeLimit * * Return logs with an offset and limit * - * @param int $offset + * @param int|null $offset * @param int|null $limit * @return array */ - public function getLogs(int $offset = 0, ?int $limit = 25): array + public function getLogs(?int $offset = null, ?int $limit = 25): array { // TODO limit potential is SCAN but needs cursor no offset + $cursor = null; $keys = $this->redis->scan($offset, self::NAMESPACE . '__*', $limit); if (!$keys) { return []; @@ -109,7 +110,7 @@ class Redis extends TimeLimit { $iterator = null; while ($iterator !== 0) { - $keys = $this->redis->scan($iterator, self::NAMESPACE . '__*__*', 10); + $keys = $this->redis->scan($iterator, self::NAMESPACE . '__*__*', 1000); $keys = $this->filterKeys($keys ? $keys : [], (int) $datetime); $this->redis->del($keys); } diff --git a/tests/Abuse/Base.php b/tests/Abuse/Base.php index 1eb9f0b7d3..1b88f411f6 100644 --- a/tests/Abuse/Base.php +++ b/tests/Abuse/Base.php @@ -63,7 +63,7 @@ abstract class Base extends TestCase $status = $this->abuse->cleanup($this->getCleanupDateTime()); $this->assertEquals($status, true); - // // Check that there are no logs in the DB + // Check that there are no logs in the DB $logs = $this->abuse->getLogs(0, 10); $this->assertEquals(0, \count($logs)); } From 9b338b6d06a5bb8ea0c824e36abc51128e7ea292 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 17 Dec 2024 20:39:50 +0530 Subject: [PATCH 23/48] feat: cleanup --- src/Abuse/Adapter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Abuse/Adapter.php b/src/Abuse/Adapter.php index d78a06f9e2..4af27dc40a 100644 --- a/src/Abuse/Adapter.php +++ b/src/Abuse/Adapter.php @@ -70,11 +70,11 @@ abstract class Adapter * * Return logs with an offset and limit * - * @param int $offset + * @param int|null $offset * @param int|null $limit * @return array */ - abstract public function getLogs(int $offset = 0, ?int $limit = 25): array; + abstract public function getLogs(?int $offset = null, ?int $limit = 25): array; /** * Delete all logs older than $datetime From 1dfcdaca0e7cb86e4482bda77f43bf40bc8be4d0 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 17 Dec 2024 20:41:16 +0530 Subject: [PATCH 24/48] feat: cleanup --- src/Abuse/Adapters/TimeLimit/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index 11cbd4747c..783f5884ed 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -88,7 +88,7 @@ class Redis extends TimeLimit { // TODO limit potential is SCAN but needs cursor no offset $cursor = null; - $keys = $this->redis->scan($offset, self::NAMESPACE . '__*', $limit); + $keys = $this->redis->scan($cursor, self::NAMESPACE . '__*', $limit); if (!$keys) { return []; } From aa15eda877a17364e3184b0b7bb4ffbb3f081736 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 17 Dec 2024 20:41:56 +0530 Subject: [PATCH 25/48] feat: cleanup --- tests/Abuse/DatabaseTest.php | 6 +++--- tests/Abuse/RedisClusterTest.php | 6 +++--- tests/Abuse/RedisTest.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Abuse/DatabaseTest.php b/tests/Abuse/DatabaseTest.php index 3890da5fa4..f4a9252caa 100755 --- a/tests/Abuse/DatabaseTest.php +++ b/tests/Abuse/DatabaseTest.php @@ -5,7 +5,7 @@ namespace Utopia\Tests; use PDO; use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapter; -use Utopia\Abuse\Adapters\TimeLimit\Database as TimeLimitDatabase; +use Utopia\Abuse\Adapters\TimeLimit\Database as TimeLimit; use Utopia\Cache\Adapter\None as NoCache; use Utopia\Cache\Cache; use Utopia\Database\Adapter\MariaDB; @@ -37,7 +37,7 @@ class DatabaseTest extends Base $db->setNamespace('namespace'); $this->db = $db; - $adapter = new TimeLimitDatabase('login-attempt-from-{{ip}}', 3, 60 * 5, $db); + $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db); if (! $db->exists('utopiaTests')) { $db->create(); $adapter->setup(); @@ -50,7 +50,7 @@ class DatabaseTest extends Base public function getAdapter(string $key, int $limit, int $seconds): Adapter { - return new TimeLimitDatabase($key, $limit, $seconds, $this->db); + return new TimeLimit($key, $limit, $seconds, $this->db); } public function getCleanupDateTime(): string diff --git a/tests/Abuse/RedisClusterTest.php b/tests/Abuse/RedisClusterTest.php index 9287670479..3d39c56667 100644 --- a/tests/Abuse/RedisClusterTest.php +++ b/tests/Abuse/RedisClusterTest.php @@ -6,7 +6,7 @@ use DateInterval; use RedisCluster; use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapter; -use Utopia\Abuse\Adapters\TimeLimit\RedisCluster as TimeLimitRedisCluster; +use Utopia\Abuse\Adapters\TimeLimit\RedisCluster as TimeLimit; use Utopia\Exception; class RedisClusterTest extends Base @@ -20,7 +20,7 @@ class RedisClusterTest extends Base public function setUp(): void { $this->redis = new RedisCluster(null, ['redis-cluster-0:6379', 'redis-cluster-1:6379', 'redis-cluster-2:6379', 'redis-cluster-3:6379']); - $adapter = new TimeLimitRedisCluster('login-attempt-from-{{ip}}', 3, 1, $this->redis); + $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()); @@ -28,7 +28,7 @@ class RedisClusterTest extends Base public function getAdapter(string $key, int $limit, int $seconds): Adapter { - return new TimeLimitRedisCluster($key, $limit, $seconds, $this->redis); + return new TimeLimit($key, $limit, $seconds, $this->redis); } public function getCleanupDateTime(): string diff --git a/tests/Abuse/RedisTest.php b/tests/Abuse/RedisTest.php index b39bc953c8..8423db8608 100644 --- a/tests/Abuse/RedisTest.php +++ b/tests/Abuse/RedisTest.php @@ -6,7 +6,7 @@ use DateInterval; use Redis as Client; use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapter; -use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimitRedis; +use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimit; use Utopia\Exception; class RedisTest extends Base @@ -21,7 +21,7 @@ class RedisTest extends Base { $this->redis = new Client(); $this->redis->connect('redis', 6379); - $adapter = new TimeLimitRedis('login-attempt-from-{{ip}}', 3, 1, $this->redis); + $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()); @@ -29,7 +29,7 @@ class RedisTest extends Base public function getAdapter(string $key, int $limit, int $seconds): Adapter { - return new TimeLimitRedis($key, $limit, $seconds, $this->redis); + return new TimeLimit($key, $limit, $seconds, $this->redis); } public function getCleanupDateTime(): string From 76fc3da33bea752165a34911ba6d16a04fca2dd7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 18 Dec 2024 10:46:03 +0530 Subject: [PATCH 26/48] fix: codeql --- composer.lock | 10 ++-- src/Abuse/Adapters/TimeLimit/Redis.php | 7 ++- src/Abuse/Adapters/TimeLimit/RedisCluster.php | 54 +++++++++++-------- tests/Abuse/Bench/Database/TimeLimitBench.php | 2 +- tests/Abuse/Bench/Redis/TimeLimitBench.php | 2 +- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/composer.lock b/composer.lock index 1769d6c2fb..0ec24c8c21 100644 --- a/composer.lock +++ b/composer.lock @@ -3040,16 +3040,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.12", + "version": "1.12.13", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0" + "reference": "9b469068840cfa031e1deaf2fa1886d00e20680f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", - "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9b469068840cfa031e1deaf2fa1886d00e20680f", + "reference": "9b469068840cfa031e1deaf2fa1886d00e20680f", "shasum": "" }, "require": { @@ -3094,7 +3094,7 @@ "type": "github" } ], - "time": "2024-11-28T22:13:23+00:00" + "time": "2024-12-17T17:00:20+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index 783f5884ed..3657a570d5 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -2,7 +2,6 @@ namespace Utopia\Abuse\Adapters\TimeLimit; -use Redis as Client; use Utopia\Abuse\Adapters\TimeLimit; class Redis extends TimeLimit @@ -10,11 +9,11 @@ class Redis extends TimeLimit public const NAMESPACE = 'abuse'; /** - * @var Client + * @var \Redis */ - protected Client $redis; + protected \Redis $redis; - public function __construct(string $key, int $limit, int $seconds, Client $redis) + public function __construct(string $key, int $limit, int $seconds, \Redis $redis) { $this->redis = $redis; $this->key = $key; diff --git a/src/Abuse/Adapters/TimeLimit/RedisCluster.php b/src/Abuse/Adapters/TimeLimit/RedisCluster.php index 426dc22fd5..24145d2b4b 100644 --- a/src/Abuse/Adapters/TimeLimit/RedisCluster.php +++ b/src/Abuse/Adapters/TimeLimit/RedisCluster.php @@ -2,7 +2,6 @@ namespace Utopia\Abuse\Adapters\TimeLimit; -use RedisCluster as Client; use Utopia\Abuse\Adapters\TimeLimit; class RedisCluster extends TimeLimit @@ -10,11 +9,11 @@ class RedisCluster extends TimeLimit public const NAMESPACE = 'abuse'; /** - * @var Client + * @var \RedisCluster */ - protected Client $redis; + protected \RedisCluster $redis; - public function __construct(string $key, int $limit, int $seconds, Client $redis) + public function __construct(string $key, int $limit, int $seconds, \RedisCluster $redis) { $this->redis = $redis; $this->key = $key; @@ -23,8 +22,8 @@ class RedisCluster extends TimeLimit $this->limit = $limit; } - /** - * Undocumented function + /** + * Get count for a key at specific datetime * * @param string $key * @param string $datetime @@ -40,9 +39,9 @@ class RedisCluster extends TimeLimit return $this->count; } - /** @var string $count */ + /** @var string|false $count */ $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime); - if (!$count) { + if ($count === false) { $this->count = 0; } else { $this->count = intval($count); @@ -52,10 +51,11 @@ class RedisCluster extends TimeLimit } /** - * @param string $key - * @param string $datetime - * @return void + * Record a hit for a key at specific datetime * + * @param string $key + * @param string $datetime + * @return void */ protected function hit(string $key, string $datetime): void { @@ -63,9 +63,9 @@ class RedisCluster extends TimeLimit return; } - /** @var string $count */ + /** @var string|false $count */ $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime); - if (!$count) { + if ($count === false) { $this->count = 0; } else { $this->count = intval($count); @@ -80,16 +80,15 @@ class RedisCluster extends TimeLimit * * Return logs with an offset and limit * - * @param int $offset - * @param int|null $limit + * @param int|null $offset + * @param int|null $limit * @return array */ - public function getLogs(int $offset = 0, ?int $limit = 25): array + public function getLogs(?int $offset = 0, ?int $limit = 25): array { // TODO limit potential is SCAN but needs cursor no offset - $cursor = null; - $keys = $this->scan($cursor, self::NAMESPACE . '__*', $limit); - if (!$keys) { + $keys = $this->scan(self::NAMESPACE . '__*', $offset, $limit); + if ($keys === false) { return []; } @@ -103,14 +102,14 @@ class RedisCluster extends TimeLimit /** * Delete all logs older than $datetime * - * @param string $datetime + * @param string $datetime * @return bool */ public function cleanup(string $datetime): bool { - $iterator = null; - $keys = $this->scan($iterator, self::NAMESPACE . '__*__*', 1000); + $keys = $this->scan(self::NAMESPACE . '__*__*'); $keys = $this->filterKeys($keys ? $keys : [], (int) $datetime); + /** @phpstan-ignore-next-line */ $this->redis->del($keys); return true; } @@ -135,12 +134,21 @@ class RedisCluster extends TimeLimit return $filteredKeys; } - protected function scan(&$testing, string $pattern, int $count): array|bool + /** + * Scan keys across all masters in the Redis cluster + * + * @param string $pattern Pattern to match keys + * @param int|null $cursor Reference to the cursor for scanning + * @param int|null $count Number of keys to return per iteration + * @return array|false + */ + protected function scan(string $pattern, ?int &$cursor = null, ?int $count = 1000): array|false { $matches = []; foreach ($this->redis->_masters() as $master) { $cursor = null; do { + /** @phpstan-ignore-next-line */ $keys = $this->redis->scan($cursor, $master, $pattern, $count); if ($keys !== false) { $matches = array_merge($matches, $keys); diff --git a/tests/Abuse/Bench/Database/TimeLimitBench.php b/tests/Abuse/Bench/Database/TimeLimitBench.php index e2a110c6b7..0525c44d81 100644 --- a/tests/Abuse/Bench/Database/TimeLimitBench.php +++ b/tests/Abuse/Bench/Database/TimeLimitBench.php @@ -4,7 +4,7 @@ namespace Abuse\Bench\Database; use PDO; use Utopia\Abuse\Abuse; -use Utopia\Abuse\Adapters\Database\TimeLimit; +use Utopia\Abuse\Adapters\TimeLimit\Database as TimeLimit; use Utopia\Cache\Adapter\None as NoCache; use Utopia\Cache\Cache; use Utopia\Database\Adapter\MariaDB; diff --git a/tests/Abuse/Bench/Redis/TimeLimitBench.php b/tests/Abuse/Bench/Redis/TimeLimitBench.php index 0d8cdb771d..3fdccfb811 100644 --- a/tests/Abuse/Bench/Redis/TimeLimitBench.php +++ b/tests/Abuse/Bench/Redis/TimeLimitBench.php @@ -4,7 +4,7 @@ namespace Abuse\Bench\Redis; use Redis as Client; use Utopia\Abuse\Abuse; -use Utopia\Abuse\Adapters\Redis\TimeLimit; +use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimit; use Utopia\Tests\Bench\Base; final class TimeLimitBench extends Base From 2663547e4216d423ad226c1b2f6680d02e936d9b Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 18 Dec 2024 11:36:01 +0530 Subject: [PATCH 27/48] fix: tests --- docker-compose.yml | 9 +++++++ tests/Abuse/Base.php | 4 ++-- .../TimeLimitBench.php => Database.php} | 4 ++-- .../{Redis/TimeLimitBench.php => Redis.php} | 4 ++-- tests/Abuse/Bench/RedisCluster.php | 24 +++++++++++++++++++ tests/Abuse/DatabaseTest.php | 3 +-- tests/Abuse/RedisClusterTest.php | 3 +-- tests/Abuse/RedisTest.php | 3 +-- 8 files changed, 42 insertions(+), 12 deletions(-) rename tests/Abuse/Bench/{Database/TimeLimitBench.php => Database.php} (94%) rename tests/Abuse/Bench/{Redis/TimeLimitBench.php => Redis.php} (87%) create mode 100644 tests/Abuse/Bench/RedisCluster.php diff --git a/docker-compose.yml b/docker-compose.yml index 0599ca8545..a139da027b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/tests/Abuse/Base.php b/tests/Abuse/Base.php index 1b88f411f6..2b7e291bed 100644 --- a/tests/Abuse/Base.php +++ b/tests/Abuse/Base.php @@ -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()); diff --git a/tests/Abuse/Bench/Database/TimeLimitBench.php b/tests/Abuse/Bench/Database.php similarity index 94% rename from tests/Abuse/Bench/Database/TimeLimitBench.php rename to tests/Abuse/Bench/Database.php index 0525c44d81..a24c9ed4a7 100644 --- a/tests/Abuse/Bench/Database/TimeLimitBench.php +++ b/tests/Abuse/Bench/Database.php @@ -1,6 +1,6 @@ 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); + } +} diff --git a/tests/Abuse/DatabaseTest.php b/tests/Abuse/DatabaseTest.php index f4a9252caa..8ca37426bf 100755 --- a/tests/Abuse/DatabaseTest.php +++ b/tests/Abuse/DatabaseTest.php @@ -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()); } } diff --git a/tests/Abuse/RedisClusterTest.php b/tests/Abuse/RedisClusterTest.php index 3d39c56667..ba1a60da96 100644 --- a/tests/Abuse/RedisClusterTest.php +++ b/tests/Abuse/RedisClusterTest.php @@ -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()); } } diff --git a/tests/Abuse/RedisTest.php b/tests/Abuse/RedisTest.php index 8423db8608..e0bf69858a 100644 --- a/tests/Abuse/RedisTest.php +++ b/tests/Abuse/RedisTest.php @@ -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()); } } From 627d1ba56451dd70ca26a1253c42e039b4bfc1a7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 18 Dec 2024 11:38:34 +0530 Subject: [PATCH 28/48] fix: tests --- tests/Abuse/Bench/RedisCluster.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Abuse/Bench/RedisCluster.php b/tests/Abuse/Bench/RedisCluster.php index 5367557ae4..74b730e70f 100644 --- a/tests/Abuse/Bench/RedisCluster.php +++ b/tests/Abuse/Bench/RedisCluster.php @@ -4,7 +4,6 @@ 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; From b3e9735cb3dd9298ac93b0f2ec1377cfc6054a79 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 18 Dec 2024 20:10:18 +0530 Subject: [PATCH 29/48] Revert "chore: update db library" --- composer.lock | 96 +++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/composer.lock b/composer.lock index 82030d2556..055b1ecad7 100644 --- a/composer.lock +++ b/composer.lock @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "0.55.1", + "version": "0.55", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "6f44079999491feb0ef85686f6b2ac7ef54db828" + "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/6f44079999491feb0ef85686f6b2ac7ef54db828", - "reference": "6f44079999491feb0ef85686f6b2ac7ef54db828", + "url": "https://api.github.com/repos/utopia-php/database/zipball/0ad2eb1c163196cd79253c59f1896c5b03d6ba91", + "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91", "shasum": "" }, "require": { @@ -316,9 +316,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.55.1" + "source": "https://github.com/utopia-php/database/tree/0.55" }, - "time": "2024-10-07T18:52:26+00:00" + "time": "2024-09-18T04:00:12+00:00" }, { "name": "utopia-php/di", @@ -884,16 +884,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.3.0", + "version": "v5.2.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "3abf7425cd284141dc5d8d14a9ee444de3345d1a" + "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/3abf7425cd284141dc5d8d14a9ee444de3345d1a", - "reference": "3abf7425cd284141dc5d8d14a9ee444de3345d1a", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", + "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", "shasum": "" }, "require": { @@ -936,9 +936,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.3.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.2.0" }, - "time": "2024-09-29T13:56:26+00:00" + "time": "2024-09-15T16:40:33+00:00" }, { "name": "phar-io/manifest", @@ -1261,16 +1261,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.6", + "version": "1.12.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "dc4d2f145a88ea7141ae698effd64d9df46527ae" + "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc4d2f145a88ea7141ae698effd64d9df46527ae", - "reference": "dc4d2f145a88ea7141ae698effd64d9df46527ae", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0fcbf194ab63d8159bb70d9aa3e1350051632009", + "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009", "shasum": "" }, "require": { @@ -1315,7 +1315,7 @@ "type": "github" } ], - "time": "2024-10-06T15:03:59+00:00" + "time": "2024-09-09T08:10:35+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1638,16 +1638,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.21", + "version": "9.6.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "de6abf3b6f8dd955fac3caad3af7a9504e8c2ffa" + "reference": "49d7820565836236411f5dc002d16dd689cde42f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/de6abf3b6f8dd955fac3caad3af7a9504e8c2ffa", - "reference": "de6abf3b6f8dd955fac3caad3af7a9504e8c2ffa", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/49d7820565836236411f5dc002d16dd689cde42f", + "reference": "49d7820565836236411f5dc002d16dd689cde42f", "shasum": "" }, "require": { @@ -1662,7 +1662,7 @@ "phar-io/manifest": "^2.0.4", "phar-io/version": "^3.2.1", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.32", + "phpunit/php-code-coverage": "^9.2.31", "phpunit/php-file-iterator": "^3.0.6", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.4", @@ -1721,7 +1721,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.21" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.20" }, "funding": [ { @@ -1737,7 +1737,7 @@ "type": "tidelift" } ], - "time": "2024-09-19T10:50:18+00:00" + "time": "2024-07-10T11:45:39+00:00" }, { "name": "psr/cache", @@ -2920,16 +2920,16 @@ }, { "name": "symfony/console", - "version": "v7.1.5", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "0fa539d12b3ccf068a722bbbffa07ca7079af9ee" + "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/0fa539d12b3ccf068a722bbbffa07ca7079af9ee", - "reference": "0fa539d12b3ccf068a722bbbffa07ca7079af9ee", + "url": "https://api.github.com/repos/symfony/console/zipball/1eed7af6961d763e7832e874d7f9b21c3ea9c111", + "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111", "shasum": "" }, "require": { @@ -2993,7 +2993,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.5" + "source": "https://github.com/symfony/console/tree/v7.1.4" }, "funding": [ { @@ -3009,7 +3009,7 @@ "type": "tidelift" } ], - "time": "2024-09-20T08:28:38+00:00" + "time": "2024-08-15T22:48:53+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3080,16 +3080,16 @@ }, { "name": "symfony/filesystem", - "version": "v7.1.5", + "version": "v7.1.2", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "61fe0566189bf32e8cfee78335d8776f64a66f5a" + "reference": "92a91985250c251de9b947a14bb2c9390b1a562c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/61fe0566189bf32e8cfee78335d8776f64a66f5a", - "reference": "61fe0566189bf32e8cfee78335d8776f64a66f5a", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/92a91985250c251de9b947a14bb2c9390b1a562c", + "reference": "92a91985250c251de9b947a14bb2c9390b1a562c", "shasum": "" }, "require": { @@ -3126,7 +3126,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v7.1.5" + "source": "https://github.com/symfony/filesystem/tree/v7.1.2" }, "funding": [ { @@ -3142,7 +3142,7 @@ "type": "tidelift" } ], - "time": "2024-09-17T09:16:35+00:00" + "time": "2024-06-28T10:03:55+00:00" }, { "name": "symfony/finder", @@ -3595,16 +3595,16 @@ }, { "name": "symfony/process", - "version": "v7.1.5", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "5c03ee6369281177f07f7c68252a280beccba847" + "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/5c03ee6369281177f07f7c68252a280beccba847", - "reference": "5c03ee6369281177f07f7c68252a280beccba847", + "url": "https://api.github.com/repos/symfony/process/zipball/7f2f542c668ad6c313dc4a5e9c3321f733197eca", + "reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca", "shasum": "" }, "require": { @@ -3636,7 +3636,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.1.5" + "source": "https://github.com/symfony/process/tree/v7.1.3" }, "funding": [ { @@ -3652,7 +3652,7 @@ "type": "tidelift" } ], - "time": "2024-09-19T21:48:23+00:00" + "time": "2024-07-26T12:44:47+00:00" }, { "name": "symfony/service-contracts", @@ -3739,16 +3739,16 @@ }, { "name": "symfony/string", - "version": "v7.1.5", + "version": "v7.1.4", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "d66f9c343fa894ec2037cc928381df90a7ad4306" + "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/d66f9c343fa894ec2037cc928381df90a7ad4306", - "reference": "d66f9c343fa894ec2037cc928381df90a7ad4306", + "url": "https://api.github.com/repos/symfony/string/zipball/6cd670a6d968eaeb1c77c2e76091c45c56bc367b", + "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b", "shasum": "" }, "require": { @@ -3806,7 +3806,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.5" + "source": "https://github.com/symfony/string/tree/v7.1.4" }, "funding": [ { @@ -3822,7 +3822,7 @@ "type": "tidelift" } ], - "time": "2024-09-20T08:28:38+00:00" + "time": "2024-08-12T09:59:40+00:00" }, { "name": "theseer/tokenizer", From 9760fee979d6aa7fdabec7a465f00e977c953654 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 18 Dec 2024 20:13:09 +0530 Subject: [PATCH 30/48] Revert "Chore: findOne now returns empty documents instead of false on miss" --- composer.json | 2 +- composer.lock | 144 +++++++++++----------- src/Abuse/Adapters/Database/TimeLimit.php | 4 +- 3 files changed, 75 insertions(+), 75 deletions(-) diff --git a/composer.json b/composer.json index 79685c2ffa..823856bc1b 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-pdo": "*", "ext-curl": "*", "ext-redis": "*", - "utopia-php/database": "0.55.*" + "utopia-php/database": "0.54.*" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index 055b1ecad7..8ab1de626e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4ae74a41329275b52e4722de01c60285", + "content-hash": "7601e6576cde00888812fb6e2e732dbe", "packages": [ { "name": "jean85/pretty-package-versions", @@ -136,20 +136,20 @@ }, { "name": "symfony/polyfill-php80", - "version": "v1.31.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" + "reference": "77fa7995ac1b21ab60769b7323d600a991a90433" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", - "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/77fa7995ac1b21ab60769b7323d600a991a90433", + "reference": "77fa7995ac1b21ab60769b7323d600a991a90433", "shasum": "" }, "require": { - "php": ">=7.2" + "php": ">=7.1" }, "type": "library", "extra": { @@ -196,7 +196,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.30.0" }, "funding": [ { @@ -212,7 +212,7 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "utopia-php/cache", @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "0.55", + "version": "0.54.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91" + "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/0ad2eb1c163196cd79253c59f1896c5b03d6ba91", - "reference": "0ad2eb1c163196cd79253c59f1896c5b03d6ba91", + "url": "https://api.github.com/repos/utopia-php/database/zipball/1e97fc8b212a8daf9b9a68244677ed34c9db143e", + "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e", "shasum": "" }, "require": { @@ -316,9 +316,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.55" + "source": "https://github.com/utopia-php/database/tree/0.54.0" }, - "time": "2024-09-18T04:00:12+00:00" + "time": "2024-09-05T16:00:42+00:00" }, { "name": "utopia-php/di", @@ -370,16 +370,16 @@ }, { "name": "utopia-php/framework", - "version": "1.0.2", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "fc63ec61c720190a5ea5bb484c615145850951e6" + "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/fc63ec61c720190a5ea5bb484c615145850951e6", - "reference": "fc63ec61c720190a5ea5bb484c615145850951e6", + "url": "https://api.github.com/repos/utopia-php/http/zipball/cc880ec41f7f163d4f9956fec26cc6be51b412cf", + "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf", "shasum": "" }, "require": { @@ -414,9 +414,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/1.0.2" + "source": "https://github.com/utopia-php/http/tree/1.0.0" }, - "time": "2024-09-10T09:04:19+00:00" + "time": "2024-09-05T15:38:08+00:00" }, { "name": "utopia-php/mongo", @@ -480,16 +480,16 @@ }, { "name": "utopia-php/servers", - "version": "0.1.1", + "version": "0.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/servers.git", - "reference": "fd5c8d32778f265256c1936372a071b944f5ba8a" + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/fd5c8d32778f265256c1936372a071b944f5ba8a", - "reference": "fd5c8d32778f265256c1936372a071b944f5ba8a", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", "shasum": "" }, "require": { @@ -527,9 +527,9 @@ ], "support": { "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/0.1.1" + "source": "https://github.com/utopia-php/servers/tree/0.1.0" }, - "time": "2024-09-06T02:25:56+00:00" + "time": "2024-08-08T14:31:39+00:00" } ], "packages-dev": [ @@ -884,16 +884,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.2.0", + "version": "v5.1.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb" + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", - "reference": "23c79fbbfb725fb92af9bcf41065c8e9a0d49ddb", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", "shasum": "" }, "require": { @@ -936,9 +936,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.2.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" }, - "time": "2024-09-15T16:40:33+00:00" + "time": "2024-07-01T20:03:41+00:00" }, { "name": "phar-io/manifest", @@ -1261,16 +1261,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.3", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009" + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0fcbf194ab63d8159bb70d9aa3e1350051632009", - "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", "shasum": "" }, "require": { @@ -1315,7 +1315,7 @@ "type": "github" } ], - "time": "2024-09-09T08:10:35+00:00" + "time": "2024-09-03T19:55:22+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1843,16 +1843,16 @@ }, { "name": "psr/log", - "version": "3.0.2", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3" + "reference": "79dff0b268932c640297f5208d6298f71855c03e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", - "reference": "f16e1d5863e37f8d8c2a01719f5b34baa2b714d3", + "url": "https://api.github.com/repos/php-fig/log/zipball/79dff0b268932c640297f5208d6298f71855c03e", + "reference": "79dff0b268932c640297f5208d6298f71855c03e", "shasum": "" }, "require": { @@ -1887,9 +1887,9 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/3.0.2" + "source": "https://github.com/php-fig/log/tree/3.0.1" }, - "time": "2024-09-11T13:17:53+00:00" + "time": "2024-08-21T13:31:24+00:00" }, { "name": "sebastian/cli-parser", @@ -3277,20 +3277,20 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.31.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638" + "reference": "0424dff1c58f028c451efff2045f5d92410bd540" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638", - "reference": "a3cc8b044a6ea513310cbd48ef7333b384945638", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/0424dff1c58f028c451efff2045f5d92410bd540", + "reference": "0424dff1c58f028c451efff2045f5d92410bd540", "shasum": "" }, "require": { - "php": ">=7.2" + "php": ">=7.1" }, "provide": { "ext-ctype": "*" @@ -3336,7 +3336,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.30.0" }, "funding": [ { @@ -3352,24 +3352,24 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.31.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe" + "reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", - "reference": "b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/64647a7c30b2283f5d49b874d84a18fc22054b7a", + "reference": "64647a7c30b2283f5d49b874d84a18fc22054b7a", "shasum": "" }, "require": { - "php": ">=7.2" + "php": ">=7.1" }, "suggest": { "ext-intl": "For best performance" @@ -3414,7 +3414,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.30.0" }, "funding": [ { @@ -3430,24 +3430,24 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.31.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "3833d7255cc303546435cb650316bff708a1c75c" + "reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c", - "reference": "3833d7255cc303546435cb650316bff708a1c75c", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/a95281b0be0d9ab48050ebd988b967875cdb9fdb", + "reference": "a95281b0be0d9ab48050ebd988b967875cdb9fdb", "shasum": "" }, "require": { - "php": ">=7.2" + "php": ">=7.1" }, "suggest": { "ext-intl": "For best performance" @@ -3495,7 +3495,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.30.0" }, "funding": [ { @@ -3511,24 +3511,24 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-05-31T15:07:36+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.31.0", + "version": "v1.30.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341" + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341", - "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c", + "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c", "shasum": "" }, "require": { - "php": ">=7.2" + "php": ">=7.1" }, "provide": { "ext-mbstring": "*" @@ -3575,7 +3575,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0" }, "funding": [ { @@ -3591,7 +3591,7 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2024-06-19T12:30:46+00:00" }, { "name": "symfony/process", @@ -3925,7 +3925,7 @@ } ], "aliases": [], - "minimum-stability": "stable", + "minimum-stability": "RC", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Abuse/Adapters/Database/TimeLimit.php b/src/Abuse/Adapters/Database/TimeLimit.php index 0f1e779295..2527442cfb 100644 --- a/src/Abuse/Adapters/Database/TimeLimit.php +++ b/src/Abuse/Adapters/Database/TimeLimit.php @@ -165,7 +165,7 @@ class TimeLimit extends TimeLimitAdapter Query::equal('time', [$datetime]), ]); - if ($data->isEmpty()) { + if ($data === false) { $data = [ '$permissions' => [], 'key' => $key, @@ -183,7 +183,7 @@ class TimeLimit extends TimeLimitAdapter Query::equal('time', [$datetime]), ]); - if (!$data->isEmpty()) { + if ($data !== false && $data instanceof Document) { $count = $data->getAttribute('count', 0); if (\is_numeric($count)) { $this->count = intval($count); From f0c49a64fd80bdf7e2f7f10ec727c7d466f3e2e7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Wed, 18 Dec 2024 20:16:53 +0530 Subject: [PATCH 31/48] Revert "Framework" --- composer.json | 2 +- composer.lock | 208 +++++------------- src/Abuse/Adapters/Database/TimeLimit.php | 77 +------ tests/Abuse/Base.php | 0 tests/Abuse/Bench/Database/TimeLimitBench.php | 2 +- tests/Abuse/DatabaseTest.php | 2 +- tests/Abuse/RedisTest.php | 2 +- 7 files changed, 61 insertions(+), 232 deletions(-) mode change 100755 => 100644 tests/Abuse/Base.php diff --git a/composer.json b/composer.json index 823856bc1b..6283871b3a 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-pdo": "*", "ext-curl": "*", "ext-redis": "*", - "utopia-php/database": "0.54.*" + "utopia-php/database": "0.53.*" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index 8ab1de626e..152575410f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7601e6576cde00888812fb6e2e732dbe", + "content-hash": "6522b9fb8652f6801bd7c5664430c672", "packages": [ { "name": "jean85/pretty-package-versions", @@ -266,16 +266,16 @@ }, { "name": "utopia-php/database", - "version": "0.54.0", + "version": "0.53.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e" + "reference": "2e116d544b14e8b2edfcb5b793d214136ff64f42" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/1e97fc8b212a8daf9b9a68244677ed34c9db143e", - "reference": "1e97fc8b212a8daf9b9a68244677ed34c9db143e", + "url": "https://api.github.com/repos/utopia-php/database/zipball/2e116d544b14e8b2edfcb5b793d214136ff64f42", + "reference": "2e116d544b14e8b2edfcb5b793d214136ff64f42", "shasum": "" }, "require": { @@ -283,7 +283,7 @@ "ext-pdo": "*", "php": ">=8.0", "utopia-php/cache": "0.10.*", - "utopia-php/framework": "1.0.*", + "utopia-php/framework": "0.33.*", "utopia-php/mongo": "0.3.*" }, "require-dev": { @@ -294,7 +294,7 @@ "phpunit/phpunit": "9.6.*", "rregeer/phpunit-coverage-check": "0.3.*", "swoole/ide-helper": "5.1.3", - "utopia-php/cli": "0.19.*" + "utopia-php/cli": "0.14.*" }, "type": "library", "autoload": { @@ -316,84 +316,32 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.54.0" + "source": "https://github.com/utopia-php/database/tree/0.53.0" }, - "time": "2024-09-05T16:00:42+00:00" - }, - { - "name": "utopia-php/di", - "version": "0.1.0", - "source": { - "type": "git", - "url": "https://github.com/utopia-php/di.git", - "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/di/zipball/22490c95f7ac3898ed1c33f1b1b5dd577305ee31", - "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31", - "shasum": "" - }, - "require": { - "php": ">=8.2" - }, - "require-dev": { - "laravel/pint": "^1.2", - "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25", - "swoole/ide-helper": "4.8.3" - }, - "type": "library", - "autoload": { - "psr-4": { - "Utopia\\": "src/", - "Tests\\E2E\\": "tests/e2e" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "A simple and lite library for managing dependency injections", - "keywords": [ - "framework", - "http", - "php", - "upf" - ], - "support": { - "issues": "https://github.com/utopia-php/di/issues", - "source": "https://github.com/utopia-php/di/tree/0.1.0" - }, - "time": "2024-08-08T14:35:19+00:00" + "time": "2024-08-30T04:32:56+00:00" }, { "name": "utopia-php/framework", - "version": "1.0.0", + "version": "0.33.8", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf" + "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/cc880ec41f7f163d4f9956fec26cc6be51b412cf", - "reference": "cc880ec41f7f163d4f9956fec26cc6be51b412cf", + "url": "https://api.github.com/repos/utopia-php/http/zipball/a7f577540a25cb90896fef2b64767bf8d700f3c5", + "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5", "shasum": "" }, "require": { - "ext-swoole": "*", - "php": ">=8.0", - "utopia-php/servers": "0.1.*" + "php": ">=8.0" }, "require-dev": { - "ext-xdebug": "*", "laravel/pint": "^1.2", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25", - "swoole/ide-helper": "4.8.3" + "phpunit/phpunit": "^9.5.25" }, "type": "library", "autoload": { @@ -405,18 +353,17 @@ "license": [ "MIT" ], - "description": "A simple, light and advanced PHP HTTP framework", + "description": "A simple, light and advanced PHP framework", "keywords": [ "framework", - "http", "php", "upf" ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/1.0.0" + "source": "https://github.com/utopia-php/http/tree/0.33.8" }, - "time": "2024-09-05T15:38:08+00:00" + "time": "2024-08-15T14:10:09+00:00" }, { "name": "utopia-php/mongo", @@ -477,74 +424,21 @@ "source": "https://github.com/utopia-php/mongo/tree/0.3.1" }, "time": "2023-09-01T17:25:28+00:00" - }, - { - "name": "utopia-php/servers", - "version": "0.1.0", - "source": { - "type": "git", - "url": "https://github.com/utopia-php/servers.git", - "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/servers/zipball/7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", - "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", - "shasum": "" - }, - "require": { - "php": ">=8.0", - "utopia-php/di": "0.1.*" - }, - "require-dev": { - "laravel/pint": "^0.2.3", - "phpstan/phpstan": "^1.8", - "phpunit/phpunit": "^9.5.5" - }, - "type": "library", - "autoload": { - "psr-4": { - "Utopia\\Servers\\": "src/Servers" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Team Appwrite", - "email": "team@appwrite.io" - } - ], - "description": "A base library for building Utopia style servers.", - "keywords": [ - "framework", - "php", - "servers", - "upf", - "utopia" - ], - "support": { - "issues": "https://github.com/utopia-php/servers/issues", - "source": "https://github.com/utopia-php/servers/tree/0.1.0" - }, - "time": "2024-08-08T14:31:39+00:00" } ], "packages-dev": [ { "name": "doctrine/annotations", - "version": "2.0.2", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "901c2ee5d26eb64ff43c47976e114bf00843acf7" + "reference": "e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/901c2ee5d26eb64ff43c47976e114bf00843acf7", - "reference": "901c2ee5d26eb64ff43c47976e114bf00843acf7", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f", + "reference": "e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f", "shasum": "" }, "require": { @@ -556,10 +450,10 @@ "require-dev": { "doctrine/cache": "^2.0", "doctrine/coding-standard": "^10", - "phpstan/phpstan": "^1.10.28", + "phpstan/phpstan": "^1.8.0", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "symfony/cache": "^5.4 || ^6.4 || ^7", - "vimeo/psalm": "^4.30 || ^5.14" + "symfony/cache": "^5.4 || ^6", + "vimeo/psalm": "^4.10" }, "suggest": { "php": "PHP 8.0 or higher comes with attributes, a native replacement for annotations" @@ -605,9 +499,9 @@ ], "support": { "issues": "https://github.com/doctrine/annotations/issues", - "source": "https://github.com/doctrine/annotations/tree/2.0.2" + "source": "https://github.com/doctrine/annotations/tree/2.0.1" }, - "time": "2024-09-05T10:17:24+00:00" + "time": "2023-02-02T22:02:53+00:00" }, { "name": "doctrine/instantiator", @@ -1261,16 +1155,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.1", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2" + "reference": "384af967d35b2162f69526c7276acadce534d0e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", - "reference": "d8ed7fffa66de1db0d2972267d8ed1d8fa0fe5a2", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", + "reference": "384af967d35b2162f69526c7276acadce534d0e1", "shasum": "" }, "require": { @@ -1315,7 +1209,7 @@ "type": "github" } ], - "time": "2024-09-03T19:55:22+00:00" + "time": "2024-08-27T09:18:05+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2920,16 +2814,16 @@ }, { "name": "symfony/console", - "version": "v7.1.4", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111" + "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/1eed7af6961d763e7832e874d7f9b21c3ea9c111", - "reference": "1eed7af6961d763e7832e874d7f9b21c3ea9c111", + "url": "https://api.github.com/repos/symfony/console/zipball/cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", + "reference": "cb1dcb30ebc7005c29864ee78adb47b5fb7c3cd9", "shasum": "" }, "require": { @@ -2993,7 +2887,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.1.4" + "source": "https://github.com/symfony/console/tree/v7.1.3" }, "funding": [ { @@ -3009,7 +2903,7 @@ "type": "tidelift" } ], - "time": "2024-08-15T22:48:53+00:00" + "time": "2024-07-26T12:41:01+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3146,16 +3040,16 @@ }, { "name": "symfony/finder", - "version": "v7.1.4", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "d95bbf319f7d052082fb7af147e0f835a695e823" + "reference": "717c6329886f32dc65e27461f80f2a465412fdca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/d95bbf319f7d052082fb7af147e0f835a695e823", - "reference": "d95bbf319f7d052082fb7af147e0f835a695e823", + "url": "https://api.github.com/repos/symfony/finder/zipball/717c6329886f32dc65e27461f80f2a465412fdca", + "reference": "717c6329886f32dc65e27461f80f2a465412fdca", "shasum": "" }, "require": { @@ -3190,7 +3084,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.1.4" + "source": "https://github.com/symfony/finder/tree/v7.1.3" }, "funding": [ { @@ -3206,7 +3100,7 @@ "type": "tidelift" } ], - "time": "2024-08-13T14:28:19+00:00" + "time": "2024-07-24T07:08:44+00:00" }, { "name": "symfony/options-resolver", @@ -3739,16 +3633,16 @@ }, { "name": "symfony/string", - "version": "v7.1.4", + "version": "v7.1.3", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b" + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/6cd670a6d968eaeb1c77c2e76091c45c56bc367b", - "reference": "6cd670a6d968eaeb1c77c2e76091c45c56bc367b", + "url": "https://api.github.com/repos/symfony/string/zipball/ea272a882be7f20cad58d5d78c215001617b7f07", + "reference": "ea272a882be7f20cad58d5d78c215001617b7f07", "shasum": "" }, "require": { @@ -3806,7 +3700,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.1.4" + "source": "https://github.com/symfony/string/tree/v7.1.3" }, "funding": [ { @@ -3822,7 +3716,7 @@ "type": "tidelift" } ], - "time": "2024-08-12T09:59:40+00:00" + "time": "2024-07-22T10:25:37+00:00" }, { "name": "theseer/tokenizer", @@ -3925,7 +3819,7 @@ } ], "aliases": [], - "minimum-stability": "RC", + "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Abuse/Adapters/Database/TimeLimit.php b/src/Abuse/Adapters/Database/TimeLimit.php index 2527442cfb..0d408295ed 100644 --- a/src/Abuse/Adapters/Database/TimeLimit.php +++ b/src/Abuse/Adapters/Database/TimeLimit.php @@ -10,7 +10,8 @@ use Utopia\Database\Exception\Authorization as AuthorizationException; use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Structure; use Utopia\Database\Query; -use Utopia\Http\Exception; +use Utopia\Database\Validator\Authorization; +use Utopia\Exception; class TimeLimit extends TimeLimitAdapter { @@ -127,7 +128,7 @@ class TimeLimit extends TimeLimitAdapter } /** @var array $result */ - $result = $this->db->getAuthorization()->skip(function () use ($key, $datetime) { + $result = Authorization::skip(function () use ($key, $datetime) { return $this->db->find(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -159,7 +160,7 @@ class TimeLimit extends TimeLimitAdapter return; } - $this->db->getAuthorization()->skip(function () use ($datetime, $key) { + Authorization::skip(function () use ($datetime, $key) { $data = $this->db->findOne(TimeLimit::COLLECTION, [ Query::equal('key', [$key]), Query::equal('time', [$datetime]), @@ -216,7 +217,7 @@ class TimeLimit extends TimeLimitAdapter public function getLogs(?int $offset = null, ?int $limit = 25): array { /** @var array $results */ - $results = $this->db->getAuthorization()->skip(function () use ($offset, $limit) { + $results = Authorization::skip(function () use ($offset, $limit) { $queries = []; $queries[] = Query::orderDesc(''); @@ -243,7 +244,7 @@ class TimeLimit extends TimeLimitAdapter */ public function cleanup(string $datetime): bool { - $this->db->getAuthorization()->skip(function () use ($datetime) { + Authorization::skip(function () use ($datetime) { do { $documents = $this->db->find(TimeLimit::COLLECTION, [ Query::lessThan('time', $datetime), @@ -257,70 +258,4 @@ class TimeLimit extends TimeLimitAdapter return true; } - - /** - * Check - * - * Checks if number of counts is bigger or smaller than current limit. limit 0 is equal to unlimited - * - * @return bool - * - * @throws \Throwable - */ - public function check(): bool - { - if (0 == $this->limit) { - return false; - } - - $key = $this->parseKey(); - - if ($this->limit > $this->count($key, $this->time)) { - $this->hit($key, $this->time); - - return false; - } - - return true; - } - - /** - * Remaining - * - * Returns the number of current remaining counts - * - * @return int - * - * @throws \Exception - */ - public function remaining(): int - { - $left = $this->limit - ($this->count($this->parseKey(), $this->time) + 1); // Add one because we need to say how many left not how many done - - return (0 > $left) ? 0 : $left; - } - - /** - * Limit - * - * Return the limit integer - * - * @return int - */ - public function limit(): int - { - return $this->limit; - } - - /** - * Time - * - * Return the Datetime - * - * @return string - */ - public function time(): string - { - return $this->time; - } } diff --git a/tests/Abuse/Base.php b/tests/Abuse/Base.php old mode 100755 new mode 100644 diff --git a/tests/Abuse/Bench/Database/TimeLimitBench.php b/tests/Abuse/Bench/Database/TimeLimitBench.php index 8f2a5be2cb..e2a110c6b7 100644 --- a/tests/Abuse/Bench/Database/TimeLimitBench.php +++ b/tests/Abuse/Bench/Database/TimeLimitBench.php @@ -10,8 +10,8 @@ use Utopia\Cache\Cache; use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Adapter\MySQL; use Utopia\Database\Database; +use Utopia\Exception; use Utopia\Tests\Bench\Base; -use Utopia\Http\Exception; class TimeLimitBench extends Base { diff --git a/tests/Abuse/DatabaseTest.php b/tests/Abuse/DatabaseTest.php index fc6c1ed197..b3820e6aa4 100755 --- a/tests/Abuse/DatabaseTest.php +++ b/tests/Abuse/DatabaseTest.php @@ -12,7 +12,7 @@ use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Adapter\MySQL; use Utopia\Database\Database; use Utopia\Database\DateTime; -use Utopia\Http\Exception; +use Utopia\Exception; class DatabaseTest extends Base { diff --git a/tests/Abuse/RedisTest.php b/tests/Abuse/RedisTest.php index 4ecd92dd50..517ee94777 100644 --- a/tests/Abuse/RedisTest.php +++ b/tests/Abuse/RedisTest.php @@ -7,7 +7,7 @@ use Redis as Client; use Utopia\Abuse\Abuse; use Utopia\Abuse\Adapter; use Utopia\Abuse\Adapters\Redis\TimeLimit; -use Utopia\Http\Exception; +use Utopia\Exception; class RedisTest extends Base { From 397a49d2f783e14c3922b186f11e1e79ef68284f Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 20 Dec 2024 19:14:35 +0530 Subject: [PATCH 32/48] chore: update tests and change timestamp type --- docker-compose.yml | 6 +- phpunit.xml | 2 +- src/Abuse/Adapter.php | 4 +- src/Abuse/Adapters/TimeLimit.php | 24 +-- src/Abuse/Adapters/TimeLimit/Database.php | 41 +++-- src/Abuse/Adapters/TimeLimit/Redis.php | 26 ++-- src/Abuse/Adapters/TimeLimit/RedisCluster.php | 22 +-- tests/Abuse/Base.php | 143 ++++++++++++------ tests/Abuse/DatabaseTest.php | 43 +++--- tests/Abuse/RedisClusterTest.php | 46 ++++-- tests/Abuse/RedisTest.php | 42 ++--- 11 files changed, 241 insertions(+), 158 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a139da027b..f614d13765 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -48,6 +48,8 @@ services: - REDIS_HOSTS=redis-cluster-0:6379 ports: - "8081:5540" + volumes: + - redisinsight:/data redis-cluster-0: image: docker.io/bitnami/redis-cluster:7.4 @@ -88,4 +90,6 @@ services: - abuse networks: - abuse: \ No newline at end of file + abuse: +volumes: + redisinsight: diff --git a/phpunit.xml b/phpunit.xml index 10d408caa0..ec39a7edea 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" > diff --git a/src/Abuse/Adapter.php b/src/Abuse/Adapter.php index 4af27dc40a..e96fa6f7de 100644 --- a/src/Abuse/Adapter.php +++ b/src/Abuse/Adapter.php @@ -79,8 +79,8 @@ abstract class Adapter /** * Delete all logs older than $datetime * - * @param string $datetime + * @param int $timestamp * @return bool */ - abstract public function cleanup(string $datetime): bool; + abstract public function cleanup(int $timestamp): bool; } diff --git a/src/Abuse/Adapters/TimeLimit.php b/src/Abuse/Adapters/TimeLimit.php index dcafee0835..d0bd655a7a 100644 --- a/src/Abuse/Adapters/TimeLimit.php +++ b/src/Abuse/Adapters/TimeLimit.php @@ -18,9 +18,9 @@ abstract class TimeLimit extends Adapter protected ?int $count = null; /** - * @var string + * @var int */ - protected string $time; + protected int $timestamp; /** * Check @@ -28,14 +28,14 @@ abstract class TimeLimit extends Adapter * Checks if number of counts is bigger or smaller than current limit * * @param string $key - * @param string $datetime + * @param int $timestamp * @return int * * @throws \Exception */ - abstract protected function count(string $key, string $datetime): int; + abstract protected function count(string $key, int $timestamp): int; - abstract protected function hit(string $key, string $datetime): void; + abstract protected function hit(string $key, int $timestamp): void; /** * Check @@ -54,8 +54,8 @@ abstract class TimeLimit extends Adapter $key = $this->parseKey(); - if ($this->limit > $this->count($key, $this->time)) { - $this->hit($key, $this->time); + if ($this->limit > $this->count($key, $this->timestamp)) { + $this->hit($key, $this->timestamp); return false; } @@ -74,7 +74,7 @@ abstract class TimeLimit extends Adapter */ public function remaining(): int { - $left = $this->limit - ($this->count($this->parseKey(), $this->time) + 1); // Add one because we need to say how many left not how many done + $left = $this->limit - ($this->count($this->parseKey(), $this->timestamp) + 1); // Add one because we need to say how many left not how many done return (0 > $left) ? 0 : $left; } @@ -94,12 +94,12 @@ abstract class TimeLimit extends Adapter /** * Time * - * Return the Datetime + * Return the timestamp * - * @return string + * @return int */ - public function time(): string + public function time(): int { - return $this->time; + return $this->timestamp; } } diff --git a/src/Abuse/Adapters/TimeLimit/Database.php b/src/Abuse/Adapters/TimeLimit/Database.php index a7ba5662c2..ae36f01cd0 100644 --- a/src/Abuse/Adapters/TimeLimit/Database.php +++ b/src/Abuse/Adapters/TimeLimit/Database.php @@ -80,8 +80,8 @@ class Database extends TimeLimit public function __construct(string $key, int $limit, int $seconds, UtopiaDB $db) { $this->key = $key; - $time = (int) \date('U', (int) (\floor(\time() / $seconds)) * $seconds); // todo: any good Idea without time()? - $this->time = DateTime::format((new \DateTime())->setTimestamp($time)); + $now = \time(); + $this->timestamp = (int)($now - ($now % $seconds)); $this->limit = $limit; $this->db = $db; } @@ -121,12 +121,12 @@ class Database extends TimeLimit * Checks if number of counts is bigger or smaller than current limit * * @param string $key - * @param string $datetime + * @param int $timestamp * @return int * * @throws \Exception */ - protected function count(string $key, string $datetime): int + protected function count(string $key, int $timestamp): int { if (0 == $this->limit) { // No limit no point for counting return 0; @@ -136,11 +136,13 @@ class Database extends TimeLimit return $this->count; } + $timestamp = $this->toDateTime($timestamp); + /** @var array $result */ - $result = Authorization::skip(function () use ($key, $datetime) { + $result = Authorization::skip(function () use ($key, $timestamp) { return $this->db->find(self::COLLECTION, [ Query::equal('key', [$key]), - Query::equal('time', [$datetime]), + Query::equal('time', [$timestamp]), ]); }); @@ -158,28 +160,29 @@ class Database extends TimeLimit /** * @param string $key - * @param string $datetime + * @param int $timestamp * @return void * * @throws AuthorizationException|Structure|\Exception|\Throwable */ - protected function hit(string $key, string $datetime): void + protected function hit(string $key, int $timestamp): void { if (0 == $this->limit) { // No limit no point for counting return; } - Authorization::skip(function () use ($datetime, $key) { + $timestamp = $this->toDateTime($timestamp); + Authorization::skip(function () use ($timestamp, $key) { $data = $this->db->findOne(self::COLLECTION, [ Query::equal('key', [$key]), - Query::equal('time', [$datetime]), + Query::equal('time', [$timestamp]), ]); if ($data->isEmpty()) { $data = [ '$permissions' => [], 'key' => $key, - 'time' => $datetime, + 'time' => $timestamp, 'count' => 1, '$collection' => self::COLLECTION, ]; @@ -190,7 +193,7 @@ class Database extends TimeLimit // Duplicate in case of race condition $data = $this->db->findOne(self::COLLECTION, [ Query::equal('key', [$key]), - Query::equal('time', [$datetime]), + Query::equal('time', [$timestamp]), ]); if (!$data->isEmpty()) { @@ -246,17 +249,18 @@ class Database extends TimeLimit /** * Delete logs older than $timestamp seconds * - * @param string $datetime + * @param int $timestamp * @return bool * * @throws AuthorizationException|\Exception */ - public function cleanup(string $datetime): bool + public function cleanup(int $timestamp): bool { - Authorization::skip(function () use ($datetime) { + $timestamp = $this->toDateTime($timestamp); + Authorization::skip(function () use ($timestamp) { do { $documents = $this->db->find(self::COLLECTION, [ - Query::lessThan('time', $datetime), + Query::lessThan('time', $timestamp), ]); foreach ($documents as $document) { @@ -267,4 +271,9 @@ class Database extends TimeLimit return true; } + + protected function toDateTime(int $timestamp): string + { + return DateTime::format((new \DateTime())->setTimestamp($timestamp)); + } } diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index 3657a570d5..80a55726f2 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -17,8 +17,8 @@ class Redis extends TimeLimit { $this->redis = $redis; $this->key = $key; - $time = (int) \date('U', (int) (\floor(\time() / $seconds)) * $seconds); - $this->time = strval($time); + $now = \time(); + $this->timestamp = (int)($now - ($now % $seconds)); $this->limit = $limit; } @@ -26,10 +26,10 @@ class Redis extends TimeLimit * Undocumented function * * @param string $key - * @param string $datetime + * @param int $timestamp * @return integer */ - protected function count(string $key, string $datetime): int + protected function count(string $key, int $timestamp): int { if (0 == $this->limit) { // No limit no point for counting return 0; @@ -40,7 +40,7 @@ class Redis extends TimeLimit } /** @var string $count */ - $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime); + $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $timestamp); if (!$count) { $this->count = 0; } else { @@ -52,25 +52,25 @@ class Redis extends TimeLimit /** * @param string $key - * @param string $datetime + * @param int $timestamp * @return void * */ - protected function hit(string $key, string $datetime): void + protected function hit(string $key, int $timestamp): void { if (0 == $this->limit) { // No limit no point for counting return; } /** @var string $count */ - $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime); + $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $timestamp); if (!$count) { $this->count = 0; } else { $this->count = intval($count); } - $this->redis->incr(self::NAMESPACE . '__'. $key .'__'. $datetime); + $this->redis->incr(self::NAMESPACE . '__'. $key .'__'. $timestamp); $this->count++; } @@ -100,17 +100,17 @@ class Redis extends TimeLimit } /** - * Delete all logs older than $datetime + * Delete all logs older than $timestamp * - * @param string $datetime + * @param int $timestamp * @return bool */ - public function cleanup(string $datetime): bool + public function cleanup(int $timestamp): bool { $iterator = null; while ($iterator !== 0) { $keys = $this->redis->scan($iterator, self::NAMESPACE . '__*__*', 1000); - $keys = $this->filterKeys($keys ? $keys : [], (int) $datetime); + $keys = $this->filterKeys($keys ? $keys : [], $timestamp); $this->redis->del($keys); } return true; diff --git a/src/Abuse/Adapters/TimeLimit/RedisCluster.php b/src/Abuse/Adapters/TimeLimit/RedisCluster.php index 24145d2b4b..4416ac8534 100644 --- a/src/Abuse/Adapters/TimeLimit/RedisCluster.php +++ b/src/Abuse/Adapters/TimeLimit/RedisCluster.php @@ -17,8 +17,8 @@ class RedisCluster extends TimeLimit { $this->redis = $redis; $this->key = $key; - $time = (int) \date('U', (int) (\floor(\time() / $seconds)) * $seconds); - $this->time = strval($time); + $now = \time(); + $this->timestamp = (int)($now - ($now % $seconds)); $this->limit = $limit; } @@ -29,7 +29,7 @@ class RedisCluster extends TimeLimit * @param string $datetime * @return integer */ - protected function count(string $key, string $datetime): int + protected function count(string $key, int $timestamp): int { if (0 == $this->limit) { // No limit no point for counting return 0; @@ -40,7 +40,7 @@ class RedisCluster extends TimeLimit } /** @var string|false $count */ - $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime); + $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $timestamp); if ($count === false) { $this->count = 0; } else { @@ -57,21 +57,21 @@ class RedisCluster extends TimeLimit * @param string $datetime * @return void */ - protected function hit(string $key, string $datetime): void + protected function hit(string $key, int $timestamp): void { if (0 == $this->limit) { // No limit no point for counting return; } /** @var string|false $count */ - $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime); + $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $timestamp); if ($count === false) { $this->count = 0; } else { $this->count = intval($count); } - $this->redis->incr(self::NAMESPACE . '__'. $key .'__'. $datetime); + $this->redis->incr(self::NAMESPACE . '__'. $key .'__'. $timestamp); $this->count++; } @@ -100,15 +100,15 @@ class RedisCluster extends TimeLimit } /** - * Delete all logs older than $datetime + * Delete all logs older than $timestamp * - * @param string $datetime + * @param int $timestamp * @return bool */ - public function cleanup(string $datetime): bool + public function cleanup(int $timestamp): bool { $keys = $this->scan(self::NAMESPACE . '__*__*'); - $keys = $this->filterKeys($keys ? $keys : [], (int) $datetime); + $keys = $this->filterKeys($keys ? $keys : [], $timestamp); /** @phpstan-ignore-next-line */ $this->redis->del($keys); return true; diff --git a/tests/Abuse/Base.php b/tests/Abuse/Base.php index 2b7e291bed..a59b32d5f4 100644 --- a/tests/Abuse/Base.php +++ b/tests/Abuse/Base.php @@ -4,67 +4,116 @@ namespace Utopia\Tests; use PHPUnit\Framework\TestCase; use Utopia\Abuse\Abuse; -use Utopia\Abuse\Adapter; +use Utopia\Abuse\Adapters\TimeLimit; abstract class Base extends TestCase { - protected Abuse $abuse; + abstract public function getAdapter(string $key, int $limit, int $seconds): TimeLimit; - protected Abuse $abuseIp; - - abstract public function getAdapter(string $key, int $limit, int $seconds): Adapter; - - abstract public function getCleanupDateTime(): string; - - public function tearDown(): void + /** + * Test a static key with a limit of 2 requests per second + */ + public function testStaticKey(): void { - unset($this->abuse); + $adapter = $this->getAdapter('static-key', 2, 1); + $abuse = new Abuse($adapter); + $this->assertEquals($abuse->check(), false); + $this->assertEquals($abuse->check(), false); + $this->assertEquals($abuse->check(), true); } - public function testImitate2Requests(): void + /** + * Test a dynamic key with a limit of 2 requests per second + */ + public function testDynamicKey(): void { - $key = '{{ip}}'; - $value = '0.0.0.10'; + $adapter = $this->getAdapter('dyamic-key-{{ip}}', 2, 1); + $adapter->setParam('{{ip}}', '0.0.0.10'); + $abuse = new Abuse($adapter); + $this->assertEquals($abuse->check(), false); + $this->assertEquals($abuse->check(), false); + $this->assertEquals($abuse->check(), true); + } - $adapter = $this->getAdapter($key, 1, 1); - $adapter->setParam($key, $value); - $this->abuseIp = new Abuse($adapter); - $this->assertEquals($this->abuseIp->check(), false); - $this->assertEquals($this->abuseIp->check(), true); + /** + * Test a dynamic key with 2 params + */ + public function testDynamicKeyWith2Params(): void + { + $adapter = $this->getAdapter('two-params-{{ip}}-{{email}}', 2, 1); + $adapter->setParam('{{ip}}', '0.0.0.10'); + $adapter->setParam('{{email}}', 'test@test.com'); + $abuse = new Abuse($adapter); + $this->assertEquals($abuse->check(), false); + $this->assertEquals($abuse->check(), false); + $this->assertEquals($abuse->check(), true); + } + + /** + * Test a dynamic key with higher request rate like 100 requests per second + */ + public function testDynamicKeyFastRequests(): void + { + $adapter = $this->getAdapter('fast-requests-{{ip}}', 100, 1); + $adapter->setParam('{{ip}}', '0.0.0.10'); + $abuse = new Abuse($adapter); + for ($i = 0; $i < 100; $i++) { + $this->assertEquals($abuse->check(), false); + } + $this->assertEquals($abuse->check(), true); + } + + /** + * Test that the limit is reset after the time limit + */ + public function testLimitReset(): void + { + $adapter = $this->getAdapter('limit-reset-{{ip}}', 100, 2); + $adapter->setParam('{{ip}}', '127.0.0.1'); + $abuse = new Abuse($adapter); + for ($i = 0; $i < 100; $i++) { + $this->assertEquals($abuse->check(), false); + } + $this->assertEquals($abuse->check(), true); + + // Wait for the limit to reset + sleep(2); + + /** Seems to be a bug in the code where if use the same adapter, it caches the result of the previous check */ + $adapter = $this->getAdapter('limit-reset-{{ip}}', 100, 1); + $adapter->setParam('{{ip}}', '127.0.0.1'); + $abuse = new Abuse($adapter); + $this->assertEquals($abuse->check(), false); + } + + /** + * Test logs are deleted after cleanup + */ + public function testCleanup(): void + { + $adapter = $this->getAdapter('', 1, 1); + $abuse = new Abuse($adapter); + + $logs = $abuse->getLogs(0, 100); + $this->assertEquals(6, \count($logs)); // 6 keys are created in the test sleep(1); - $adapter = $this->getAdapter($key, 1, 1); - $adapter->setParam($key, $value); - $this->abuseIp = new Abuse($adapter); - - $this->assertEquals($this->abuseIp->check(), false); - $this->assertEquals($this->abuseIp->check(), true); - } - - public function testIsValid(): void - { - // Use vars to resolve adapter key - $this->assertEquals($this->abuse->check(), false); - $this->assertEquals($this->abuse->check(), false); - $this->assertEquals($this->abuse->check(), false); - $this->assertEquals($this->abuse->check(), true); - } - - public function testCleanup(): void - { - // Check that there are 3 logs - $logs = $this->abuse->getLogs(0, 10); - $this->assertEquals(3, \count($logs)); - - sleep(2); - // Delete the log - - $status = $this->abuse->cleanup($this->getCleanupDateTime()); + $status = $abuse->cleanup(time()); $this->assertEquals($status, true); - // Check that there are no logs in the DB - $logs = $this->abuse->getLogs(0, 10); + $logs = $abuse->getLogs(0, 100); $this->assertEquals(0, \count($logs)); } + + /** + * Verify that the time format is correct + */ + public function testTimeFormat(): void + { + $now = time(); + $adapter = $this->getAdapter('', 1, 1); + $this->assertEquals($adapter->time(), $now); + $this->assertEquals(true, \is_int($adapter->time())); + } } diff --git a/tests/Abuse/DatabaseTest.php b/tests/Abuse/DatabaseTest.php index 8ca37426bf..dd2be3e21c 100755 --- a/tests/Abuse/DatabaseTest.php +++ b/tests/Abuse/DatabaseTest.php @@ -3,57 +3,56 @@ namespace Utopia\Tests; use PDO; -use Utopia\Abuse\Abuse; -use Utopia\Abuse\Adapter; -use Utopia\Abuse\Adapters\TimeLimit\Database as TimeLimit; +use Utopia\Abuse\Adapters\TimeLimit; +use Utopia\Abuse\Adapters\TimeLimit\Database as AdapterDatabase; use Utopia\Cache\Adapter\None as NoCache; use Utopia\Cache\Cache; use Utopia\Database\Adapter\MariaDB; use Utopia\Database\Adapter\MySQL; use Utopia\Database\Database; -use Utopia\Database\DateTime; -use Utopia\Exception; class DatabaseTest extends Base { - protected Database $db; + protected static ?Database $db = null; - /** - * @throws Exception - * @throws \Exception - */ - public function setUp(): void + public static function setUpBeforeClass(): void + { + if (self::$db === null) { + self::$db = self::initialiseDatabase(); + } + } + + private static function initialiseDatabase(): Database { - // Limit login attempts to 3 time in 5 minutes time frame $dbHost = 'mysql'; $dbUser = 'root'; $dbPort = '3306'; $dbPass = 'password'; $pdo = new PDO("mysql:host={$dbHost};port={$dbPort};charset=utf8mb4", $dbUser, $dbPass, MariaDB::getPdoAttributes()); - $db = new Database(new MySQL($pdo), new Cache(new NoCache())); $db->setDatabase('utopiaTests'); $db->setNamespace('namespace'); - $this->db = $db; - $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 60 * 5, $db); - if (! $db->exists('utopiaTests')) { + $adapter = new AdapterDatabase('', 1, 1, $db); + if (!$db->exists('utopiaTests')) { $db->create(); $adapter->setup(); } - $adapter->setParam('{{ip}}', '127.0.0.1'); - $this->abuse = new Abuse($adapter); + return $db; } - public function getAdapter(string $key, int $limit, int $seconds): Adapter + public function getAdapter(string $key, int $limit, int $seconds): TimeLimit { - return new TimeLimit($key, $limit, $seconds, $this->db); + return new AdapterDatabase($key, $limit, $seconds, self::$db); } - public function getCleanupDateTime(): string + public static function tearDownAfterClass(): void { - return DateTime::format(new \DateTime()); + if (self::$db !== null) { + self::$db->delete(); + self::$db = null; + } } } diff --git a/tests/Abuse/RedisClusterTest.php b/tests/Abuse/RedisClusterTest.php index ba1a60da96..31fbed968a 100644 --- a/tests/Abuse/RedisClusterTest.php +++ b/tests/Abuse/RedisClusterTest.php @@ -2,37 +2,51 @@ namespace Utopia\Tests; -use DateInterval; -use RedisCluster; -use Utopia\Abuse\Abuse; -use Utopia\Abuse\Adapter; -use Utopia\Abuse\Adapters\TimeLimit\RedisCluster as TimeLimit; +use Utopia\Abuse\Adapters\TimeLimit; +use Utopia\Abuse\Adapters\TimeLimit\RedisCluster as AdapterRedisCluster; use Utopia\Exception; class RedisClusterTest extends Base { - protected RedisCluster $redis; + /** + * @var \RedisCluster|null + */ + protected static ?\RedisCluster $redis = null; /** * @throws Exception * @throws \Exception */ - public function setUp(): void + public static function setUpBeforeClass(): void { - $this->redis = new RedisCluster(null, ['redis-cluster-0:6379', 'redis-cluster-1:6379', 'redis-cluster-2:6379', 'redis-cluster-3:6379']); - $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 1, $this->redis); - $adapter->setParam('{{ip}}', '127.0.0.1'); - $this->abuse = new Abuse($adapter); + if (self::$redis === null) { + self::$redis = self::initialiseRedis(); + } } - public function getAdapter(string $key, int $limit, int $seconds): Adapter + private static function initialiseRedis(): \RedisCluster { - return new TimeLimit($key, $limit, $seconds, $this->redis); + return new \RedisCluster(null, [ + 'redis-cluster-0:6379', + 'redis-cluster-1:6379', + 'redis-cluster-2:6379', + 'redis-cluster-3:6379' + ]); } - public function getCleanupDateTime(): string + public function getAdapter(string $key, int $limit, int $seconds): TimeLimit { - $interval = DateInterval::createFromDateString('now'); - return strval((new \DateTime())->sub($interval)->getTimestamp()); + return new AdapterRedisCluster($key, $limit, $seconds, self::$redis); + } + + /** + * Clean up Redis connection after all tests + */ + public static function tearDownAfterClass(): void + { + if (self::$redis !== null) { + self::$redis->close(); + self::$redis = null; + } } } diff --git a/tests/Abuse/RedisTest.php b/tests/Abuse/RedisTest.php index e0bf69858a..643fdc50cf 100644 --- a/tests/Abuse/RedisTest.php +++ b/tests/Abuse/RedisTest.php @@ -2,38 +2,46 @@ namespace Utopia\Tests; -use DateInterval; -use Redis as Client; -use Utopia\Abuse\Abuse; -use Utopia\Abuse\Adapter; -use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimit; +use Redis; +use Utopia\Abuse\Adapters\TimeLimit; +use Utopia\Abuse\Adapters\TimeLimit\Redis as AdapterRedis; use Utopia\Exception; class RedisTest extends Base { - protected Client $redis; + protected static ?\Redis $redis = null; /** * @throws Exception * @throws \Exception */ - public function setUp(): void + public static function setUpBeforeClass(): void { - $this->redis = new Client(); - $this->redis->connect('redis', 6379); - $adapter = new TimeLimit('login-attempt-from-{{ip}}', 3, 1, $this->redis); - $adapter->setParam('{{ip}}', '127.0.0.1'); - $this->abuse = new Abuse($adapter); + if (self::$redis === null) { + self::$redis = self::initialiseRedis(); + } } - public function getAdapter(string $key, int $limit, int $seconds): Adapter + private static function initialiseRedis(): \Redis { - return new TimeLimit($key, $limit, $seconds, $this->redis); + $redis = new \Redis(); + $redis->connect('redis', 6379); + return $redis; } - public function getCleanupDateTime(): string + public function getAdapter(string $key, int $limit, int $seconds): TimeLimit { - $interval = DateInterval::createFromDateString('now'); - return strval((new \DateTime())->sub($interval)->getTimestamp()); + return new AdapterRedis($key, $limit, $seconds, self::$redis); + } + + /** + * Clean up Redis connection after all tests + */ + public static function tearDownAfterClass(): void + { + if (self::$redis !== null) { + self::$redis->close(); + self::$redis = null; + } } } From d3119238ea05edd59f93ec99fb11545070e86eff Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 20 Dec 2024 19:41:20 +0530 Subject: [PATCH 33/48] chore: codeql and linter --- src/Abuse/Abuse.php | 8 ++++---- src/Abuse/Adapters/ReCaptcha.php | 6 +++--- src/Abuse/Adapters/TimeLimit/RedisCluster.php | 8 ++++---- tests/Abuse/DatabaseTest.php | 11 ++++++----- tests/Abuse/RedisClusterTest.php | 14 ++++++-------- tests/Abuse/RedisTest.php | 11 ++++++----- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Abuse/Abuse.php b/src/Abuse/Abuse.php index 7386c8a4fa..948939913d 100644 --- a/src/Abuse/Abuse.php +++ b/src/Abuse/Abuse.php @@ -44,13 +44,13 @@ class Abuse } /** - * Delete all logs older than $datetime + * Delete all logs older than $timestamp * - * @param string $datetime + * @param int $timestamp * @return bool */ - public function cleanup(string $datetime): bool + public function cleanup(int $timestamp): bool { - return $this->adapter->cleanup($datetime); + return $this->adapter->cleanup($timestamp); } } diff --git a/src/Abuse/Adapters/ReCaptcha.php b/src/Abuse/Adapters/ReCaptcha.php index ae117ac5b9..15ecbdda84 100644 --- a/src/Abuse/Adapters/ReCaptcha.php +++ b/src/Abuse/Adapters/ReCaptcha.php @@ -90,14 +90,14 @@ class ReCaptcha extends Adapter } /** - * Delete logs older than $datetime + * Delete logs older than $timestamp * - * @param string $datetime + * @param int $timestamp * @return bool * * @throws Exception */ - public function cleanup(string $datetime): bool + public function cleanup(int $timestamp): bool { throw new Exception('Method not supported'); } diff --git a/src/Abuse/Adapters/TimeLimit/RedisCluster.php b/src/Abuse/Adapters/TimeLimit/RedisCluster.php index 4416ac8534..80bd0e519a 100644 --- a/src/Abuse/Adapters/TimeLimit/RedisCluster.php +++ b/src/Abuse/Adapters/TimeLimit/RedisCluster.php @@ -23,10 +23,10 @@ class RedisCluster extends TimeLimit } /** - * Get count for a key at specific datetime + * Get count for a key at specific timestamp * * @param string $key - * @param string $datetime + * @param int $timestamp * @return integer */ protected function count(string $key, int $timestamp): int @@ -51,10 +51,10 @@ class RedisCluster extends TimeLimit } /** - * Record a hit for a key at specific datetime + * Record a hit for a key at specific timestamp * * @param string $key - * @param string $datetime + * @param int $timestamp * @return void */ protected function hit(string $key, int $timestamp): void diff --git a/tests/Abuse/DatabaseTest.php b/tests/Abuse/DatabaseTest.php index dd2be3e21c..58356b2fe1 100755 --- a/tests/Abuse/DatabaseTest.php +++ b/tests/Abuse/DatabaseTest.php @@ -13,13 +13,15 @@ use Utopia\Database\Database; class DatabaseTest extends Base { - protected static ?Database $db = null; + protected static Database $db; public static function setUpBeforeClass(): void { - if (self::$db === null) { - self::$db = self::initialiseDatabase(); + if (isset(self::$db)) { + return; } + + self::$db = self::initialiseDatabase(); } private static function initialiseDatabase(): Database @@ -50,9 +52,8 @@ class DatabaseTest extends Base public static function tearDownAfterClass(): void { - if (self::$db !== null) { + if (isset(self::$db)) { self::$db->delete(); - self::$db = null; } } } diff --git a/tests/Abuse/RedisClusterTest.php b/tests/Abuse/RedisClusterTest.php index 31fbed968a..e1029f946a 100644 --- a/tests/Abuse/RedisClusterTest.php +++ b/tests/Abuse/RedisClusterTest.php @@ -8,10 +8,7 @@ use Utopia\Exception; class RedisClusterTest extends Base { - /** - * @var \RedisCluster|null - */ - protected static ?\RedisCluster $redis = null; + protected static \RedisCluster $redis; /** * @throws Exception @@ -19,9 +16,11 @@ class RedisClusterTest extends Base */ public static function setUpBeforeClass(): void { - if (self::$redis === null) { - self::$redis = self::initialiseRedis(); + if (isset(self::$redis)) { + return; } + + self::$redis = self::initialiseRedis(); } private static function initialiseRedis(): \RedisCluster @@ -44,9 +43,8 @@ class RedisClusterTest extends Base */ public static function tearDownAfterClass(): void { - if (self::$redis !== null) { + if (isset(self::$redis)) { self::$redis->close(); - self::$redis = null; } } } diff --git a/tests/Abuse/RedisTest.php b/tests/Abuse/RedisTest.php index 643fdc50cf..085da1e4fa 100644 --- a/tests/Abuse/RedisTest.php +++ b/tests/Abuse/RedisTest.php @@ -9,7 +9,7 @@ use Utopia\Exception; class RedisTest extends Base { - protected static ?\Redis $redis = null; + protected static \Redis $redis; /** * @throws Exception @@ -17,9 +17,11 @@ class RedisTest extends Base */ public static function setUpBeforeClass(): void { - if (self::$redis === null) { - self::$redis = self::initialiseRedis(); + if (isset(self::$redis)) { + return; } + + self::$redis = self::initialiseRedis(); } private static function initialiseRedis(): \Redis @@ -39,9 +41,8 @@ class RedisTest extends Base */ public static function tearDownAfterClass(): void { - if (self::$redis !== null) { + if (isset(self::$redis)) { self::$redis->close(); - self::$redis = null; } } } From 82f77e2875a58eca55ff5edbf4ae3083ceaf5f9b Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 20 Dec 2024 21:47:50 +0530 Subject: [PATCH 34/48] chore: review comment --- tests/Abuse/Base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Abuse/Base.php b/tests/Abuse/Base.php index a59b32d5f4..a1d008fffe 100644 --- a/tests/Abuse/Base.php +++ b/tests/Abuse/Base.php @@ -27,7 +27,7 @@ abstract class Base extends TestCase */ public function testDynamicKey(): void { - $adapter = $this->getAdapter('dyamic-key-{{ip}}', 2, 1); + $adapter = $this->getAdapter('dynamic-key-{{ip}}', 2, 1); $adapter->setParam('{{ip}}', '0.0.0.10'); $abuse = new Abuse($adapter); $this->assertEquals($abuse->check(), false); From d985da2a80b129caf901ecfd597b0db3827439b1 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 11:24:45 +0000 Subject: [PATCH 35/48] chore: optimise abuse --- src/Abuse/Adapters/TimeLimit/Redis.php | 73 +++++++++----------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index 80a55726f2..d4b27e4d42 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -12,11 +12,17 @@ class Redis extends TimeLimit * @var \Redis */ protected \Redis $redis; + + /** + * @var int + */ + protected int $ttl; public function __construct(string $key, int $limit, int $seconds, \Redis $redis) { $this->redis = $redis; $this->key = $key; + $this->ttl = $seconds; $now = \time(); $this->timestamp = (int)($now - ($now % $seconds)); $this->limit = $limit; @@ -62,16 +68,13 @@ class Redis extends TimeLimit return; } - /** @var string $count */ - $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $timestamp); - if (!$count) { - $this->count = 0; - } else { - $this->count = intval($count); - } - - $this->redis->incr(self::NAMESPACE . '__'. $key .'__'. $timestamp); - $this->count++; + $key = self::NAMESPACE . '__' . $key . '__' . $timestamp; + $this->redis->multi() + ->incr($key) + ->expire($key, $this->ttl) + ->exec(); + + $this->count = ($this->count ?? 0) + 1; } /** @@ -85,18 +88,19 @@ class Redis extends TimeLimit */ public function getLogs(?int $offset = null, ?int $limit = 25): array { - // TODO limit potential is SCAN but needs cursor no offset - $cursor = null; - $keys = $this->redis->scan($cursor, self::NAMESPACE . '__*', $limit); - if (!$keys) { - return []; - } + $cursor = 0; + $matches = []; + $pattern = self::NAMESPACE . '__*'; + + do { + [$cursor, $keys] = $this->redis->scan($cursor, $pattern, $limit); + if (!empty($keys)) { + $values = $this->redis->mget($keys); + $matches = array_merge($matches, array_combine($keys, $values)); + } + } while ($cursor > 0 && (!$limit || count($matches) < $limit)); - $logs = []; - foreach ($keys as $key) { - $logs[$key] = $this->redis->get($key); - } - return $logs; + return $matches; } /** @@ -107,32 +111,7 @@ class Redis extends TimeLimit */ public function cleanup(int $timestamp): bool { - $iterator = null; - while ($iterator !== 0) { - $keys = $this->redis->scan($iterator, self::NAMESPACE . '__*__*', 1000); - $keys = $this->filterKeys($keys ? $keys : [], $timestamp); - $this->redis->del($keys); - } + // No need for manual cleanup - Redis TTL handles this automatically return true; } - - /** - * Filter keys - * - * @param array $keys - * @param integer $timestamp - * @return array - */ - protected function filterKeys(array $keys, int $timestamp): array - { - $filteredKeys = []; - foreach ($keys as $key) { - $parts = explode('__', $key); - $keyTimestamp = (int)end($parts); // Assuming the last part is always the timestamp - if ($keyTimestamp < $timestamp) { - $filteredKeys[] = $key; - } - } - return $filteredKeys; - } } From a9c7993286bf688b91ef84a2a101282da3b41d41 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 11:35:54 +0000 Subject: [PATCH 36/48] fix: check --- src/Abuse/Adapters/TimeLimit/Redis.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index d4b27e4d42..3b93684f9d 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -84,7 +84,7 @@ class Redis extends TimeLimit * * @param int|null $offset * @param int|null $limit - * @return array + * @return array */ public function getLogs(?int $offset = null, ?int $limit = 25): array { @@ -93,10 +93,26 @@ class Redis extends TimeLimit $pattern = self::NAMESPACE . '__*'; do { - [$cursor, $keys] = $this->redis->scan($cursor, $pattern, $limit); + /** @var array{0: string|false, 1: array} */ + $result = $this->redis->scan($cursor, $pattern, $limit); + + if ($result === false) { + break; + } + + [$newCursor, $keys] = $result; + $cursor = (int)$newCursor; + if (!empty($keys)) { + /** @var array */ $values = $this->redis->mget($keys); - $matches = array_merge($matches, array_combine($keys, $values)); + if ($values !== false) { + /** @var array */ + $combinedArray = array_combine($keys, $values); + if ($combinedArray !== false) { + $matches = array_merge($matches, $combinedArray); + } + } } } while ($cursor > 0 && (!$limit || count($matches) < $limit)); From 79c8ce63ec244207762ee1ee9bd6d0ff39ddea52 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 11:36:05 +0000 Subject: [PATCH 37/48] chore: fmt --- src/Abuse/Adapters/TimeLimit/Redis.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index 3b93684f9d..d0afa8ba70 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -12,7 +12,7 @@ class Redis extends TimeLimit * @var \Redis */ protected \Redis $redis; - + /** * @var int */ @@ -73,7 +73,7 @@ class Redis extends TimeLimit ->incr($key) ->expire($key, $this->ttl) ->exec(); - + $this->count = ($this->count ?? 0) + 1; } @@ -91,18 +91,18 @@ class Redis extends TimeLimit $cursor = 0; $matches = []; $pattern = self::NAMESPACE . '__*'; - + do { /** @var array{0: string|false, 1: array} */ $result = $this->redis->scan($cursor, $pattern, $limit); - + if ($result === false) { break; } - + [$newCursor, $keys] = $result; $cursor = (int)$newCursor; - + if (!empty($keys)) { /** @var array */ $values = $this->redis->mget($keys); From cf97de1722ed95cceef426c76000a6204ec5d11e Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 11:37:05 +0000 Subject: [PATCH 38/48] chore: remove obselete version --- docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f614d13765..1756697386 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3' - services: mysql: image: mysql:8 From 03cf65cbe360fa8f6c760838af2d4f577294cbea Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 11:42:43 +0000 Subject: [PATCH 39/48] feat: redis cluster --- src/Abuse/Adapters/TimeLimit/RedisCluster.php | 112 +++++++----------- 1 file changed, 42 insertions(+), 70 deletions(-) diff --git a/src/Abuse/Adapters/TimeLimit/RedisCluster.php b/src/Abuse/Adapters/TimeLimit/RedisCluster.php index 80bd0e519a..47fa140b2e 100644 --- a/src/Abuse/Adapters/TimeLimit/RedisCluster.php +++ b/src/Abuse/Adapters/TimeLimit/RedisCluster.php @@ -13,10 +13,16 @@ class RedisCluster extends TimeLimit */ protected \RedisCluster $redis; + /** + * @var int + */ + protected int $ttl; + public function __construct(string $key, int $limit, int $seconds, \RedisCluster $redis) { $this->redis = $redis; $this->key = $key; + $this->ttl = $seconds; $now = \time(); $this->timestamp = (int)($now - ($now % $seconds)); $this->limit = $limit; @@ -63,22 +69,18 @@ class RedisCluster extends TimeLimit return; } - /** @var string|false $count */ - $count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $timestamp); - if ($count === false) { - $this->count = 0; - } else { - $this->count = intval($count); - } + $key = self::NAMESPACE . '__'. $key .'__'. $timestamp; + + $this->redis->multi(\RedisCluster::MULTI); + $this->redis->incr($key); + $this->redis->expire($key, $this->ttl); + $this->redis->exec(); - $this->redis->incr(self::NAMESPACE . '__'. $key .'__'. $timestamp); - $this->count++; + $this->count = ($this->count ?? 0) + 1; } /** - * Get abuse logs - * - * Return logs with an offset and limit + * Get abuse logs with proper cursor-based pagination * * @param int|null $offset * @param int|null $limit @@ -86,76 +88,46 @@ class RedisCluster extends TimeLimit */ public function getLogs(?int $offset = 0, ?int $limit = 25): array { - // TODO limit potential is SCAN but needs cursor no offset - $keys = $this->scan(self::NAMESPACE . '__*', $offset, $limit); - if ($keys === false) { + $offset = $offset ?? 0; + $limit = $limit ?? 25; + $matches = []; + $pattern = self::NAMESPACE . '__*'; + + // Get all keys from each master + foreach ($this->redis->_masters() as $master) { + $cursor = null; + do { + /** @phpstan-ignore-next-line */ + $keys = $this->redis->scan($cursor, $master, $pattern, 100); + if ($keys !== false) { + $matches = array_merge($matches, $keys); + } + } while ($cursor > 0 && count($matches) < $offset + $limit); + } + + // Sort to ensure consistent ordering + sort($matches); + + // Apply offset and limit + $matches = array_slice($matches, $offset, $limit); + + if (empty($matches)) { return []; } - $logs = []; - foreach ($keys as $key) { - $logs[$key] = $this->redis->get($key); - } - return $logs; + // Batch fetch values using mget + $values = $this->redis->mget($matches); + return array_combine($matches, $values); } /** - * Delete all logs older than $timestamp + * No need for manual cleanup - using Redis TTL * * @param int $timestamp * @return bool */ public function cleanup(int $timestamp): bool { - $keys = $this->scan(self::NAMESPACE . '__*__*'); - $keys = $this->filterKeys($keys ? $keys : [], $timestamp); - /** @phpstan-ignore-next-line */ - $this->redis->del($keys); return true; } - - /** - * Filter keys - * - * @param array $keys - * @param integer $timestamp - * @return array - */ - protected function filterKeys(array $keys, int $timestamp): array - { - $filteredKeys = []; - foreach ($keys as $key) { - $parts = explode('__', $key); - $keyTimestamp = (int)end($parts); // Assuming the last part is always the timestamp - if ($keyTimestamp < $timestamp) { - $filteredKeys[] = $key; - } - } - return $filteredKeys; - } - - /** - * Scan keys across all masters in the Redis cluster - * - * @param string $pattern Pattern to match keys - * @param int|null $cursor Reference to the cursor for scanning - * @param int|null $count Number of keys to return per iteration - * @return array|false - */ - protected function scan(string $pattern, ?int &$cursor = null, ?int $count = 1000): array|false - { - $matches = []; - foreach ($this->redis->_masters() as $master) { - $cursor = null; - do { - /** @phpstan-ignore-next-line */ - $keys = $this->redis->scan($cursor, $master, $pattern, $count); - if ($keys !== false) { - $matches = array_merge($matches, $keys); - } - } while ($cursor > 0); - } - - return empty($matches) ? false : $matches; - } } From 7f2b6b032cf7e83613af29bad60a3ce03e39e1a9 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 11:54:53 +0000 Subject: [PATCH 40/48] fix: redis scan --- src/Abuse/Adapters/TimeLimit/Redis.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index d0afa8ba70..fc4cb8fc64 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -93,20 +93,19 @@ class Redis extends TimeLimit $pattern = self::NAMESPACE . '__*'; do { - /** @var array{0: string|false, 1: array} */ $result = $this->redis->scan($cursor, $pattern, $limit); - - if ($result === false) { - break; + + // Early return if scan failed + if (!is_array($result)) { + return []; } [$newCursor, $keys] = $result; $cursor = (int)$newCursor; if (!empty($keys)) { - /** @var array */ $values = $this->redis->mget($keys); - if ($values !== false) { + if (is_array($values)) { /** @var array */ $combinedArray = array_combine($keys, $values); if ($combinedArray !== false) { From e7c208fa993741e7cce90b40ca6b96cc3356237c Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 12:03:46 +0000 Subject: [PATCH 41/48] chore: revert redis --- src/Abuse/Adapters/TimeLimit/Redis.php | 40 ++++++++------------------ 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index fc4cb8fc64..19602613a2 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -84,38 +84,22 @@ class Redis extends TimeLimit * * @param int|null $offset * @param int|null $limit - * @return array + * @return array */ public function getLogs(?int $offset = null, ?int $limit = 25): array { - $cursor = 0; - $matches = []; - $pattern = self::NAMESPACE . '__*'; + // TODO limit potential is SCAN but needs cursor no offset + $cursor = null; + $keys = $this->redis->scan($cursor, self::NAMESPACE . '__*', $limit); + if (!$keys) { + return []; + } - do { - $result = $this->redis->scan($cursor, $pattern, $limit); - - // Early return if scan failed - if (!is_array($result)) { - return []; - } - - [$newCursor, $keys] = $result; - $cursor = (int)$newCursor; - - if (!empty($keys)) { - $values = $this->redis->mget($keys); - if (is_array($values)) { - /** @var array */ - $combinedArray = array_combine($keys, $values); - if ($combinedArray !== false) { - $matches = array_merge($matches, $combinedArray); - } - } - } - } while ($cursor > 0 && (!$limit || count($matches) < $limit)); - - return $matches; + $logs = []; + foreach ($keys as $key) { + $logs[$key] = $this->redis->get($key); + } + return $logs; } /** From b63b78274506e617ce6e2f93f2bcddbd970014eb Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 12:15:56 +0000 Subject: [PATCH 42/48] chore: fmt --- src/Abuse/Adapters/TimeLimit/RedisCluster.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Abuse/Adapters/TimeLimit/RedisCluster.php b/src/Abuse/Adapters/TimeLimit/RedisCluster.php index 47fa140b2e..72c297edbf 100644 --- a/src/Abuse/Adapters/TimeLimit/RedisCluster.php +++ b/src/Abuse/Adapters/TimeLimit/RedisCluster.php @@ -70,7 +70,7 @@ class RedisCluster extends TimeLimit } $key = self::NAMESPACE . '__'. $key .'__'. $timestamp; - + $this->redis->multi(\RedisCluster::MULTI); $this->redis->incr($key); $this->redis->expire($key, $this->ttl); From d7b8cf59966511fc7181f5ed26e50b780e93430b Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 12:17:16 +0000 Subject: [PATCH 43/48] fix: tests --- src/Abuse/Adapters/TimeLimit/RedisCluster.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Abuse/Adapters/TimeLimit/RedisCluster.php b/src/Abuse/Adapters/TimeLimit/RedisCluster.php index 72c297edbf..6acc99a8f4 100644 --- a/src/Abuse/Adapters/TimeLimit/RedisCluster.php +++ b/src/Abuse/Adapters/TimeLimit/RedisCluster.php @@ -71,7 +71,7 @@ class RedisCluster extends TimeLimit $key = self::NAMESPACE . '__'. $key .'__'. $timestamp; - $this->redis->multi(\RedisCluster::MULTI); + $this->redis->multi(); $this->redis->incr($key); $this->redis->expire($key, $this->ttl); $this->redis->exec(); From 91091d66e97fa02c25f02ae35f286937b87ed8cf Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 12:27:21 +0000 Subject: [PATCH 44/48] chore: remove test cleanup --- tests/Abuse/Base.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/Abuse/Base.php b/tests/Abuse/Base.php index a1d008fffe..5cb59c7da7 100644 --- a/tests/Abuse/Base.php +++ b/tests/Abuse/Base.php @@ -86,26 +86,6 @@ abstract class Base extends TestCase $this->assertEquals($abuse->check(), false); } - /** - * Test logs are deleted after cleanup - */ - public function testCleanup(): void - { - $adapter = $this->getAdapter('', 1, 1); - $abuse = new Abuse($adapter); - - $logs = $abuse->getLogs(0, 100); - $this->assertEquals(6, \count($logs)); // 6 keys are created in the test - - sleep(1); - - $status = $abuse->cleanup(time()); - $this->assertEquals($status, true); - - $logs = $abuse->getLogs(0, 100); - $this->assertEquals(0, \count($logs)); - } - /** * Verify that the time format is correct */ From a59fe2a949e499db56647e28e01511ab0ef3e9bd Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 12:37:59 +0000 Subject: [PATCH 45/48] chore: fix benchmarking --- composer.lock | 12 ++++++------ phpbench.json | 10 ++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/composer.lock b/composer.lock index 0ec24c8c21..e9343924bd 100644 --- a/composer.lock +++ b/composer.lock @@ -149,16 +149,16 @@ }, { "name": "google/protobuf", - "version": "v4.29.1", + "version": "v4.29.2", "source": { "type": "git", "url": "https://github.com/protocolbuffers/protobuf-php.git", - "reference": "6042b5483f8029e42473faeb8ef75ba266278381" + "reference": "79aa5014efeeec3d137df5cdb0ae2fc163953945" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/6042b5483f8029e42473faeb8ef75ba266278381", - "reference": "6042b5483f8029e42473faeb8ef75ba266278381", + "url": "https://api.github.com/repos/protocolbuffers/protobuf-php/zipball/79aa5014efeeec3d137df5cdb0ae2fc163953945", + "reference": "79aa5014efeeec3d137df5cdb0ae2fc163953945", "shasum": "" }, "require": { @@ -187,9 +187,9 @@ "proto" ], "support": { - "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.29.1" + "source": "https://github.com/protocolbuffers/protobuf-php/tree/v4.29.2" }, - "time": "2024-12-03T22:07:45+00:00" + "time": "2024-12-18T14:11:12+00:00" }, { "name": "jean85/pretty-package-versions", diff --git a/phpbench.json b/phpbench.json index adc40d1294..45395c8d87 100644 --- a/phpbench.json +++ b/phpbench.json @@ -1,6 +1,8 @@ { - "$schema":"vendor/phpbench/phpbench/phpbench.schema.json", - "runner.bootstrap": "vendor/autoload.php", - "runner.path": "tests", - "runner.file_pattern": "*Bench.php" + "$schema": "vendor/phpbench/phpbench/phpbench.schema.json", + "runner": { + "bootstrap": "vendor/autoload.php", + "path": "tests/Abuse/Bench", + "file_pattern": "*.php" + } } \ No newline at end of file From 440ebd62c35b79f176d4ec5674f91a6d5528d6e3 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 12:39:32 +0000 Subject: [PATCH 46/48] fix: bench --- composer.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/composer.json b/composer.json index 5edc270736..cc801b6c31 100755 --- a/composer.json +++ b/composer.json @@ -29,5 +29,11 @@ "phpstan/phpstan": "^1.9", "laravel/pint": "1.5.*", "phpbench/phpbench": "^1.2" + }, + "config": { + "allow-plugins": { + "php-http/discovery": true, + "tbachert/spi": true + } } } From 072725daa471ae53eb7483d06ed9689632525e0c Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Fri, 27 Dec 2024 12:44:21 +0000 Subject: [PATCH 47/48] chore: bench --- phpbench.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/phpbench.json b/phpbench.json index 45395c8d87..19e8aa0594 100644 --- a/phpbench.json +++ b/phpbench.json @@ -1,8 +1,6 @@ { "$schema": "vendor/phpbench/phpbench/phpbench.schema.json", - "runner": { - "bootstrap": "vendor/autoload.php", - "path": "tests/Abuse/Bench", - "file_pattern": "*.php" - } + "runner.bootstrap": "vendor/autoload.php", + "runner.path": "tests/Abuse/Bench", + "runner.file_pattern": "*.php" } \ No newline at end of file From 8c950cc3d09cf0d1824f86d1cbcf8e064aaeaceb Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 2 Jan 2025 14:26:25 +0200 Subject: [PATCH 48/48] bumb database version --- composer.json | 2 +- composer.lock | 80 +++++++++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/composer.json b/composer.json index cc801b6c31..731ef5c0b2 100755 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-pdo": "*", "ext-curl": "*", "ext-redis": "*", - "utopia-php/database": "0.53.200" + "utopia-php/database": "0.53.29" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index e9343924bd..0e33d8a2bf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "99ca13df0ed5cb02c170e711cc847511", + "content-hash": "c8191f8fc4877e68521bc8d2f97394c7", "packages": [ { "name": "brick/math", @@ -1408,12 +1408,12 @@ }, "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, "branch-alias": { "dev-main": "3.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -1458,16 +1458,16 @@ }, { "name": "symfony/http-client", - "version": "v7.2.1", + "version": "v7.2.2", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "ff4df2b68d1c67abb9fef146e6540ea16b58d99e" + "reference": "339ba21476eb184290361542f732ad12c97591ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/ff4df2b68d1c67abb9fef146e6540ea16b58d99e", - "reference": "ff4df2b68d1c67abb9fef146e6540ea16b58d99e", + "url": "https://api.github.com/repos/symfony/http-client/zipball/339ba21476eb184290361542f732ad12c97591ec", + "reference": "339ba21476eb184290361542f732ad12c97591ec", "shasum": "" }, "require": { @@ -1533,7 +1533,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.2.1" + "source": "https://github.com/symfony/http-client/tree/v7.2.2" }, "funding": [ { @@ -1549,7 +1549,7 @@ "type": "tidelift" } ], - "time": "2024-12-07T08:50:44+00:00" + "time": "2024-12-30T18:35:15+00:00" }, { "name": "symfony/http-client-contracts", @@ -1889,12 +1889,12 @@ }, "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, "branch-alias": { "dev-main": "3.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" } }, "autoload": { @@ -2098,16 +2098,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.200", + "version": "0.53.29", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "570c63a3760d0e1404679ddfacd9484af40bd9fc" + "reference": "466ddedc0708c9faa09916d13608c117980602d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/570c63a3760d0e1404679ddfacd9484af40bd9fc", - "reference": "570c63a3760d0e1404679ddfacd9484af40bd9fc", + "url": "https://api.github.com/repos/utopia-php/database/zipball/466ddedc0708c9faa09916d13608c117980602d8", + "reference": "466ddedc0708c9faa09916d13608c117980602d8", "shasum": "" }, "require": { @@ -2148,9 +2148,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.200" + "source": "https://github.com/utopia-php/database/tree/0.53.29" }, - "time": "2024-12-01T07:59:15+00:00" + "time": "2025-01-02T10:57:56+00:00" }, { "name": "utopia-php/framework", @@ -2662,16 +2662,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.3.1", + "version": "v5.4.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b" + "reference": "447a020a1f875a434d62f2a401f53b82a396e494" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8eea230464783aa9671db8eea6f8c6ac5285794b", - "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/447a020a1f875a434d62f2a401f53b82a396e494", + "reference": "447a020a1f875a434d62f2a401f53b82a396e494", "shasum": "" }, "require": { @@ -2714,9 +2714,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.3.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.4.0" }, - "time": "2024-10-08T18:51:32+00:00" + "time": "2024-12-30T11:07:19+00:00" }, { "name": "phar-io/manifest", @@ -3040,16 +3040,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.13", + "version": "1.12.14", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "9b469068840cfa031e1deaf2fa1886d00e20680f" + "reference": "e73868f809e68fff33be961ad4946e2e43ec9e38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9b469068840cfa031e1deaf2fa1886d00e20680f", - "reference": "9b469068840cfa031e1deaf2fa1886d00e20680f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e73868f809e68fff33be961ad4946e2e43ec9e38", + "reference": "e73868f809e68fff33be961ad4946e2e43ec9e38", "shasum": "" }, "require": { @@ -3094,7 +3094,7 @@ "type": "github" } ], - "time": "2024-12-17T17:00:20+00:00" + "time": "2024-12-31T07:26:13+00:00" }, { "name": "phpunit/php-code-coverage", @@ -4755,16 +4755,16 @@ }, { "name": "symfony/finder", - "version": "v7.2.0", + "version": "v7.2.2", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "6de263e5868b9a137602dd1e33e4d48bfae99c49" + "reference": "87a71856f2f56e4100373e92529eed3171695cfb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/6de263e5868b9a137602dd1e33e4d48bfae99c49", - "reference": "6de263e5868b9a137602dd1e33e4d48bfae99c49", + "url": "https://api.github.com/repos/symfony/finder/zipball/87a71856f2f56e4100373e92529eed3171695cfb", + "reference": "87a71856f2f56e4100373e92529eed3171695cfb", "shasum": "" }, "require": { @@ -4799,7 +4799,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.2.0" + "source": "https://github.com/symfony/finder/tree/v7.2.2" }, "funding": [ { @@ -4815,7 +4815,7 @@ "type": "tidelift" } ], - "time": "2024-10-23T06:56:12+00:00" + "time": "2024-12-30T19:00:17+00:00" }, { "name": "symfony/options-resolver", @@ -5372,7 +5372,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -5381,6 +5381,6 @@ "ext-curl": "*", "ext-redis": "*" }, - "platform-dev": {}, + "platform-dev": [], "plugin-api-version": "2.6.0" }