mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge branch 'main' of https://github.com/appwrite/appwrite into bump-database-7-1-3
# Conflicts: # composer.lock
This commit is contained in:
commit
9c4c6e332d
88 files changed
+1935
-1108
No files matched your search
@@ -18,6 +18,8 @@ Self-hosted Backend-as-a-Service platform. Hybrid monolithic-microservice archit
|
||||
| `composer refactor:check` | Rector dry-run over `tests/` (CI "Refactor" check) |
|
||||
| `composer refactor` | Apply Rector fixes |
|
||||
|
||||
_Note: When running `composer check` or `composer analyze`, be aware that running this for entire project is very slow, and running for specific files is always recommended during development._
|
||||
|
||||
## Stack
|
||||
|
||||
- PHP 8.3+, Swoole 6.x (async runtime, replaces PHP-FPM)
|
||||
|
||||
@@ -762,7 +762,14 @@ return [
|
||||
'attributes' => ['userInternalId'],
|
||||
'lengths' => [Database::LENGTH_KEY],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
]
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_key_expire'),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['expire'],
|
||||
'lengths' => [],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
@@ -311,6 +311,152 @@ return [
|
||||
'$description' => 'This event triggers when a database is deleted.',
|
||||
],
|
||||
],
|
||||
'documentsdb' => [
|
||||
'$model' => Response::MODEL_DATABASE,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any DocumentsDB database event.',
|
||||
'collections' => [
|
||||
'$model' => Response::MODEL_COLLECTION,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any collection event.',
|
||||
'documents' => [
|
||||
'$model' => Response::MODEL_DOCUMENT,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any documents event.',
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when a document is created.',
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when a document is updated.'
|
||||
],
|
||||
'upsert' => [
|
||||
'$description' => 'This event triggers when a document is upserted.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when a document is deleted.'
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'$model' => Response::MODEL_INDEX,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any indexes event.',
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when an index is created.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when an index is deleted.'
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when an index is updated.',
|
||||
],
|
||||
],
|
||||
'attributes' => [
|
||||
'$model' => Response::MODEL_ATTRIBUTE,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any attributes event.',
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when an attribute is created.',
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when an attribute is updated.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when an attribute is deleted.'
|
||||
]
|
||||
],
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when a collection is created.'
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when a collection is updated.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when a collection is deleted.',
|
||||
],
|
||||
],
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when a database is created.'
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when a database is updated.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when a database is deleted.',
|
||||
],
|
||||
],
|
||||
'vectorsdb' => [
|
||||
'$model' => Response::MODEL_DATABASE,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any VectorsDB database event.',
|
||||
'collections' => [
|
||||
'$model' => Response::MODEL_COLLECTION,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any collection event.',
|
||||
'documents' => [
|
||||
'$model' => Response::MODEL_DOCUMENT,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any documents event.',
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when a document is created.',
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when a document is updated.'
|
||||
],
|
||||
'upsert' => [
|
||||
'$description' => 'This event triggers when a document is upserted.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when a document is deleted.'
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'$model' => Response::MODEL_INDEX,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any indexes event.',
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when an index is created.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when an index is deleted.'
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when an index is updated.',
|
||||
],
|
||||
],
|
||||
'attributes' => [
|
||||
'$model' => Response::MODEL_ATTRIBUTE,
|
||||
'$resource' => true,
|
||||
'$description' => 'This event triggers on any attributes event.',
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when an attribute is created.',
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when an attribute is updated.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when an attribute is deleted.'
|
||||
]
|
||||
],
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when a collection is created.'
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when a collection is updated.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when a collection is deleted.',
|
||||
],
|
||||
],
|
||||
'create' => [
|
||||
'$description' => 'This event triggers when a database is created.'
|
||||
],
|
||||
'update' => [
|
||||
'$description' => 'This event triggers when a database is updated.',
|
||||
],
|
||||
'delete' => [
|
||||
'$description' => 'This event triggers when a database is deleted.',
|
||||
],
|
||||
],
|
||||
'buckets' => [
|
||||
'$model' => Response::MODEL_BUCKET,
|
||||
'$resource' => true,
|
||||
|
||||
@@ -18,6 +18,7 @@ $member = [
|
||||
'documents.write',
|
||||
'rows.read',
|
||||
'rows.write',
|
||||
'embeddings.write',
|
||||
'files.read',
|
||||
'files.write',
|
||||
'projects.read',
|
||||
@@ -43,6 +44,7 @@ $admins = [
|
||||
'documents.write',
|
||||
'rows.read',
|
||||
'rows.write',
|
||||
'embeddings.write',
|
||||
'files.read',
|
||||
'files.write',
|
||||
'buckets.read',
|
||||
@@ -129,6 +131,7 @@ return [
|
||||
'documents.write',
|
||||
'rows.read',
|
||||
'rows.write',
|
||||
'embeddings.write',
|
||||
'files.read',
|
||||
'files.write',
|
||||
'locale.read',
|
||||
|
||||
@@ -163,6 +163,10 @@ return [
|
||||
'description' => 'Access to create, update, and delete database table rows',
|
||||
'category' => 'Databases',
|
||||
],
|
||||
'embeddings.write' => [
|
||||
'description' => 'Access to generate vector embeddings',
|
||||
'category' => 'Databases',
|
||||
],
|
||||
'collections.read' => [
|
||||
'description' => 'Access to read database collections',
|
||||
'category' => 'Databases',
|
||||
|
||||
@@ -168,6 +168,7 @@ use Appwrite\Utopia\Response\Model\PlatformWeb;
|
||||
use Appwrite\Utopia\Response\Model\PlatformWindows;
|
||||
use Appwrite\Utopia\Response\Model\PolicyList;
|
||||
use Appwrite\Utopia\Response\Model\PolicyMembershipPrivacy;
|
||||
use Appwrite\Utopia\Response\Model\PolicyMFAFactors;
|
||||
use Appwrite\Utopia\Response\Model\PolicyPasswordDictionary;
|
||||
use Appwrite\Utopia\Response\Model\PolicyPasswordHistory;
|
||||
use Appwrite\Utopia\Response\Model\PolicyPasswordPersonalData;
|
||||
@@ -473,6 +474,7 @@ Response::setModel(new PolicySessionInvalidation());
|
||||
Response::setModel(new PolicySessionLimit());
|
||||
Response::setModel(new PolicyUserLimit());
|
||||
Response::setModel(new PolicyMembershipPrivacy());
|
||||
Response::setModel(new PolicyMFAFactors());
|
||||
Response::setModel(new AuthProvider());
|
||||
Response::setModel(new PlatformWeb());
|
||||
Response::setModel(new PlatformApple());
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@
|
||||
"utopia-php/dsn": "0.2.1",
|
||||
"utopia-php/http": "^2.0@RC",
|
||||
"utopia-php/fetch": "^1.1",
|
||||
"utopia-php/validators": "0.3.*",
|
||||
"utopia-php/validators": "^0.4",
|
||||
"utopia-php/image": "0.8.*",
|
||||
"utopia-php/locale": "0.8.*",
|
||||
"utopia-php/lock": "0.2.*",
|
||||
|
||||
Generated
+107
-110
@@ -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": "47fed84fa9ca6c3d7da20266a4e04587",
|
||||
"content-hash": "b8f482127f1d48cb4026f35a161b15f5",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adhocore/jwt",
|
||||
@@ -157,7 +157,6 @@
|
||||
"issues": "https://github.com/appwrite/php-clamav/issues",
|
||||
"source": "https://github.com/appwrite/php-clamav/tree/2.0.0"
|
||||
},
|
||||
"abandoned": true,
|
||||
"time": "2023-02-24T09:50:42+00:00"
|
||||
},
|
||||
{
|
||||
@@ -3168,16 +3167,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/audit",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/audit.git",
|
||||
"reference": "065b1dc5da8e7eabde4b8bfb4217d0a78d1bf9bd"
|
||||
"reference": "fd584e0892b636ac3dfb3e6463b96f9ec0a58818"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/065b1dc5da8e7eabde4b8bfb4217d0a78d1bf9bd",
|
||||
"reference": "065b1dc5da8e7eabde4b8bfb4217d0a78d1bf9bd",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/fd584e0892b636ac3dfb3e6463b96f9ec0a58818",
|
||||
"reference": "fd584e0892b636ac3dfb3e6463b96f9ec0a58818",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -3185,7 +3184,7 @@
|
||||
"utopia-php/database": "^7.0.0",
|
||||
"utopia-php/fetch": "^1.1",
|
||||
"utopia-php/query": "0.1.*",
|
||||
"utopia-php/validators": "0.3.*"
|
||||
"utopia-php/validators": "^0.4"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@@ -3207,9 +3206,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/audit/issues",
|
||||
"source": "https://github.com/utopia-php/audit/tree/3.0.0"
|
||||
"source": "https://github.com/utopia-php/audit/tree/3.0.1"
|
||||
},
|
||||
"time": "2026-07-31T14:52:39+00:00"
|
||||
"time": "2026-08-10T04:51:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/auth",
|
||||
@@ -3638,16 +3637,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/database",
|
||||
"version": "7.1.1",
|
||||
"version": "7.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database.git",
|
||||
"reference": "80b5b3d85556d9d17d882e1bb972d239a634ebdd"
|
||||
"reference": "9eed1f1ed7da154ca7356c5f051bbc192e7b3c73"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/80b5b3d85556d9d17d882e1bb972d239a634ebdd",
|
||||
"reference": "80b5b3d85556d9d17d882e1bb972d239a634ebdd",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/9eed1f1ed7da154ca7356c5f051bbc192e7b3c73",
|
||||
"reference": "9eed1f1ed7da154ca7356c5f051bbc192e7b3c73",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -3660,7 +3659,7 @@
|
||||
"utopia-php/console": "0.1.*",
|
||||
"utopia-php/mongo": "1.*",
|
||||
"utopia-php/pools": "2.*",
|
||||
"utopia-php/validators": "0.3.*"
|
||||
"utopia-php/validators": "^0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "1.23.*",
|
||||
@@ -3692,9 +3691,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/database/issues",
|
||||
"source": "https://github.com/utopia-php/database/tree/7.1.1"
|
||||
"source": "https://github.com/utopia-php/database/tree/7.1.2"
|
||||
},
|
||||
"time": "2026-08-09T01:36:59+00:00"
|
||||
"time": "2026-08-10T04:39:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/detector",
|
||||
@@ -3791,16 +3790,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/dns",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/dns.git",
|
||||
"reference": "1de89cfe0c616159b8af94cfcfd8b2f12e42784c"
|
||||
"reference": "0762b38095c67149b5b1c77392d870c1b24ffe27"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/dns/zipball/1de89cfe0c616159b8af94cfcfd8b2f12e42784c",
|
||||
"reference": "1de89cfe0c616159b8af94cfcfd8b2f12e42784c",
|
||||
"url": "https://api.github.com/repos/utopia-php/dns/zipball/0762b38095c67149b5b1c77392d870c1b24ffe27",
|
||||
"reference": "0762b38095c67149b5b1c77392d870c1b24ffe27",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -3808,7 +3807,7 @@
|
||||
"php": ">=8.5",
|
||||
"utopia-php/domains": "^3.0",
|
||||
"utopia-php/telemetry": "^0.4",
|
||||
"utopia-php/validators": "0.3.*"
|
||||
"utopia-php/validators": "^0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"swoole/ide-helper": "5.1.8"
|
||||
@@ -3842,9 +3841,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/dns/issues",
|
||||
"source": "https://github.com/utopia-php/dns/tree/3.0.0"
|
||||
"source": "https://github.com/utopia-php/dns/tree/3.0.1"
|
||||
},
|
||||
"time": "2026-07-31T15:11:37+00:00"
|
||||
"time": "2026-08-10T04:51:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/domains",
|
||||
@@ -4058,16 +4057,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/http",
|
||||
"version": "2.0.0-rc20",
|
||||
"version": "2.0.0-rc21",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/http.git",
|
||||
"reference": "6a1c7fe9305fd5adad9ba97bae3f6a6faca7a711"
|
||||
"reference": "9d8d374926dd2d3c35808deb72199ab943355d64"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/http/zipball/6a1c7fe9305fd5adad9ba97bae3f6a6faca7a711",
|
||||
"reference": "6a1c7fe9305fd5adad9ba97bae3f6a6faca7a711",
|
||||
"url": "https://api.github.com/repos/utopia-php/http/zipball/9d8d374926dd2d3c35808deb72199ab943355d64",
|
||||
"reference": "9d8d374926dd2d3c35808deb72199ab943355d64",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -4078,7 +4077,7 @@
|
||||
"utopia-php/servers": "^0.4",
|
||||
"utopia-php/system": "^0.10",
|
||||
"utopia-php/telemetry": "^0.4",
|
||||
"utopia-php/validators": "0.3.*"
|
||||
"utopia-php/validators": "^0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"swoole/ide-helper": "4.8.3"
|
||||
@@ -4105,9 +4104,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/http/issues",
|
||||
"source": "https://github.com/utopia-php/http/tree/2.0.0-rc20"
|
||||
"source": "https://github.com/utopia-php/http/tree/2.0.0-rc21"
|
||||
},
|
||||
"time": "2026-08-05T18:37:51+00:00"
|
||||
"time": "2026-08-10T04:51:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/image",
|
||||
@@ -4725,16 +4724,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/queue",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/queue.git",
|
||||
"reference": "fc32fce2616a56b84923761a77b8f0c8e66e403e"
|
||||
"reference": "ade5660eadcd042a313d1ed4aa25d260a2737b5c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/queue/zipball/fc32fce2616a56b84923761a77b8f0c8e66e403e",
|
||||
"reference": "fc32fce2616a56b84923761a77b8f0c8e66e403e",
|
||||
"url": "https://api.github.com/repos/utopia-php/queue/zipball/ade5660eadcd042a313d1ed4aa25d260a2737b5c",
|
||||
"reference": "ade5660eadcd042a313d1ed4aa25d260a2737b5c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -4744,7 +4743,7 @@
|
||||
"utopia-php/pools": "^2.0",
|
||||
"utopia-php/servers": "^0.4",
|
||||
"utopia-php/telemetry": "^0.4",
|
||||
"utopia-php/validators": "0.3.*"
|
||||
"utopia-php/validators": "^0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-redis": "*",
|
||||
@@ -4783,9 +4782,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/queue/issues",
|
||||
"source": "https://github.com/utopia-php/queue/tree/1.1.3"
|
||||
"source": "https://github.com/utopia-php/queue/tree/1.1.4"
|
||||
},
|
||||
"time": "2026-08-05T12:34:31+00:00"
|
||||
"time": "2026-08-10T04:51:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/registry",
|
||||
@@ -4841,22 +4840,22 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/servers",
|
||||
"version": "0.4.6",
|
||||
"version": "0.4.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/servers.git",
|
||||
"reference": "036c4da1c8b9a5bba1a973270158ba745a5944c9"
|
||||
"reference": "18572544b1da5af415e5abbd59ba00af29e37de7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/servers/zipball/036c4da1c8b9a5bba1a973270158ba745a5944c9",
|
||||
"reference": "036c4da1c8b9a5bba1a973270158ba745a5944c9",
|
||||
"url": "https://api.github.com/repos/utopia-php/servers/zipball/18572544b1da5af415e5abbd59ba00af29e37de7",
|
||||
"reference": "18572544b1da5af415e5abbd59ba00af29e37de7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.5",
|
||||
"utopia-php/di": "^0.3",
|
||||
"utopia-php/validators": "0.3.*"
|
||||
"utopia-php/validators": "^0.4"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@@ -4884,9 +4883,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/servers/issues",
|
||||
"source": "https://github.com/utopia-php/servers/tree/0.4.6"
|
||||
"source": "https://github.com/utopia-php/servers/tree/0.4.7"
|
||||
},
|
||||
"time": "2026-07-13T11:15:40+00:00"
|
||||
"time": "2026-08-10T04:51:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/span",
|
||||
@@ -4930,16 +4929,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/storage",
|
||||
"version": "4.0.2",
|
||||
"version": "4.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/storage.git",
|
||||
"reference": "64a391f5dcf043458868322dfc4d402e4d154c4c"
|
||||
"reference": "f8b122e753c01f30f774d390d7a36f030dfaef46"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/storage/zipball/64a391f5dcf043458868322dfc4d402e4d154c4c",
|
||||
"reference": "64a391f5dcf043458868322dfc4d402e4d154c4c",
|
||||
"url": "https://api.github.com/repos/utopia-php/storage/zipball/f8b122e753c01f30f774d390d7a36f030dfaef46",
|
||||
"reference": "f8b122e753c01f30f774d390d7a36f030dfaef46",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -4952,7 +4951,7 @@
|
||||
"utopia-php/client": "0.2.* || 0.3.*",
|
||||
"utopia-php/psr7": "0.2.*",
|
||||
"utopia-php/telemetry": "^0.4.6",
|
||||
"utopia-php/validators": "0.3.*"
|
||||
"utopia-php/validators": "^0.4"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
@@ -4974,9 +4973,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/storage/issues",
|
||||
"source": "https://github.com/utopia-php/storage/tree/4.0.2"
|
||||
"source": "https://github.com/utopia-php/storage/tree/4.0.3"
|
||||
},
|
||||
"time": "2026-08-05T18:07:20+00:00"
|
||||
"time": "2026-08-10T04:51:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/system",
|
||||
@@ -5124,16 +5123,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/validators",
|
||||
"version": "0.3.2",
|
||||
"version": "0.4.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/validators.git",
|
||||
"reference": "444a3dbfcd5f2d167214f07f6e8a9962048def1c"
|
||||
"reference": "61832b7c863831466ccdeccd4e4f76a43765fbbf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/validators/zipball/444a3dbfcd5f2d167214f07f6e8a9962048def1c",
|
||||
"reference": "444a3dbfcd5f2d167214f07f6e8a9962048def1c",
|
||||
"url": "https://api.github.com/repos/utopia-php/validators/zipball/61832b7c863831466ccdeccd4e4f76a43765fbbf",
|
||||
"reference": "61832b7c863831466ccdeccd4e4f76a43765fbbf",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -5158,9 +5157,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/validators/issues",
|
||||
"source": "https://github.com/utopia-php/validators/tree/0.4.0"
|
||||
"source": "https://github.com/utopia-php/validators/tree/0.4.1"
|
||||
},
|
||||
"time": "2026-08-07T10:53:49+00:00"
|
||||
"time": "2026-08-10T04:15:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/vcs",
|
||||
@@ -5420,16 +5419,16 @@
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "appwrite/sdk-generator",
|
||||
"version": "2.11.1",
|
||||
"version": "2.10.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/appwrite/sdk-generator.git",
|
||||
"reference": "4bf377c6b8c4f9620d8e5fd525ab6160bdc95a41"
|
||||
"reference": "3019e3e939cc5f12a41dab98ded1043423467dd0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/4bf377c6b8c4f9620d8e5fd525ab6160bdc95a41",
|
||||
"reference": "4bf377c6b8c4f9620d8e5fd525ab6160bdc95a41",
|
||||
"url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/3019e3e939cc5f12a41dab98ded1043423467dd0",
|
||||
"reference": "3019e3e939cc5f12a41dab98ded1043423467dd0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -5466,9 +5465,9 @@
|
||||
"description": "SDK generator for Appwrite APIs across multiple programming languages and platforms",
|
||||
"support": {
|
||||
"issues": "https://github.com/appwrite/sdk-generator/issues",
|
||||
"source": "https://github.com/appwrite/sdk-generator/tree/2.11.1"
|
||||
"source": "https://github.com/appwrite/sdk-generator/tree/2.10.1"
|
||||
},
|
||||
"time": "2026-08-10T11:13:18+00:00"
|
||||
"time": "2026-08-06T07:56:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "brianium/paratest",
|
||||
@@ -5750,16 +5749,16 @@
|
||||
},
|
||||
{
|
||||
"name": "laravel/pint",
|
||||
"version": "v1.30.5",
|
||||
"version": "v1.29.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/pint.git",
|
||||
"reference": "fe4148c503a0e266353d61396b79bbf7f35122df"
|
||||
"reference": "da1d1111a6aa2e082d2a388b194afe1ba0a05d14"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/fe4148c503a0e266353d61396b79bbf7f35122df",
|
||||
"reference": "fe4148c503a0e266353d61396b79bbf7f35122df",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/da1d1111a6aa2e082d2a388b194afe1ba0a05d14",
|
||||
"reference": "da1d1111a6aa2e082d2a388b194afe1ba0a05d14",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -5767,19 +5766,17 @@
|
||||
"ext-mbstring": "*",
|
||||
"ext-tokenizer": "*",
|
||||
"ext-xml": "*",
|
||||
"php": "^8.3.0"
|
||||
"php": "^8.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/semver": "^3.4.4",
|
||||
"friendsofphp/php-cs-fixer": "^3.95.18",
|
||||
"illuminate/view": "^13.24.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.95.8",
|
||||
"illuminate/view": "^12.62.0",
|
||||
"larastan/larastan": "^3.10.0",
|
||||
"laravel-zero/framework": "^13.0.0",
|
||||
"laravel-zero/framework": "^12.1.0",
|
||||
"laravel/agent-detector": "^2.0.2",
|
||||
"laravel/prompts": "^0.3.22",
|
||||
"mockery/mockery": "^1.6.12",
|
||||
"nunomaduro/termwind": "^2.4.0",
|
||||
"pestphp/pest": "^4.7.8"
|
||||
"pestphp/pest": "^3.8.6"
|
||||
},
|
||||
"bin": [
|
||||
"builds/pint"
|
||||
@@ -5816,7 +5813,7 @@
|
||||
"issues": "https://github.com/laravel/pint/issues",
|
||||
"source": "https://github.com/laravel/pint"
|
||||
},
|
||||
"time": "2026-08-10T15:35:50+00:00"
|
||||
"time": "2026-06-16T15:34:04+00:00"
|
||||
},
|
||||
{
|
||||
"name": "matthiasmullie/minify",
|
||||
@@ -6178,11 +6175,11 @@
|
||||
},
|
||||
{
|
||||
"name": "phpstan/phpstan",
|
||||
"version": "2.2.8",
|
||||
"version": "2.2.6",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/e285254e60f33c21902efef4a926ca0987c06804",
|
||||
"reference": "e285254e60f33c21902efef4a926ca0987c06804",
|
||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/a6e9b5a9420f6109c091e87d82683bd1a80b87ed",
|
||||
"reference": "a6e9b5a9420f6109c091e87d82683bd1a80b87ed",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -6238,7 +6235,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2026-08-04T22:21:45+00:00"
|
||||
"time": "2026-07-26T21:22:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
@@ -6587,16 +6584,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpunit/phpunit",
|
||||
"version": "12.5.33",
|
||||
"version": "12.5.32",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||
"reference": "b98e028a26c5c5ba7e4a54be96ccf35f2914d184"
|
||||
"reference": "c02591dd7840ed124a98d7770753329ad28e9f8f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b98e028a26c5c5ba7e4a54be96ccf35f2914d184",
|
||||
"reference": "b98e028a26c5c5ba7e4a54be96ccf35f2914d184",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c02591dd7840ed124a98d7770753329ad28e9f8f",
|
||||
"reference": "c02591dd7840ed124a98d7770753329ad28e9f8f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -6665,7 +6662,7 @@
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.33"
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.32"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -6673,20 +6670,20 @@
|
||||
"type": "other"
|
||||
}
|
||||
],
|
||||
"time": "2026-07-28T13:58:09+00:00"
|
||||
"time": "2026-07-25T06:54:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "rector/rector",
|
||||
"version": "2.6.1",
|
||||
"version": "2.5.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/rectorphp/rector.git",
|
||||
"reference": "b8e68f058bca43e01a2e1caa51ef022d6551ed95"
|
||||
"reference": "861c77fd2a6d45317a401f4e0b617f947e8b6f96"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/rectorphp/rector/zipball/b8e68f058bca43e01a2e1caa51ef022d6551ed95",
|
||||
"reference": "b8e68f058bca43e01a2e1caa51ef022d6551ed95",
|
||||
"url": "https://api.github.com/repos/rectorphp/rector/zipball/861c77fd2a6d45317a401f4e0b617f947e8b6f96",
|
||||
"reference": "861c77fd2a6d45317a401f4e0b617f947e8b6f96",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -6725,7 +6722,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/rectorphp/rector/issues",
|
||||
"source": "https://github.com/rectorphp/rector/tree/2.6.1"
|
||||
"source": "https://github.com/rectorphp/rector/tree/2.5.8"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -6733,7 +6730,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2026-08-03T17:30:34+00:00"
|
||||
"time": "2026-07-27T06:19:16+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/cli-parser",
|
||||
@@ -7730,16 +7727,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/console",
|
||||
"version": "v8.1.4",
|
||||
"version": "v8.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/console.git",
|
||||
"reference": "68efa2ebfd9a362951eb5a8b09fd177c66ddec24"
|
||||
"reference": "b711a8ab808b6c074c6b8caef70d0fd8d6b6d07d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/68efa2ebfd9a362951eb5a8b09fd177c66ddec24",
|
||||
"reference": "68efa2ebfd9a362951eb5a8b09fd177c66ddec24",
|
||||
"url": "https://api.github.com/repos/symfony/console/zipball/b711a8ab808b6c074c6b8caef70d0fd8d6b6d07d",
|
||||
"reference": "b711a8ab808b6c074c6b8caef70d0fd8d6b6d07d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -7806,7 +7803,7 @@
|
||||
"terminal"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/console/tree/v8.1.4"
|
||||
"source": "https://github.com/symfony/console/tree/v8.1.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -7826,7 +7823,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-07-31T12:43:13+00:00"
|
||||
"time": "2026-06-16T12:55:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
@@ -7913,16 +7910,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-intl-grapheme",
|
||||
"version": "v1.41.0",
|
||||
"version": "v1.38.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
|
||||
"reference": "bb899c1db0aa8127dc3afe8cda4a67eb24915f8d"
|
||||
"reference": "e9247d281d694a5120554d9afaf54e070e88a603"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/bb899c1db0aa8127dc3afe8cda4a67eb24915f8d",
|
||||
"reference": "bb899c1db0aa8127dc3afe8cda4a67eb24915f8d",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/e9247d281d694a5120554d9afaf54e070e88a603",
|
||||
"reference": "e9247d281d694a5120554d9afaf54e070e88a603",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -7971,7 +7968,7 @@
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.41.0"
|
||||
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.38.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -7991,7 +7988,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-07-28T08:25:59+00:00"
|
||||
"time": "2026-05-26T05:58:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-intl-normalizer",
|
||||
@@ -8145,16 +8142,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/string",
|
||||
"version": "v8.1.2",
|
||||
"version": "v8.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/string.git",
|
||||
"reference": "286a76b7255e5cc4bf0101a0bc5388ecf1c38ccc"
|
||||
"reference": "afd5944f4005862d961efb85c8bbd5c523c4e3c9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/286a76b7255e5cc4bf0101a0bc5388ecf1c38ccc",
|
||||
"reference": "286a76b7255e5cc4bf0101a0bc5388ecf1c38ccc",
|
||||
"url": "https://api.github.com/repos/symfony/string/zipball/afd5944f4005862d961efb85c8bbd5c523c4e3c9",
|
||||
"reference": "afd5944f4005862d961efb85c8bbd5c523c4e3c9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -8211,7 +8208,7 @@
|
||||
"utf8"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/string/tree/v8.1.2"
|
||||
"source": "https://github.com/symfony/string/tree/v8.1.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -8231,7 +8228,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-07-28T07:35:25+00:00"
|
||||
"time": "2026-05-29T05:06:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "textalk/websocket",
|
||||
@@ -8439,5 +8436,5 @@
|
||||
"platform-dev": {
|
||||
"ext-fileinfo": "*"
|
||||
},
|
||||
"plugin-api-version": "2.6.0"
|
||||
"plugin-api-version": "2.9.0"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Begin Appwrite's Bitbucket OAuth authorization to set up version control integration. This endpoint responds with a redirect URL to Bitbucket's authorization page. The Bitbucket OAuth consumer must be configured in your environment for this endpoint to work.
|
||||
@@ -0,0 +1 @@
|
||||
Begin Appwrite's Gitea OAuth authorization to set up version control integration. This endpoint responds with a redirect URL to Gitea's authorization page. The Gitea OAuth application must be configured in your environment for this endpoint to work.
|
||||
@@ -0,0 +1 @@
|
||||
Begin Appwrite's GitLab OAuth authorization to set up version control integration. This endpoint responds with a redirect URL to GitLab's authorization page. The GitLab OAuth application must be configured in your environment for this endpoint to work.
|
||||
@@ -3,22 +3,15 @@
|
||||
namespace Appwrite\Auth\Validator;
|
||||
|
||||
use Utopia\Messaging\Adapter\SMS\GEOSMS\CallingCode;
|
||||
use Utopia\Validator;
|
||||
use Utopia\Validator\Phone as UtopiaPhone;
|
||||
|
||||
/**
|
||||
* Phone.
|
||||
*
|
||||
* Validates a number for the E.164 format.
|
||||
*/
|
||||
class Phone extends Validator
|
||||
class Phone extends UtopiaPhone
|
||||
{
|
||||
protected bool $allowEmpty;
|
||||
|
||||
public function __construct(bool $allowEmpty = false)
|
||||
{
|
||||
$this->allowEmpty = $allowEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Description.
|
||||
*
|
||||
@@ -38,44 +31,18 @@ class Phone extends Validator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($value): bool
|
||||
public function isValid(mixed $value): bool
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
if (!parent::isValid($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->allowEmpty && \strlen($value) === 0) {
|
||||
if ($this->allowEmpty && $value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (CallingCode::fromPhoneNumber($value) === null) {
|
||||
return false;
|
||||
}
|
||||
$value = $this->normalize ? self::normalize($value) : $value;
|
||||
|
||||
return !!\preg_match('/^\+[1-9]\d{6,14}$/', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is array
|
||||
*
|
||||
* Function will return true if object is array.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isArray(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* Returns validator type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return self::TYPE_STRING;
|
||||
return CallingCode::fromPhoneNumber($value) !== null;
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,15 @@ class V25 extends Migration
|
||||
$this->dbForProject->purgeCachedCollection($id);
|
||||
break;
|
||||
|
||||
case 'challenges':
|
||||
try {
|
||||
$this->createIndexFromCollection($this->dbForProject, $id, '_key_expire');
|
||||
} catch (Throwable $th) {
|
||||
Console::warning("Failed to create index \"_key_expire\" from {$id}: {$th->getMessage()}");
|
||||
}
|
||||
$this->dbForProject->purgeCachedCollection($id);
|
||||
break;
|
||||
|
||||
case 'databases':
|
||||
if ($collectionType === 'projects') {
|
||||
try {
|
||||
|
||||
@@ -7,9 +7,9 @@ use Utopia\Validator\Hostname;
|
||||
/**
|
||||
* Generate CORS response headers for an incoming request.
|
||||
*
|
||||
* Allowed origins are matched by hostname only. Arrays passed to the
|
||||
* constructor (methods, headers, exposed headers) are formatted into
|
||||
* comma-separated header strings.
|
||||
* Allowed origins are matched by hostname only, with loopback hostnames always
|
||||
* accepted. Arrays passed to the constructor (methods, headers, exposed
|
||||
* headers) are formatted into comma-separated header strings.
|
||||
*/
|
||||
final class Cors
|
||||
{
|
||||
@@ -77,13 +77,20 @@ final class Cors
|
||||
return $headers;
|
||||
}
|
||||
|
||||
// Match only by host
|
||||
// Match only by host, falling back to the alias the host spells out.
|
||||
// See Platform::LOOPBACK_ALIASES -- responses here carry credentials.
|
||||
$validator = new Hostname($this->allowedHosts);
|
||||
if (!$validator->isValid($host)) {
|
||||
return $headers;
|
||||
$alias = \in_array($host, Platform::LOOPBACK_ALIASES, true)
|
||||
&& $validator->isValid(Platform::LOOPBACK_HOSTNAME);
|
||||
|
||||
if (!$alias) {
|
||||
return $headers;
|
||||
}
|
||||
}
|
||||
|
||||
// Accepted
|
||||
// Accepted. Echo the caller's origin exactly, never a wildcard, so the
|
||||
// browser's own literal-match rule stays the last line of defence.
|
||||
$headers[self::HEADER_ALLOW_ORIGIN] = $origin;
|
||||
|
||||
return $headers;
|
||||
|
||||
@@ -27,6 +27,31 @@ class Platform
|
||||
public const SCHEME_LINUX = 'appwrite-linux';
|
||||
public const SCHEME_TAURI = 'tauri';
|
||||
|
||||
public const string LOOPBACK_HOSTNAME = 'localhost';
|
||||
|
||||
/**
|
||||
* Other spellings of LOOPBACK_HOSTNAME. They address the same interface, so
|
||||
* they resolve to it when matching an allow list: a deployment that trusts
|
||||
* `localhost` trusts these too, and one that does not trusts neither. IPv6
|
||||
* is bracketed to match what parse_url() returns for a host.
|
||||
*
|
||||
* They are aliases rather than an unconditional allowance on purpose.
|
||||
* Session cookies are SameSite=None (see `cookieSamesite`) and CORS runs
|
||||
* with credentials, so any origin accepted here can read authenticated
|
||||
* responses. Matching is host-only, which means every port on the interface
|
||||
* counts -- trusting loopback outright would hand that to any local web UI,
|
||||
* including one with an XSS. Tying it to the configured allow list keeps the
|
||||
* decision with whoever set _APP_DOMAIN / _APP_CONSOLE_DOMAIN.
|
||||
*
|
||||
* Match exactly. A prefix or substring test would wrongly accept remote
|
||||
* hosts such as `127.0.0.1.example.com`, `xlocalhost` or `[::1].evil.com`.
|
||||
* Spellings outside this list (`127.0.0.2`, `0:0:0:0:0:0:0:1`, `localhost.`)
|
||||
* fail closed.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
public const array LOOPBACK_ALIASES = ['127.0.0.1', '[::1]'];
|
||||
|
||||
/**
|
||||
* @var array<string, string> Map scheme types to user-friendly platform names.
|
||||
*/
|
||||
|
||||
@@ -73,7 +73,13 @@ class Origin extends Validator
|
||||
];
|
||||
if (in_array($this->scheme, $webPlatforms, true)) {
|
||||
$validator = new Hostname($this->allowedHostnames);
|
||||
return $validator->isValid($this->host);
|
||||
if ($validator->isValid($this->host)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Fall back to the alias, see Platform::LOOPBACK_ALIASES */
|
||||
return in_array($this->host, Platform::LOOPBACK_ALIASES, true)
|
||||
&& $validator->isValid(Platform::LOOPBACK_HOSTNAME);
|
||||
}
|
||||
|
||||
if (!empty($this->scheme) && in_array($this->scheme, $this->allowedSchemes, true)) {
|
||||
|
||||
@@ -131,6 +131,19 @@ class Create extends Action
|
||||
ProofsToken $proofForToken,
|
||||
ProofsCode $proofForCode
|
||||
): void {
|
||||
$mfaFactors = $project->getAttribute('auths', [])['mfaFactors'] ?? [];
|
||||
$factorEnabled = match ($factor) {
|
||||
Type::TOTP => $mfaFactors['totp'] ?? true,
|
||||
Type::EMAIL => $mfaFactors['email'] ?? true,
|
||||
Type::PHONE => $mfaFactors['phone'] ?? true,
|
||||
Type::CUSTOM => $mfaFactors['custom'] ?? false,
|
||||
default => true, // Recovery codes always remain available as a fallback
|
||||
};
|
||||
|
||||
if (!$factorEnabled) {
|
||||
throw new Exception(Exception::USER_AUTH_METHOD_UNSUPPORTED, 'The requested factor is disabled by the MFA factors policy');
|
||||
}
|
||||
|
||||
$expire = DateTime::formatTz(DateTime::addSeconds(new \DateTime(), TOKEN_EXPIRATION_CONFIRM));
|
||||
|
||||
$code = $proofForCode->generate();
|
||||
|
||||
@@ -105,8 +105,26 @@ class Update extends Action
|
||||
throw new Exception(Exception::USER_INVALID_TOKEN);
|
||||
}
|
||||
|
||||
if ($challenge->getAttribute('expire') < DateTime::formatTz(DateTime::now())) {
|
||||
throw new Exception(Exception::USER_INVALID_TOKEN);
|
||||
}
|
||||
|
||||
$type = $challenge->getAttribute('type');
|
||||
|
||||
// Consult the current policy so disabling a factor also invalidates outstanding challenges
|
||||
$mfaFactors = $project->getAttribute('auths', [])['mfaFactors'] ?? [];
|
||||
$factorEnabled = match ($type) {
|
||||
Type::TOTP => $mfaFactors['totp'] ?? true,
|
||||
Type::EMAIL => $mfaFactors['email'] ?? true,
|
||||
Type::PHONE => $mfaFactors['phone'] ?? true,
|
||||
Type::CUSTOM => $mfaFactors['custom'] ?? false,
|
||||
default => true, // Recovery codes always remain available as a fallback
|
||||
};
|
||||
|
||||
if (!$factorEnabled) {
|
||||
throw new Exception(Exception::USER_AUTH_METHOD_UNSUPPORTED, 'The requested factor is disabled by the MFA factors policy');
|
||||
}
|
||||
|
||||
$recoveryCodeChallenge = function (Document $challenge, Document $user, string $otp) use ($dbForProject) {
|
||||
if (
|
||||
$challenge->isSet('type') &&
|
||||
|
||||
@@ -68,21 +68,25 @@ class XList extends Action
|
||||
])
|
||||
->inject('response')
|
||||
->inject('user')
|
||||
->inject('project')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(Response $response, Document $user): void
|
||||
public function action(Response $response, Document $user, Document $project): void
|
||||
{
|
||||
$mfaRecoveryCodes = $user->getAttribute('mfaRecoveryCodes', []);
|
||||
$recoveryCodeEnabled = \is_array($mfaRecoveryCodes) && \count($mfaRecoveryCodes) > 0;
|
||||
|
||||
$totp = TOTP::getAuthenticatorFromUser($user);
|
||||
|
||||
$mfaFactors = $project->getAttribute('auths', [])['mfaFactors'] ?? [];
|
||||
|
||||
$factors = new Document([
|
||||
Type::TOTP => $totp !== null && $totp->getAttribute('verified', false),
|
||||
Type::EMAIL => $user->getAttribute('email', false) && $user->getAttribute('emailVerification', false),
|
||||
Type::PHONE => $user->getAttribute('phone', false) && $user->getAttribute('phoneVerification', false),
|
||||
Type::RECOVERY_CODE => $recoveryCodeEnabled
|
||||
Type::TOTP => ($mfaFactors['totp'] ?? true) && $totp !== null && $totp->getAttribute('verified', false),
|
||||
Type::EMAIL => ($mfaFactors['email'] ?? true) && $user->getAttribute('email', false) && $user->getAttribute('emailVerification', false),
|
||||
Type::PHONE => ($mfaFactors['phone'] ?? true) && $user->getAttribute('phone', false) && $user->getAttribute('phoneVerification', false),
|
||||
Type::RECOVERY_CODE => $recoveryCodeEnabled,
|
||||
Type::CUSTOM => $mfaFactors['custom'] ?? false
|
||||
]);
|
||||
|
||||
$response->dynamic($factors, Response::MODEL_MFA_FACTORS);
|
||||
|
||||
@@ -9,6 +9,7 @@ use Appwrite\SDK\ContentType;
|
||||
use Appwrite\SDK\Deprecated;
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Database\Attribute;
|
||||
use Appwrite\Utopia\Database\Validator\Attributes as AttributesValidator;
|
||||
use Appwrite\Utopia\Database\Validator\CustomId;
|
||||
use Appwrite\Utopia\Database\Validator\Indexes as IndexesValidator;
|
||||
@@ -81,7 +82,7 @@ class Create extends Action
|
||||
->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE)), 'An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true)
|
||||
->param('documentSecurity', false, new Boolean(true), 'Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).', true)
|
||||
->param('enabled', true, new Boolean(), 'Is collection enabled? When set to \'disabled\', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.', true)
|
||||
->param('attributes', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, integer, float, boolean, datetime), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.', true)
|
||||
->param('attributes', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, varchar, text, mediumtext, longtext, integer, bigint, float, boolean, datetime, email, url, ip, enum), size (integer, required for string and varchar types), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.', true)
|
||||
->param('indexes', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
@@ -279,13 +280,12 @@ class Create extends Action
|
||||
Document $collection,
|
||||
array $attribute,
|
||||
): array {
|
||||
['type' => $type, 'format' => $format, 'size' => $size] = Attribute::resolve($attribute);
|
||||
|
||||
$key = $attribute['key'];
|
||||
$type = $attribute['type'];
|
||||
$size = $attribute['size'] ?? 0;
|
||||
$required = $attribute['required'] ?? false;
|
||||
$signed = $attribute['signed'] ?? true;
|
||||
$array = $attribute['array'] ?? false;
|
||||
$format = $attribute['format'] ?? '';
|
||||
$formatOptions = [];
|
||||
$filters = $attribute['filters'] ?? [];
|
||||
$default = $attribute['default'] ?? null;
|
||||
|
||||
@@ -46,7 +46,7 @@ class Create extends CreateDocumentAction
|
||||
->setHttpPath('/v1/embeddings/text')
|
||||
->desc('Create text embeddings')
|
||||
->groups(['api', 'database'])
|
||||
->label('scope', 'documents.write')
|
||||
->label('scope', 'embeddings.write')
|
||||
->label('resourceType', RESOURCE_TYPE_EMBEDDINGS_TEXT)
|
||||
->label('audits.event', 'embedding.create')
|
||||
->label('audits.resource', 'embeddings/text')
|
||||
|
||||
@@ -64,7 +64,7 @@ class Create extends CollectionCreate
|
||||
->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE)), 'An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true)
|
||||
->param('rowSecurity', false, new Boolean(true), 'Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a row. [Learn more about permissions](https://appwrite.io/docs/permissions).', true)
|
||||
->param('enabled', true, new Boolean(), 'Is table enabled? When set to \'disabled\', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.', true)
|
||||
->param('columns', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of column definitions to create. Each column should contain: key (string), type (string: string, integer, float, boolean, datetime, relationship), size (integer, required for string type), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.', true)
|
||||
->param('columns', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of column definitions to create. Each column should contain: key (string), type (string: string, varchar, text, mediumtext, longtext, integer, bigint, float, boolean, datetime, email, url, ip, enum), size (integer, required for string and varchar types), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.', true)
|
||||
->param('indexes', [], new ArrayList(new JSONObject(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial), attributes (array of column keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).', true)
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Audits;
|
||||
|
||||
use Appwrite\Event\Publisher\Audit;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueAudits';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/audits')
|
||||
->desc('Get audits queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForAudits')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, Audit $publisherForAudits, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForAudits->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Builds;
|
||||
|
||||
use Appwrite\Event\Publisher\Build as BuildPublisher;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueBuilds';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/builds')
|
||||
->desc('Get builds queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForBuilds')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, BuildPublisher $publisherForBuilds, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForBuilds->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Certificates;
|
||||
|
||||
use Appwrite\Event\Publisher\Certificate;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueCertificates';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/certificates')
|
||||
->desc('Get certificates queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForCertificates')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, Certificate $publisherForCertificates, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForCertificates->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Databases;
|
||||
|
||||
use Appwrite\Event\Publisher\Database;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Queue\Queue;
|
||||
use Utopia\Validator\Integer;
|
||||
use Utopia\Validator\Text;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueDatabases';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/databases')
|
||||
->desc('Get databases queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('name', 'database_db_main', new Text(256), 'Queue name for which to check the queue size', true)
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForDatabase')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(string $name, int|string $threshold, Database $publisherForDatabase, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
$size = $publisherForDatabase->getSize(queue: new Queue($name));
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Deletes;
|
||||
|
||||
use Appwrite\Event\Publisher\Delete;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueDeletes';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/deletes')
|
||||
->desc('Get deletes queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForDeletes')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, Delete $publisherForDeletes, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForDeletes->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Functions;
|
||||
|
||||
use Appwrite\Event\Publisher\Func as FunctionPublisher;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueFunctions';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/functions')
|
||||
->desc('Get functions queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForFunctions')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, FunctionPublisher $publisherForFunctions, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForFunctions->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Mails;
|
||||
|
||||
use Appwrite\Event\Publisher\Mail as MailPublisher;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueMails';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/mails')
|
||||
->desc('Get mails queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForMails')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, MailPublisher $publisherForMails, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForMails->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Messaging;
|
||||
|
||||
use Appwrite\Event\Publisher\Messaging as MessagingPublisher;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueMessaging';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/messaging')
|
||||
->desc('Get messaging queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForMessaging')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, MessagingPublisher $publisherForMessaging, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForMessaging->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Migrations;
|
||||
|
||||
use Appwrite\Event\Publisher\Migration as MigrationPublisher;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueMigrations';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/migrations')
|
||||
->desc('Get migrations queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForMigrations')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, MigrationPublisher $publisherForMigrations, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForMigrations->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Notifications;
|
||||
|
||||
use Appwrite\Event\Publisher\Notification as NotificationPublisher;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueNotifications';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/notifications')
|
||||
->desc('Get notifications queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForNotifications')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, NotificationPublisher $publisherForNotifications, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForNotifications->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\StatsResources;
|
||||
|
||||
use Appwrite\Event\Publisher\StatsResources as StatsResourcesPublisher;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueStatsResources';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/stats-resources')
|
||||
->desc('Get stats resources queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForStatsResources')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, StatsResourcesPublisher $publisherForStatsResources, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForStatsResources->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\StatsUsage;
|
||||
|
||||
use Appwrite\Event\Publisher\Usage as UsagePublisher;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueUsage';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/stats-usage')
|
||||
->desc('Get stats usage queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('publisherForUsage')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, UsagePublisher $publisherForUsage, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $publisherForUsage->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Health\Http\Health\Queue\Webhooks;
|
||||
|
||||
use Appwrite\Event\Webhook;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Base;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Validator\Integer;
|
||||
|
||||
class Get extends Base
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return 'getQueueWebhooks';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Base::HTTP_REQUEST_METHOD_GET)
|
||||
->setHttpPath('/v1/health/queue/webhooks')
|
||||
->desc('Get webhooks queue')
|
||||
->groups(['api', 'health'])
|
||||
->label('scope', 'health.read')
|
||||
->param('threshold', 5000, new Integer(true), 'Queue size threshold. When hit (equal or higher), endpoint returns server error. Default value is 5000.', true)
|
||||
->inject('queueForWebhooks')
|
||||
->inject('response')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(int|string $threshold, Webhook $queueForWebhooks, Response $response): void
|
||||
{
|
||||
$threshold = (int) $threshold;
|
||||
|
||||
$size = $queueForWebhooks->getSize();
|
||||
|
||||
$this->assertQueueThreshold($size, $threshold);
|
||||
|
||||
$response->dynamic(new Document(['size' => $size]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
}
|
||||
@@ -9,20 +9,7 @@ use Appwrite\Platform\Modules\Health\Http\Health\DB\Get as GetDB;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Geo\Get as GetGeo;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Get as GetHealth;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\PubSub\Get as GetPubSub;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Audits\Get as GetQueueAudits;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Builds\Get as GetQueueBuilds;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Certificates\Get as GetQueueCertificates;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Databases\Get as GetQueueDatabases;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Deletes\Get as GetQueueDeletes;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Failed\Get as GetFailedJobs;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Functions\Get as GetQueueFunctions;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Mails\Get as GetQueueMails;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Messaging\Get as GetQueueMessaging;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Migrations\Get as GetQueueMigrations;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Notifications\Get as GetQueueNotifications;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\StatsResources\Get as GetQueueStatsResources;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\StatsUsage\Get as GetQueueUsage;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Webhooks\Get as GetQueueWebhooks;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Stats\Get as GetStats;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Storage\Get as GetStorage;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Storage\Local\Get as GetStorageLocal;
|
||||
@@ -48,19 +35,6 @@ class Http extends Service
|
||||
$this->addAction(GetAntivirus::getName(), new GetAntivirus());
|
||||
$this->addAction(GetGeo::getName(), new GetGeo());
|
||||
|
||||
$this->addAction(GetQueueAudits::getName(), new GetQueueAudits());
|
||||
$this->addAction(GetQueueWebhooks::getName(), new GetQueueWebhooks());
|
||||
$this->addAction(GetQueueCertificates::getName(), new GetQueueCertificates());
|
||||
$this->addAction(GetQueueBuilds::getName(), new GetQueueBuilds());
|
||||
$this->addAction(GetQueueDatabases::getName(), new GetQueueDatabases());
|
||||
$this->addAction(GetQueueDeletes::getName(), new GetQueueDeletes());
|
||||
$this->addAction(GetQueueMails::getName(), new GetQueueMails());
|
||||
$this->addAction(GetQueueMessaging::getName(), new GetQueueMessaging());
|
||||
$this->addAction(GetQueueMigrations::getName(), new GetQueueMigrations());
|
||||
$this->addAction(GetQueueNotifications::getName(), new GetQueueNotifications());
|
||||
$this->addAction(GetQueueFunctions::getName(), new GetQueueFunctions());
|
||||
$this->addAction(GetQueueStatsResources::getName(), new GetQueueStatsResources());
|
||||
$this->addAction(GetQueueUsage::getName(), new GetQueueUsage());
|
||||
$this->addAction(GetFailedJobs::getName(), new GetFailedJobs());
|
||||
|
||||
$this->addAction(GetStats::getName(), new GetStats());
|
||||
|
||||
@@ -102,7 +102,13 @@ class Create extends Action
|
||||
'membershipsMfa' => false,
|
||||
'membershipsUserId' => false,
|
||||
'membershipsUserPhone' => false,
|
||||
'invalidateSessions' => true
|
||||
'invalidateSessions' => true,
|
||||
'mfaFactors' => [
|
||||
'totp' => true,
|
||||
'email' => true,
|
||||
'phone' => true,
|
||||
'custom' => false,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($auth as $method) {
|
||||
|
||||
@@ -52,7 +52,7 @@ class Delete extends Action
|
||||
],
|
||||
contentType: ContentType::NONE
|
||||
))
|
||||
->param('number', null, new Phone(), 'Phone number associated with the mock phone. Must be a valid E.164 formatted phone number.')
|
||||
->param('number', null, new Phone(normalize: true), 'Phone number associated with the mock phone. Must be a valid E.164 formatted phone number.')
|
||||
->inject('response')
|
||||
->inject('queueForEvents')
|
||||
->inject('project')
|
||||
@@ -69,6 +69,7 @@ class Delete extends Action
|
||||
Database $dbForPlatform,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
$number = Phone::normalize($number);
|
||||
$auths = $project->getAttribute('auths', []);
|
||||
|
||||
$mockNumbers = $auths['mockNumbers'] ?? [];
|
||||
|
||||
@@ -44,7 +44,7 @@ class Get extends Action
|
||||
)
|
||||
]
|
||||
))
|
||||
->param('number', null, new Phone(), 'Phone number associated with the mock phone. Must be a valid E.164 formatted phone number.')
|
||||
->param('number', null, new Phone(normalize: true), 'Phone number associated with the mock phone. Must be a valid E.164 formatted phone number.')
|
||||
->inject('response')
|
||||
->inject('project')
|
||||
->callback($this->action(...));
|
||||
@@ -55,6 +55,7 @@ class Get extends Action
|
||||
Response $response,
|
||||
Document $project
|
||||
) {
|
||||
$number = Phone::normalize($number);
|
||||
$auths = $project->getAttribute('auths', []);
|
||||
|
||||
$mockNumbers = $auths['mockNumbers'] ?? [];
|
||||
|
||||
@@ -52,7 +52,7 @@ class Update extends Action
|
||||
)
|
||||
]
|
||||
))
|
||||
->param('number', null, new Phone(), 'Phone number associated with the mock phone. Must be a valid E.164 formatted phone number.')
|
||||
->param('number', null, new Phone(normalize: true), 'Phone number associated with the mock phone. Must be a valid E.164 formatted phone number.')
|
||||
->param('otp', '', new Text(6, 6, Text::NUMBERS), 'One-time password (OTP) to associate with the mock phone. Must be a 6-digit numeric code.')
|
||||
->inject('response')
|
||||
->inject('queueForEvents')
|
||||
@@ -71,6 +71,7 @@ class Update extends Action
|
||||
Database $dbForPlatform,
|
||||
Authorization $authorization,
|
||||
) {
|
||||
$number = Phone::normalize($number);
|
||||
$auths = $project->getAttribute('auths', []);
|
||||
|
||||
$mockNumbers = $auths['mockNumbers'] ?? [];
|
||||
|
||||
@@ -85,6 +85,7 @@ class Get extends Action
|
||||
'session-limit' => Response::MODEL_POLICY_SESSION_LIMIT,
|
||||
'user-limit' => Response::MODEL_POLICY_USER_LIMIT,
|
||||
'membership-privacy' => Response::MODEL_POLICY_MEMBERSHIP_PRIVACY,
|
||||
'mfa-factors' => Response::MODEL_POLICY_MFA_FACTORS,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -176,6 +177,17 @@ class Get extends Action
|
||||
]),
|
||||
Response::MODEL_POLICY_MEMBERSHIP_PRIVACY,
|
||||
],
|
||||
'mfa-factors' => [
|
||||
new Document(\array_merge([
|
||||
'totp' => true,
|
||||
'email' => true,
|
||||
'phone' => true,
|
||||
'custom' => false,
|
||||
], $auths['mfaFactors'] ?? [], [
|
||||
'$id' => 'mfa-factors',
|
||||
])),
|
||||
Response::MODEL_POLICY_MFA_FACTORS,
|
||||
],
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Platform\Modules\Project\Http\Project\Policies\MFAFactors;
|
||||
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Platform\Action;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Boolean;
|
||||
|
||||
class Update extends Action
|
||||
{
|
||||
use HTTP;
|
||||
|
||||
public static function getName()
|
||||
{
|
||||
return 'updateProjectMFAFactorsPolicy';
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH)
|
||||
->setHttpPath('/v1/project/policies/mfa-factors')
|
||||
->desc('Update MFA factors policy')
|
||||
->groups(['api', 'project'])
|
||||
->label('scope', ['policies.write', 'project.policies.write'])
|
||||
->label('event', 'projects.[projectId].policies.[policy].update')
|
||||
->label('audits.event', 'projects.[projectId].policies.[policy].update')
|
||||
->label('audits.resource', 'project/{response.$id}')
|
||||
->label('sdk', new Method(
|
||||
namespace: 'project',
|
||||
group: 'policies',
|
||||
name: 'updateMFAFactorsPolicy',
|
||||
description: <<<EOT
|
||||
Updating this policy allows you to control which factors users can use to complete an MFA challenge. Disabled factors cannot be used to create a challenge and are reported as unavailable when listing factors. The custom factor is disabled by default; enable it to deliver challenge codes through your own channel. Recovery codes always remain available as a fallback.
|
||||
EOT,
|
||||
auth: [AuthType::ADMIN, AuthType::KEY],
|
||||
responses: [
|
||||
new SDKResponse(
|
||||
code: Response::STATUS_CODE_OK,
|
||||
model: Response::MODEL_PROJECT,
|
||||
)
|
||||
],
|
||||
))
|
||||
->param('totp', null, new Boolean(), 'Set to true to allow TOTP to complete an MFA challenge, or false to disable it.', optional: true)
|
||||
->param('email', null, new Boolean(), 'Set to true to allow email to complete an MFA challenge, or false to disable it.', optional: true)
|
||||
->param('phone', null, new Boolean(), 'Set to true to allow phone (SMS) to complete an MFA challenge, or false to disable it.', optional: true)
|
||||
->param('custom', null, new Boolean(), 'Set to true to allow the custom factor to complete an MFA challenge, or false to disable it.', optional: true)
|
||||
->inject('response')
|
||||
->inject('dbForPlatform')
|
||||
->inject('project')
|
||||
->inject('queueForEvents')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(
|
||||
?bool $totp,
|
||||
?bool $email,
|
||||
?bool $phone,
|
||||
?bool $custom,
|
||||
Response $response,
|
||||
Database $dbForPlatform,
|
||||
Document $project,
|
||||
Event $queueForEvents,
|
||||
): void {
|
||||
$auths = $project->getAttribute('auths', []);
|
||||
$factors = $auths['mfaFactors'] ?? [];
|
||||
|
||||
if ($totp !== null) {
|
||||
$factors['totp'] = $totp;
|
||||
}
|
||||
if ($email !== null) {
|
||||
$factors['email'] = $email;
|
||||
}
|
||||
if ($phone !== null) {
|
||||
$factors['phone'] = $phone;
|
||||
}
|
||||
if ($custom !== null) {
|
||||
$factors['custom'] = $custom;
|
||||
}
|
||||
|
||||
$auths['mfaFactors'] = $factors;
|
||||
|
||||
$updates = new Document([
|
||||
'auths' => $auths,
|
||||
]);
|
||||
|
||||
$project = $dbForPlatform->updateDocument('projects', $project->getId(), $updates);
|
||||
$dbForPlatform->purgeCachedDocument('projects', $project->getId());
|
||||
|
||||
$queueForEvents
|
||||
->setParam('projectId', $project->getId())
|
||||
->setParam('policy', 'mfa-factors');
|
||||
|
||||
$response->dynamic($project, Response::MODEL_PROJECT);
|
||||
}
|
||||
}
|
||||
@@ -145,6 +145,14 @@ class XList extends Action
|
||||
'userMFA' => $auths['membershipsMfa'] ?? false,
|
||||
'userAccessedAt' => $auths['membershipsUserAccessedAt'] ?? false,
|
||||
]),
|
||||
new Document(\array_merge([
|
||||
'totp' => true,
|
||||
'email' => true,
|
||||
'phone' => true,
|
||||
'custom' => false,
|
||||
], $auths['mfaFactors'] ?? [], [
|
||||
'$id' => 'mfa-factors',
|
||||
])),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,7 @@ use Appwrite\Platform\Modules\Project\Http\Project\Platforms\Windows\Update as U
|
||||
use Appwrite\Platform\Modules\Project\Http\Project\Platforms\XList as ListPlatforms;
|
||||
use Appwrite\Platform\Modules\Project\Http\Project\Policies\Get as GetPolicy;
|
||||
use Appwrite\Platform\Modules\Project\Http\Project\Policies\MembershipPrivacy\Update as UpdateMembershipPrivacyPolicy;
|
||||
use Appwrite\Platform\Modules\Project\Http\Project\Policies\MFAFactors\Update as UpdateMFAFactorsPolicy;
|
||||
use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordDictionary\Update as UpdatePasswordDictionaryPolicy;
|
||||
use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordHistory\Update as UpdatePasswordHistoryPolicy;
|
||||
use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPersonalData\Update as UpdatePasswordPersonalDataPolicy;
|
||||
@@ -168,6 +169,7 @@ class Http extends Service
|
||||
$this->addAction(ListPolicies::getName(), new ListPolicies());
|
||||
$this->addAction(GetPolicy::getName(), new GetPolicy());
|
||||
$this->addAction(UpdateMembershipPrivacyPolicy::getName(), new UpdateMembershipPrivacyPolicy());
|
||||
$this->addAction(UpdateMFAFactorsPolicy::getName(), new UpdateMFAFactorsPolicy());
|
||||
$this->addAction(UpdatePasswordDictionaryPolicy::getName(), new UpdatePasswordDictionaryPolicy());
|
||||
$this->addAction(UpdatePasswordHistoryPolicy::getName(), new UpdatePasswordHistoryPolicy());
|
||||
$this->addAction(UpdatePasswordStrengthPolicy::getName(), new UpdatePasswordStrengthPolicy());
|
||||
|
||||
@@ -105,7 +105,13 @@ class Create extends Action
|
||||
'membershipsMfa' => false,
|
||||
'membershipsUserId' => false,
|
||||
'membershipsUserPhone' => false,
|
||||
'invalidateSessions' => true
|
||||
'invalidateSessions' => true,
|
||||
'mfaFactors' => [
|
||||
'totp' => true,
|
||||
'email' => true,
|
||||
'phone' => true,
|
||||
'custom' => false,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($auth as $method) {
|
||||
|
||||
@@ -10,6 +10,7 @@ use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Validator\UID;
|
||||
use Utopia\Platform\Scope\HTTP;
|
||||
use Utopia\Validator\Text;
|
||||
@@ -68,6 +69,7 @@ class Get extends Action
|
||||
$challenge->isEmpty()
|
||||
|| $challenge->getAttribute('userId') !== $userId
|
||||
|| $challenge->getAttribute('type') !== Type::CUSTOM
|
||||
|| $challenge->getAttribute('expire') < DateTime::formatTz(DateTime::now())
|
||||
) {
|
||||
throw new Exception(Exception::USER_INVALID_TOKEN);
|
||||
}
|
||||
|
||||
@@ -70,10 +70,11 @@ class XList extends Action
|
||||
->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject'])
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
->inject('project')
|
||||
->callback($this->action(...));
|
||||
}
|
||||
|
||||
public function action(string $userId, Response $response, Database $dbForProject): void
|
||||
public function action(string $userId, Response $response, Database $dbForProject, Document $project): void
|
||||
{
|
||||
$user = $dbForProject->getDocument('users', $userId);
|
||||
|
||||
@@ -83,10 +84,13 @@ class XList extends Action
|
||||
|
||||
$totp = TOTP::getAuthenticatorFromUser($user);
|
||||
|
||||
$mfaFactors = $project->getAttribute('auths', [])['mfaFactors'] ?? [];
|
||||
|
||||
$factors = new Document([
|
||||
Type::TOTP => $totp !== null && $totp->getAttribute('verified', false),
|
||||
Type::EMAIL => $user->getAttribute('email', false) && $user->getAttribute('emailVerification', false),
|
||||
Type::PHONE => $user->getAttribute('phone', false) && $user->getAttribute('phoneVerification', false)
|
||||
Type::TOTP => ($mfaFactors['totp'] ?? true) && $totp !== null && $totp->getAttribute('verified', false),
|
||||
Type::EMAIL => ($mfaFactors['email'] ?? true) && $user->getAttribute('email', false) && $user->getAttribute('emailVerification', false),
|
||||
Type::PHONE => ($mfaFactors['phone'] ?? true) && $user->getAttribute('phone', false) && $user->getAttribute('phoneVerification', false),
|
||||
Type::CUSTOM => $mfaFactors['custom'] ?? false
|
||||
]);
|
||||
|
||||
$response->dynamic($factors, Response::MODEL_MFA_FACTORS);
|
||||
|
||||
@@ -36,6 +36,18 @@ abstract class ScheduleBase extends Action
|
||||
abstract public static function getSupportedResource(): string;
|
||||
abstract public static function getCollectionId(): string;
|
||||
|
||||
/**
|
||||
* Deterministic per-resource offset, in seconds, within [0, $window).
|
||||
*
|
||||
* Schedules that share a cron slot are spread across the window instead
|
||||
* of all being enqueued in the same second, while each resource keeps a
|
||||
* stable slot so run intervals stay exact.
|
||||
*/
|
||||
public static function spreadOffset(string $resourceId, int $window): int
|
||||
{
|
||||
return $window <= 1 ? 0 : \abs(\crc32($resourceId)) % $window;
|
||||
}
|
||||
|
||||
protected function loadResource(Document $project, callable $getProjectDB, array $schedule): Document
|
||||
{
|
||||
return $getProjectDB($project)->getDocument(static::getCollectionId(), $schedule['resourceId']);
|
||||
@@ -237,10 +249,19 @@ abstract class ScheduleBase extends Action
|
||||
|
||||
foreach ($batches as $batch) {
|
||||
$dbStart = microtime(true);
|
||||
$documents = $dbForPlatform->find('projects', [
|
||||
Query::equal('$id', $batch),
|
||||
Query::limit(count($batch)),
|
||||
]);
|
||||
// The project's subquery attributes cost one query each, per project — five
|
||||
// thousand extra queries for a batch of a thousand projects — and no
|
||||
// schedule task reads them. The only attributes used here are accessedAt,
|
||||
// teamId, database and the sequence, and the documents enqueued for the
|
||||
// workers are reloaded there by id, so the stripped arrays never reach the
|
||||
// code that needs them. Same group Action::$filters marks as Project.
|
||||
$documents = $dbForPlatform->skipFilters(
|
||||
fn () => $dbForPlatform->find('projects', [
|
||||
Query::equal('$id', $batch),
|
||||
Query::limit(count($batch)),
|
||||
]),
|
||||
['subQueryKeys', 'subQueryWebhooks', 'subQueryPlatforms', 'subQueryBlocks', 'subQueryDevKeys']
|
||||
);
|
||||
$dbQueryDuration += microtime(true) - $dbStart;
|
||||
|
||||
$transformStart = microtime(true);
|
||||
|
||||
@@ -37,18 +37,6 @@ class ScheduleFunctions extends ScheduleBase
|
||||
return RESOURCE_TYPE_FUNCTIONS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deterministic per-function offset, in seconds, within [0, $window).
|
||||
*
|
||||
* Schedules that share a cron slot (everyone runs `0 * * * *`) are spread
|
||||
* across the window instead of all being enqueued in the same second,
|
||||
* while each function keeps a stable slot so run intervals stay exact.
|
||||
*/
|
||||
public static function spreadOffset(string $resourceId, int $window): int
|
||||
{
|
||||
return $window <= 1 ? 0 : \abs(\crc32($resourceId)) % $window;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spread window, in seconds, for a given schedule. The default applies
|
||||
* _APP_FUNCTIONS_SCHEDULE_SPREAD to every schedule; override to scope
|
||||
|
||||
@@ -779,7 +779,10 @@ class Specs extends Action
|
||||
$parsedSpecs = $specs->parse();
|
||||
$this->verifyParsedSpec($parsedSpecs);
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new \RuntimeException("Spec generation failed for {$platform} ({$format}): " . $e->getMessage(), 0, $e);
|
||||
// A throw is reported and carried on from, so stop here
|
||||
Console::error("Spec generation failed for {$platform} ({$format}): " . $e->getMessage());
|
||||
Console::exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
$encodedSpecs = \json_encode($parsedSpecs, JSON_PRETTY_PRINT);
|
||||
|
||||
@@ -211,6 +211,7 @@ class Deletes extends Action
|
||||
$this->deleteUsageStats($project, $getProjectDB, $getLogsDB, $hourlyUsageRetentionDatetime);
|
||||
$this->deleteExpiredSessions($project, $getProjectDB);
|
||||
$this->deleteExpiredOAuth2Grants($project, $getProjectDB);
|
||||
$this->deleteExpiredChallenges($project, $getProjectDB);
|
||||
$this->deleteExpiredTransactions($project, $getProjectDB);
|
||||
$this->deleteExpiredPresences($project, $getProjectDB, $publisherForUsage);
|
||||
$this->deleteOldDeployments($publisherForDeletes, $project, $getProjectDB);
|
||||
@@ -1166,6 +1167,24 @@ class Deletes extends Action
|
||||
], $dbForProject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Document $project
|
||||
* @param callable $getProjectDB
|
||||
* @return void
|
||||
* @throws Exception|Throwable
|
||||
*/
|
||||
private function deleteExpiredChallenges(Document $project, callable $getProjectDB): void
|
||||
{
|
||||
Console::info('Delete expired challenges');
|
||||
|
||||
$this->deleteByGroup('challenges', [
|
||||
Query::select([...$this->selects, 'expire']),
|
||||
Query::lessThan('expire', DateTime::format(new \DateTime())),
|
||||
Query::orderAsc('expire'),
|
||||
Query::orderAsc(),
|
||||
], $getProjectDB($project));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Database $dbForPlatform
|
||||
* @param Device $deviceForFiles
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Database;
|
||||
|
||||
use Utopia\Database\Database;
|
||||
|
||||
/**
|
||||
* Shared definition of the attribute types the API exposes.
|
||||
*
|
||||
* The dedicated per-attribute endpoints hardcode a type, a format and a size
|
||||
* each. This holds the same mapping so the inline `attributes`/`columns` array
|
||||
* on create collection/table produces identical attribute documents.
|
||||
*/
|
||||
class Attribute
|
||||
{
|
||||
/**
|
||||
* Types whose size is fixed by the type itself.
|
||||
*
|
||||
* @var array<string, int>
|
||||
*/
|
||||
public const SIZES = [
|
||||
Database::VAR_TEXT => 65535,
|
||||
Database::VAR_MEDIUMTEXT => 16777215,
|
||||
Database::VAR_LONGTEXT => 2147483647,
|
||||
];
|
||||
|
||||
/**
|
||||
* String formats, mapped to the size their dedicated endpoint uses. Each
|
||||
* format is also accepted as a shorthand type, mirroring the endpoints
|
||||
* (`createEmailColumn` and friends) that create a string with that format.
|
||||
*
|
||||
* @var array<string, int>
|
||||
*/
|
||||
public const FORMAT_SIZES = [
|
||||
APP_DATABASE_ATTRIBUTE_EMAIL => 254,
|
||||
APP_DATABASE_ATTRIBUTE_ENUM => Database::LENGTH_KEY,
|
||||
APP_DATABASE_ATTRIBUTE_IP => 39,
|
||||
APP_DATABASE_ATTRIBUTE_URL => 2000,
|
||||
];
|
||||
|
||||
/**
|
||||
* Types accepted in an inline definition, including the format shorthands.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function types(): array
|
||||
{
|
||||
return [
|
||||
Database::VAR_STRING,
|
||||
Database::VAR_VARCHAR,
|
||||
Database::VAR_TEXT,
|
||||
Database::VAR_MEDIUMTEXT,
|
||||
Database::VAR_LONGTEXT,
|
||||
Database::VAR_INTEGER,
|
||||
Database::VAR_BIGINT,
|
||||
Database::VAR_FLOAT,
|
||||
Database::VAR_BOOLEAN,
|
||||
Database::VAR_DATETIME,
|
||||
Database::VAR_POINT,
|
||||
Database::VAR_LINESTRING,
|
||||
Database::VAR_POLYGON,
|
||||
...\array_keys(self::FORMAT_SIZES),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an inline definition into the type, format and size stored on the
|
||||
* attribute document. A format shorthand becomes a string of that format,
|
||||
* and a size is filled in from the type or format when the caller omits it.
|
||||
*
|
||||
* @param array<string, mixed> $attribute
|
||||
* @return array{type: string, format: string, size: int}
|
||||
*/
|
||||
public static function resolve(array $attribute): array
|
||||
{
|
||||
$type = $attribute['type'] ?? '';
|
||||
$format = $attribute['format'] ?? '';
|
||||
|
||||
if (isset(self::FORMAT_SIZES[$type])) {
|
||||
$format = $type;
|
||||
$type = Database::VAR_STRING;
|
||||
}
|
||||
|
||||
$size = $attribute['size'] ?? 0;
|
||||
$size = \is_int($size) ? $size : 0;
|
||||
|
||||
if (isset(self::SIZES[$type])) {
|
||||
// Fixed width types ignore any size the caller sent.
|
||||
$size = self::SIZES[$type];
|
||||
} elseif ($size < 1) {
|
||||
$size = self::FORMAT_SIZES[$format] ?? $size;
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => $type,
|
||||
'format' => $format,
|
||||
'size' => $size,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Appwrite\Utopia\Database\Validator;
|
||||
|
||||
use Appwrite\Utopia\Database\Attribute;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
||||
use Utopia\Database\Validator\Key;
|
||||
@@ -17,21 +18,6 @@ class Attributes extends Validator
|
||||
protected int $maxAttributes;
|
||||
protected string $message = 'Invalid attributes';
|
||||
|
||||
/**
|
||||
* @var array<string> Supported attribute types
|
||||
*/
|
||||
protected array $supportedTypes = [
|
||||
Database::VAR_STRING,
|
||||
Database::VAR_INTEGER,
|
||||
Database::VAR_BIGINT,
|
||||
Database::VAR_FLOAT,
|
||||
Database::VAR_BOOLEAN,
|
||||
Database::VAR_DATETIME,
|
||||
Database::VAR_POINT,
|
||||
Database::VAR_LINESTRING,
|
||||
Database::VAR_POLYGON,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string> Supported formats for string attributes
|
||||
*/
|
||||
@@ -92,6 +78,7 @@ class Attributes extends Validator
|
||||
}
|
||||
|
||||
$keyValidator = new Key();
|
||||
$supportedTypes = Attribute::types();
|
||||
$keys = [];
|
||||
|
||||
foreach ($value as $index => $attribute) {
|
||||
@@ -132,34 +119,44 @@ class Attributes extends Validator
|
||||
}
|
||||
|
||||
// Validate type
|
||||
if (!\in_array($attribute['type'], $this->supportedTypes)) {
|
||||
if (!\in_array($attribute['type'], $supportedTypes)) {
|
||||
$this->message = "Invalid type for attribute '" . $attribute['key'] . "': " . $attribute['type'];
|
||||
return false;
|
||||
}
|
||||
|
||||
// Resolve format shorthands and implicit sizes the same way the
|
||||
// attribute document is built, so both agree on what was asked for.
|
||||
['type' => $type, 'format' => $format, 'size' => $size] = Attribute::resolve($attribute);
|
||||
|
||||
// Validate spatial type support
|
||||
if (\in_array($attribute['type'], Database::SPATIAL_TYPES) && !$this->supportForSpatialAttributes) {
|
||||
if (\in_array($type, Database::SPATIAL_TYPES) && !$this->supportForSpatialAttributes) {
|
||||
$this->message = "Spatial attributes are not supported by the current database";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate size for string types
|
||||
if ($attribute['type'] === Database::VAR_STRING) {
|
||||
if (!isset($attribute['size']) || !is_int($attribute['size']) || $attribute['size'] < 1 || $attribute['size'] > APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH) {
|
||||
if (isset($attribute['size']) && !\is_int($attribute['size'])) {
|
||||
$this->message = "Invalid size for attribute '" . $attribute['key'] . "': must be an integer";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate size for the types that take one. The remaining string
|
||||
// types (text, mediumtext, longtext) are fixed width.
|
||||
if (\in_array($type, [Database::VAR_STRING, Database::VAR_VARCHAR])) {
|
||||
if ($size < 1 || $size > APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH) {
|
||||
$this->message = "Invalid or missing size for string attribute '" . $attribute['key'] . "'. Size must be between 1 and " . APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate format if provided
|
||||
if (isset($attribute['format']) && $attribute['format'] !== '') {
|
||||
// Format is only allowed for string type
|
||||
if ($attribute['type'] !== Database::VAR_STRING) {
|
||||
if ($format !== '') {
|
||||
// Format is only allowed for sized string types
|
||||
if (!\in_array($type, [Database::VAR_STRING, Database::VAR_VARCHAR])) {
|
||||
$this->message = "Format is only allowed for string type for attribute '" . $attribute['key'] . "'";
|
||||
return false;
|
||||
}
|
||||
if (!in_array($attribute['format'], $this->supportedFormats)) {
|
||||
$this->message = "Invalid format for attribute '" . $attribute['key'] . "': " . $attribute['format'];
|
||||
if (!in_array($format, $this->supportedFormats)) {
|
||||
$this->message = "Invalid format for attribute '" . $attribute['key'] . "': " . $format;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -183,7 +180,7 @@ class Attributes extends Validator
|
||||
}
|
||||
|
||||
// Validate signed only for integer/bigint/float types
|
||||
if (isset($attribute['signed']) && !in_array($attribute['type'], [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) {
|
||||
if (isset($attribute['signed']) && !in_array($type, [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) {
|
||||
$this->message = "Attribute '" . $attribute['key'] . "': 'signed' can only be used with integer, bigint or float types";
|
||||
return false;
|
||||
}
|
||||
@@ -202,7 +199,7 @@ class Attributes extends Validator
|
||||
|
||||
// Validate min/max range for integer/bigint/float
|
||||
if (isset($attribute['min']) || isset($attribute['max'])) {
|
||||
if (!in_array($attribute['type'], [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) {
|
||||
if (!in_array($type, [Database::VAR_INTEGER, Database::VAR_BIGINT, Database::VAR_FLOAT])) {
|
||||
$this->message = "Attribute '" . $attribute['key'] . "': min/max can only be used with integer, bigint or float types";
|
||||
return false;
|
||||
}
|
||||
@@ -216,15 +213,18 @@ class Attributes extends Validator
|
||||
|
||||
// Validate default value matches attribute type
|
||||
if (isset($attribute['default'])) {
|
||||
switch ($attribute['type']) {
|
||||
switch ($type) {
|
||||
case Database::VAR_STRING:
|
||||
case Database::VAR_VARCHAR:
|
||||
case Database::VAR_TEXT:
|
||||
case Database::VAR_MEDIUMTEXT:
|
||||
case Database::VAR_LONGTEXT:
|
||||
if (!is_string($attribute['default'])) {
|
||||
$this->message = "Default value for string attribute '" . $attribute['key'] . "' must be a string";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate string size
|
||||
$size = $attribute['size'] ?? 0;
|
||||
if ($size > 0) {
|
||||
$textValidator = new Text($size, 0);
|
||||
if (!$textValidator->isValid($attribute['default'])) {
|
||||
@@ -234,7 +234,6 @@ class Attributes extends Validator
|
||||
}
|
||||
|
||||
// Validate format-specific defaults
|
||||
$format = $attribute['format'] ?? '';
|
||||
if ($format === APP_DATABASE_ATTRIBUTE_EMAIL) {
|
||||
$emailValidator = new Email();
|
||||
if (!$emailValidator->isValid($attribute['default'])) {
|
||||
@@ -330,7 +329,7 @@ class Attributes extends Validator
|
||||
}
|
||||
|
||||
// Validate enum elements if format is enum
|
||||
if (isset($attribute['format']) && $attribute['format'] === APP_DATABASE_ATTRIBUTE_ENUM) {
|
||||
if ($format === APP_DATABASE_ATTRIBUTE_ENUM) {
|
||||
if (!isset($attribute['elements']) || !is_array($attribute['elements']) || empty($attribute['elements'])) {
|
||||
$this->message = "Attribute '" . $attribute['key'] . "' with enum format must have 'elements' array";
|
||||
return false;
|
||||
|
||||
@@ -91,7 +91,11 @@ class Base extends Queries
|
||||
new Limit(),
|
||||
new Offset(),
|
||||
new Cursor(),
|
||||
new Filter($attributes, APP_DATABASE_QUERY_MAX_VALUES),
|
||||
new Filter(
|
||||
attributes: $attributes,
|
||||
idAttributeType: Database::VAR_INTEGER,
|
||||
maxValuesCount: APP_DATABASE_QUERY_MAX_VALUES
|
||||
),
|
||||
new Order($attributes),
|
||||
];
|
||||
|
||||
|
||||
@@ -277,6 +277,7 @@ class Response extends SwooleResponse
|
||||
public const MODEL_POLICY_SESSION_LIMIT = 'policySessionLimit';
|
||||
public const MODEL_POLICY_USER_LIMIT = 'policyUserLimit';
|
||||
public const MODEL_POLICY_MEMBERSHIP_PRIVACY = 'policyMembershipPrivacy';
|
||||
public const MODEL_POLICY_MFA_FACTORS = 'policyMfaFactors';
|
||||
public const MODEL_AUTH_PROVIDER = 'authProvider';
|
||||
public const MODEL_AUTH_PROVIDER_LIST = 'authProviderList';
|
||||
public const MODEL_PLATFORM_APPLE = 'platformApple';
|
||||
|
||||
@@ -35,6 +35,12 @@ class MFAFactors extends Model
|
||||
'default' => false,
|
||||
'example' => true
|
||||
])
|
||||
->addRule(Type::CUSTOM, [
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
'description' => 'Can custom factor be used for MFA challenge for this account.',
|
||||
'default' => false,
|
||||
'example' => true
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ class PolicyList extends Model
|
||||
Response::MODEL_POLICY_SESSION_LIMIT,
|
||||
Response::MODEL_POLICY_USER_LIMIT,
|
||||
Response::MODEL_POLICY_MEMBERSHIP_PRIVACY,
|
||||
Response::MODEL_POLICY_MFA_FACTORS,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Auth\MFA\Type;
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
class PolicyMFAFactors extends PolicyBase
|
||||
{
|
||||
public array $conditions = [
|
||||
'$id' => 'mfa-factors',
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this
|
||||
->addRule(Type::TOTP, [
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
'description' => 'Whether TOTP can be used to complete an MFA challenge.',
|
||||
'default' => true,
|
||||
'example' => true,
|
||||
])
|
||||
->addRule(Type::EMAIL, [
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
'description' => 'Whether email can be used to complete an MFA challenge.',
|
||||
'default' => true,
|
||||
'example' => true,
|
||||
])
|
||||
->addRule(Type::PHONE, [
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
'description' => 'Whether phone (SMS) can be used to complete an MFA challenge.',
|
||||
'default' => true,
|
||||
'example' => true,
|
||||
])
|
||||
->addRule(Type::CUSTOM, [
|
||||
'type' => self::TYPE_BOOLEAN,
|
||||
'description' => 'Whether the custom factor can be used to complete an MFA challenge.',
|
||||
'default' => false,
|
||||
'example' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return 'Policy MFA Factors';
|
||||
}
|
||||
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_POLICY_MFA_FACTORS;
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,64 @@ final class HTTPTest extends Scope
|
||||
$this->assertNull($response['headers']['access-control-allow-origin'] ?? null);
|
||||
}
|
||||
|
||||
public function testCorsLoopback()
|
||||
{
|
||||
$endpoint = '/v1/projects'; // Can be any non-404 route
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*
|
||||
* Loopback origins are allowed without a registered platform.
|
||||
*/
|
||||
$origins = [
|
||||
'http://localhost',
|
||||
'http://localhost:3000',
|
||||
'http://127.0.0.1',
|
||||
'https://127.0.0.1:5173',
|
||||
'http://[::1]',
|
||||
'http://[::1]:3000',
|
||||
];
|
||||
|
||||
foreach ($origins as $origin) {
|
||||
$response = $this->client->call(Client::METHOD_GET, $endpoint, [
|
||||
'origin' => $origin,
|
||||
]);
|
||||
$this->assertEquals($origin, $response['headers']['access-control-allow-origin'] ?? null, 'Origin ' . $origin . ' was not allowed');
|
||||
|
||||
// Trusting loopback with credentials relies on the origin being
|
||||
// echoed verbatim, so the browser's literal match still applies
|
||||
$this->assertNotEquals('*', $response['headers']['access-control-allow-origin']);
|
||||
$this->assertEquals('true', $response['headers']['access-control-allow-credentials']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*
|
||||
* Hostnames that only look like loopback must not be allowed.
|
||||
*/
|
||||
$origins = [
|
||||
'http://127.0.0.1.example.com',
|
||||
'http://localhost.example.com',
|
||||
'http://128.0.0.1',
|
||||
'http://[2001:db8::1]',
|
||||
// A prefix or substring match would wrongly accept these
|
||||
'http://xlocalhost',
|
||||
'http://127.0.0.1x.example.com',
|
||||
'http://[::1].evil.com',
|
||||
// Only the exact loopback spellings are hardcoded
|
||||
'http://127.0.0.2',
|
||||
'http://[0:0:0:0:0:0:0:1]',
|
||||
'http://localhost.',
|
||||
];
|
||||
|
||||
foreach ($origins as $origin) {
|
||||
$response = $this->client->call(Client::METHOD_GET, $endpoint, [
|
||||
'origin' => $origin,
|
||||
]);
|
||||
$this->assertNull($response['headers']['access-control-allow-origin'] ?? null, 'Origin ' . $origin . ' was unexpectedly allowed');
|
||||
}
|
||||
}
|
||||
|
||||
public function testPreflight()
|
||||
{
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ trait ProjectCustom
|
||||
'documents.write',
|
||||
'rows.read',
|
||||
'rows.write',
|
||||
'embeddings.write',
|
||||
'files.read',
|
||||
'files.write',
|
||||
'buckets.read',
|
||||
|
||||
@@ -2228,6 +2228,131 @@ final class AccountCustomClientTest extends Scope
|
||||
$this->assertEquals(412, $response['headers']['status-code']);
|
||||
}
|
||||
|
||||
public function testCreateOAuth2AccountSessionLoopback(): void
|
||||
{
|
||||
$this->setupAccountWithSession();
|
||||
|
||||
$provider = 'mock';
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $this->getProject()['$id'] . '/oauth2', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console',
|
||||
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||
]), [
|
||||
'provider' => $provider,
|
||||
'appId' => '1',
|
||||
'secret' => '123456',
|
||||
'enabled' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*
|
||||
* Loopback redirects are allowed without a registered platform.
|
||||
*/
|
||||
$hosts = [
|
||||
'localhost',
|
||||
'localhost:3000',
|
||||
'127.0.0.1',
|
||||
'127.0.0.1:5173',
|
||||
'[::1]',
|
||||
'[::1]:3000',
|
||||
];
|
||||
|
||||
foreach ($hosts as $host) {
|
||||
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'success' => 'http://' . $host . '/v1/mock/tests/general/oauth2/success',
|
||||
'failure' => 'http://' . $host . '/v1/mock/tests/general/oauth2/failure',
|
||||
], followRedirects: false);
|
||||
|
||||
$this->assertEquals(301, $response['headers']['status-code'], 'Host ' . $host . ' was not allowed');
|
||||
$this->assertStringStartsWith('http://localhost/v1/mock/tests/general/oauth2', $response['headers']['location']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*
|
||||
* Hostnames that only look like loopback must not be allowed.
|
||||
*/
|
||||
$hosts = [
|
||||
'127.0.0.1.example.com',
|
||||
'localhost.example.com',
|
||||
'128.0.0.1',
|
||||
'[2001:db8::1]',
|
||||
// Only the exact loopback spellings are hardcoded
|
||||
'127.0.0.2',
|
||||
'[0:0:0:0:0:0:0:1]',
|
||||
];
|
||||
|
||||
foreach ($hosts as $host) {
|
||||
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'success' => 'http://' . $host . '/v1/mock/tests/general/oauth2/success',
|
||||
'failure' => 'http://' . $host . '/v1/mock/tests/general/oauth2/failure',
|
||||
], followRedirects: false);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code'], 'Host ' . $host . ' was unexpectedly allowed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk the whole token flow to prove the loopback success URL survives
|
||||
* the provider round trip and the callback validation.
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/account/tokens/oauth2/' . $provider, array_merge([
|
||||
'origin' => 'http://127.0.0.1',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'success' => 'http://127.0.0.1/v1/mock/tests/general/oauth2/success',
|
||||
'failure' => 'http://127.0.0.1/v1/mock/tests/general/oauth2/failure',
|
||||
], followRedirects: false);
|
||||
|
||||
$this->assertEquals(301, $response['headers']['status-code']);
|
||||
|
||||
$oauthClient = new Client();
|
||||
$oauthClient->setEndpoint('');
|
||||
|
||||
$response = $oauthClient->call(Client::METHOD_GET, $response['headers']['location'], followRedirects: false);
|
||||
$this->assertEquals(301, $response['headers']['status-code']);
|
||||
$this->assertStringStartsWith('http://appwrite:/v1/account/sessions/oauth2/callback/mock/' . $this->getProject()['$id'] . '?code=', $response['headers']['location']);
|
||||
|
||||
$response = $oauthClient->call(Client::METHOD_GET, $response['headers']['location'], followRedirects: false);
|
||||
$this->assertEquals(301, $response['headers']['status-code']);
|
||||
$this->assertStringStartsWith('http://appwrite:/v1/account/sessions/oauth2/mock/redirect?code=', $response['headers']['location']);
|
||||
|
||||
$response = $oauthClient->call(Client::METHOD_GET, $response['headers']['location'], followRedirects: false);
|
||||
$this->assertEquals(301, $response['headers']['status-code']);
|
||||
$this->assertStringStartsWith('http://127.0.0.1/v1/mock/tests/general/oauth2/success?secret=', $response['headers']['location']);
|
||||
|
||||
$oauthParams = [];
|
||||
\parse_str((string) \parse_url($response['headers']['location'], PHP_URL_QUERY), $oauthParams);
|
||||
|
||||
$this->assertNotEmpty($oauthParams['secret']);
|
||||
$this->assertNotEmpty($oauthParams['userId']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/token', [
|
||||
'origin' => 'http://127.0.0.1',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], [
|
||||
'userId' => $oauthParams['userId'],
|
||||
'secret' => $oauthParams['secret'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
$this->assertEquals('mock', $response['body']['provider']);
|
||||
}
|
||||
|
||||
public function testOAuth2TokenSessionProviderAccessToken(): void
|
||||
{
|
||||
// Just ensure we have a session set up
|
||||
@@ -3981,6 +4106,89 @@ final class AccountCustomClientTest extends Scope
|
||||
$this->assertStringContainsStringIgnoringCase($phrase, $lastEmail['text']);
|
||||
}
|
||||
|
||||
public function testCreateMagicUrlLoopback(): void
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*
|
||||
* Loopback redirect URLs are allowed without a registered platform.
|
||||
*/
|
||||
$hosts = [
|
||||
'localhost',
|
||||
'localhost:3000',
|
||||
'127.0.0.1',
|
||||
'127.0.0.1:5173',
|
||||
'[::1]',
|
||||
'[::1]:3000',
|
||||
];
|
||||
|
||||
$email = 'magic-loopback-' . uniqid() . '-' . \time() . '@appwrite.io';
|
||||
|
||||
foreach ($hosts as $host) {
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/tokens/magic-url', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => ID::unique(),
|
||||
'email' => $email,
|
||||
'url' => 'http://' . $host . '/magiclogin',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code'], 'Host ' . $host . ' was not allowed');
|
||||
}
|
||||
|
||||
/**
|
||||
* The emailed link must keep pointing at the loopback host.
|
||||
*/
|
||||
$email = 'magic-loopback-' . uniqid() . '-' . \time() . '@appwrite.io';
|
||||
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/tokens/magic-url', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => ID::unique(),
|
||||
'email' => $email,
|
||||
'url' => 'http://127.0.0.1:5173/magiclogin',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $response['headers']['status-code']);
|
||||
|
||||
$lastEmail = $this->getLastEmailByAddress($email);
|
||||
$this->assertNotEmpty($lastEmail, 'Email not found for address: ' . $email);
|
||||
$this->assertStringContainsString('http://127.0.0.1:5173/magiclogin?', (string) $lastEmail['text']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*
|
||||
* Hostnames that only look like loopback must not be allowed.
|
||||
*/
|
||||
$hosts = [
|
||||
'127.0.0.1.example.com',
|
||||
'localhost.example.com',
|
||||
'128.0.0.1',
|
||||
'[2001:db8::1]',
|
||||
// Only the exact loopback spellings are hardcoded
|
||||
'127.0.0.2',
|
||||
'[0:0:0:0:0:0:0:1]',
|
||||
];
|
||||
|
||||
foreach ($hosts as $host) {
|
||||
$response = $this->client->call(Client::METHOD_POST, '/account/tokens/magic-url', array_merge([
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
]), [
|
||||
'userId' => ID::unique(),
|
||||
'email' => 'magic-loopback-' . uniqid() . '-' . \time() . '@appwrite.io',
|
||||
'url' => 'http://' . $host . '/magiclogin',
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code'], 'Host ' . $host . ' was unexpectedly allowed');
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreateSessionWithMagicUrl(): void
|
||||
{
|
||||
$projectId = $this->getProject()['$id'];
|
||||
@@ -4276,6 +4484,26 @@ final class AccountCustomClientTest extends Scope
|
||||
$projectId = $this->getProject()['$id'];
|
||||
$apiKey = $this->getProject()['apiKey'];
|
||||
|
||||
// Enable the custom factor, which the MFA factors policy disables by default
|
||||
$policy = $this->client->call(Client::METHOD_PATCH, '/project/policies/mfa-factors', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $apiKey,
|
||||
], [
|
||||
'custom' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $policy['headers']['status-code']);
|
||||
|
||||
// Custom factor becomes visible when the policy enables it
|
||||
$factors = $this->client->call(Client::METHOD_GET, '/account/mfa/factors', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $factors['headers']['status-code']);
|
||||
$this->assertTrue($factors['body']['custom']);
|
||||
|
||||
// Create custom factor challenge using existing authenticated session
|
||||
$challenge = $this->client->call(Client::METHOD_POST, '/account/mfa/challenge', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Databases\TablesDB;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Helpers\Permission;
|
||||
use Utopia\Database\Helpers\Role;
|
||||
|
||||
final class TablesDBColumnsTest extends Scope
|
||||
{
|
||||
use ProjectCustom;
|
||||
use SideServer;
|
||||
|
||||
/**
|
||||
* Every column type the dedicated endpoints expose must also be creatable
|
||||
* inline on create table.
|
||||
*/
|
||||
public function testCreateTableColumns(): void
|
||||
{
|
||||
$headers = [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
];
|
||||
|
||||
$database = $this->client->call(Client::METHOD_POST, '/tablesdb', $headers, [
|
||||
'databaseId' => ID::unique(),
|
||||
'name' => 'Inline Columns',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $database['headers']['status-code']);
|
||||
$databaseId = $database['body']['$id'];
|
||||
|
||||
$table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $headers, [
|
||||
'tableId' => ID::unique(),
|
||||
'name' => 'Modules',
|
||||
'permissions' => [
|
||||
Permission::create(Role::any()),
|
||||
Permission::read(Role::any()),
|
||||
],
|
||||
'columns' => [
|
||||
['key' => 'title', 'type' => 'string', 'size' => 128, 'required' => true],
|
||||
['key' => 'slug', 'type' => 'varchar', 'size' => 64],
|
||||
['key' => 'modulePath', 'type' => 'text'],
|
||||
['key' => 'summary', 'type' => 'mediumtext'],
|
||||
['key' => 'archive', 'type' => 'longtext'],
|
||||
['key' => 'email', 'type' => 'email'],
|
||||
['key' => 'website', 'type' => 'url'],
|
||||
['key' => 'address', 'type' => 'ip'],
|
||||
['key' => 'status', 'type' => 'enum', 'elements' => ['on', 'off'], 'default' => 'on'],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $table['headers']['status-code']);
|
||||
$tableId = $table['body']['$id'];
|
||||
|
||||
$columns = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/columns', $headers);
|
||||
|
||||
$this->assertEquals(200, $columns['headers']['status-code']);
|
||||
$this->assertEquals(9, $columns['body']['total']);
|
||||
|
||||
$byKey = [];
|
||||
foreach ($columns['body']['columns'] as $column) {
|
||||
$this->assertEquals('available', $column['status']);
|
||||
$byKey[$column['key']] = $column;
|
||||
}
|
||||
|
||||
// Sizes must match the dedicated per-column endpoints. The fixed width
|
||||
// types do not expose a size, it is implied by the type.
|
||||
$this->assertEquals('string', $byKey['title']['type']);
|
||||
$this->assertEquals(128, $byKey['title']['size']);
|
||||
$this->assertEquals('varchar', $byKey['slug']['type']);
|
||||
$this->assertEquals(64, $byKey['slug']['size']);
|
||||
$this->assertEquals('text', $byKey['modulePath']['type']);
|
||||
$this->assertEquals('mediumtext', $byKey['summary']['type']);
|
||||
$this->assertEquals('longtext', $byKey['archive']['type']);
|
||||
|
||||
// Format shorthands become a string of that format
|
||||
$this->assertEquals('string', $byKey['email']['type']);
|
||||
$this->assertEquals('email', $byKey['email']['format']);
|
||||
$this->assertEquals('string', $byKey['website']['type']);
|
||||
$this->assertEquals('url', $byKey['website']['format']);
|
||||
$this->assertEquals('string', $byKey['address']['type']);
|
||||
$this->assertEquals('ip', $byKey['address']['format']);
|
||||
$this->assertEquals('string', $byKey['status']['type']);
|
||||
$this->assertEquals('enum', $byKey['status']['format']);
|
||||
$this->assertEquals(['on', 'off'], $byKey['status']['elements']);
|
||||
$this->assertEquals('on', $byKey['status']['default']);
|
||||
|
||||
// Longer than any of the sized string types allow, so it only fits if
|
||||
// the text column really got its 65535 default
|
||||
$modulePath = \str_repeat('src/Appwrite/Platform/Modules/Databases/', 200);
|
||||
|
||||
$row = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $tableId . '/rows', $headers, [
|
||||
'rowId' => ID::unique(),
|
||||
'data' => [
|
||||
'title' => 'Appwrite',
|
||||
'modulePath' => $modulePath,
|
||||
'email' => 'team@appwrite.io',
|
||||
'website' => 'https://appwrite.io',
|
||||
'address' => '127.0.0.1',
|
||||
'status' => 'off',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $row['headers']['status-code']);
|
||||
$this->assertEquals($modulePath, $row['body']['modulePath']);
|
||||
$this->assertEquals('off', $row['body']['status']);
|
||||
}
|
||||
|
||||
public function testCreateTableUnsupportedColumnType(): void
|
||||
{
|
||||
$headers = [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
];
|
||||
|
||||
$database = $this->client->call(Client::METHOD_POST, '/tablesdb', $headers, [
|
||||
'databaseId' => ID::unique(),
|
||||
'name' => 'Inline Columns Invalid',
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $database['headers']['status-code']);
|
||||
$databaseId = $database['body']['$id'];
|
||||
|
||||
$table = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', $headers, [
|
||||
'tableId' => ID::unique(),
|
||||
'name' => 'Invalid',
|
||||
'columns' => [
|
||||
['key' => 'unknown', 'type' => 'blob'],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $table['headers']['status-code']);
|
||||
$this->assertStringContainsString("Invalid type for attribute 'unknown': blob", (string) $table['body']['message']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class AuditsQueueTest extends HealthBase
|
||||
{
|
||||
public function testAuditsQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/audits');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/audits', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class BuildsQueueTest extends HealthBase
|
||||
{
|
||||
public function testBuildsQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/builds');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/builds', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class CertificatesQueueTest extends HealthBase
|
||||
{
|
||||
public function testCertificatesQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/certificates');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/certificates', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class DatabasesQueueTest extends HealthBase
|
||||
{
|
||||
public function testDatabasesQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/databases', ['name' => 'database_db_main']);
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/databases', ['name' => 'database_db_main', 'threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class DeletesQueueTest extends HealthBase
|
||||
{
|
||||
public function testDeletesQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/deletes');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/deletes', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class FunctionsQueueTest extends HealthBase
|
||||
{
|
||||
public function testFunctionsQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/functions');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/functions', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class MailsQueueTest extends HealthBase
|
||||
{
|
||||
public function testMailsQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/mails');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/mails', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class MessagingQueueTest extends HealthBase
|
||||
{
|
||||
public function testMessagingQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/messaging');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/messaging', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class MigrationsQueueTest extends HealthBase
|
||||
{
|
||||
public function testMigrationsQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/migrations');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/migrations', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class StatsResourcesQueueTest extends HealthBase
|
||||
{
|
||||
public function testStatsResources(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/stats-resources');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/stats-resources', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class StatsUsageQueueTest extends HealthBase
|
||||
{
|
||||
public function testStatsUsage(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/stats-usage');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/stats-usage', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Health;
|
||||
|
||||
final class WebhooksQueueTest extends HealthBase
|
||||
{
|
||||
public function testWebhooksQueue(): void
|
||||
{
|
||||
$response = $this->callGet('/health/queue/webhooks');
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
$failure = $this->callGet('/health/queue/webhooks', ['threshold' => '0']);
|
||||
$this->assertEquals(503, $failure['headers']['status-code']);
|
||||
}
|
||||
}
|
||||
@@ -8,16 +8,14 @@ use Utopia\Database\Helpers\ID;
|
||||
use Utopia\System\System;
|
||||
|
||||
/**
|
||||
* End-to-end coverage for the notifications queue health surface and the
|
||||
* End-to-end coverage for the notifications failed-jobs health surface and the
|
||||
* notifications user-facing API.
|
||||
*
|
||||
* The notification worker itself is exercised in unit tests with a pinned
|
||||
* queue payload; the server side cannot deterministically inject a
|
||||
* Notification onto the live queue without an admin endpoint, so the health
|
||||
* portion validates the public contract that ops and KEDA scale on:
|
||||
* Notification onto the live queue without an admin endpoint. This suite keeps
|
||||
* coverage for the failed-jobs health surface and the user-facing API:
|
||||
*
|
||||
* - GET /v1/health/queue/notifications returns the live queue depth
|
||||
* - the threshold guard returns 503 when the depth exceeds the budget
|
||||
* - the failed-jobs surface accepts the notifications queue name
|
||||
*
|
||||
* The notifications portion exercises the full webhook-paused fanout end-to-end:
|
||||
@@ -37,28 +35,6 @@ use Utopia\System\System;
|
||||
*/
|
||||
trait NotificationsBase
|
||||
{
|
||||
public function testHealthQueueNotificationsReportsSize(): void
|
||||
{
|
||||
$response = $this->client->call(Client::METHOD_GET, '/health/queue/notifications', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertGreaterThanOrEqual(0, $response['body']['size']);
|
||||
}
|
||||
|
||||
public function testHealthQueueNotificationsThresholdGuard(): void
|
||||
{
|
||||
$response = $this->client->call(Client::METHOD_GET, '/health/queue/notifications', \array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), ['threshold' => '0']);
|
||||
|
||||
$this->assertContains($response['headers']['status-code'], [200, 503]);
|
||||
}
|
||||
|
||||
public function testHealthQueueFailedAcceptsNotifications(): void
|
||||
{
|
||||
$response = $this->client->call(Client::METHOD_GET, '/health/queue/failed/v1-notifications', \array_merge([
|
||||
|
||||
@@ -23,6 +23,7 @@ trait PoliciesBase
|
||||
'session-limit' => ['total'],
|
||||
'user-limit' => ['total'],
|
||||
'membership-privacy' => ['userId', 'userEmail', 'userPhone', 'userName', 'userMFA', 'userAccessedAt'],
|
||||
'mfa-factors' => ['totp', 'email', 'phone', 'custom'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\E2E\Services\Project;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Tests\E2E\Scopes\ProjectCustom;
|
||||
use Tests\E2E\Scopes\Scope;
|
||||
use Tests\E2E\Scopes\SideServer;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
|
||||
final class PoliciesMFAFactorsIntegrationTest extends Scope
|
||||
{
|
||||
use ProjectCustom;
|
||||
use SideServer;
|
||||
|
||||
public function testMFAFactorsDefaults(): void
|
||||
{
|
||||
// A project that never set the policy allows native factors and blocks custom
|
||||
$project = $this->getProject(true);
|
||||
$projectId = $project['$id'];
|
||||
|
||||
$serverHeaders = [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $project['apiKey'],
|
||||
];
|
||||
|
||||
$policy = $this->client->call(Client::METHOD_GET, '/project/policies/mfa-factors', $serverHeaders);
|
||||
$this->assertSame(200, $policy['headers']['status-code']);
|
||||
$this->assertTrue($policy['body']['totp']);
|
||||
$this->assertTrue($policy['body']['email']);
|
||||
$this->assertTrue($policy['body']['phone']);
|
||||
$this->assertFalse($policy['body']['custom']);
|
||||
|
||||
$list = $this->client->call(Client::METHOD_GET, '/project/policies', $serverHeaders);
|
||||
$this->assertSame(200, $list['headers']['status-code']);
|
||||
|
||||
$byId = [];
|
||||
foreach ($list['body']['policies'] as $listed) {
|
||||
$byId[$listed['$id']] = $listed;
|
||||
}
|
||||
$this->assertArrayHasKey('mfa-factors', $byId);
|
||||
$this->assertSame($policy['body'], $byId['mfa-factors']);
|
||||
|
||||
$member = $this->createUserWithSession($serverHeaders);
|
||||
|
||||
$factors = $this->client->call(Client::METHOD_GET, '/account/mfa/factors', $member['sessionHeaders']);
|
||||
$this->assertSame(200, $factors['headers']['status-code']);
|
||||
$this->assertFalse($factors['body']['custom']);
|
||||
|
||||
$challenge = $this->client->call(Client::METHOD_POST, '/account/mfa/challenges', $member['sessionHeaders'], [
|
||||
'factor' => 'custom',
|
||||
]);
|
||||
$this->assertSame(501, $challenge['headers']['status-code']);
|
||||
$this->assertSame('user_auth_method_unsupported', $challenge['body']['type']);
|
||||
}
|
||||
|
||||
public function testMFAFactorsPolicyIntegration(): void
|
||||
{
|
||||
$project = $this->getProject(true);
|
||||
$projectId = $project['$id'];
|
||||
|
||||
$serverHeaders = [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
'x-appwrite-key' => $project['apiKey'],
|
||||
];
|
||||
|
||||
// Step 1: Enable the custom factor and disable email
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/project/policies/mfa-factors', $serverHeaders, [
|
||||
'custom' => true,
|
||||
'email' => false,
|
||||
]);
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
|
||||
$policy = $this->client->call(Client::METHOD_GET, '/project/policies/mfa-factors', $serverHeaders);
|
||||
$this->assertSame(200, $policy['headers']['status-code']);
|
||||
$this->assertTrue($policy['body']['totp']);
|
||||
$this->assertFalse($policy['body']['email']);
|
||||
$this->assertTrue($policy['body']['phone']);
|
||||
$this->assertTrue($policy['body']['custom']);
|
||||
|
||||
// Step 2: A user with a verified email sees the policy reflected in factors
|
||||
$member = $this->createUserWithSession($serverHeaders, verifiedEmail: true);
|
||||
|
||||
$factors = $this->client->call(Client::METHOD_GET, '/account/mfa/factors', $member['sessionHeaders']);
|
||||
$this->assertSame(200, $factors['headers']['status-code']);
|
||||
$this->assertTrue($factors['body']['custom']);
|
||||
$this->assertFalse($factors['body']['email']);
|
||||
|
||||
// Step 3: Challenges for a disabled factor are rejected
|
||||
$challenge = $this->client->call(Client::METHOD_POST, '/account/mfa/challenges', $member['sessionHeaders'], [
|
||||
'factor' => 'email',
|
||||
]);
|
||||
$this->assertSame(501, $challenge['headers']['status-code']);
|
||||
$this->assertSame('user_auth_method_unsupported', $challenge['body']['type']);
|
||||
|
||||
// Step 4: The custom factor completes the full challenge flow
|
||||
$challenge = $this->client->call(Client::METHOD_POST, '/account/mfa/challenges', $member['sessionHeaders'], [
|
||||
'factor' => 'custom',
|
||||
]);
|
||||
$this->assertSame(201, $challenge['headers']['status-code']);
|
||||
$this->assertArrayNotHasKey('code', $challenge['body']);
|
||||
$challengeId = $challenge['body']['$id'];
|
||||
|
||||
$secret = $this->client->call(Client::METHOD_GET, '/users/' . $member['userId'] . '/mfa/challenges/' . $challengeId, $serverHeaders);
|
||||
$this->assertSame(200, $secret['headers']['status-code']);
|
||||
$this->assertNotEmpty($secret['body']['code']);
|
||||
|
||||
$verification = $this->client->call(Client::METHOD_PUT, '/account/mfa/challenges', $member['sessionHeaders'], [
|
||||
'challengeId' => $challengeId,
|
||||
'otp' => $secret['body']['code'],
|
||||
]);
|
||||
$this->assertSame(200, $verification['headers']['status-code']);
|
||||
$this->assertContains('custom', $verification['body']['factors']);
|
||||
|
||||
// Step 5: Leave a custom challenge pending, then restore email and disable custom again
|
||||
$pending = $this->client->call(Client::METHOD_POST, '/account/mfa/challenges', $member['sessionHeaders'], [
|
||||
'factor' => 'custom',
|
||||
]);
|
||||
$this->assertSame(201, $pending['headers']['status-code']);
|
||||
|
||||
$pendingSecret = $this->client->call(Client::METHOD_GET, '/users/' . $member['userId'] . '/mfa/challenges/' . $pending['body']['$id'], $serverHeaders);
|
||||
$this->assertSame(200, $pendingSecret['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/project/policies/mfa-factors', $serverHeaders, [
|
||||
'custom' => false,
|
||||
'email' => true,
|
||||
]);
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
|
||||
// Disabling a factor also invalidates challenges issued while it was enabled
|
||||
$verification = $this->client->call(Client::METHOD_PUT, '/account/mfa/challenges', $member['sessionHeaders'], [
|
||||
'challengeId' => $pending['body']['$id'],
|
||||
'otp' => $pendingSecret['body']['code'],
|
||||
]);
|
||||
$this->assertSame(501, $verification['headers']['status-code']);
|
||||
$this->assertSame('user_auth_method_unsupported', $verification['body']['type']);
|
||||
|
||||
$factors = $this->client->call(Client::METHOD_GET, '/account/mfa/factors', $member['sessionHeaders']);
|
||||
$this->assertSame(200, $factors['headers']['status-code']);
|
||||
$this->assertFalse($factors['body']['custom']);
|
||||
$this->assertTrue($factors['body']['email']);
|
||||
|
||||
$challenge = $this->client->call(Client::METHOD_POST, '/account/mfa/challenges', $member['sessionHeaders'], [
|
||||
'factor' => 'custom',
|
||||
]);
|
||||
$this->assertSame(501, $challenge['headers']['status-code']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user with a server-issued session.
|
||||
*
|
||||
* @param array<string, string> $serverHeaders
|
||||
* @return array{userId: string, sessionHeaders: array<string, string>}
|
||||
*/
|
||||
private function createUserWithSession(array $serverHeaders, bool $verifiedEmail = false): array
|
||||
{
|
||||
$user = $this->client->call(Client::METHOD_POST, '/users', $serverHeaders, [
|
||||
'userId' => ID::unique(),
|
||||
'email' => 'mfa_' . \uniqid() . '@localhost.test',
|
||||
'password' => 'password1234',
|
||||
'name' => 'Morgan Miller',
|
||||
]);
|
||||
$this->assertSame(201, $user['headers']['status-code']);
|
||||
$userId = $user['body']['$id'];
|
||||
|
||||
if ($verifiedEmail) {
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/verification', $serverHeaders, [
|
||||
'emailVerification' => true,
|
||||
]);
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
}
|
||||
|
||||
$session = $this->client->call(Client::METHOD_POST, '/users/' . $userId . '/sessions', $serverHeaders);
|
||||
$this->assertSame(201, $session['headers']['status-code']);
|
||||
|
||||
return [
|
||||
'userId' => $userId,
|
||||
'sessionHeaders' => [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $serverHeaders['x-appwrite-project'],
|
||||
'x-appwrite-session' => $session['body']['secret'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -633,6 +633,16 @@ trait UsersBase
|
||||
{
|
||||
$projectId = $this->getProject()['$id'];
|
||||
|
||||
// Enable the custom factor, which the MFA factors policy disables by default
|
||||
$policy = $this->client->call(Client::METHOD_PATCH, '/project/policies/mfa-factors', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], $this->getHeaders()), [
|
||||
'custom' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $policy['headers']['status-code']);
|
||||
|
||||
$user = $this->client->call(Client::METHOD_POST, '/users', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
|
||||
@@ -45,4 +45,29 @@ final class PhoneTest extends TestCase
|
||||
$this->assertTrue($this->object->isValid('+55115525632534'));
|
||||
$this->assertTrue($this->object->isValid('+919367788755111'));
|
||||
}
|
||||
|
||||
public function testNormalizeRecoversPathEncoding(): void
|
||||
{
|
||||
$this->assertSame('+15550102680', Phone::normalize('%2B15550102680'));
|
||||
$this->assertSame('+15550102680', Phone::normalize(' 15550102680'));
|
||||
$this->assertSame(' 15550102680', Phone::normalize(' 15550102680'));
|
||||
$this->assertSame('+15550102680', Phone::normalize('15550102680'));
|
||||
$this->assertSame('+15550102680', Phone::normalize('+15550102680'));
|
||||
}
|
||||
|
||||
public function testNormalizeFlagAcceptsPathEncoding(): void
|
||||
{
|
||||
$phone = new Phone(normalize: true);
|
||||
|
||||
$this->assertTrue($phone->isValid('%2B15550102680'));
|
||||
$this->assertTrue($phone->isValid(' 15550102680'));
|
||||
$this->assertTrue($phone->isValid('15550102680'));
|
||||
$this->assertTrue($phone->isValid('+15550102680'));
|
||||
$this->assertFalse($phone->isValid(' 15550102680'));
|
||||
|
||||
// Default validator still rejects path-damaged values.
|
||||
$this->assertFalse($this->object->isValid('%2B15550102680'));
|
||||
$this->assertFalse($this->object->isValid(' 15550102680'));
|
||||
$this->assertFalse($this->object->isValid('15550102680'));
|
||||
}
|
||||
}
|
||||
@@ -216,5 +216,15 @@ final class EventTest extends TestCase
|
||||
$this->assertContains('documentsdb.factory-db.collections.assembly.documents.doc-123.update', $documentsDbEvents);
|
||||
$this->assertNotContains('documentsdb.factory-db.tables.assembly.rows.doc-123.update', $documentsDbEvents);
|
||||
$this->assertNotContains('databases.factory-db.collections.assembly.documents.doc-123.update', $documentsDbEvents);
|
||||
|
||||
$vectorsDb = new Document(['type' => 'vectorsdb']);
|
||||
$vectorsDbEvents = Event::generateEvents('databases.[databaseId].collections.[collectionId].documents.[documentId].update', [
|
||||
'databaseId' => 'factory-db',
|
||||
'collectionId' => 'assembly',
|
||||
'documentId' => 'doc-123',
|
||||
], $vectorsDb);
|
||||
$this->assertContains('vectorsdb.factory-db.collections.assembly.documents.doc-123.update', $vectorsDbEvents);
|
||||
$this->assertNotContains('vectorsdb.factory-db.tables.assembly.rows.doc-123.update', $vectorsDbEvents);
|
||||
$this->assertNotContains('databases.factory-db.collections.assembly.documents.doc-123.update', $vectorsDbEvents);
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,50 @@ final class EventValidatorTest extends TestCase
|
||||
$this->assertTrue($this->object->isValid('tablesdb.books.tables.chapters'));
|
||||
$this->assertTrue($this->object->isValid('tablesdb.books.tables.*'));
|
||||
$this->assertTrue($this->object->isValid('tablesdb.books.tables.chapters.columns.name.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.prolog'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.*'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.*.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.*.documents.prolog'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.*.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.*.documents.*'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.chapters.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.chapters.documents.prolog'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.chapters.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.chapters.documents.*'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.prolog'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.*'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.*'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.*'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.attributes.name.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.prolog'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.*'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.*.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.*.documents.prolog'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.*.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.*.documents.*'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.chapters.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.chapters.documents.prolog'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.chapters.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.chapters.documents.*'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.prolog'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.*'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.*'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.*'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.attributes.name.create'));
|
||||
$this->assertTrue($this->object->isValid('functions.*'));
|
||||
$this->assertTrue($this->object->isValid('buckets.*'));
|
||||
$this->assertTrue($this->object->isValid('teams.*'));
|
||||
@@ -97,6 +141,10 @@ final class EventValidatorTest extends TestCase
|
||||
$this->assertFalse($this->object->isValid('tables.*.rows.*.unknown'));
|
||||
$this->assertFalse($this->object->isValid('tablesdb.books.collections.chapters.documents.prolog.create'));
|
||||
$this->assertFalse($this->object->isValid('tablesdb.books.tables.chapters.rows.prolog.unknown'));
|
||||
$this->assertFalse($this->object->isValid('documentsdb.books.tables.chapters.rows.prolog.create'));
|
||||
$this->assertFalse($this->object->isValid('documentsdb.books.collections.chapters.documents.prolog.unknown'));
|
||||
$this->assertFalse($this->object->isValid('vectorsdb.books.tables.chapters.rows.prolog.create'));
|
||||
$this->assertFalse($this->object->isValid('vectorsdb.books.collections.chapters.documents.prolog.unknown'));
|
||||
$this->assertFalse($this->object->isValid('users.torsten.unknown'));
|
||||
$this->assertFalse($this->object->isValid('users.torsten.delete.email'));
|
||||
$this->assertFalse($this->object->isValid('teams.*.memberships.*.update.unknown'));
|
||||
|
||||
@@ -62,6 +62,16 @@ final class FunctionEventValidatorTest extends TestCase
|
||||
$this->assertTrue($this->object->isValid('tablesdb.*.tables.*.rows.*.create'));
|
||||
$this->assertTrue($this->object->isValid('tablesdb.*.tables.*'));
|
||||
$this->assertTrue($this->object->isValid('tablesdb.*'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*.collections.*'));
|
||||
$this->assertTrue($this->object->isValid('documentsdb.*'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.prolog.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.*.create'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*.collections.*'));
|
||||
$this->assertTrue($this->object->isValid('vectorsdb.*'));
|
||||
$this->assertTrue($this->object->isValid('buckets.*'));
|
||||
$this->assertTrue($this->object->isValid('teams.*'));
|
||||
$this->assertTrue($this->object->isValid('users.*'));
|
||||
@@ -78,6 +88,8 @@ final class FunctionEventValidatorTest extends TestCase
|
||||
$this->assertFalse($this->object->isValid('tables.*.unknown'));
|
||||
$this->assertFalse($this->object->isValid('tables.*.rows.*.unknown'));
|
||||
$this->assertFalse($this->object->isValid('tablesdb.books.collections.chapters.documents.prolog.create'));
|
||||
$this->assertFalse($this->object->isValid('documentsdb.books.tables.chapters.rows.prolog.create'));
|
||||
$this->assertFalse($this->object->isValid('vectorsdb.books.tables.chapters.rows.prolog.create'));
|
||||
$this->assertFalse($this->object->isValid('users.torsten.unknown'));
|
||||
$this->assertFalse($this->object->isValid('users.torsten.delete.email'));
|
||||
$this->assertFalse($this->object->isValid('teams.*.memberships.*.update.unknown'));
|
||||
|
||||
@@ -131,6 +131,112 @@ final class CorsTest extends TestCase
|
||||
$this->assertSame('https://example.com', $result[Cors::HEADER_ALLOW_ORIGIN]);
|
||||
}
|
||||
|
||||
public function testLoopbackOriginIsAllowed(): void
|
||||
{
|
||||
$cors = new Cors(
|
||||
allowedHosts: ['example.com', 'localhost'],
|
||||
allowedMethods: ['GET'],
|
||||
allowedHeaders: ['X-Test'],
|
||||
exposedHeaders: [],
|
||||
allowCredentials: true
|
||||
);
|
||||
|
||||
foreach (
|
||||
[
|
||||
'http://localhost',
|
||||
'http://localhost:3000',
|
||||
'http://127.0.0.1',
|
||||
'https://127.0.0.1:5173',
|
||||
'http://[::1]',
|
||||
'http://[::1]:3000',
|
||||
] as $origin
|
||||
) {
|
||||
$this->assertSame($origin, $cors->headers($origin)[Cors::HEADER_ALLOW_ORIGIN] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoopbackOriginIsEchoedExactly(): void
|
||||
{
|
||||
$cors = new Cors(
|
||||
allowedHosts: ['example.com', 'localhost'],
|
||||
allowedMethods: ['GET'],
|
||||
allowedHeaders: ['X-Test'],
|
||||
exposedHeaders: [],
|
||||
allowCredentials: true
|
||||
);
|
||||
|
||||
/**
|
||||
* Trusting loopback with credentials is only safe while the origin is
|
||||
* echoed back verbatim, since the browser requires a literal match.
|
||||
* A wildcard here would hand the allowance to every remote page.
|
||||
*/
|
||||
$result = $cors->headers('http://127.0.0.1:5173');
|
||||
|
||||
$this->assertSame('http://127.0.0.1:5173', $result[Cors::HEADER_ALLOW_ORIGIN]);
|
||||
$this->assertNotSame('*', $result[Cors::HEADER_ALLOW_ORIGIN]);
|
||||
$this->assertSame('true', $result[Cors::HEADER_ALLOW_CREDENTIALS]);
|
||||
}
|
||||
|
||||
public function testLoopbackLookalikeOriginIsRejected(): void
|
||||
{
|
||||
$cors = new Cors(
|
||||
allowedHosts: ['example.com', 'localhost'],
|
||||
allowedMethods: ['GET'],
|
||||
allowedHeaders: ['X-Test'],
|
||||
exposedHeaders: [],
|
||||
allowCredentials: true
|
||||
);
|
||||
|
||||
foreach (
|
||||
[
|
||||
'http://127.0.0.1.evil.com',
|
||||
'http://localhost.evil.com',
|
||||
'http://128.0.0.1',
|
||||
'http://[2001:db8::1]',
|
||||
/* A prefix or substring match would wrongly accept these */
|
||||
'http://xlocalhost',
|
||||
'http://127.0.0.1x.example.com',
|
||||
'http://[::1].evil.com',
|
||||
'http://[::1]evil.com',
|
||||
/* Only the exact alias spellings resolve to localhost */
|
||||
'http://127.0.0.2',
|
||||
'http://[0:0:0:0:0:0:0:1]',
|
||||
'http://localhost.',
|
||||
] as $origin
|
||||
) {
|
||||
$this->assertArrayNotHasKey(Cors::HEADER_ALLOW_ORIGIN, $cors->headers($origin));
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoopbackRequiresLocalhostToBeAllowed(): void
|
||||
{
|
||||
/**
|
||||
* Credentialed CORS plus SameSite=None cookies means an accepted origin
|
||||
* can read authenticated responses, so a deployment that does not trust
|
||||
* localhost must not have any spelling of it reflected back.
|
||||
*/
|
||||
$cors = new Cors(
|
||||
allowedHosts: ['example.com'],
|
||||
allowedMethods: ['GET'],
|
||||
allowedHeaders: ['X-Test'],
|
||||
exposedHeaders: [],
|
||||
allowCredentials: true
|
||||
);
|
||||
|
||||
foreach (
|
||||
[
|
||||
'http://localhost',
|
||||
'http://localhost:3000',
|
||||
'http://127.0.0.1',
|
||||
'https://127.0.0.1:5173',
|
||||
'http://[::1]',
|
||||
'http://[::1]:3000',
|
||||
] as $origin
|
||||
) {
|
||||
$this->assertArrayNotHasKey(Cors::HEADER_ALLOW_ORIGIN, $cors->headers($origin), 'Origin ' . $origin . ' was unexpectedly allowed');
|
||||
}
|
||||
}
|
||||
|
||||
public function testHeaderFormatting(): void
|
||||
{
|
||||
$cors = new Cors(
|
||||
|
||||
@@ -83,6 +83,72 @@ final class OriginTest extends TestCase
|
||||
$this->assertSame('Invalid Scheme. The scheme used (random-scheme) in the Origin (random-scheme://localhost) is not supported. If you are using a custom scheme, please change it to `appwrite-callback-<PROJECT_ID>`', $validator->getDescription());
|
||||
}
|
||||
|
||||
public function testLoopback(): void
|
||||
{
|
||||
$validator = new Origin(
|
||||
allowedHostnames: ['appwrite.io', 'localhost'],
|
||||
allowedSchemes: ['exp']
|
||||
);
|
||||
|
||||
/* Allowing localhost allows its other spellings too */
|
||||
$this->assertEquals(true, $validator->isValid('http://localhost'));
|
||||
$this->assertEquals(true, $validator->isValid('http://localhost:3000'));
|
||||
$this->assertEquals(true, $validator->isValid('http://127.0.0.1'));
|
||||
$this->assertEquals(true, $validator->isValid('https://127.0.0.1:5173'));
|
||||
$this->assertEquals(true, $validator->isValid('http://[::1]'));
|
||||
$this->assertEquals(true, $validator->isValid('http://[::1]:3000'));
|
||||
|
||||
/* Hostnames that only look like loopback are still rejected */
|
||||
$this->assertEquals(false, $validator->isValid('http://127.0.0.1.example.com'));
|
||||
$this->assertEquals(false, $validator->isValid('http://localhost.example.com'));
|
||||
$this->assertEquals(false, $validator->isValid('http://127.0.0.1@example.com'));
|
||||
$this->assertEquals(false, $validator->isValid('http://128.0.0.1'));
|
||||
$this->assertEquals(false, $validator->isValid('http://[2001:db8::1]'));
|
||||
|
||||
/* A prefix or substring match would wrongly accept these */
|
||||
$this->assertEquals(false, $validator->isValid('http://xlocalhost'));
|
||||
$this->assertEquals(false, $validator->isValid('http://127.0.0.1x.example.com'));
|
||||
$this->assertEquals(false, $validator->isValid('http://[::1].evil.com'));
|
||||
$this->assertEquals(false, $validator->isValid('http://[::1]evil.com'));
|
||||
|
||||
/* Only the exact loopback spellings are hardcoded */
|
||||
$this->assertEquals(false, $validator->isValid('http://127.0.0.2'));
|
||||
$this->assertEquals(false, $validator->isValid('http://[0:0:0:0:0:0:0:1]'));
|
||||
$this->assertEquals(false, $validator->isValid('http://localhost.'));
|
||||
|
||||
/* Loopback does not bypass the scheme allow list */
|
||||
$this->assertEquals(false, $validator->isValid('random-scheme://127.0.0.1'));
|
||||
}
|
||||
|
||||
public function testLoopbackRequiresLocalhostToBeAllowed(): void
|
||||
{
|
||||
/* A deployment that does not trust localhost trusts no spelling of it */
|
||||
$validator = new Origin(
|
||||
allowedHostnames: ['appwrite.io'],
|
||||
allowedSchemes: ['exp']
|
||||
);
|
||||
|
||||
$this->assertEquals(false, $validator->isValid('http://localhost'));
|
||||
$this->assertEquals(false, $validator->isValid('http://localhost:3000'));
|
||||
$this->assertEquals(false, $validator->isValid('http://127.0.0.1'));
|
||||
$this->assertEquals(false, $validator->isValid('https://127.0.0.1:5173'));
|
||||
$this->assertEquals(false, $validator->isValid('http://[::1]'));
|
||||
$this->assertEquals(false, $validator->isValid('http://[::1]:3000'));
|
||||
}
|
||||
|
||||
public function testLoopbackAliasHonoursAnExplicitEntry(): void
|
||||
{
|
||||
/* An explicitly allowed literal still matches on its own */
|
||||
$validator = new Origin(
|
||||
allowedHostnames: ['127.0.0.1'],
|
||||
allowedSchemes: ['exp']
|
||||
);
|
||||
|
||||
$this->assertEquals(true, $validator->isValid('http://127.0.0.1:5173'));
|
||||
$this->assertEquals(false, $validator->isValid('http://localhost'));
|
||||
$this->assertEquals(false, $validator->isValid('http://[::1]'));
|
||||
}
|
||||
|
||||
public function testGetAllowedHostnames(): void
|
||||
{
|
||||
$validator = new Origin(
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Platform\Tasks;
|
||||
|
||||
use Appwrite\Platform\Tasks\ScheduleBase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ScheduleBaseTest extends TestCase
|
||||
{
|
||||
public function testSpreadOffsetIsDeterministic(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
ScheduleBase::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', 60),
|
||||
ScheduleBase::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', 60)
|
||||
);
|
||||
}
|
||||
|
||||
public function testSpreadOffsetIsBounded(): void
|
||||
{
|
||||
foreach ($this->sampleIds() as $id) {
|
||||
foreach ([2, 30, 60, 300] as $window) {
|
||||
$offset = ScheduleBase::spreadOffset($id, $window);
|
||||
$this->assertGreaterThanOrEqual(0, $offset);
|
||||
$this->assertLessThan($window, $offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testSpreadOffsetIsZeroWhenDisabled(): void
|
||||
{
|
||||
$this->assertSame(0, ScheduleBase::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', 1));
|
||||
$this->assertSame(0, ScheduleBase::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', 0));
|
||||
$this->assertSame(0, ScheduleBase::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', -5));
|
||||
}
|
||||
|
||||
public function testSpreadOffsetDispersesDistinctResources(): void
|
||||
{
|
||||
$offsets = [];
|
||||
foreach ($this->sampleIds() as $id) {
|
||||
$offsets[] = ScheduleBase::spreadOffset($id, 60);
|
||||
}
|
||||
|
||||
// Resources sharing a cron slot must not all land in the same second.
|
||||
$this->assertGreaterThan(10, count(array_unique($offsets)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function sampleIds(): array
|
||||
{
|
||||
$ids = [];
|
||||
for ($i = 0; $i < 50; $i++) {
|
||||
$ids[] = md5("resource-{$i}");
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
@@ -13,44 +13,6 @@ use Utopia\Database\Database;
|
||||
|
||||
final class ScheduleFunctionsTest extends TestCase
|
||||
{
|
||||
public function testSpreadOffsetIsDeterministic(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
ScheduleFunctions::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', 60),
|
||||
ScheduleFunctions::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', 60)
|
||||
);
|
||||
}
|
||||
|
||||
public function testSpreadOffsetIsBounded(): void
|
||||
{
|
||||
foreach ($this->sampleIds() as $id) {
|
||||
foreach ([2, 30, 60, 300] as $window) {
|
||||
$offset = ScheduleFunctions::spreadOffset($id, $window);
|
||||
$this->assertGreaterThanOrEqual(0, $offset);
|
||||
$this->assertLessThan($window, $offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testSpreadOffsetIsZeroWhenDisabled(): void
|
||||
{
|
||||
$this->assertSame(0, ScheduleFunctions::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', 1));
|
||||
$this->assertSame(0, ScheduleFunctions::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', 0));
|
||||
$this->assertSame(0, ScheduleFunctions::spreadOffset('64f5c8e2a1b3d4e5f6a7b8c9', -5));
|
||||
}
|
||||
|
||||
public function testSpreadOffsetDispersesDistinctFunctions(): void
|
||||
{
|
||||
$offsets = [];
|
||||
foreach ($this->sampleIds() as $id) {
|
||||
$offsets[] = ScheduleFunctions::spreadOffset($id, 60);
|
||||
}
|
||||
|
||||
// The whole point: functions sharing a cron slot must not all land
|
||||
// in the same second. Expect real dispersion across the window.
|
||||
$this->assertGreaterThan(10, count(array_unique($offsets)));
|
||||
}
|
||||
|
||||
public function testSpreadWindowDefaultsToEnv(): void
|
||||
{
|
||||
$task = new class () extends ScheduleFunctions {
|
||||
@@ -74,17 +36,4 @@ final class ScheduleFunctionsTest extends TestCase
|
||||
: putenv("_APP_FUNCTIONS_SCHEDULE_SPREAD={$previous}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function sampleIds(): array
|
||||
{
|
||||
$ids = [];
|
||||
for ($i = 0; $i < 50; $i++) {
|
||||
$ids[] = md5("function-{$i}");
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Utopia\Database\Validator;
|
||||
|
||||
use Appwrite\Utopia\Database\Attribute;
|
||||
use Appwrite\Utopia\Database\Validator\Attributes;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Utopia\Database\Database;
|
||||
|
||||
final class AttributesTest extends TestCase
|
||||
{
|
||||
protected Attributes $object;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->object = new Attributes();
|
||||
}
|
||||
|
||||
public function testStringTypes(): void
|
||||
{
|
||||
$this->assertTrue($this->object->isValid([
|
||||
['key' => 'title', 'type' => Database::VAR_STRING, 'size' => 128],
|
||||
['key' => 'slug', 'type' => Database::VAR_VARCHAR, 'size' => 128],
|
||||
['key' => 'body', 'type' => Database::VAR_TEXT],
|
||||
['key' => 'summary', 'type' => Database::VAR_MEDIUMTEXT],
|
||||
['key' => 'archive', 'type' => Database::VAR_LONGTEXT],
|
||||
]), $this->object->getDescription());
|
||||
}
|
||||
|
||||
public function testStringTypeDefaults(): void
|
||||
{
|
||||
$this->assertTrue($this->object->isValid([
|
||||
['key' => 'body', 'type' => Database::VAR_TEXT, 'default' => 'hello'],
|
||||
]), $this->object->getDescription());
|
||||
|
||||
$this->assertFalse($this->object->isValid([
|
||||
['key' => 'body', 'type' => Database::VAR_TEXT, 'default' => 1],
|
||||
]));
|
||||
|
||||
$this->assertFalse($this->object->isValid([
|
||||
['key' => 'slug', 'type' => Database::VAR_VARCHAR, 'size' => 4, 'default' => 'toolong'],
|
||||
]));
|
||||
}
|
||||
|
||||
public function testVarcharRequiresSize(): void
|
||||
{
|
||||
$this->assertFalse($this->object->isValid([
|
||||
['key' => 'slug', 'type' => Database::VAR_VARCHAR],
|
||||
]));
|
||||
}
|
||||
|
||||
public function testFormatTypes(): void
|
||||
{
|
||||
$this->assertTrue($this->object->isValid([
|
||||
['key' => 'email', 'type' => APP_DATABASE_ATTRIBUTE_EMAIL, 'required' => true],
|
||||
['key' => 'website', 'type' => APP_DATABASE_ATTRIBUTE_URL],
|
||||
['key' => 'address', 'type' => APP_DATABASE_ATTRIBUTE_IP],
|
||||
['key' => 'status', 'type' => APP_DATABASE_ATTRIBUTE_ENUM, 'elements' => ['on', 'off'], 'default' => 'on'],
|
||||
]), $this->object->getDescription());
|
||||
|
||||
$this->assertFalse($this->object->isValid([
|
||||
['key' => 'email', 'type' => APP_DATABASE_ATTRIBUTE_EMAIL, 'default' => 'not-an-email'],
|
||||
]));
|
||||
|
||||
$this->assertFalse($this->object->isValid([
|
||||
['key' => 'status', 'type' => APP_DATABASE_ATTRIBUTE_ENUM],
|
||||
]));
|
||||
}
|
||||
|
||||
public function testEmailWithoutSize(): void
|
||||
{
|
||||
$this->assertTrue($this->object->isValid([
|
||||
['key' => 'email', 'type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_EMAIL],
|
||||
]), $this->object->getDescription());
|
||||
}
|
||||
|
||||
public function testUnsupportedType(): void
|
||||
{
|
||||
$this->assertFalse($this->object->isValid([
|
||||
['key' => 'rel', 'type' => Database::VAR_RELATIONSHIP],
|
||||
]));
|
||||
$this->assertSame("Invalid type for attribute 'rel': relationship", $this->object->getDescription());
|
||||
}
|
||||
|
||||
public function testResolveMatchesDedicatedEndpoints(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
['type' => Database::VAR_TEXT, 'format' => '', 'size' => 65535],
|
||||
Attribute::resolve(['key' => 'body', 'type' => Database::VAR_TEXT])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
['type' => Database::VAR_MEDIUMTEXT, 'format' => '', 'size' => 16777215],
|
||||
Attribute::resolve(['key' => 'body', 'type' => Database::VAR_MEDIUMTEXT])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
['type' => Database::VAR_LONGTEXT, 'format' => '', 'size' => 2147483647],
|
||||
Attribute::resolve(['key' => 'body', 'type' => Database::VAR_LONGTEXT])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_EMAIL, 'size' => 254],
|
||||
Attribute::resolve(['key' => 'email', 'type' => APP_DATABASE_ATTRIBUTE_EMAIL])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_IP, 'size' => 39],
|
||||
Attribute::resolve(['key' => 'ip', 'type' => APP_DATABASE_ATTRIBUTE_IP])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_URL, 'size' => 2000],
|
||||
Attribute::resolve(['key' => 'url', 'type' => APP_DATABASE_ATTRIBUTE_URL])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_ENUM, 'size' => Database::LENGTH_KEY],
|
||||
Attribute::resolve(['key' => 'enum', 'type' => APP_DATABASE_ATTRIBUTE_ENUM])
|
||||
);
|
||||
}
|
||||
|
||||
public function testResolveKeepsExplicitSize(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
['type' => Database::VAR_STRING, 'format' => APP_DATABASE_ATTRIBUTE_EMAIL, 'size' => 512],
|
||||
Attribute::resolve(['key' => 'email', 'type' => APP_DATABASE_ATTRIBUTE_EMAIL, 'size' => 512])
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
['type' => Database::VAR_VARCHAR, 'format' => '', 'size' => 128],
|
||||
Attribute::resolve(['key' => 'slug', 'type' => Database::VAR_VARCHAR, 'size' => 128])
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Utopia\Database\Validator\Queries;
|
||||
|
||||
use Appwrite\Utopia\Database\Validator\Queries\Presences;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Utopia\Database\Query;
|
||||
|
||||
final class BaseTest extends TestCase
|
||||
{
|
||||
public function testQueryAtMaxValuesIsValid(): void
|
||||
{
|
||||
$validator = new Presences();
|
||||
$values = \array_fill(0, APP_DATABASE_QUERY_MAX_VALUES, 'user');
|
||||
|
||||
$this->assertTrue(
|
||||
$validator->isValid([Query::equal('userId', $values)]),
|
||||
$validator->getDescription()
|
||||
);
|
||||
}
|
||||
|
||||
public function testQueryOverMaxValuesIsInvalid(): void
|
||||
{
|
||||
$validator = new Presences();
|
||||
$values = \array_fill(0, APP_DATABASE_QUERY_MAX_VALUES + 1, 'user');
|
||||
|
||||
$this->assertFalse(
|
||||
$validator->isValid([Query::equal('userId', $values)]),
|
||||
'Query with ' . \count($values) . ' values must exceed the ' . APP_DATABASE_QUERY_MAX_VALUES . ' value cap'
|
||||
);
|
||||
$this->assertStringContainsString(
|
||||
'greater than ' . APP_DATABASE_QUERY_MAX_VALUES . ' values',
|
||||
$validator->getDescription(),
|
||||
'Rejection must be reported against the configured cap, not the validator default'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSequenceTypedAttributeIsValidated(): void
|
||||
{
|
||||
$validator = new Presences();
|
||||
|
||||
$this->assertTrue(
|
||||
$validator->isValid([Query::equal('userInternalId', [1])]),
|
||||
$validator->getDescription()
|
||||
);
|
||||
$this->assertFalse(
|
||||
$validator->isValid([Query::equal('userInternalId', [1.5])]),
|
||||
'Fractional value must not validate against a sequence attribute'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user