From 661329b9774842dcad6a3b5a731f2c3805ed1881 Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 9 May 2024 19:54:28 +0300 Subject: [PATCH 01/21] Invalid cursor value --- app/controllers/api/databases.php | 6 +++++ composer.lock | 22 +++++++++---------- .../e2e/Services/Databases/DatabasesBase.php | 15 +++++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c8903538d0..48f2b40acd 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -36,6 +36,7 @@ use Utopia\Database\Validator\Index as IndexValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\Structure; @@ -3006,6 +3007,11 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') $cursor = \reset($cursor); if ($cursor) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $documentId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId)); diff --git a/composer.lock b/composer.lock index 76f51b75c5..34e6031fdc 100644 --- a/composer.lock +++ b/composer.lock @@ -822,16 +822,16 @@ }, { "name": "paragonie/constant_time_encoding", - "version": "v2.6.3", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/paragonie/constant_time_encoding.git", - "reference": "58c3f47f650c94ec05a151692652a868995d2938" + "reference": "52a0d99e69f56b9ec27ace92ba56897fe6993105" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/58c3f47f650c94ec05a151692652a868995d2938", - "reference": "58c3f47f650c94ec05a151692652a868995d2938", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/52a0d99e69f56b9ec27ace92ba56897fe6993105", + "reference": "52a0d99e69f56b9ec27ace92ba56897fe6993105", "shasum": "" }, "require": { @@ -885,7 +885,7 @@ "issues": "https://github.com/paragonie/constant_time_encoding/issues", "source": "https://github.com/paragonie/constant_time_encoding" }, - "time": "2022-06-14T06:56:20+00:00" + "time": "2024-05-08T12:18:48+00:00" }, { "name": "phpmailer/phpmailer", @@ -3660,16 +3660,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.28.0", + "version": "1.29.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb" + "reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", - "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/536889f2b340489d328f5ffb7b02bb6b183ddedc", + "reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc", "shasum": "" }, "require": { @@ -3701,9 +3701,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.28.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.0" }, - "time": "2024-04-03T18:51:33+00:00" + "time": "2024-05-06T12:04:23+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 6f65552f1c..0aac8045a7 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -1743,6 +1743,21 @@ trait DatabasesBase $this->assertEquals(400, $documents['headers']['status-code']); + /** + * Test null value for cursor + */ + + $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => [ + '{"method":"cursorAfter","values":[null]}', + ], + ]); + + $this->assertEquals(400, $documents['headers']['status-code']); + return []; } From 8bf1d4924b596dedeadcd3fd0d56b08072a1bfb0 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 15 May 2024 10:36:18 +0300 Subject: [PATCH 02/21] Use original delete throw --- composer.json | 2 +- composer.lock | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 8865a32d91..26032698ec 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "utopia-php/cache": "0.9.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.49.*", + "utopia-php/database": "dev-main as 0.49.9", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index 34e6031fdc..d31d08315e 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": "6ce62f5b54254e5023c5ace349a0ced7", + "content-hash": "26d20d884c55e5bcbc24ae42e5040d02", "packages": [ { "name": "adhocore/jwt", @@ -1556,16 +1556,16 @@ }, { "name": "utopia-php/database", - "version": "0.49.8", + "version": "dev-main", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "4fb1f6d216f6f628dd5b013e1f539ae2191228b1" + "reference": "ee93c14b99820f791c669648854f094fe399a085" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/4fb1f6d216f6f628dd5b013e1f539ae2191228b1", - "reference": "4fb1f6d216f6f628dd5b013e1f539ae2191228b1", + "url": "https://api.github.com/repos/utopia-php/database/zipball/ee93c14b99820f791c669648854f094fe399a085", + "reference": "ee93c14b99820f791c669648854f094fe399a085", "shasum": "" }, "require": { @@ -1586,6 +1586,7 @@ "swoole/ide-helper": "4.8.0", "utopia-php/cli": "^0.14.0" }, + "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -1606,9 +1607,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.49.8" + "source": "https://github.com/utopia-php/database/tree/0.49.9" }, - "time": "2024-05-09T04:43:05+00:00" + "time": "2024-05-12T23:58:34+00:00" }, { "name": "utopia-php/domains", @@ -5503,9 +5504,18 @@ "time": "2023-11-21T18:54:41+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-main", + "alias": "0.49.9", + "alias_normalized": "0.49.9.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { From 6a4581671f79def9096c9dd7cfa767a1321f57f8 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 15 May 2024 10:52:45 +0300 Subject: [PATCH 03/21] Use original delete throw --- composer.json | 2 +- composer.lock | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 26032698ec..412490ece6 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "utopia-php/cache": "0.9.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-main as 0.49.9", + "utopia-php/database": "dev-original-exception as 0.49.9", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index d31d08315e..d5f431bb26 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": "26d20d884c55e5bcbc24ae42e5040d02", + "content-hash": "3ecdbc85939cda3b739dcc76c356f3b4", "packages": [ { "name": "adhocore/jwt", @@ -1556,16 +1556,16 @@ }, { "name": "utopia-php/database", - "version": "dev-main", + "version": "dev-original-exception", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "ee93c14b99820f791c669648854f094fe399a085" + "reference": "1a85827705a420b0dbc6c15845c33ba039cde900" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/ee93c14b99820f791c669648854f094fe399a085", - "reference": "ee93c14b99820f791c669648854f094fe399a085", + "url": "https://api.github.com/repos/utopia-php/database/zipball/1a85827705a420b0dbc6c15845c33ba039cde900", + "reference": "1a85827705a420b0dbc6c15845c33ba039cde900", "shasum": "" }, "require": { @@ -1586,7 +1586,6 @@ "swoole/ide-helper": "4.8.0", "utopia-php/cli": "^0.14.0" }, - "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -1607,9 +1606,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.49.9" + "source": "https://github.com/utopia-php/database/tree/original-exception" }, - "time": "2024-05-12T23:58:34+00:00" + "time": "2024-05-15T07:29:54+00:00" }, { "name": "utopia-php/domains", @@ -5507,7 +5506,7 @@ "aliases": [ { "package": "utopia-php/database", - "version": "dev-main", + "version": "dev-original-exception", "alias": "0.49.9", "alias_normalized": "0.49.9.0" } From 1a5ae40e15695446bf2c630259693dec437936cb Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 15 May 2024 10:56:02 +0300 Subject: [PATCH 04/21] revert --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 412490ece6..8865a32d91 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,7 @@ "utopia-php/cache": "0.9.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-original-exception as 0.49.9", + "utopia-php/database": "0.49.*", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", From 7efa5b59f5fec032993d7cf9b9f7d4e7ff60e72e Mon Sep 17 00:00:00 2001 From: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> Date: Thu, 3 Oct 2024 14:40:31 -0700 Subject: [PATCH 05/21] fix: update blr region name to the new preferred name --- app/config/regions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/regions.php b/app/config/regions.php index b40667ab5e..61029a9996 100644 --- a/app/config/regions.php +++ b/app/config/regions.php @@ -31,7 +31,7 @@ return [ ], 'blr' => [ '$id' => 'blr', - 'name' => 'Banglore', + 'name' => 'Bengaluru', 'disabled' => true, 'flag' => 'in', 'default' => true, From c3d6dcad866f93b8ead7a366dab30269df8805f7 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:46:00 +0100 Subject: [PATCH 06/21] chore: bump assistant --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6ecb0ecff8..479ca38b8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -863,7 +863,7 @@ services: appwrite-assistant: container_name: appwrite-assistant - image: appwrite/assistant:0.4.0 + image: appwrite/assistant:0.5.0 networks: - appwrite environment: From 801724e90e01191edb38ad39711482bbd0814460 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 15 Oct 2024 15:50:02 +0300 Subject: [PATCH 07/21] APP_DATABASE_QUERY_VALUES --- app/init.php | 10 ++-- composer.json | 2 +- composer.lock | 54 +++++++++++-------- .../Database/Validator/Queries/Base.php | 2 +- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/app/init.php b/app/init.php index c2777f36f1..dcf9a21f56 100644 --- a/app/init.php +++ b/app/init.php @@ -130,6 +130,7 @@ const APP_DATABASE_ATTRIBUTE_INT_RANGE = 'intRange'; const APP_DATABASE_ATTRIBUTE_FLOAT_RANGE = 'floatRange'; const APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH = 1_073_741_824; // 2^32 bits / 4 bits per char const APP_DATABASE_TIMEOUT_MILLISECONDS = 15_000; +const APP_DATABASE_QUERY_VALUES = 100; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_FUNCTIONS = '/storage/functions'; const APP_STORAGE_BUILDS = '/storage/builds'; @@ -1398,7 +1399,8 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForConsole, $database ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()) - ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS); + ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS) + ->setMaxQueryValues(APP_DATABASE_QUERY_VALUES); try { $dsn = new DSN($project->getAttribute('database')); @@ -1434,7 +1436,8 @@ App::setResource('dbForConsole', function (Group $pools, Cache $cache) { ->setNamespace('_console') ->setMetadata('host', \gethostname()) ->setMetadata('project', 'console') - ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS); + ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS) + ->setMaxQueryValues(APP_DATABASE_QUERY_VALUES); return $database; }, ['pools', 'cache']); @@ -1458,7 +1461,8 @@ App::setResource('getProjectDB', function (Group $pools, Database $dbForConsole, $database ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()) - ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS); + ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS) + ->setMaxQueryValues(APP_DATABASE_QUERY_VALUES); if ($dsn->getHost() === System::getEnv('_APP_DATABASE_SHARED_TABLES', '')) { $database diff --git a/composer.json b/composer.json index 813e9feff2..e12fc531ec 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.10.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.53.6", + "utopia-php/database": "dev-0.53.x-max-query-size as 0.53.6", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index 7213e1ecd5..6f9b7eb6cd 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": "5fef87b7ea4352869a502d1570bd43e7", + "content-hash": "59f5ddee3c1259ce3f63762f2f064cc6", "packages": [ { "name": "adhocore/jwt", @@ -1724,16 +1724,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.6", + "version": "dev-0.53.x-max-query-size", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "feddc8e808eaea9a11c65cca3f01683def422f52" + "reference": "7c15e2ba06e82d7daeb4edbf43564b435324a7d4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/feddc8e808eaea9a11c65cca3f01683def422f52", - "reference": "feddc8e808eaea9a11c65cca3f01683def422f52", + "url": "https://api.github.com/repos/utopia-php/database/zipball/7c15e2ba06e82d7daeb4edbf43564b435324a7d4", + "reference": "7c15e2ba06e82d7daeb4edbf43564b435324a7d4", "shasum": "" }, "require": { @@ -1774,9 +1774,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.6" + "source": "https://github.com/utopia-php/database/tree/0.53.x-max-query-size" }, - "time": "2024-10-08T02:18:46+00:00" + "time": "2024-10-15T12:20:07+00:00" }, { "name": "utopia-php/domains", @@ -2070,16 +2070,16 @@ }, { "name": "utopia-php/logger", - "version": "0.6.1", + "version": "0.6.2", "source": { "type": "git", "url": "https://github.com/utopia-php/logger.git", - "reference": "7e8ff512c6f04577aba1df67c7b9628971946f9c" + "reference": "25b5bd2ad8bb51292f76332faa7034644fd0941d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/logger/zipball/7e8ff512c6f04577aba1df67c7b9628971946f9c", - "reference": "7e8ff512c6f04577aba1df67c7b9628971946f9c", + "url": "https://api.github.com/repos/utopia-php/logger/zipball/25b5bd2ad8bb51292f76332faa7034644fd0941d", + "reference": "25b5bd2ad8bb51292f76332faa7034644fd0941d", "shasum": "" }, "require": { @@ -2118,9 +2118,9 @@ ], "support": { "issues": "https://github.com/utopia-php/logger/issues", - "source": "https://github.com/utopia-php/logger/tree/0.6.1" + "source": "https://github.com/utopia-php/logger/tree/0.6.2" }, - "time": "2024-09-20T14:02:12+00:00" + "time": "2024-10-14T16:02:49+00:00" }, { "name": "utopia-php/messaging", @@ -3847,6 +3847,7 @@ "issues": "https://github.com/phpbench/dom/issues", "source": "https://github.com/phpbench/dom/tree/0.3.3" }, + "abandoned": true, "time": "2023-03-06T23:46:57+00:00" }, { @@ -4194,16 +4195,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.32.0", + "version": "1.33.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4" + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6ca22b154efdd9e3c68c56f5d94670920a1c19a4", - "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", "shasum": "" }, "require": { @@ -4235,9 +4236,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.32.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" }, - "time": "2024-09-26T07:23:32+00:00" + "time": "2024-10-13T11:25:22+00:00" }, { "name": "phpunit/php-code-coverage", @@ -7002,9 +7003,18 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/database", + "version": "dev-0.53.x-max-query-size", + "alias": "0.53.6", + "alias_normalized": "0.53.6.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/database": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -7028,5 +7038,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index a3555c08dd..7dc1bb6800 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -66,7 +66,7 @@ class Base extends Queries new Limit(), new Offset(), new Cursor(), - new Filter($attributes), + new Filter($attributes, APP_DATABASE_QUERY_VALUES), new Order($attributes), ]; From 20800d760bc0d0bc76c4482e4d190748707acef2 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 15 Oct 2024 15:56:12 +0300 Subject: [PATCH 08/21] Set to 500 --- app/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/init.php b/app/init.php index dcf9a21f56..e3c9cb374a 100644 --- a/app/init.php +++ b/app/init.php @@ -130,7 +130,7 @@ const APP_DATABASE_ATTRIBUTE_INT_RANGE = 'intRange'; const APP_DATABASE_ATTRIBUTE_FLOAT_RANGE = 'floatRange'; const APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH = 1_073_741_824; // 2^32 bits / 4 bits per char const APP_DATABASE_TIMEOUT_MILLISECONDS = 15_000; -const APP_DATABASE_QUERY_VALUES = 100; +const APP_DATABASE_QUERY_VALUES = 500; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_FUNCTIONS = '/storage/functions'; const APP_STORAGE_BUILDS = '/storage/builds'; From c9e2be0e08d63f88c0064d78be099fffd8c25479 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 15 Oct 2024 16:35:26 +0300 Subject: [PATCH 09/21] Fix failing test --- tests/e2e/Services/Databases/DatabasesBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 04f2dbd8c8..39ba3b04df 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -2096,7 +2096,7 @@ trait DatabasesBase */ $conditions = []; - for ($i = 0; $i < 101; $i++) { + for ($i = 0; $i < APP_DATABASE_QUERY_VALUES + 1; $i++) { $conditions[] = $i; } From 7a64987da72180464bdcf5f7dfa6415d86e027ff Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 15 Oct 2024 17:25:10 +0300 Subject: [PATCH 10/21] Fix message --- tests/e2e/Services/Databases/DatabasesBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 39ba3b04df..f63865d9a6 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -2109,7 +2109,7 @@ trait DatabasesBase ], ]); $this->assertEquals(400, $documents['headers']['status-code']); - $this->assertEquals('Invalid query: Query on attribute has greater than 100 values: releaseYear', $documents['body']['message']); + $this->assertEquals('Invalid query: Query on attribute has greater than '.APP_DATABASE_QUERY_VALUES.' values: releaseYear', $documents['body']['message']); $value = ''; From 1b93c78c5f7f9d3892426f26e2aeb6947bc08ea1 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 15 Oct 2024 16:34:33 +0000 Subject: [PATCH 11/21] chore: add missing indexes --- app/config/collections.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/config/collections.php b/app/config/collections.php index bd9a4550c8..a55ab1abd0 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -4575,6 +4575,20 @@ $consoleCollections = array_merge([ 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => ID::custom('_key_pingCount'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['pingCount'], + 'lengths' => [], + 'orders' => [], + ], + [ + '$id' => ID::custom('_key_pingedAt'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['pingedAt'], + 'lengths' => [], + 'orders' => [], + ] ], ], From 0bbfcd3888e27dfd3cc26e8415bdf12c191be686 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 15 Oct 2024 16:37:01 +0000 Subject: [PATCH 12/21] chore: update dependencies --- composer.lock | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/composer.lock b/composer.lock index 7213e1ecd5..afac75fa5e 100644 --- a/composer.lock +++ b/composer.lock @@ -2070,16 +2070,16 @@ }, { "name": "utopia-php/logger", - "version": "0.6.1", + "version": "0.6.2", "source": { "type": "git", "url": "https://github.com/utopia-php/logger.git", - "reference": "7e8ff512c6f04577aba1df67c7b9628971946f9c" + "reference": "25b5bd2ad8bb51292f76332faa7034644fd0941d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/logger/zipball/7e8ff512c6f04577aba1df67c7b9628971946f9c", - "reference": "7e8ff512c6f04577aba1df67c7b9628971946f9c", + "url": "https://api.github.com/repos/utopia-php/logger/zipball/25b5bd2ad8bb51292f76332faa7034644fd0941d", + "reference": "25b5bd2ad8bb51292f76332faa7034644fd0941d", "shasum": "" }, "require": { @@ -2118,9 +2118,9 @@ ], "support": { "issues": "https://github.com/utopia-php/logger/issues", - "source": "https://github.com/utopia-php/logger/tree/0.6.1" + "source": "https://github.com/utopia-php/logger/tree/0.6.2" }, - "time": "2024-09-20T14:02:12+00:00" + "time": "2024-10-14T16:02:49+00:00" }, { "name": "utopia-php/messaging", @@ -3847,6 +3847,7 @@ "issues": "https://github.com/phpbench/dom/issues", "source": "https://github.com/phpbench/dom/tree/0.3.3" }, + "abandoned": true, "time": "2023-03-06T23:46:57+00:00" }, { @@ -4194,16 +4195,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.32.0", + "version": "1.33.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4" + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6ca22b154efdd9e3c68c56f5d94670920a1c19a4", - "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", "shasum": "" }, "require": { @@ -4235,9 +4236,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.32.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" }, - "time": "2024-09-26T07:23:32+00:00" + "time": "2024-10-13T11:25:22+00:00" }, { "name": "phpunit/php-code-coverage", @@ -7028,5 +7029,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From 481c0b9d7aa73970ad27e33287d29a4953871b1c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 16 Oct 2024 21:22:36 +1300 Subject: [PATCH 13/21] Update database --- composer.json | 2 +- composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 813e9feff2..dd5472a0fa 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.10.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.53.6", + "utopia-php/database": "0.53.8", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index afac75fa5e..867030f289 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": "5fef87b7ea4352869a502d1570bd43e7", + "content-hash": "18505aa5baca1170e7cbdbb2a355b173", "packages": [ { "name": "adhocore/jwt", @@ -1724,16 +1724,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.6", + "version": "0.53.8", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "feddc8e808eaea9a11c65cca3f01683def422f52" + "reference": "f4f9297d633b9f8407c6261535549bfd6024a468" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/feddc8e808eaea9a11c65cca3f01683def422f52", - "reference": "feddc8e808eaea9a11c65cca3f01683def422f52", + "url": "https://api.github.com/repos/utopia-php/database/zipball/f4f9297d633b9f8407c6261535549bfd6024a468", + "reference": "f4f9297d633b9f8407c6261535549bfd6024a468", "shasum": "" }, "require": { @@ -1774,9 +1774,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.6" + "source": "https://github.com/utopia-php/database/tree/0.53.8" }, - "time": "2024-10-08T02:18:46+00:00" + "time": "2024-10-16T08:16:33+00:00" }, { "name": "utopia-php/domains", From 16d65f32b3214be695557a93be9da816e6365caf Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 16 Oct 2024 21:35:32 +1300 Subject: [PATCH 14/21] Review fixes --- app/init.php | 8 +++--- composer.json | 2 +- composer.lock | 27 +++++++------------ .../Database/Validator/Queries/Base.php | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 4 +-- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/app/init.php b/app/init.php index e3c9cb374a..eb149adc04 100644 --- a/app/init.php +++ b/app/init.php @@ -130,7 +130,7 @@ const APP_DATABASE_ATTRIBUTE_INT_RANGE = 'intRange'; const APP_DATABASE_ATTRIBUTE_FLOAT_RANGE = 'floatRange'; const APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH = 1_073_741_824; // 2^32 bits / 4 bits per char const APP_DATABASE_TIMEOUT_MILLISECONDS = 15_000; -const APP_DATABASE_QUERY_VALUES = 500; +const APP_DATABASE_QUERY_MAX_VALUES = 500; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_FUNCTIONS = '/storage/functions'; const APP_STORAGE_BUILDS = '/storage/builds'; @@ -1400,7 +1400,7 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForConsole, ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()) ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS) - ->setMaxQueryValues(APP_DATABASE_QUERY_VALUES); + ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES); try { $dsn = new DSN($project->getAttribute('database')); @@ -1437,7 +1437,7 @@ App::setResource('dbForConsole', function (Group $pools, Cache $cache) { ->setMetadata('host', \gethostname()) ->setMetadata('project', 'console') ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS) - ->setMaxQueryValues(APP_DATABASE_QUERY_VALUES); + ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES); return $database; }, ['pools', 'cache']); @@ -1462,7 +1462,7 @@ App::setResource('getProjectDB', function (Group $pools, Database $dbForConsole, ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()) ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS) - ->setMaxQueryValues(APP_DATABASE_QUERY_VALUES); + ->setMaxQueryValues(APP_DATABASE_QUERY_MAX_VALUES); if ($dsn->getHost() === System::getEnv('_APP_DATABASE_SHARED_TABLES', '')) { $database diff --git a/composer.json b/composer.json index e12fc531ec..dd5472a0fa 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.10.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "dev-0.53.x-max-query-size as 0.53.6", + "utopia-php/database": "0.53.8", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index 6f9b7eb6cd..867030f289 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": "59f5ddee3c1259ce3f63762f2f064cc6", + "content-hash": "18505aa5baca1170e7cbdbb2a355b173", "packages": [ { "name": "adhocore/jwt", @@ -1724,16 +1724,16 @@ }, { "name": "utopia-php/database", - "version": "dev-0.53.x-max-query-size", + "version": "0.53.8", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "7c15e2ba06e82d7daeb4edbf43564b435324a7d4" + "reference": "f4f9297d633b9f8407c6261535549bfd6024a468" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/7c15e2ba06e82d7daeb4edbf43564b435324a7d4", - "reference": "7c15e2ba06e82d7daeb4edbf43564b435324a7d4", + "url": "https://api.github.com/repos/utopia-php/database/zipball/f4f9297d633b9f8407c6261535549bfd6024a468", + "reference": "f4f9297d633b9f8407c6261535549bfd6024a468", "shasum": "" }, "require": { @@ -1774,9 +1774,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.x-max-query-size" + "source": "https://github.com/utopia-php/database/tree/0.53.8" }, - "time": "2024-10-15T12:20:07+00:00" + "time": "2024-10-16T08:16:33+00:00" }, { "name": "utopia-php/domains", @@ -7003,18 +7003,9 @@ "time": "2024-03-07T20:33:40+00:00" } ], - "aliases": [ - { - "package": "utopia-php/database", - "version": "dev-0.53.x-max-query-size", - "alias": "0.53.6", - "alias_normalized": "0.53.6.0" - } - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/database": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 7dc1bb6800..af5d59ddfd 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -66,7 +66,7 @@ class Base extends Queries new Limit(), new Offset(), new Cursor(), - new Filter($attributes, APP_DATABASE_QUERY_VALUES), + new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES), new Order($attributes), ]; diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index f63865d9a6..6d8622276e 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -2096,7 +2096,7 @@ trait DatabasesBase */ $conditions = []; - for ($i = 0; $i < APP_DATABASE_QUERY_VALUES + 1; $i++) { + for ($i = 0; $i < APP_DATABASE_QUERY_MAX_VALUES + 1; $i++) { $conditions[] = $i; } @@ -2109,7 +2109,7 @@ trait DatabasesBase ], ]); $this->assertEquals(400, $documents['headers']['status-code']); - $this->assertEquals('Invalid query: Query on attribute has greater than '.APP_DATABASE_QUERY_VALUES.' values: releaseYear', $documents['body']['message']); + $this->assertEquals('Invalid query: Query on attribute has greater than '.APP_DATABASE_QUERY_MAX_VALUES.' values: releaseYear', $documents['body']['message']); $value = ''; From 45c8584903e36b37022a6b35fb165c0a96913d57 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 16 Oct 2024 21:36:18 +1300 Subject: [PATCH 15/21] Update migration --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 867030f289..9079512e60 100644 --- a/composer.lock +++ b/composer.lock @@ -2175,16 +2175,16 @@ }, { "name": "utopia-php/migration", - "version": "0.6.8", + "version": "0.6.9", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "c3740de52c1b616aa7f054d0fadb9207895b5279" + "reference": "ce97cdf2ca82e7cec78e2ed484ef2c71ebe8744b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/c3740de52c1b616aa7f054d0fadb9207895b5279", - "reference": "c3740de52c1b616aa7f054d0fadb9207895b5279", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/ce97cdf2ca82e7cec78e2ed484ef2c71ebe8744b", + "reference": "ce97cdf2ca82e7cec78e2ed484ef2c71ebe8744b", "shasum": "" }, "require": { @@ -2225,9 +2225,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/0.6.8" + "source": "https://github.com/utopia-php/migration/tree/0.6.9" }, - "time": "2024-10-10T08:09:19+00:00" + "time": "2024-10-16T08:33:21+00:00" }, { "name": "utopia-php/mongo", From a7f1cc128a4516d70f778fafbdb62c1bfeddd3a7 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 17 Oct 2024 18:41:24 +1300 Subject: [PATCH 16/21] Validate cursor queries to avoid getDocument type error --- app/controllers/api/account.php | 7 +++++++ app/controllers/api/databases.php | 23 +++++++++++++++++++++++ app/controllers/api/functions.php | 19 +++++++++++++++++++ app/controllers/api/messaging.php | 26 ++++++++++++++++++++++++++ app/controllers/api/migrations.php | 7 +++++++ app/controllers/api/projects.php | 7 +++++++ app/controllers/api/proxy.php | 7 +++++++ app/controllers/api/storage.php | 13 +++++++++++++ app/controllers/api/teams.php | 14 ++++++++++++++ app/controllers/api/users.php | 18 ++++++++++++++++++ app/controllers/api/vcs.php | 7 +++++++ 11 files changed, 148 insertions(+) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 64441fee5c..cb71818df3 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -42,6 +42,7 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; @@ -4486,6 +4487,12 @@ App::get('/v1/account/identities') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $identityId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('identities', $identityId); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 2784d7f57b..a44d5dab6d 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -547,6 +547,13 @@ App::get('/v1/databases') }); $cursor = reset($cursor); if ($cursor) { + /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $databaseId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('databases', $databaseId); @@ -879,6 +886,12 @@ App::get('/v1/databases/:databaseId/collections') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $collectionId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); @@ -1789,6 +1802,11 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') $cursor = \reset($cursor); if ($cursor) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $attributeId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->find('attributes', [ Query::equal('collectionInternalId', [$collection->getInternalId()]), @@ -2668,6 +2686,11 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') $cursor = reset($cursor); if ($cursor) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $indexId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->find('indexes', [ Query::equal('collectionInternalId', [$collection->getInternalId()]), diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index f1e8d82a9b..c3051ef476 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -37,6 +37,7 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Datetime as DatetimeValidator; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\Roles; use Utopia\Database\Validator\UID; use Utopia\Storage\Device; @@ -431,6 +432,12 @@ App::get('/v1/functions') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $functionId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('functions', $functionId); @@ -1407,6 +1414,12 @@ App::get('/v1/functions/:functionId/deployments') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $deploymentId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('deployments', $deploymentId); @@ -2153,6 +2166,12 @@ App::get('/v1/functions/:functionId/executions') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $executionId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('executions', $executionId); diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 7da0348a8f..c68ba91297 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -32,6 +32,7 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\Roles; @@ -866,6 +867,11 @@ App::get('/v1/messaging/providers') $cursor = reset($cursor); if ($cursor) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $providerId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('providers', $providerId)); @@ -1998,6 +2004,11 @@ App::get('/v1/messaging/topics') $cursor = reset($cursor); if ($cursor) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $topicId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('topics', $topicId)); @@ -2352,6 +2363,11 @@ App::get('/v1/messaging/topics/:topicId/subscribers') $cursor = reset($cursor); if ($cursor) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $subscriberId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('subscribers', $subscriberId)); @@ -3048,6 +3064,11 @@ App::get('/v1/messaging/messages') $cursor = reset($cursor); if ($cursor) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $messageId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('messages', $messageId)); @@ -3202,6 +3223,11 @@ App::get('/v1/messaging/messages/:messageId/targets') $cursor = reset($cursor); if ($cursor) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $targetId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('targets', $targetId); diff --git a/app/controllers/api/migrations.php b/app/controllers/api/migrations.php index bb89d4a26f..a4880cef86 100644 --- a/app/controllers/api/migrations.php +++ b/app/controllers/api/migrations.php @@ -16,6 +16,7 @@ use Utopia\Database\Document; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Migration\Sources\Appwrite; use Utopia\Migration\Sources\Firebase; @@ -409,6 +410,12 @@ App::get('/v1/migrations') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $migrationId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('migrations', $migrationId); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 934793410b..3bfa416bd8 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -31,6 +31,7 @@ use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Domains\Validator\PublicDomain; use Utopia\DSN\DSN; @@ -279,6 +280,12 @@ App::get('/v1/projects') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $projectId = $cursor->getValue(); $cursorDocument = $dbForConsole->getDocument('projects', $projectId); diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 84484a7209..984a9fb974 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -13,6 +13,7 @@ use Utopia\Database\Document; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Domains\Domain; use Utopia\Logger\Log; @@ -185,6 +186,12 @@ App::get('/v1/proxy/rules') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $ruleId = $cursor->getValue(); $cursorDocument = $dbForConsole->getDocument('rules', $ruleId); diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 4e30832a67..c3d57e5470 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -24,6 +24,7 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Image\Image; use Utopia\Storage\Compression\Algorithms\GZIP; @@ -178,6 +179,12 @@ App::get('/v1/storage/buckets') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $bucketId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('buckets', $bucketId); @@ -744,6 +751,12 @@ App::get('/v1/storage/buckets/:bucketId/files') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $fileId = $cursor->getValue(); if ($fileSecurity && !$valid) { diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 146b5d5f81..f9abaeeb44 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -34,6 +34,7 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; @@ -170,6 +171,12 @@ App::get('/v1/teams') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $teamId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('teams', $teamId); @@ -751,6 +758,13 @@ App::get('/v1/teams/:teamId/memberships') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + + $membershipId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('memberships', $membershipId); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 571df4fdb2..f0378ed0e3 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -36,6 +36,7 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Queries; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; @@ -576,6 +577,12 @@ App::get('/v1/users') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $userId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('users', $userId); @@ -886,6 +893,11 @@ App::get('/v1/users/:userId/targets') $cursor = reset($cursor); if ($cursor) { + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $targetId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('targets', $targetId); @@ -938,6 +950,12 @@ App::get('/v1/users/identities') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $identityId = $cursor->getValue(); $cursorDocument = $dbForProject->getDocument('identities', $identityId); diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index f3381490ec..e79eb67936 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -20,6 +20,7 @@ use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; +use Utopia\Database\Validator\Query\Cursor; use Utopia\Detector\Adapter\Bun; use Utopia\Detector\Adapter\CPP; use Utopia\Detector\Adapter\Dart; @@ -1069,6 +1070,12 @@ App::get('/v1/vcs/installations') $cursor = reset($cursor); if ($cursor) { /** @var Query $cursor */ + + $validator = new Cursor(); + if (!$validator->isValid($cursor)) { + throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); + } + $installationId = $cursor->getValue(); $cursorDocument = $dbForConsole->getDocument('installations', $installationId); From ea2192a83cb1b890f2ad4e44bcf456e1833df812 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 17 Oct 2024 18:51:26 +1300 Subject: [PATCH 17/21] Force CI --- app/controllers/api/databases.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index a44d5dab6d..454ab89de3 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -3123,6 +3123,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); } + $documentId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId)); From b32cb30737c749f47f64e7dadd68fc74be1cb887 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 17 Oct 2024 18:51:41 +1300 Subject: [PATCH 18/21] Force CI --- app/controllers/api/databases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 454ab89de3..473f09cb7c 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -3123,7 +3123,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') throw new Exception(Exception::GENERAL_QUERY_INVALID, $validator->getDescription()); } - + $documentId = $cursor->getValue(); $cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $documentId)); From 4cd951ae414d8898c9b45954205e0efe65aff9c2 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:35:17 +0530 Subject: [PATCH 19/21] Add tests for project variables --- .../Projects/ProjectsConsoleClientTest.php | 269 ++++++++++++++++++ 1 file changed, 269 insertions(+) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 05893be3a8..8f022d7e0e 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -3793,4 +3793,273 @@ class ProjectsConsoleClientTest extends Scope return $data; } + + /** + * @depends testCreateProject + */ + public function testCreateProjectVariable(array $data) + { + /** + * Test for SUCCESS + */ + $variable = $this->client->call(Client::METHOD_POST, '/project/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => 'APP_TEST', + 'value' => 'TESTINGVALUE' + ]); + + $this->assertEquals(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + /** + * Test for FAILURE + */ + // Test for duplicate key + $variable = $this->client->call(Client::METHOD_POST, '/project/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => 'APP_TEST', + 'value' => 'ANOTHERTESTINGVALUE' + ]); + + $this->assertEquals(409, $variable['headers']['status-code']); + + // Test for invalid key + $variable = $this->client->call(Client::METHOD_POST, '/project/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => str_repeat("A", 256), + 'value' => 'TESTINGVALUE' + ]); + + $this->assertEquals(400, $variable['headers']['status-code']); + + // Test for invalid value + $variable = $this->client->call(Client::METHOD_POST, '/project/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => 'LONGKEY', + 'value' => str_repeat("#", 8193), + ]); + + $this->assertEquals(400, $variable['headers']['status-code']); + + return array_merge( + $data, + [ + 'variableId' => $variableId, + ] + ); + } + + /** + * @depends testCreateProjectVariable + */ + public function testListVariables(array $data) + { + /** + * Test for SUCCESS + */ + + $response = $this->client->call(Client::METHOD_GET, '/project/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, sizeof($response['body']['variables'])); + $this->assertEquals(1, $response['body']['total']); + $this->assertEquals("APP_TEST", $response['body']['variables'][0]['key']); + $this->assertEquals("TESTINGVALUE", $response['body']['variables'][0]['value']); + + return $data; + } + + /** + * @depends testListVariables + */ + public function testGetVariable(array $data) + { + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals("APP_TEST", $response['body']['key']); + $this->assertEquals("TESTINGVALUE", $response['body']['value']); + + /** + * Test for FAILURE + */ + + $response = $this->client->call(Client::METHOD_GET, '/project/variables/NON_EXISTING_VARIABLE', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders())); + + $this->assertEquals(404, $response['headers']['status-code']); + + return $data; + } + + /** + * @depends testGetVariable + */ + public function testUpdateVariable(array $data) + { + /** + * Test for SUCCESS + */ + + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => 'APP_TEST_UPDATE', + 'value' => 'TESTINGVALUEUPDATED' + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals("APP_TEST_UPDATE", $response['body']['key']); + $this->assertEquals("TESTINGVALUEUPDATED", $response['body']['value']); + + $variable = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders())); + + $this->assertEquals(200, $variable['headers']['status-code']); + $this->assertEquals("APP_TEST_UPDATE", $variable['body']['key']); + $this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']); + + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => 'APP_TEST_UPDATE_2', + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals("APP_TEST_UPDATE_2", $response['body']['key']); + $this->assertEquals("TESTINGVALUEUPDATED", $response['body']['value']); + + $variable = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders())); + + $this->assertEquals(200, $variable['headers']['status-code']); + $this->assertEquals("APP_TEST_UPDATE_2", $variable['body']['key']); + $this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']); + + /** + * Test for FAILURE + */ + + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders())); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'value' => 'TESTINGVALUEUPDATED_2' + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $longKey = str_repeat("A", 256); + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => $longKey, + 'value' => 'TESTINGVALUEUPDATED' + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $longValue = str_repeat("#", 8193); + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => 'APP_TEST_UPDATE', + 'value' => $longValue + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + return $data; + } + + /** + * @depends testUpdateVariable + */ + public function testDeleteVariable(array $data) + { + /** + * Test for SUCCESS + */ + + $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/' . $data['variableId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders())); + + $this->assertEquals(204, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/project/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(0, sizeof($response['body']['variables'])); + $this->assertEquals(0, $response['body']['total']); + + /** + * Test for FAILURE + */ + + $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/NON_EXISTING_VARIABLE', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders())); + + $this->assertEquals(404, $response['headers']['status-code']); + + return $data; + } } From 5a74f351dc5cb2d6787df2ab5fafefb7c8e5a2e0 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 18 Oct 2024 00:07:44 +0530 Subject: [PATCH 20/21] Add tests to update non-existent var --- .../Projects/ProjectsConsoleClientTest.php | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 8f022d7e0e..9e2039077e 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -3950,27 +3950,15 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals("APP_TEST_UPDATE", $variable['body']['key']); $this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $data['projectId'], - 'x-appwrite-mode' => 'admin', - ], $this->getHeaders()), [ - 'key' => 'APP_TEST_UPDATE_2', - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals("APP_TEST_UPDATE_2", $response['body']['key']); - $this->assertEquals("TESTINGVALUEUPDATED", $response['body']['value']); - - $variable = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['variableId'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/project/variables', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); - $this->assertEquals(200, $variable['headers']['status-code']); - $this->assertEquals("APP_TEST_UPDATE_2", $variable['body']['key']); - $this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, sizeof($response['body']['variables'])); + $this->assertEquals("APP_TEST_UPDATE", $response['body']['variables'][0]['key']); /** * Test for FAILURE @@ -4018,6 +4006,17 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/NON_EXISTING_VARIABLE', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => 'APP_TEST_UPDATE', + 'value' => 'TESTINGVALUEUPDATED' + ]); + + $this->assertEquals(404, $response['headers']['status-code']); + return $data; } From 73918b137e2c7c1712a5738b8dafdf9278224a16 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:48:59 +0530 Subject: [PATCH 21/21] Replace sizeof with assertCount --- tests/e2e/Services/Projects/ProjectsConsoleClientTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 9e2039077e..7b0847126c 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -3877,7 +3877,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(1, sizeof($response['body']['variables'])); + $this->assertCount(1, $response['body']['variables']); $this->assertEquals(1, $response['body']['total']); $this->assertEquals("APP_TEST", $response['body']['variables'][0]['key']); $this->assertEquals("TESTINGVALUE", $response['body']['variables'][0]['value']); @@ -3957,7 +3957,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(1, sizeof($response['body']['variables'])); + $this->assertCount(1, $response['body']['variables']); $this->assertEquals("APP_TEST_UPDATE", $response['body']['variables'][0]['key']); /** @@ -4044,7 +4044,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(0, sizeof($response['body']['variables'])); + $this->assertCount(0, $response['body']['variables']); $this->assertEquals(0, $response['body']['total']); /**