diff --git a/composer.lock b/composer.lock index bc2dcd0a4..dfcd966e8 100644 --- a/composer.lock +++ b/composer.lock @@ -839,16 +839,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.32", + "version": "1.10.33", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "c47e47d3ab03137c0e121e77c4d2cb58672f6d44" + "reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c47e47d3ab03137c0e121e77c4d2cb58672f6d44", - "reference": "c47e47d3ab03137c0e121e77c4d2cb58672f6d44", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1", + "reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1", "shasum": "" }, "require": { @@ -897,20 +897,20 @@ "type": "tidelift" } ], - "time": "2023-08-24T21:54:50+00:00" + "time": "2023-09-04T12:20:53+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.27", + "version": "9.2.28", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1" + "reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/b0a88255cb70d52653d80c890bd7f38740ea50d1", - "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef", + "reference": "7134a5ccaaf0f1c92a4f5501a6c9f98ac4dcc0ef", "shasum": "" }, "require": { @@ -967,7 +967,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.27" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.28" }, "funding": [ { @@ -975,7 +975,7 @@ "type": "github" } ], - "time": "2023-07-26T13:44:30+00:00" + "time": "2023-09-12T14:36:20+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1220,16 +1220,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.11", + "version": "9.6.12", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "810500e92855eba8a7a5319ae913be2da6f957b0" + "reference": "a122c2ebd469b751d774aa0f613dc0d67697653f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/810500e92855eba8a7a5319ae913be2da6f957b0", - "reference": "810500e92855eba8a7a5319ae913be2da6f957b0", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a122c2ebd469b751d774aa0f613dc0d67697653f", + "reference": "a122c2ebd469b751d774aa0f613dc0d67697653f", "shasum": "" }, "require": { @@ -1244,7 +1244,7 @@ "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.13", + "phpunit/php-code-coverage": "^9.2.28", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -1303,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.11" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.12" }, "funding": [ { @@ -1319,7 +1319,7 @@ "type": "tidelift" } ], - "time": "2023-08-19T07:10:56+00:00" + "time": "2023-09-12T14:39:31+00:00" }, { "name": "psr/container", @@ -2608,5 +2608,5 @@ "php": ">=8.0" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/src/Database/Validator/Cursor.php b/src/Database/Validator/Cursor.php new file mode 100644 index 000000000..9d731c9b0 --- /dev/null +++ b/src/Database/Validator/Cursor.php @@ -0,0 +1,21 @@ +maxLength); + } +} diff --git a/src/Database/Validator/Key.php b/src/Database/Validator/Key.php index d1cdf8793..d8a18599e 100644 --- a/src/Database/Validator/Key.php +++ b/src/Database/Validator/Key.php @@ -6,7 +6,8 @@ class Key extends Validator { - protected bool $allowInternal = false; // If true, you keys starting with $ are allowed + protected bool $allowInternal = false; // If true, keys starting with $ are allowed + protected int $maxLength = 36; /** * @var string @@ -73,7 +74,7 @@ public function isValid($value): bool return false; } - if (\mb_strlen($value) > 36) { + if (\mb_strlen($value) > $this->maxLength) { return false; } diff --git a/src/Database/Validator/Query/Cursor.php b/src/Database/Validator/Query/Cursor.php index b976d8412..8f59e5c0f 100644 --- a/src/Database/Validator/Query/Cursor.php +++ b/src/Database/Validator/Query/Cursor.php @@ -4,7 +4,7 @@ use Utopia\Database\Document; use Utopia\Database\Query; -use Utopia\Database\Validator\UID; +use Utopia\Database\Validator\Cursor as CursorUid; class Cursor extends Base { @@ -33,7 +33,7 @@ public function isValid($value): bool $cursor = $cursor->getId(); } - $validator = new UID(); + $validator = new CursorUid(); if ($validator->isValid($cursor)) { return true; } diff --git a/tests/Database/Validator/Query/CursorTest.php b/tests/Database/Validator/Query/CursorTest.php index f68d2bd3a..fcf4a3f41 100644 --- a/tests/Database/Validator/Query/CursorTest.php +++ b/tests/Database/Validator/Query/CursorTest.php @@ -3,6 +3,7 @@ namespace Utopia\Tests\Validator\Query; use PHPUnit\Framework\TestCase; +use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; @@ -14,6 +15,7 @@ public function testValueSuccess(): void $this->assertTrue($validator->isValid(new Query(Query::TYPE_CURSORAFTER, values: ['asdf']))); $this->assertTrue($validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: ['asdf']))); + $this->assertTrue($validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: [new Document(['$id' => 'abc102030'])]))); } public function testValueFailure(): void @@ -28,5 +30,11 @@ public function testValueFailure(): void $this->assertFalse($validator->isValid(Query::equal('attr', ['v']))); $this->assertFalse($validator->isValid(Query::orderAsc('attr'))); $this->assertFalse($validator->isValid(Query::orderDesc('attr'))); + + $uid = 'uid0123456_uid0123456_uid0123456_uid0123456_uid0123456_uid0123456_uid0123456_uid0123456_uid0123456_uid0123456_'; + + $this->assertFalse($validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: [$uid]))); + $this->assertFalse($validator->isValid(new Query(Query::TYPE_CURSORBEFORE, values: [new Document(['$id' => $uid])]))); + $this->assertEquals('Invalid cursor: Cursor must contain at most 100 chars. Valid chars are a-z, A-Z, 0-9, and underscore. Can\'t start with a leading underscore', $validator->getDescription()); } }