From 23281f141e95cb22569cfd75fbf9c230ec125c55 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Tue, 2 Jun 2026 16:47:12 +0530 Subject: [PATCH 01/19] feat: expose userAccessedAt in membership responses --- app/config/console.php | 1 + .../Platform/Modules/Teams/Http/Memberships/Get.php | 5 +++++ .../Platform/Modules/Teams/Http/Memberships/XList.php | 5 +++++ src/Appwrite/Utopia/Response/Model/Membership.php | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/app/config/console.php b/app/config/console.php index b7a3f2195a..2070660020 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -39,6 +39,7 @@ $console = [ 'membershipsMfa' => true, 'membershipsUserId' => true, 'membershipsUserPhone' => true, + 'membershipsUserAccessedAt' => false, 'mockNumbers' => [], 'invites' => System::getEnv('_APP_CONSOLE_INVITES', 'enabled') === 'enabled', 'limit' => (System::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled') === 'enabled') ? 1 : 0, // limit signup to 1 user diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php index 0a856bb5a8..a39b05158e 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Get.php @@ -81,6 +81,7 @@ class Get extends Action 'mfa' => $project->getAttribute('auths', [])['membershipsMfa'] ?? true, 'userId' => $project->getAttribute('auths', [])['membershipsUserId'] ?? true, 'userPhone' => $project->getAttribute('auths', [])['membershipsUserPhone'] ?? true, + 'userAccessedAt' => $project->getAttribute('auths', [])['membershipsUserAccessedAt'] ?? false, ]; $roles = $authorization->getRoles(); @@ -130,6 +131,10 @@ class Get extends Action $membership->setAttribute('userPhone', $memberUser->getAttribute('phone')); } + if ($membershipsPrivacy['userAccessedAt']) { + $membership->setAttribute('userAccessedAt', $memberUser->getAttribute('accessedAt')); + } + $membership->setAttribute('teamName', $team->getAttribute('name')); $response->dynamic($membership, Response::MODEL_MEMBERSHIP); diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/XList.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/XList.php index 45f7eb33aa..ee6e69672a 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/XList.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/XList.php @@ -130,6 +130,7 @@ class XList extends Action 'mfa' => $project->getAttribute('auths', [])['membershipsMfa'] ?? true, 'userId' => $project->getAttribute('auths', [])['membershipsUserId'] ?? true, 'userPhone' => $project->getAttribute('auths', [])['membershipsUserPhone'] ?? true, + 'userAccessedAt' => $project->getAttribute('auths', [])['membershipsUserAccessedAt'] ?? false, ]; $roles = $authorization->getRoles(); @@ -180,6 +181,10 @@ class XList extends Action $membership->setAttribute('userPhone', $memberUser->getAttribute('phone')); } + if ($membershipsPrivacy['userAccessedAt']) { + $membership->setAttribute('userAccessedAt', $memberUser->getAttribute('accessedAt')); + } + $membership->setAttribute('teamName', $team->getAttribute('name')); return $membership; diff --git a/src/Appwrite/Utopia/Response/Model/Membership.php b/src/Appwrite/Utopia/Response/Model/Membership.php index 9be7102145..8cc9e0cc7c 100644 --- a/src/Appwrite/Utopia/Response/Model/Membership.php +++ b/src/Appwrite/Utopia/Response/Model/Membership.php @@ -88,6 +88,12 @@ class Membership extends Model 'default' => false, 'example' => false, ]) + ->addRule('userAccessedAt', [ + 'type' => self::TYPE_DATETIME, + 'description' => 'Most recent access date in ISO 8601 format. Hide this attribute by toggling membership privacy in the Console.', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, + ]) ->addRule('roles', [ 'type' => self::TYPE_STRING, 'description' => 'User list of roles', From 81e41ce61f9ccb1f5aae4302f7c22236c14f4c9d Mon Sep 17 00:00:00 2001 From: Harsh Mahajan <127186841+HarshMN2345@users.noreply.github.com> Date: Tue, 2 Jun 2026 16:53:37 +0530 Subject: [PATCH 02/19] Update src/Appwrite/Utopia/Response/Model/Membership.php Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- src/Appwrite/Utopia/Response/Model/Membership.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Model/Membership.php b/src/Appwrite/Utopia/Response/Model/Membership.php index 8cc9e0cc7c..f07ef79398 100644 --- a/src/Appwrite/Utopia/Response/Model/Membership.php +++ b/src/Appwrite/Utopia/Response/Model/Membership.php @@ -90,7 +90,7 @@ class Membership extends Model ]) ->addRule('userAccessedAt', [ 'type' => self::TYPE_DATETIME, - 'description' => 'Most recent access date in ISO 8601 format. Hide this attribute by toggling membership privacy in the Console.', + 'description' => 'Most recent access date in ISO 8601 format. Show this attribute by toggling membership privacy in the Console.', 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE, ]) From 31d7a934e4f60253b95f179aa322d065029de97a Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 4 Jun 2026 14:04:50 +0100 Subject: [PATCH 03/19] Upgrade utopia-php/queue to 0.20.0 Refactors the queue integration for utopia-php/queue 0.20.0, which removes the AMQP broker and replaces the Consumer::consume() loop with adapter-owned fan-out (receive/commit/reject primitives). - Bump utopia-php/queue to 0.20.* and utopia-php/platform to 1.0.0-rc5 (rc5 requires queue ^0.20). - registers.php: split publisher/consumer. Publishers only issue commands, never the blocking receive, so a single connection now backs both broker slots; the pool isolates concurrent callers. The consumer pool is removed. - worker.php: build the consumer broker directly as Broker\Redis(receive, Locking(commands)) instead of a pool -- one blocking-receive connection drives the loop while a lock-guarded commands connection serializes acks from the per-message coroutines. Removed the now-dead consumer* DI resources. - Audits worker: drop the removed Commit/NoCommit result types. The Redis broker always ignored the callback return value (it only mattered for AMQP), so batching behaviour is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) --- app/init/registers.php | 19 +- app/worker.php | 38 +--- composer.json | 4 +- composer.lock | 272 ++--------------------- src/Appwrite/Platform/Workers/Audits.php | 8 +- 5 files changed, 39 insertions(+), 302 deletions(-) diff --git a/app/init/registers.php b/app/init/registers.php index f47cc43e60..bdb9f8a643 100644 --- a/app/init/registers.php +++ b/app/init/registers.php @@ -222,12 +222,6 @@ $register->set('pools', function () { 'multiple' => false, 'schemes' => ['redis'], ], - 'consumer' => [ - 'type' => 'consumer', - 'dsns' => $fallbackForRedis, - 'multiple' => false, - 'schemes' => ['redis'], - ], 'pubsub' => [ 'type' => 'pubsub', 'dsns' => $fallbackForRedis, @@ -344,11 +338,8 @@ $register->set('pools', function () { // PubSub workers hold one long-lived subscribed connection and also need // spare capacity for publishes from the same process. - // Consumer pools lease one connection per consume coroutine for the - // lifetime of the worker, plus headroom for queue-size reads. $connectionPoolSize = match ($type) { 'pubsub' => max(2, $poolSize), - 'consumer' => $poolSize + 2, default => $poolSize, }; @@ -372,9 +363,15 @@ $register->set('pools', function () { default => null }; case 'publisher': - case 'consumer': + // Publishers only issue commands (enqueue/retry/size), never + // the blocking receive, so a single connection backs both the + // receive and commands slots. The pool isolates concurrent + // callers, so no locking is needed here. return match ($dsn->getScheme()) { - 'redis' => new Queue\Broker\Redis(new Queue\Connection\Redis($dsn->getHost(), $dsn->getPort())), + 'redis' => (function () use ($dsn) { + $connection = new Queue\Connection\Redis($dsn->getHost(), $dsn->getPort()); + return new Queue\Broker\Redis($connection, $connection); + })(), default => null }; case 'cache': diff --git a/app/worker.php b/app/worker.php index 063d4746ac..ee1d36d65a 100644 --- a/app/worker.php +++ b/app/worker.php @@ -12,9 +12,10 @@ use Utopia\Database\Validator\Authorization; use Utopia\Logger\Log; use Utopia\Logger\Logger; use Utopia\Platform\Service; -use Utopia\Pools\Group; use Utopia\Queue\Adapter\Swoole; -use Utopia\Queue\Broker\Pool as BrokerPool; +use Utopia\Queue\Broker\Redis as BrokerRedis; +use Utopia\Queue\Connection\Locking; +use Utopia\Queue\Connection\Redis as RedisConnection; use Utopia\Queue\Server; use Utopia\Span\Span; use Utopia\System\System; @@ -38,22 +39,6 @@ $container->set('project', fn () => new Document([]), []); $container->set('log', fn () => new Log(), []); -$container->set('consumer', function (Group $pools) { - return new BrokerPool(consumer: $pools->get('consumer')); -}, ['pools']); - -$container->set('consumerDatabases', function (BrokerPool $consumer) { - return $consumer; -}, ['consumer']); - -$container->set('consumerMigrations', function (BrokerPool $consumer) { - return $consumer; -}, ['consumer']); - -$container->set('consumerStatsUsage', function (BrokerPool $consumer) { - return $consumer; -}, ['consumer']); - $container->set('certificates', function () { $email = System::getEnv('_APP_EMAIL_CERTIFICATES', System::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS')); if (empty($email)) { @@ -80,16 +65,17 @@ if (\str_starts_with($workerName, 'databases')) { $queueName = System::getEnv('_APP_QUEUE_NAME', 'v1-' . strtolower($workerName)); } -/** @var \Utopia\Pools\Group $pools */ -$pools = $container->get('pools'); +$redisHost = System::getEnv('_APP_REDIS_HOST', 'redis'); +$redisPort = (int) System::getEnv('_APP_REDIS_PORT', 6379); -// Each consume coroutine leases its own broker connection from the pool for -// the lifetime of its consume loop, so concurrent coroutines never share a -// connection. The publisher side backs the queue-depth telemetry gauge. +// The consumer is a single broker, not a pool: one blocking-receive connection +// drives the receive loop while a separate, lock-guarded connection serializes +// acks and publishes issued from the per-message coroutines. Broker\Redis is +// both Publisher and Consumer, so it also backs the queue-depth telemetry gauge. $adapter = new Swoole( - new BrokerPool( - publisher: $pools->get('consumer'), - consumer: $pools->get('consumer'), + new BrokerRedis( + receive: new RedisConnection($redisHost, $redisPort), + commands: new Locking(new RedisConnection($redisHost, $redisPort)), ), System::getEnv('_APP_WORKERS_NUM', 1), $queueName, diff --git a/composer.json b/composer.json index b78637ccd9..9c2eadb5df 100644 --- a/composer.json +++ b/composer.json @@ -76,11 +76,11 @@ "utopia-php/logger": "0.8.*", "utopia-php/messaging": "1.0.*", "utopia-php/migration": "1.*", - "utopia-php/platform": "1.0.0-rc4", + "utopia-php/platform": "1.0.0-rc5", "utopia-php/pools": "1.*", "utopia-php/span": "1.1.*", "utopia-php/preloader": "0.2.*", - "utopia-php/queue": "0.19.*", + "utopia-php/queue": "0.20.*", "utopia-php/servers": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/storage": "2.*", diff --git a/composer.lock b/composer.lock index 79cee0b33e..a9f942a4a9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0c23c30bba86ad84377d4d1abce0992a", + "content-hash": "1e4c395aa9b713af1fddd704f79fcf72", "packages": [ { "name": "adhocore/jwt", @@ -1703,137 +1703,6 @@ }, "time": "2025-09-24T15:06:41+00:00" }, - { - "name": "paragonie/random_compat", - "version": "v9.99.100", - "source": { - "type": "git", - "url": "https://github.com/paragonie/random_compat.git", - "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a", - "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a", - "shasum": "" - }, - "require": { - "php": ">= 7" - }, - "require-dev": { - "phpunit/phpunit": "4.*|5.*", - "vimeo/psalm": "^1" - }, - "suggest": { - "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." - }, - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Paragon Initiative Enterprises", - "email": "security@paragonie.com", - "homepage": "https://paragonie.com" - } - ], - "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", - "keywords": [ - "csprng", - "polyfill", - "pseudorandom", - "random" - ], - "support": { - "email": "info@paragonie.com", - "issues": "https://github.com/paragonie/random_compat/issues", - "source": "https://github.com/paragonie/random_compat" - }, - "time": "2020-10-15T08:29:30+00:00" - }, - { - "name": "php-amqplib/php-amqplib", - "version": "v3.7.4", - "source": { - "type": "git", - "url": "https://github.com/php-amqplib/php-amqplib.git", - "reference": "381b6f7c600e0e0c7463cdd7f7a1a3bc6268e5fd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-amqplib/php-amqplib/zipball/381b6f7c600e0e0c7463cdd7f7a1a3bc6268e5fd", - "reference": "381b6f7c600e0e0c7463cdd7f7a1a3bc6268e5fd", - "shasum": "" - }, - "require": { - "ext-mbstring": "*", - "ext-sockets": "*", - "php": "^7.2||^8.0", - "phpseclib/phpseclib": "^2.0|^3.0" - }, - "conflict": { - "php": "7.4.0 - 7.4.1" - }, - "replace": { - "videlalvaro/php-amqplib": "self.version" - }, - "require-dev": { - "ext-curl": "*", - "nategood/httpful": "^0.2.20", - "phpunit/phpunit": "^7.5|^9.5", - "squizlabs/php_codesniffer": "^3.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "PhpAmqpLib\\": "PhpAmqpLib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-2.1-or-later" - ], - "authors": [ - { - "name": "Alvaro Videla", - "role": "Original Maintainer" - }, - { - "name": "Raúl Araya", - "email": "nubeiro@gmail.com", - "role": "Maintainer" - }, - { - "name": "Luke Bakken", - "email": "luke@bakken.io", - "role": "Maintainer" - }, - { - "name": "Ramūnas Dronga", - "email": "github@ramuno.lt", - "role": "Maintainer" - } - ], - "description": "Formerly videlalvaro/php-amqplib. This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.", - "homepage": "https://github.com/php-amqplib/php-amqplib/", - "keywords": [ - "message", - "queue", - "rabbitmq" - ], - "support": { - "issues": "https://github.com/php-amqplib/php-amqplib/issues", - "source": "https://github.com/php-amqplib/php-amqplib/tree/v3.7.4" - }, - "time": "2025-11-23T17:00:56+00:00" - }, { "name": "php-http/discovery", "version": "1.20.0", @@ -1994,116 +1863,6 @@ ], "time": "2023-11-25T22:23:28+00:00" }, - { - "name": "phpseclib/phpseclib", - "version": "3.0.52", - "source": { - "type": "git", - "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "2adaefc83df2ec548558307690f376dd7d4f4fce" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/2adaefc83df2ec548558307690f376dd7d4f4fce", - "reference": "2adaefc83df2ec548558307690f376dd7d4f4fce", - "shasum": "" - }, - "require": { - "paragonie/constant_time_encoding": "^1|^2|^3", - "paragonie/random_compat": "^1.4|^2.0|^9.99.99", - "php": ">=5.6.1" - }, - "require-dev": { - "phpunit/phpunit": "*" - }, - "suggest": { - "ext-dom": "Install the DOM extension to load XML formatted public keys.", - "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.", - "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.", - "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.", - "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations." - }, - "type": "library", - "autoload": { - "files": [ - "phpseclib/bootstrap.php" - ], - "psr-4": { - "phpseclib3\\": "phpseclib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jim Wigginton", - "email": "terrafrost@php.net", - "role": "Lead Developer" - }, - { - "name": "Patrick Monnerat", - "email": "pm@datasphere.ch", - "role": "Developer" - }, - { - "name": "Andreas Fischer", - "email": "bantu@phpbb.com", - "role": "Developer" - }, - { - "name": "Hans-Jürgen Petrich", - "email": "petrich@tronic-media.com", - "role": "Developer" - }, - { - "name": "Graham Campbell", - "email": "graham@alt-three.com", - "role": "Developer" - } - ], - "description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.", - "homepage": "http://phpseclib.sourceforge.net", - "keywords": [ - "BigInteger", - "aes", - "asn.1", - "asn1", - "blowfish", - "crypto", - "cryptography", - "encryption", - "rsa", - "security", - "sftp", - "signature", - "signing", - "ssh", - "twofish", - "x.509", - "x509" - ], - "support": { - "issues": "https://github.com/phpseclib/phpseclib/issues", - "source": "https://github.com/phpseclib/phpseclib/tree/3.0.52" - }, - "funding": [ - { - "url": "https://github.com/terrafrost", - "type": "github" - }, - { - "url": "https://www.patreon.com/phpseclib", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpseclib/phpseclib", - "type": "tidelift" - } - ], - "time": "2026-04-27T07:02:15+00:00" - }, { "name": "psr/clock", "version": "1.0.0", @@ -4774,16 +4533,16 @@ }, { "name": "utopia-php/platform", - "version": "1.0.0-rc4", + "version": "1.0.0-rc5", "source": { "type": "git", "url": "https://github.com/utopia-php/platform.git", - "reference": "455c84f8d1cdaec6fc2c39587a78aa5ef263ddd0" + "reference": "edf46c6e9c62af1cec1cbd1386a84c730d76a9f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/platform/zipball/455c84f8d1cdaec6fc2c39587a78aa5ef263ddd0", - "reference": "455c84f8d1cdaec6fc2c39587a78aa5ef263ddd0", + "url": "https://api.github.com/repos/utopia-php/platform/zipball/edf46c6e9c62af1cec1cbd1386a84c730d76a9f8", + "reference": "edf46c6e9c62af1cec1cbd1386a84c730d76a9f8", "shasum": "" }, "require": { @@ -4792,7 +4551,7 @@ "php": ">=8.3", "utopia-php/cli": "0.23.*", "utopia-php/http": "^2.0@RC", - "utopia-php/queue": "^0.19", + "utopia-php/queue": "^0.20", "utopia-php/servers": "0.4.*" }, "require-dev": { @@ -4819,9 +4578,9 @@ ], "support": { "issues": "https://github.com/utopia-php/platform/issues", - "source": "https://github.com/utopia-php/platform/tree/1.0.0-rc4" + "source": "https://github.com/utopia-php/platform/tree/1.0.0-rc5" }, - "time": "2026-06-02T20:19:26+00:00" + "time": "2026-06-04T13:00:46+00:00" }, { "name": "utopia-php/pools", @@ -4977,21 +4736,20 @@ }, { "name": "utopia-php/queue", - "version": "0.19.0", + "version": "0.20.0", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "cd4248af69006b2568c3486a675f27cb21191859" + "reference": "d4da9e8d4a8879eb529ec1cda6b93cad2cf8d940" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/cd4248af69006b2568c3486a675f27cb21191859", - "reference": "cd4248af69006b2568c3486a675f27cb21191859", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/d4da9e8d4a8879eb529ec1cda6b93cad2cf8d940", + "reference": "d4da9e8d4a8879eb529ec1cda6b93cad2cf8d940", "shasum": "" }, "require": { - "php": ">=8.3", - "php-amqplib/php-amqplib": "^3.7", + "php": ">=8.4", "utopia-php/di": "0.3.*", "utopia-php/lock": "0.2.*", "utopia-php/pools": "1.*", @@ -5038,9 +4796,9 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/0.19.0" + "source": "https://github.com/utopia-php/queue/tree/0.20.0" }, - "time": "2026-06-02T20:12:18+00:00" + "time": "2026-06-04T12:33:31+00:00" }, { "name": "utopia-php/registry", diff --git a/src/Appwrite/Platform/Workers/Audits.php b/src/Appwrite/Platform/Workers/Audits.php index 09863b8626..e0f50756cb 100644 --- a/src/Appwrite/Platform/Workers/Audits.php +++ b/src/Appwrite/Platform/Workers/Audits.php @@ -10,8 +10,6 @@ use Utopia\Database\Document; use Utopia\Database\Exception\Structure; use Utopia\Platform\Action; use Utopia\Queue\Message; -use Utopia\Queue\Result\Commit; -use Utopia\Queue\Result\NoCommit; use Utopia\System\System; class Audits extends Action @@ -51,12 +49,11 @@ class Audits extends Action /** * @param Message $message * @param callable(Document): \Utopia\Audit\Audit $getAudit - * @return Commit|NoCommit * @throws Throwable * @throws \Utopia\Database\Exception * @throws Structure */ - public function action(Message $message, callable $getAudit): Commit|NoCommit + public function action(Message $message, callable $getAudit): void { $payload = $message->getPayload(); @@ -148,7 +145,7 @@ class Audits extends Action } if (!$shouldProcessBatch) { - return new NoCommit(); + return; } foreach ($this->logs as $sequence => $projectLogs) { @@ -168,6 +165,5 @@ class Audits extends Action } $this->lastTriggeredTime = time(); - return new Commit(); } } From f97c0b670eb8e490ed2cf5340bd06b4b2a067f87 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 4 Jun 2026 14:07:59 +0100 Subject: [PATCH 04/19] Trim verbose queue setup comments Co-Authored-By: Claude Opus 4.8 (1M context) --- app/init/registers.php | 5 +---- app/worker.php | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/init/registers.php b/app/init/registers.php index bdb9f8a643..e7ede8b025 100644 --- a/app/init/registers.php +++ b/app/init/registers.php @@ -363,10 +363,7 @@ $register->set('pools', function () { default => null }; case 'publisher': - // Publishers only issue commands (enqueue/retry/size), never - // the blocking receive, so a single connection backs both the - // receive and commands slots. The pool isolates concurrent - // callers, so no locking is needed here. + // Publishers never block on receive, so one connection backs both broker slots. return match ($dsn->getScheme()) { 'redis' => (function () use ($dsn) { $connection = new Queue\Connection\Redis($dsn->getHost(), $dsn->getPort()); diff --git a/app/worker.php b/app/worker.php index ee1d36d65a..a7a1f7633d 100644 --- a/app/worker.php +++ b/app/worker.php @@ -68,10 +68,8 @@ if (\str_starts_with($workerName, 'databases')) { $redisHost = System::getEnv('_APP_REDIS_HOST', 'redis'); $redisPort = (int) System::getEnv('_APP_REDIS_PORT', 6379); -// The consumer is a single broker, not a pool: one blocking-receive connection -// drives the receive loop while a separate, lock-guarded connection serializes -// acks and publishes issued from the per-message coroutines. Broker\Redis is -// both Publisher and Consumer, so it also backs the queue-depth telemetry gauge. +// A dedicated connection drives the blocking receive loop; a lock-guarded one +// serializes acks/publishes from the per-message coroutines. $adapter = new Swoole( new BrokerRedis( receive: new RedisConnection($redisHost, $redisPort), From 4a7d47d2ccca579929b9edab9bbadb2b4807b92d Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 5 Jun 2026 09:34:59 +0530 Subject: [PATCH 05/19] Fix build log stream parsing warning (#12498) --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index dd0f9d541b..53d615d3b6 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -809,6 +809,10 @@ class Builds extends Action $streamLog = \str_replace('{APPWRITE_LINEBREAK_PLACEHOLDER}', "\n", $streamLog); $streamParts = \explode(' ', $streamLog, 2); + if (! isset($streamParts[1])) { + continue; + } + // TODO: use part[0] as timestamp when switching to dbForLogs for build logs $currentLogs .= $streamParts[1]; From 53091fd649d017a74e7778d1b8cf1af8be6cada9 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 12:27:22 +0530 Subject: [PATCH 06/19] changes --- app/config/console.php | 2 +- .../Project/Http/Project/Policies/Get.php | 1 + .../Policies/MembershipPrivacy/Update.php | 19 +++++++++++-- .../Model/PolicyMembershipPrivacy.php | 6 +++++ ...liciesMembershipPrivacyIntegrationTest.php | 27 ++++++++++++------- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/app/config/console.php b/app/config/console.php index 2070660020..9a5df31866 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -39,7 +39,7 @@ $console = [ 'membershipsMfa' => true, 'membershipsUserId' => true, 'membershipsUserPhone' => true, - 'membershipsUserAccessedAt' => false, + 'membershipsUserAccessedAt' => true, 'mockNumbers' => [], 'invites' => System::getEnv('_APP_CONSOLE_INVITES', 'enabled') === 'enabled', 'limit' => (System::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled') === 'enabled') ? 1 : 0, // limit signup to 1 user diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php index c0c247936d..cdc1605ddf 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php @@ -159,6 +159,7 @@ class Get extends Action 'userPhone' => $auths['membershipsUserPhone'] ?? false, 'userName' => $auths['membershipsUserName'] ?? false, 'userMFA' => $auths['membershipsMfa'] ?? false, + 'userAccessedAt' => $auths['membershipsUserAccessedAt'] ?? false, ]), Response::MODEL_POLICY_MEMBERSHIP_PRIVACY, ], diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php index 41a6168b07..f6f85ebf51 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php @@ -46,7 +46,7 @@ class Update extends Action responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, + model: Response::MODEL_POLICY_MEMBERSHIP_PRIVACY, ) ], )) @@ -55,6 +55,7 @@ class Update extends Action ->param('userPhone', null, new Boolean(), 'Set to true if you want make user phone number visible to all team members, or false to hide it.', optional: true) ->param('userName', null, new Boolean(), 'Set to true if you want make user name visible to all team members, or false to hide it.', optional: true) ->param('userMFA', null, new Boolean(), 'Set to true if you want make user MFA status visible to all team members, or false to hide it.', optional: true) + ->param('userAccessedAt', null, new Boolean(), 'Set to true if you want make user last access time visible to all team members, or false to hide it.', optional: true) ->inject('response') ->inject('dbForPlatform') ->inject('project') @@ -69,6 +70,7 @@ class Update extends Action ?bool $userPhone, ?bool $userName, ?bool $userMFA, + ?bool $userAccessedAt, Response $response, Database $dbForPlatform, Document $project, @@ -92,6 +94,9 @@ class Update extends Action if ($userMFA !== null) { $auths['membershipsMfa'] = $userMFA; } + if ($userAccessedAt !== null) { + $auths['membershipsUserAccessedAt'] = $userAccessedAt; + } $updates = new Document([ 'auths' => $auths, @@ -103,6 +108,16 @@ class Update extends Action ->setParam('projectId', $project->getId()) ->setParam('policy', 'membership-privacy'); - $response->dynamic($project, Response::MODEL_PROJECT); + $auths = $project->getAttribute('auths', []); + + $response->dynamic(new Document([ + '$id' => 'membership-privacy', + 'userId' => $auths['membershipsUserId'] ?? false, + 'userEmail' => $auths['membershipsUserEmail'] ?? false, + 'userPhone' => $auths['membershipsUserPhone'] ?? false, + 'userName' => $auths['membershipsUserName'] ?? false, + 'userMFA' => $auths['membershipsMfa'] ?? false, + 'userAccessedAt' => $auths['membershipsUserAccessedAt'] ?? false, + ]), Response::MODEL_POLICY_MEMBERSHIP_PRIVACY); } } diff --git a/src/Appwrite/Utopia/Response/Model/PolicyMembershipPrivacy.php b/src/Appwrite/Utopia/Response/Model/PolicyMembershipPrivacy.php index fe2851d35b..bb89462a3c 100644 --- a/src/Appwrite/Utopia/Response/Model/PolicyMembershipPrivacy.php +++ b/src/Appwrite/Utopia/Response/Model/PolicyMembershipPrivacy.php @@ -44,6 +44,12 @@ class PolicyMembershipPrivacy extends PolicyBase 'description' => 'Whether user MFA status is visible in memberships.', 'default' => false, 'example' => true, + ]) + ->addRule('userAccessedAt', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether user last access time is visible in memberships.', + 'default' => false, + 'example' => true, ]); } diff --git a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php index 95d96c49e2..cb7801448a 100644 --- a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php +++ b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php @@ -32,14 +32,16 @@ class PoliciesMembershipPrivacyIntegrationTest extends Scope 'userPhone' => false, 'userName' => false, 'userMFA' => false, + 'userAccessedAt' => false, ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertFalse($response['body']['authMembershipsUserId']); - $this->assertFalse($response['body']['authMembershipsUserEmail']); - $this->assertFalse($response['body']['authMembershipsUserPhone']); - $this->assertFalse($response['body']['authMembershipsUserName']); - $this->assertFalse($response['body']['authMembershipsMfa']); + $this->assertFalse($response['body']['userId']); + $this->assertFalse($response['body']['userEmail']); + $this->assertFalse($response['body']['userPhone']); + $this->assertFalse($response['body']['userName']); + $this->assertFalse($response['body']['userMFA']); + $this->assertFalse($response['body']['userAccessedAt']); // Step 2: Setup two users $user1Email = 'user1_' . uniqid() . '@localhost.test'; @@ -132,6 +134,7 @@ class PoliciesMembershipPrivacyIntegrationTest extends Scope $this->assertSame('', $membership['userPhone']); $this->assertSame('', $membership['userId']); $this->assertFalse($membership['mfa']); + $this->assertSame('', $membership['userAccessedAt']); } // Step 5: Update privacy to true @@ -141,13 +144,15 @@ class PoliciesMembershipPrivacyIntegrationTest extends Scope 'userPhone' => true, 'userName' => true, 'userMFA' => true, + 'userAccessedAt' => true, ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertTrue($response['body']['authMembershipsUserId']); - $this->assertTrue($response['body']['authMembershipsUserEmail']); - $this->assertTrue($response['body']['authMembershipsUserPhone']); - $this->assertTrue($response['body']['authMembershipsUserName']); - $this->assertTrue($response['body']['authMembershipsMfa']); + $this->assertTrue($response['body']['userId']); + $this->assertTrue($response['body']['userEmail']); + $this->assertTrue($response['body']['userPhone']); + $this->assertTrue($response['body']['userName']); + $this->assertTrue($response['body']['userMFA']); + $this->assertTrue($response['body']['userAccessedAt']); // Step 6: List memberships with privacy enabled - user details exposed $response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId . '/memberships', $clientHeaders); @@ -166,6 +171,7 @@ class PoliciesMembershipPrivacyIntegrationTest extends Scope $this->assertSame($user1Email, $membershipsByUser[$user1Id]['userEmail']); $this->assertSame($user1Phone, $membershipsByUser[$user1Id]['userPhone']); $this->assertFalse($membershipsByUser[$user1Id]['mfa']); + $this->assertNotEmpty($membershipsByUser[$user1Id]['userAccessedAt']); $this->assertArrayHasKey($user2Id, $membershipsByUser); $this->assertSame($user2Id, $membershipsByUser[$user2Id]['userId']); @@ -173,5 +179,6 @@ class PoliciesMembershipPrivacyIntegrationTest extends Scope $this->assertSame($user2Email, $membershipsByUser[$user2Id]['userEmail']); $this->assertSame($user2Phone, $membershipsByUser[$user2Id]['userPhone']); $this->assertFalse($membershipsByUser[$user2Id]['mfa']); + $this->assertNotEmpty($membershipsByUser[$user2Id]['userAccessedAt']); } } From fae2e20c46818e4758ac84f645b83c5f77fece2f Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 13:42:32 +0530 Subject: [PATCH 07/19] feat: add impersonation keys to LOCATION methods in Swagger2 and OpenAPI3 specs --- src/Appwrite/SDK/Specification/Format/OpenAPI3.php | 10 ++++++++++ src/Appwrite/SDK/Specification/Format/Swagger2.php | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index dfa38b0bf5..8e8d5e6301 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -384,6 +384,16 @@ class OpenAPI3 extends Format } $temp['x-appwrite']['auth'] = array_slice($securities, 0, $this->authCount); + + if ($sdk->getType() === MethodType::LOCATION) { + foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { + if (\array_key_exists($key, $this->keys)) { + $securities[$key] = []; + $temp['x-appwrite']['auth'][$key] = []; + } + } + } + $temp['security'][] = $securities; } diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 20b1fb9b94..7fc23b0d99 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -374,6 +374,16 @@ class Swagger2 extends Format } $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); + + if ($sdk->getType() === MethodType::LOCATION) { + foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { + if (\array_key_exists($key, $this->keys)) { + $securities[$key] = []; + $temp['x-appwrite']['auth'][$key] = []; + } + } + } + $temp['security'][] = $securities; } From 4c257d09342c8a5399962f64d016ea8fe68c33af Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 14:37:04 +0530 Subject: [PATCH 08/19] revert --- .../Policies/MembershipPrivacy/Update.php | 14 ++--------- ...liciesMembershipPrivacyIntegrationTest.php | 24 +++++++++---------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php index f6f85ebf51..5d7043fedf 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/MembershipPrivacy/Update.php @@ -46,7 +46,7 @@ class Update extends Action responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, - model: Response::MODEL_POLICY_MEMBERSHIP_PRIVACY, + model: Response::MODEL_PROJECT, ) ], )) @@ -108,16 +108,6 @@ class Update extends Action ->setParam('projectId', $project->getId()) ->setParam('policy', 'membership-privacy'); - $auths = $project->getAttribute('auths', []); - - $response->dynamic(new Document([ - '$id' => 'membership-privacy', - 'userId' => $auths['membershipsUserId'] ?? false, - 'userEmail' => $auths['membershipsUserEmail'] ?? false, - 'userPhone' => $auths['membershipsUserPhone'] ?? false, - 'userName' => $auths['membershipsUserName'] ?? false, - 'userMFA' => $auths['membershipsMfa'] ?? false, - 'userAccessedAt' => $auths['membershipsUserAccessedAt'] ?? false, - ]), Response::MODEL_POLICY_MEMBERSHIP_PRIVACY); + $response->dynamic($project, Response::MODEL_PROJECT); } } diff --git a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php index 2077d1fd96..6bb2ce7c69 100644 --- a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php +++ b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php @@ -38,12 +38,12 @@ final class PoliciesMembershipPrivacyIntegrationTest extends Scope ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertFalse($response['body']['userId']); - $this->assertFalse($response['body']['userEmail']); - $this->assertFalse($response['body']['userPhone']); - $this->assertFalse($response['body']['userName']); - $this->assertFalse($response['body']['userMFA']); - $this->assertFalse($response['body']['userAccessedAt']); + $this->assertFalse($response['body']['authMembershipsUserId']); + $this->assertFalse($response['body']['authMembershipsUserEmail']); + $this->assertFalse($response['body']['authMembershipsUserPhone']); + $this->assertFalse($response['body']['authMembershipsUserName']); + $this->assertFalse($response['body']['authMembershipsMfa']); + $this->assertFalse($response['body']['authMembershipsUserAccessedAt']); // Step 2: Setup two users $user1Email = 'user1_' . uniqid() . '@localhost.test'; @@ -149,12 +149,12 @@ final class PoliciesMembershipPrivacyIntegrationTest extends Scope 'userAccessedAt' => true, ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertTrue($response['body']['userId']); - $this->assertTrue($response['body']['userEmail']); - $this->assertTrue($response['body']['userPhone']); - $this->assertTrue($response['body']['userName']); - $this->assertTrue($response['body']['userMFA']); - $this->assertTrue($response['body']['userAccessedAt']); + $this->assertTrue($response['body']['authMembershipsUserId']); + $this->assertTrue($response['body']['authMembershipsUserEmail']); + $this->assertTrue($response['body']['authMembershipsUserPhone']); + $this->assertTrue($response['body']['authMembershipsUserName']); + $this->assertTrue($response['body']['authMembershipsMfa']); + $this->assertTrue($response['body']['authMembershipsUserAccessedAt']); // Step 6: List memberships with privacy enabled - user details exposed $response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId . '/memberships', $clientHeaders); From 133d6d1e46d2136d03ecae3d8d72b463bc61a515 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 14:42:18 +0530 Subject: [PATCH 09/19] Revert "feat: add impersonation keys to LOCATION methods in Swagger2 and OpenAPI3 specs" This reverts commit fae2e20c46818e4758ac84f645b83c5f77fece2f. --- src/Appwrite/SDK/Specification/Format/OpenAPI3.php | 10 ---------- src/Appwrite/SDK/Specification/Format/Swagger2.php | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index 8e8d5e6301..dfa38b0bf5 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -384,16 +384,6 @@ class OpenAPI3 extends Format } $temp['x-appwrite']['auth'] = array_slice($securities, 0, $this->authCount); - - if ($sdk->getType() === MethodType::LOCATION) { - foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { - if (\array_key_exists($key, $this->keys)) { - $securities[$key] = []; - $temp['x-appwrite']['auth'][$key] = []; - } - } - } - $temp['security'][] = $securities; } diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 7fc23b0d99..20b1fb9b94 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -374,16 +374,6 @@ class Swagger2 extends Format } $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); - - if ($sdk->getType() === MethodType::LOCATION) { - foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { - if (\array_key_exists($key, $this->keys)) { - $securities[$key] = []; - $temp['x-appwrite']['auth'][$key] = []; - } - } - } - $temp['security'][] = $securities; } From 3a3b556f4f0a2d14b3005f7f3be69cb85804f0d2 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 15:15:39 +0530 Subject: [PATCH 10/19] done --- src/Appwrite/Utopia/Response/Filters/V26.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Utopia/Response/Filters/V26.php b/src/Appwrite/Utopia/Response/Filters/V26.php index 3867ba907f..30b4e7dacb 100644 --- a/src/Appwrite/Utopia/Response/Filters/V26.php +++ b/src/Appwrite/Utopia/Response/Filters/V26.php @@ -58,6 +58,7 @@ class V26 extends Filter $content['authMembershipsMfa'] = $auths->getAttribute('membershipsMfa', false); $content['authMembershipsUserId'] = $auths->getAttribute('membershipsUserId', false); $content['authMembershipsUserPhone'] = $auths->getAttribute('membershipsUserPhone', false); + $content['authMembershipsUserAccessedAt'] = $auths->getAttribute('membershipsUserAccessedAt', false); $content['authInvalidateSessions'] = $auths->getAttribute('invalidateSessions', false); $content['description'] = $raw->getAttribute('description', ''); From 1dc9c76473c6d1d12c90311f334a930747128012 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 15:29:59 +0530 Subject: [PATCH 11/19] add session --- .../PoliciesMembershipPrivacyIntegrationTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php index 6bb2ce7c69..a6fa769d22 100644 --- a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php +++ b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php @@ -156,7 +156,18 @@ final class PoliciesMembershipPrivacyIntegrationTest extends Scope $this->assertTrue($response['body']['authMembershipsMfa']); $this->assertTrue($response['body']['authMembershipsUserAccessedAt']); - // Step 6: List memberships with privacy enabled - user details exposed + // Step 6: Sign in as user2 so accessedAt is populated + $session2 = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], [ + 'email' => $user2Email, + 'password' => $password, + ]); + $this->assertSame(201, $session2['headers']['status-code']); + + // Step 7: List memberships with privacy enabled - user details exposed $response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId . '/memberships', $clientHeaders); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(2, $response['body']['total']); From 89cdd79f3781d9f659e4591f22d1b36aec3eeaf7 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 15:43:24 +0530 Subject: [PATCH 12/19] added it before --- ...liciesMembershipPrivacyIntegrationTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php index a6fa769d22..2b8f8482af 100644 --- a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php +++ b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php @@ -125,6 +125,17 @@ final class PoliciesMembershipPrivacyIntegrationTest extends Scope 'cookie' => 'a_session_' . $projectId . '=' . $user1Session, ]; + // Also sign in as user2 so accessedAt is populated before privacy is enabled + $session2 = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], [ + 'email' => $user2Email, + 'password' => $password, + ]); + $this->assertSame(201, $session2['headers']['status-code']); + $response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId . '/memberships', $clientHeaders); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(2, $response['body']['total']); @@ -156,18 +167,7 @@ final class PoliciesMembershipPrivacyIntegrationTest extends Scope $this->assertTrue($response['body']['authMembershipsMfa']); $this->assertTrue($response['body']['authMembershipsUserAccessedAt']); - // Step 6: Sign in as user2 so accessedAt is populated - $session2 = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], [ - 'email' => $user2Email, - 'password' => $password, - ]); - $this->assertSame(201, $session2['headers']['status-code']); - - // Step 7: List memberships with privacy enabled - user details exposed + // Step 6: List memberships with privacy enabled - user details exposed $response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId . '/memberships', $clientHeaders); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(2, $response['body']['total']); From 9977852623043a3dbd6b4ea25311c4aceda55d55 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 5 Jun 2026 15:49:51 +0530 Subject: [PATCH 13/19] Fix flaky storage preview cache hit test (#12501) --- tests/e2e/Services/Storage/StorageBase.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index f654083d80..d5a9765c60 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -1016,7 +1016,20 @@ trait StorageBase $this->assertEquals(200, $cachedPreview['headers']['status-code']); $this->assertEquals('image/png', $cachedPreview['headers']['content-type']); $this->assertStringStartsWith('private, max-age=', $cachedPreview['headers']['cache-control']); - $this->assertEquals($preview['body'], $cachedPreview['body']); + $this->assertNotEmpty($cachedPreview['body']); + + $cachedPreviewAgain = $this->client->call( + Client::METHOD_GET, + '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', + $headers, + $params + ); + + $this->assertEquals(200, $cachedPreviewAgain['headers']['status-code']); + $this->assertEquals('image/png', $cachedPreviewAgain['headers']['content-type']); + $this->assertStringStartsWith('private, max-age=', $cachedPreviewAgain['headers']['cache-control']); + $this->assertEquals('hit', $cachedPreviewAgain['headers']['x-appwrite-cache']); + $this->assertEquals($cachedPreview['body'], $cachedPreviewAgain['body']); } public function testFilePreviewZstdCompression(): void From 3b1e744a5428044eb849f9ff5abf8ae962832dff Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 16:01:23 +0530 Subject: [PATCH 14/19] move order --- .../PoliciesMembershipPrivacyIntegrationTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php index 2b8f8482af..dbac9268fd 100644 --- a/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php +++ b/tests/e2e/Services/Project/PoliciesMembershipPrivacyIntegrationTest.php @@ -125,7 +125,7 @@ final class PoliciesMembershipPrivacyIntegrationTest extends Scope 'cookie' => 'a_session_' . $projectId . '=' . $user1Session, ]; - // Also sign in as user2 so accessedAt is populated before privacy is enabled + // Also sign in as user2 and make a request so accessedAt is populated before privacy is enabled $session2 = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', @@ -135,6 +135,17 @@ final class PoliciesMembershipPrivacyIntegrationTest extends Scope 'password' => $password, ]); $this->assertSame(201, $session2['headers']['status-code']); + $user2Session = $session2['cookies']['a_session_' . $projectId]; + + $client2Headers = [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'cookie' => 'a_session_' . $projectId . '=' . $user2Session, + ]; + + // Make a request as user2 to ensure accessedAt is updated + $this->client->call(Client::METHOD_GET, '/account', $client2Headers); $response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId . '/memberships', $clientHeaders); $this->assertSame(200, $response['headers']['status-code']); From 2601aae6ebac56f30e10e00df59f53de66573012 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 5 Jun 2026 16:54:50 +0530 Subject: [PATCH 15/19] Refactor OAuth2 provider tests (#12502) * Refactor OAuth2 provider tests * Fix OAuth2 provider test helper expectations --- tests/e2e/Services/Project/OAuth2Base.php | 2742 +---------------- .../Project/OAuth2/OAuth2ProviderTest.php | 593 ++++ 2 files changed, 698 insertions(+), 2637 deletions(-) create mode 100644 tests/unit/Platform/Modules/Project/OAuth2/OAuth2ProviderTest.php diff --git a/tests/e2e/Services/Project/OAuth2Base.php b/tests/e2e/Services/Project/OAuth2Base.php index 8a317f3e1d..1bf607fc29 100644 --- a/tests/e2e/Services/Project/OAuth2Base.php +++ b/tests/e2e/Services/Project/OAuth2Base.php @@ -3,41 +3,38 @@ namespace Tests\E2E\Services\Project; use PHPUnit\Framework\Attributes\Before; -use PHPUnit\Framework\Attributes\DataProvider; use Tests\E2E\Client; use Utopia\Database\Query; trait OAuth2Base { /** - * Reset providers we mutate in tests back to a known empty/disabled state. - * The ProjectCustom trait reuses the same project across tests in a class, - * and the OAuth2 PATCH endpoint is additive (omitted fields are preserved), - * so without a reset state would leak between tests. - * - * Assert on the reset response so a silently broken reset (e.g. validation - * change) surfaces immediately rather than corrupting downstream tests. + * Reset only providers this compact smoke suite mutates. Most provider + * matrix and response-shape coverage now lives in unit tests. */ #[Before(priority: -1)] protected function resetProjectOAuth2(): void { - $response = $this->updateOAuth2('amazon', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); + $providers = [ + 'amazon' => ['clientId' => '', 'clientSecret' => '', 'enabled' => false], + 'github' => ['clientId' => '', 'clientSecret' => '', 'enabled' => false], + 'apple' => ['serviceId' => '', 'keyId' => '', 'teamId' => '', 'p8File' => '', 'enabled' => false], + 'oidc' => ['clientId' => '', 'clientSecret' => '', 'wellKnownURL' => '', 'authorizationURL' => '', 'tokenURL' => '', 'userInfoURL' => '', 'enabled' => false], + 'okta' => ['clientId' => '', 'clientSecret' => '', 'domain' => '', 'authorizationServerId' => '', 'enabled' => false], + 'google' => ['clientId' => '', 'clientSecret' => '', 'prompt' => ['consent'], 'enabled' => false], + 'dropbox' => ['appKey' => '', 'appSecret' => '', 'enabled' => false], + ]; - $this->assertSame( - 200, - $response['headers']['status-code'], - 'OAuth2 reset failed — downstream tests will be unreliable. Body: ' . \json_encode($response['body'] ?? null), - ); + foreach ($providers as $provider => $payload) { + $response = $this->updateOAuth2($provider, $payload); + $this->assertSame( + 200, + $response['headers']['status-code'], + "OAuth2 reset failed for {$provider}. Body: " . \json_encode($response['body'] ?? null), + ); + } } - // ========================================================================= - // List OAuth2 providers - // ========================================================================= - public function testListOAuth2Providers(): void { $response = $this->listOAuth2Providers(); @@ -47,120 +44,11 @@ trait OAuth2Base $this->assertArrayHasKey('providers', $response['body']); $this->assertGreaterThan(0, $response['body']['total']); $this->assertSame($response['body']['total'], \count($response['body']['providers'])); - } - - public function testListOAuth2ProvidersIncludesKnownProviders(): void - { - $response = $this->listOAuth2Providers(); - - $this->assertSame(200, $response['headers']['status-code']); $ids = \array_column($response['body']['providers'], '$id'); - - // Spot-check a representative cross-section of providers across all - // provider shapes (plain, multi-field, sandboxed, custom param names). - $expected = [ - 'github', - 'amazon', - 'apple', - 'auth0', - 'authentik', - 'fusionauth', - 'gitlab', - 'keycloak', - 'oidc', - 'okta', - 'microsoft', - 'dropbox', - 'paypalSandbox', - 'kick', - ]; - - foreach ($expected as $providerId) { - $this->assertContains($providerId, $ids, "Missing provider {$providerId} in listOAuth2Providers response"); - } - } - - public function testListOAuth2ProvidersSortedAlphabetically(): void - { - $response = $this->listOAuth2Providers(); - - $this->assertSame(200, $response['headers']['status-code']); - - $ids = \array_column($response['body']['providers'], '$id'); - $sorted = $ids; - \sort($sorted); - - $this->assertSame($sorted, $ids); - } - - /** - * Pin the exact set of registered providers — adding or removing a - * provider must be a deliberate change to this assertion. Catches - * registration drift (e.g. forgetting to wire a new provider into - * `Base::getProviderActions()`). - */ - public function testListOAuth2ProvidersExposesEntireRegistry(): void - { - $response = $this->listOAuth2Providers(); - $this->assertSame(200, $response['headers']['status-code']); - - $ids = \array_column($response['body']['providers'], '$id'); - \sort($ids); - - $expected = [ - 'amazon', 'apple', 'auth0', 'authentik', 'autodesk', 'bitbucket', - 'bitly', 'box', 'dailymotion', 'discord', 'disqus', 'dropbox', - 'etsy', 'facebook', 'figma', 'fusionauth', 'github', 'gitlab', - 'google', 'keycloak', 'kick', 'linkedin', 'microsoft', 'notion', - 'oidc', 'okta', 'paypal', 'paypalSandbox', 'podio', 'salesforce', - 'slack', 'spotify', 'stripe', 'tradeshift', 'tradeshiftBox', - 'twitch', 'wordpress', 'x', 'yahoo', 'yandex', 'zoho', 'zoom', - ]; - \sort($expected); - - $this->assertSame($expected, $ids, 'Registry drift — listed providers do not match the expected set.'); - } - - public function testListOAuth2ProvidersResponseShape(): void - { - $response = $this->listOAuth2Providers(); - - $this->assertSame(200, $response['headers']['status-code']); - - foreach ($response['body']['providers'] as $provider) { - $this->assertArrayHasKey('$id', $provider); - $this->assertArrayHasKey('enabled', $provider); - $this->assertIsString($provider['$id']); - $this->assertIsBool($provider['enabled']); - } - } - - public function testListOAuth2ProvidersClientSecretsNotExposed(): void - { - // Seed credentials so the list cannot trivially return empty values. - $this->updateOAuth2('amazon', [ - 'clientId' => 'amzn1.application-oa2-client.testListSeed', - 'clientSecret' => 'super-secret-must-not-leak', - 'enabled' => false, - ]); - - $response = $this->listOAuth2Providers(); - - $this->assertSame(200, $response['headers']['status-code']); - - $matched = false; - foreach ($response['body']['providers'] as $provider) { - if ($provider['$id'] !== 'amazon') { - continue; - } - - $matched = true; - $this->assertSame('amzn1.application-oa2-client.testListSeed', $provider['clientId']); - $this->assertSame('', $provider['clientSecret']); - } - - $this->assertTrue($matched, 'List did not include the seeded provider.'); + $this->assertContains('github', $ids); + $this->assertContains('apple', $ids); + $this->assertContains('oidc', $ids); } public function testListOAuth2ProvidersWithoutAuthentication(): void @@ -170,22 +58,6 @@ trait OAuth2Base $this->assertSame(401, $response['headers']['status-code']); } - public function testListOAuth2ProvidersExcludesUnregisteredConfigEntries(): void - { - // `mock` and `mock-unverified` exist in oAuthProviders config (enabled: true) - // but are intentionally absent from Base::getProviderActions() — they're - // internal Mock OAuth2 adapters used by other test suites, not public - // providers. XList iterates the action registry, so they must never be - // included even though config marks them enabled. - $response = $this->listOAuth2Providers(); - - $this->assertSame(200, $response['headers']['status-code']); - - $ids = \array_column($response['body']['providers'], '$id'); - $this->assertNotContains('mock', $ids); - $this->assertNotContains('mock-unverified', $ids); - } - public function testListOAuth2ProvidersTotalFalse(): void { $response = $this->listOAuth2Providers(total: false); @@ -195,35 +67,26 @@ trait OAuth2Base $this->assertGreaterThan(0, \count($response['body']['providers'])); } - public function testListOAuth2ProvidersWithLimit(): void - { - $response = $this->listOAuth2Providers([ - Query::limit(1)->toString(), - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertCount(1, $response['body']['providers']); - $this->assertGreaterThan(1, $response['body']['total']); - } - - public function testListOAuth2ProvidersWithOffset(): void + public function testListOAuth2ProvidersWithLimitAndOffset(): void { $listAll = $this->listOAuth2Providers(); $this->assertSame(200, $listAll['headers']['status-code']); - $listOffset = $this->listOAuth2Providers([ + $limited = $this->listOAuth2Providers([ + Query::limit(1)->toString(), + ]); + $this->assertSame(200, $limited['headers']['status-code']); + $this->assertCount(1, $limited['body']['providers']); + $this->assertSame($listAll['body']['total'], $limited['body']['total']); + + $offset = $this->listOAuth2Providers([ Query::offset(1)->toString(), ]); - - $this->assertSame(200, $listOffset['headers']['status-code']); - $this->assertCount(\count($listAll['body']['providers']) - 1, $listOffset['body']['providers']); - $this->assertSame($listAll['body']['total'], $listOffset['body']['total']); + $this->assertSame(200, $offset['headers']['status-code']); + $this->assertCount(\count($listAll['body']['providers']) - 1, $offset['body']['providers']); + $this->assertSame($listAll['body']['total'], $offset['body']['total']); } - // ========================================================================= - // Get OAuth2 provider - // ========================================================================= - public function testGetOAuth2Provider(): void { $response = $this->getOAuth2Provider('github'); @@ -232,22 +95,17 @@ trait OAuth2Base $this->assertSame('github', $response['body']['$id']); $this->assertArrayHasKey('enabled', $response['body']); $this->assertArrayHasKey('clientId', $response['body']); - $this->assertArrayHasKey('clientSecret', $response['body']); $this->assertSame('', $response['body']['clientSecret']); } public function testGetOAuth2ProviderWithAlias(): void { - // The action declares the canonical param name as `providerId` and - // registers `provider` as an alias so that older SDK versions that - // send the provider in the query string continue to work. $headers = [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]; $headers = \array_merge($headers, $this->getHeaders()); - // Call with `provider` in query string (legacy behaviour) $response = $this->client->call( Client::METHOD_GET, '/project/oauth2/github?provider=github', @@ -258,43 +116,8 @@ trait OAuth2Base $this->assertSame('github', $response['body']['$id']); } - public function testGetOAuth2ProviderClientSecretWriteOnly(): void - { - $this->updateOAuth2('amazon', [ - 'clientId' => 'amzn1.application-oa2-client.getSecretCheck', - 'clientSecret' => 'must-never-be-returned', - 'enabled' => false, - ]); - - $response = $this->getOAuth2Provider('amazon'); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('amzn1.application-oa2-client.getSecretCheck', $response['body']['clientId']); - $this->assertSame('', $response['body']['clientSecret']); - } - - public function testGetOAuth2ProviderMatchesListEntry(): void - { - $list = $this->listOAuth2Providers(); - $this->assertSame(200, $list['headers']['status-code']); - - // Drive the loop directly off the LIST result so any provider added - // to the registry is automatically checked for List/Get parity. - foreach ($list['body']['providers'] as $listEntry) { - $providerId = $listEntry['$id']; - $get = $this->getOAuth2Provider($providerId); - - $this->assertSame(200, $get['headers']['status-code'], "GET failed for {$providerId}"); - $this->assertSame($listEntry, $get['body'], "List/Get drift on {$providerId}"); - } - } - public function testGetOAuth2ProviderUnsupported(): void { - // The `providerId` param is validated by a WhiteList of registered - // OAuth2 provider keys, so an unknown value is rejected at validation - // time — before the action runs — and surfaces as a generic argument - // error rather than `project_provider_unsupported`. $response = $this->getOAuth2Provider('not-a-real-provider'); $this->assertSame(400, $response['headers']['status-code']); @@ -303,11 +126,6 @@ trait OAuth2Base public function testGetOAuth2ProviderRegisteredInConfigButNoUpdateClass(): void { - // `mock` is present in oAuthProviders config (enabled: true) but is - // NOT registered in Base::getProviderActions(). It passes the - // WhiteList validator (which only checks config membership) and - // reaches the action body, where the action-registry check throws - // `project_provider_unsupported`. $response = $this->getOAuth2Provider('mock'); $this->assertSame(400, $response['headers']['status-code']); @@ -321,132 +139,24 @@ trait OAuth2Base $this->assertSame(401, $response['headers']['status-code']); } - // ========================================================================= - // Update plain provider (Amazon — clientId + clientSecret, no extra fields) - // ========================================================================= - - public function testUpdateOAuth2Plain(): void + public function testUpdateOAuth2PlainProviderRoundTrip(): void { - $response = $this->updateOAuth2('amazon', [ - 'clientId' => 'amzn1.application-oa2-client.test01', - 'clientSecret' => 'test-secret-01', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('amazon', $response['body']['$id']); - $this->assertSame('amzn1.application-oa2-client.test01', $response['body']['clientId']); - $this->assertSame(false, $response['body']['enabled']); - } - - public function testUpdateOAuth2PlainEnable(): void - { - // Amazon has no verifyCredentials() hook, so enabling with arbitrary - // credentials succeeds without making a real network call. - $response = $this->updateOAuth2('amazon', [ - 'clientId' => 'amzn1.application-oa2-client.test02', - 'clientSecret' => 'test-secret-02', + $update = $this->updateOAuth2('amazon', [ + 'clientId' => 'amzn1.application-oa2-client.smoke', + 'clientSecret' => 'smoke-secret', 'enabled' => true, ]); - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(true, $response['body']['enabled']); - } + $this->assertSame(200, $update['headers']['status-code']); + $this->assertSame('amazon', $update['body']['$id']); + $this->assertSame('amzn1.application-oa2-client.smoke', $update['body']['clientId']); + $this->assertTrue($update['body']['enabled']); - public function testUpdateOAuth2PlainDisable(): void - { - $this->updateOAuth2('amazon', [ - 'clientId' => 'amzn1.application-oa2-client.test03', - 'clientSecret' => 'test-secret-03', - 'enabled' => true, - ]); - - $response = $this->updateOAuth2('amazon', [ - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(false, $response['body']['enabled']); - // Credentials persist across an enabled toggle. - $this->assertSame('amzn1.application-oa2-client.test03', $response['body']['clientId']); - } - - public function testUpdateOAuth2PlainPartial(): void - { - // Seed both credentials. - $this->updateOAuth2('amazon', [ - 'clientId' => 'seed-client-id', - 'clientSecret' => 'seed-secret', - 'enabled' => false, - ]); - - // Patch only clientId. - $response = $this->updateOAuth2('amazon', [ - 'clientId' => 'updated-client-id', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('updated-client-id', $response['body']['clientId']); - - // Read back through GET to confirm the secret is still set internally - // (write-only, so we cannot inspect the value, but enabling should still - // succeed because the secret remains non-empty). - $enable = $this->updateOAuth2('amazon', [ - 'enabled' => true, - ]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertSame(true, $enable['body']['enabled']); - } - - public function testUpdateOAuth2PlainEnableRequiresCredentials(): void - { - // Start from a clean state with no credentials. - $this->updateOAuth2('amazon', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('amazon', [ - 'enabled' => true, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2PlainEnabledOmittedDoesNotThrow(): void - { - // With enabled omitted (null) and no credentials, the silent-validation - // branch must not surface as an error. - $this->updateOAuth2('amazon', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('amazon', [ - 'clientId' => 'partial-only', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(false, $response['body']['enabled']); - $this->assertSame('partial-only', $response['body']['clientId']); - } - - public function testUpdateOAuth2PlainResponseModel(): void - { - $response = $this->updateOAuth2('amazon', [ - 'clientId' => 'amzn1.application-oa2-client.modelCheck', - 'clientSecret' => 'model-check-secret', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertArrayHasKey('$id', $response['body']); - $this->assertArrayHasKey('enabled', $response['body']); - $this->assertArrayHasKey('clientId', $response['body']); - $this->assertArrayHasKey('clientSecret', $response['body']); + $get = $this->getOAuth2Provider('amazon'); + $this->assertSame(200, $get['headers']['status-code']); + $this->assertSame('amzn1.application-oa2-client.smoke', $get['body']['clientId']); + $this->assertSame('', $get['body']['clientSecret']); + $this->assertTrue($get['body']['enabled']); } public function testUpdateOAuth2WithoutAuthentication(): void @@ -462,8 +172,6 @@ trait OAuth2Base public function testUpdateOAuth2UnknownProvider(): void { - // Each Update endpoint is registered at a fixed `/oauth2/{providerId}` - // path, so an unknown provider does not match any route → 404. $response = $this->updateOAuth2('not-a-real-provider', [ 'clientId' => 'whatever', 'clientSecret' => 'whatever', @@ -483,21 +191,18 @@ trait OAuth2Base $this->assertSame('general_argument_invalid', $response['body']['type']); } - // ========================================================================= - // Update GitHub (verifyCredentials makes a real call to GitHub on enable) - // - // Only failure paths and the silent-on-disable branch are tested here. - // Happy-path enable would require real GitHub OAuth2 credentials, which - // CI doesn't have. Wiring, validation, and the non-enabling branch are - // sufficient to surface most regressions; success-path issues are caught - // by integration / staging environments instead. - // ========================================================================= + public function testUpdateOAuth2PlainEnableRequiresCredentials(): void + { + $response = $this->updateOAuth2('amazon', [ + 'enabled' => true, + ]); + + $this->assertSame(400, $response['headers']['status-code']); + $this->assertSame('general_argument_invalid', $response['body']['type']); + } public function testUpdateOAuth2GitHubInvalidCredentialsRejected(): void { - // GitHub is the only provider with a real verifyCredentials() hook. - // Enabling with bogus credentials must surface a 400 from the wrapping - // exception, not silently succeed. $response = $this->updateOAuth2('github', [ 'clientId' => 'fake-client-id-' . \uniqid(), 'clientSecret' => 'fake-client-secret', @@ -506,2368 +211,131 @@ trait OAuth2Base $this->assertSame(400, $response['headers']['status-code']); $this->assertSame('general_argument_invalid', $response['body']['type']); - - // Cleanup: ensure it's left disabled. - $this->updateOAuth2('github', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); } public function testUpdateOAuth2GitHubInvalidCredentialsSilentWhenNotEnabling(): void { - // When `enabled` is omitted, verifyCredentials() failure is swallowed. - // The provider remains disabled but the request succeeds. $response = $this->updateOAuth2('github', [ 'clientId' => 'still-fake-' . \uniqid(), 'clientSecret' => 'still-fake-secret', ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(false, $response['body']['enabled']); - - // Cleanup - $this->updateOAuth2('github', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); + $this->assertFalse($response['body']['enabled']); } - // ========================================================================= - // Update Apple (serviceId + keyId + teamId + p8File) - // ========================================================================= - - public function testUpdateOAuth2Apple(): void + public function testUpdateOAuth2AppleRoundTrip(): void { - $response = $this->updateOAuth2('apple', [ + $update = $this->updateOAuth2('apple', [ 'serviceId' => 'ip.appwrite.app.web', 'keyId' => 'P4000000N8', 'teamId' => 'D4000000R6', 'p8File' => '-----BEGIN PRIVATE KEY-----TEST-----END PRIVATE KEY-----', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('apple', $response['body']['$id']); - $this->assertSame('ip.appwrite.app.web', $response['body']['serviceId']); - $this->assertSame('P4000000N8', $response['body']['keyId']); - $this->assertSame('D4000000R6', $response['body']['teamId']); - $this->assertSame('', $response['body']['p8File']); - $this->assertSame(false, $response['body']['enabled']); - - // Cleanup - $this->updateOAuth2('apple', [ - 'serviceId' => '', - 'keyId' => '', - 'teamId' => '', - 'p8File' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2ApplePartial(): void - { - // Seed all four fields. - $this->updateOAuth2('apple', [ - 'serviceId' => 'ip.appwrite.app.seed', - 'keyId' => 'KEYSEED01', - 'teamId' => 'TEAMSEED01', - 'p8File' => '-----BEGIN PRIVATE KEY-----SEED-----END PRIVATE KEY-----', - 'enabled' => false, - ]); - - // Patch only `keyId` — others must be preserved. - $response = $this->updateOAuth2('apple', [ - 'keyId' => 'KEYUPDATED', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('ip.appwrite.app.seed', $response['body']['serviceId']); - $this->assertSame('KEYUPDATED', $response['body']['keyId']); - $this->assertSame('TEAMSEED01', $response['body']['teamId']); - $this->assertSame('', $response['body']['p8File']); - - // Cleanup - $this->updateOAuth2('apple', [ - 'serviceId' => '', - 'keyId' => '', - 'teamId' => '', - 'p8File' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2ApplePartialPreservesEachField(): void - { - // Seed all four fields, then patch each one individually and confirm - // the others survive across the chain. testUpdateOAuth2ApplePartial - // only covers `keyId`; this exercises serviceId/teamId/p8File too. - $this->updateOAuth2('apple', [ - 'serviceId' => 'ip.appwrite.app.merge', - 'keyId' => 'KEYMERGE01', - 'teamId' => 'TEAMMERGE', - 'p8File' => '-----BEGIN PRIVATE KEY-----MERGE-----END PRIVATE KEY-----', - 'enabled' => false, - ]); - - // Patch only `teamId`. - $teamOnly = $this->updateOAuth2('apple', [ - 'teamId' => 'TEAMROTATED', - ]); - $this->assertSame(200, $teamOnly['headers']['status-code']); - $this->assertSame('TEAMROTATED', $teamOnly['body']['teamId']); - $this->assertSame('KEYMERGE01', $teamOnly['body']['keyId']); - $this->assertSame('', $teamOnly['body']['p8File']); - $this->assertSame('ip.appwrite.app.merge', $teamOnly['body']['serviceId']); - - // Patch only `serviceId` — keyId/teamId/p8File live in the JSON blob - // and must survive a top-level (non-blob) field update. - $serviceOnly = $this->updateOAuth2('apple', [ - 'serviceId' => 'ip.appwrite.app.rotated', - ]); - $this->assertSame(200, $serviceOnly['headers']['status-code']); - $this->assertSame('ip.appwrite.app.rotated', $serviceOnly['body']['serviceId']); - - // Patch only `p8File`. keyId/teamId/serviceId must still be set - // internally — confirm by enabling. Apple has no verifyCredentials() - // hook, so persistCredentials only checks for non-empty serviceId and - // non-empty stored secret blob. - $p8Only = $this->updateOAuth2('apple', [ - 'p8File' => '-----BEGIN PRIVATE KEY-----ROTATED-----END PRIVATE KEY-----', - ]); - $this->assertSame(200, $p8Only['headers']['status-code']); - - $enable = $this->updateOAuth2('apple', ['enabled' => true]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertTrue($enable['body']['enabled']); - - // Cleanup - $this->updateOAuth2('apple', [ - 'serviceId' => '', - 'keyId' => '', - 'teamId' => '', - 'p8File' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2AppleClearAllFieldsBlocksEnable(): void - { - // Seed all four Apple fields. - $this->updateOAuth2('apple', [ - 'serviceId' => 'ip.appwrite.app.clearAll', - 'keyId' => 'KEYCLEARALL', - 'teamId' => 'TEAMCLEARALL', - 'p8File' => '-----BEGIN PRIVATE KEY-----CLEARALL-----END PRIVATE KEY-----', - 'enabled' => false, - ]); - - // Clear all credentials with empty strings. With `enabled` omitted, the - // silent-validation branch swallows the empty-credentials throw, so the - // call still succeeds — see testUpdateOAuth2PlainEnabledOmittedDoesNotThrow. - $clear = $this->updateOAuth2('apple', [ - 'serviceId' => '', - 'keyId' => '', - 'teamId' => '', - 'p8File' => '', - ]); - $this->assertSame(200, $clear['headers']['status-code']); - $this->assertSame('', $clear['body']['serviceId']); - - // A subsequent `enabled => true` must now 400. Empty serviceId trips - // persistCredentials' empty(appId) guard before any provider hook runs, - // proving that the clear actually took effect on stored state. - $enable = $this->updateOAuth2('apple', [ - 'enabled' => true, - ]); - $this->assertSame(400, $enable['headers']['status-code']); - $this->assertSame('general_argument_invalid', $enable['body']['type']); - - // Cleanup (already cleared; included for reset symmetry). - $this->updateOAuth2('apple', [ - 'serviceId' => '', - 'keyId' => '', - 'teamId' => '', - 'p8File' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2AppleResponseModel(): void - { - $response = $this->updateOAuth2('apple', [ - 'serviceId' => 'ip.appwrite.app.shape', - 'keyId' => 'SHAPEKEY01', - 'teamId' => 'SHAPETEAM', - 'p8File' => '-----BEGIN PRIVATE KEY-----SHAPE-----END PRIVATE KEY-----', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertArrayHasKey('$id', $response['body']); - $this->assertArrayHasKey('enabled', $response['body']); - $this->assertArrayHasKey('serviceId', $response['body']); - $this->assertArrayHasKey('keyId', $response['body']); - $this->assertArrayHasKey('teamId', $response['body']); - $this->assertArrayHasKey('p8File', $response['body']); - // Apple has no clientId/clientSecret in the response model. - $this->assertArrayNotHasKey('clientId', $response['body']); - $this->assertArrayNotHasKey('clientSecret', $response['body']); - - // Cleanup - $this->updateOAuth2('apple', [ - 'serviceId' => '', - 'keyId' => '', - 'teamId' => '', - 'p8File' => '', - 'enabled' => false, - ]); - } - - public function testGetOAuth2AppleSecretsWriteOnly(): void - { - $this->updateOAuth2('apple', [ - 'serviceId' => 'ip.appwrite.app.read', - 'keyId' => 'KEYREAD', - 'teamId' => 'TEAMREAD', - 'p8File' => '-----BEGIN PRIVATE KEY-----READ-----END PRIVATE KEY-----', - 'enabled' => false, - ]); - - $response = $this->getOAuth2Provider('apple'); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('ip.appwrite.app.read', $response['body']['serviceId']); - $this->assertSame('KEYREAD', $response['body']['keyId']); - $this->assertSame('TEAMREAD', $response['body']['teamId']); - $this->assertSame('', $response['body']['p8File']); - - // Cleanup - $this->updateOAuth2('apple', [ - 'serviceId' => '', - 'keyId' => '', - 'teamId' => '', - 'p8File' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2AppleEnableAndReadBack(): void - { - // Apple has no verifyCredentials() hook, so enabling with arbitrary - // (well-formed) values succeeds without any real Apple network call. - $update = $this->updateOAuth2('apple', [ - 'serviceId' => 'ip.appwrite.app.enable', - 'keyId' => 'ENABLEKEY', - 'teamId' => 'ENABLETEAM', - 'p8File' => '-----BEGIN PRIVATE KEY-----ENABLE-----END PRIVATE KEY-----', 'enabled' => true, ]); $this->assertSame(200, $update['headers']['status-code']); + $this->assertSame('apple', $update['body']['$id']); + $this->assertSame('ip.appwrite.app.web', $update['body']['serviceId']); + $this->assertSame('P4000000N8', $update['body']['keyId']); + $this->assertSame('D4000000R6', $update['body']['teamId']); + $this->assertSame('', $update['body']['p8File']); $this->assertTrue($update['body']['enabled']); - // GET must hide p8File while keeping the non-secret fields. $get = $this->getOAuth2Provider('apple'); $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('ip.appwrite.app.enable', $get['body']['serviceId']); - $this->assertSame('ENABLEKEY', $get['body']['keyId']); - $this->assertSame('ENABLETEAM', $get['body']['teamId']); + $this->assertSame('ip.appwrite.app.web', $get['body']['serviceId']); $this->assertSame('', $get['body']['p8File']); - - // Cleanup - $this->updateOAuth2('apple', [ - 'serviceId' => '', - 'keyId' => '', - 'teamId' => '', - 'p8File' => '', - 'enabled' => false, - ]); } - // ========================================================================= - // Update Auth0 (clientId + clientSecret + optional endpoint) - // ========================================================================= - - public function testUpdateOAuth2Auth0(): void + public function testUpdateOAuth2OidcRoundTrip(): void { - $response = $this->updateOAuth2('auth0', [ - 'clientId' => 'OaOkIA000000000000000000005KLSYq', - 'clientSecret' => 'auth0-test-secret', - 'endpoint' => 'example.us.auth0.com', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('auth0', $response['body']['$id']); - $this->assertSame('OaOkIA000000000000000000005KLSYq', $response['body']['clientId']); - $this->assertSame('example.us.auth0.com', $response['body']['endpoint']); - - // Cleanup - $this->updateOAuth2('auth0', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2Auth0PartialEndpoint(): void - { - // Seed clientSecret + endpoint. - $this->updateOAuth2('auth0', [ - 'clientId' => 'auth0-seed-client', - 'clientSecret' => 'auth0-seed-secret', - 'endpoint' => 'seed.us.auth0.com', - 'enabled' => false, - ]); - - // Update only endpoint. - $response = $this->updateOAuth2('auth0', [ - 'endpoint' => 'updated.us.auth0.com', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('updated.us.auth0.com', $response['body']['endpoint']); - // clientId is unchanged on top-level provider state. - $this->assertSame('auth0-seed-client', $response['body']['clientId']); - - // Cleanup - $this->updateOAuth2('auth0', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2Auth0PartialPreservesEachField(): void - { - // testUpdateOAuth2Auth0PartialEndpoint only patches `endpoint`. Cover - // patching `clientSecret` alone (must not wipe endpoint) and `clientId` - // alone (must not wipe the JSON-blob fields). - $this->updateOAuth2('auth0', [ - 'clientId' => 'auth0-merge-client', - 'clientSecret' => 'auth0-merge-secret', - 'endpoint' => 'merge.us.auth0.com', - 'enabled' => false, - ]); - - // Patch only clientSecret — clientId and endpoint must survive. - $secretOnly = $this->updateOAuth2('auth0', [ - 'clientSecret' => 'auth0-rotated-secret', - ]); - $this->assertSame(200, $secretOnly['headers']['status-code']); - $this->assertSame('auth0-merge-client', $secretOnly['body']['clientId']); - $this->assertSame('merge.us.auth0.com', $secretOnly['body']['endpoint']); - - // Patch only clientId — endpoint must survive. - $idOnly = $this->updateOAuth2('auth0', [ - 'clientId' => 'auth0-rotated-client', - ]); - $this->assertSame(200, $idOnly['headers']['status-code']); - $this->assertSame('auth0-rotated-client', $idOnly['body']['clientId']); - $this->assertSame('merge.us.auth0.com', $idOnly['body']['endpoint']); - - // Confirm the rotated clientSecret survived the chain by enabling. - // Auth0 has no verifyCredentials() hook; non-empty secret is enough. - $enable = $this->updateOAuth2('auth0', ['enabled' => true]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertTrue($enable['body']['enabled']); - - // Cleanup - $this->updateOAuth2('auth0', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2Auth0EndpointAcceptsEmpty(): void - { - // Auth0's `endpoint` validator is `Nullable(Text(256, 0))`. Passing - // `''` must clear the stored value rather than leave it untouched - // (would happen if the merge fell back to existing on empty-string). - $this->updateOAuth2('auth0', [ - 'clientId' => 'auth0-clear-client', - 'clientSecret' => 'auth0-clear-secret', - 'endpoint' => 'before.us.auth0.com', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('auth0', [ - 'endpoint' => '', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('', $response['body']['endpoint']); - $this->assertSame('auth0-clear-client', $response['body']['clientId']); - - // Cleanup - $this->updateOAuth2('auth0', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2Auth0EnableAndReadBack(): void - { - $update = $this->updateOAuth2('auth0', [ - 'clientId' => 'auth0-enable-client', - 'clientSecret' => 'auth0-enable-secret', - 'endpoint' => 'enable.us.auth0.com', + $update = $this->updateOAuth2('oidc', [ + 'clientId' => 'oidc-client', + 'clientSecret' => 'oidc-secret', + 'wellKnownURL' => 'https://idp.example/.well-known/openid-configuration', 'enabled' => true, ]); $this->assertSame(200, $update['headers']['status-code']); + $this->assertSame('oidc', $update['body']['$id']); + $this->assertSame('oidc-client', $update['body']['clientId']); + $this->assertSame('', $update['body']['clientSecret']); + $this->assertSame('https://idp.example/.well-known/openid-configuration', $update['body']['wellKnownURL']); $this->assertTrue($update['body']['enabled']); - - // GET must hide clientSecret while keeping clientId and endpoint. - $get = $this->getOAuth2Provider('auth0'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('auth0-enable-client', $get['body']['clientId']); - $this->assertSame('enable.us.auth0.com', $get['body']['endpoint']); - $this->assertSame('', $get['body']['clientSecret']); - - // Cleanup - $this->updateOAuth2('auth0', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); } - // ========================================================================= - // Update Authentik (clientId + clientSecret + optional endpoint) - // ========================================================================= - - public function testUpdateOAuth2AuthentikAllowsOmittedEndpointWhenDisabled(): void - { - $response = $this->updateOAuth2('authentik', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('authentik', $response['body']['$id']); - - // Cleanup - $this->updateOAuth2('authentik', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2AuthentikEmptyEndpointRejectedWhenEnabling(): void - { - $response = $this->updateOAuth2('authentik', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'endpoint' => '', - 'enabled' => true, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2Authentik(): void - { - $response = $this->updateOAuth2('authentik', [ - 'clientId' => 'dTKOPa0000000000000000000000000000e7G8hv', - 'clientSecret' => 'authentik-secret', - 'endpoint' => 'example.authentik.com', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('authentik', $response['body']['$id']); - $this->assertSame('dTKOPa0000000000000000000000000000e7G8hv', $response['body']['clientId']); - $this->assertSame('example.authentik.com', $response['body']['endpoint']); - - // Cleanup - $this->updateOAuth2('authentik', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2AuthentikPartialPreservesSecret(): void - { - // The `clientSecret` and `endpoint` live in the JSON blob and must - // survive when omitted on a subsequent call that only changes clientId. - $this->updateOAuth2('authentik', [ - 'clientId' => 'authentik-merge-client', - 'clientSecret' => 'authentik-merge-secret', - 'endpoint' => 'merge.authentik.com', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('authentik', [ - 'clientId' => 'authentik-rotated-client', - ]); - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('authentik-rotated-client', $response['body']['clientId']); - $this->assertSame('merge.authentik.com', $response['body']['endpoint']); - - // Confirm clientSecret survived the omitted-field merge by enabling - // without re-sending endpoint. - $enable = $this->updateOAuth2('authentik', [ - 'enabled' => true, - ]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertTrue($enable['body']['enabled']); - - // Cleanup - $this->updateOAuth2('authentik', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2AuthentikEnableAndReadBack(): void - { - $update = $this->updateOAuth2('authentik', [ - 'clientId' => 'authentik-enable-client', - 'clientSecret' => 'authentik-enable-secret', - 'endpoint' => 'enable.authentik.com', - 'enabled' => true, - ]); - - $this->assertSame(200, $update['headers']['status-code']); - $this->assertTrue($update['body']['enabled']); - - // GET must hide clientSecret while keeping clientId and endpoint. - $get = $this->getOAuth2Provider('authentik'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('authentik-enable-client', $get['body']['clientId']); - $this->assertSame('enable.authentik.com', $get['body']['endpoint']); - $this->assertSame('', $get['body']['clientSecret']); - - // Cleanup - $this->updateOAuth2('authentik', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update FusionAuth (clientId + clientSecret + optional endpoint) - // ========================================================================= - - public function testUpdateOAuth2FusionAuthAllowsOmittedEndpointWhenDisabled(): void - { - $response = $this->updateOAuth2('fusionauth', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('fusionauth', $response['body']['$id']); - - // Cleanup - $this->updateOAuth2('fusionauth', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2FusionAuthEmptyEndpointRejectedWhenEnabling(): void - { - $response = $this->updateOAuth2('fusionauth', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'endpoint' => '', - 'enabled' => true, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2FusionAuth(): void - { - $response = $this->updateOAuth2('fusionauth', [ - 'clientId' => 'b2222c00-0000-0000-0000-000000862097', - 'clientSecret' => 'fusionauth-secret', - 'endpoint' => 'example.fusionauth.io', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('fusionauth', $response['body']['$id']); - $this->assertSame('b2222c00-0000-0000-0000-000000862097', $response['body']['clientId']); - $this->assertSame('example.fusionauth.io', $response['body']['endpoint']); - - // Cleanup - $this->updateOAuth2('fusionauth', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2FusionAuthPartialPreservesSecret(): void - { - // The `clientSecret` and `endpoint` live in the JSON blob and must - // survive when omitted on a subsequent call that only changes clientId. - $this->updateOAuth2('fusionauth', [ - 'clientId' => 'fusionauth-merge-client', - 'clientSecret' => 'fusionauth-merge-secret', - 'endpoint' => 'merge.fusionauth.io', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('fusionauth', [ - 'clientId' => 'fusionauth-rotated-client', - ]); - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('fusionauth-rotated-client', $response['body']['clientId']); - $this->assertSame('merge.fusionauth.io', $response['body']['endpoint']); - - // Confirm clientSecret survived the omitted-field merge by enabling - // without re-sending endpoint. - $enable = $this->updateOAuth2('fusionauth', [ - 'enabled' => true, - ]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertTrue($enable['body']['enabled']); - - // Cleanup - $this->updateOAuth2('fusionauth', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2FusionAuthEnableAndReadBack(): void - { - $update = $this->updateOAuth2('fusionauth', [ - 'clientId' => 'fusionauth-enable-client', - 'clientSecret' => 'fusionauth-enable-secret', - 'endpoint' => 'enable.fusionauth.io', - 'enabled' => true, - ]); - - $this->assertSame(200, $update['headers']['status-code']); - $this->assertTrue($update['body']['enabled']); - - // GET must hide clientSecret while keeping clientId and endpoint. - $get = $this->getOAuth2Provider('fusionauth'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('fusionauth-enable-client', $get['body']['clientId']); - $this->assertSame('enable.fusionauth.io', $get['body']['endpoint']); - $this->assertSame('', $get['body']['clientSecret']); - - // Cleanup - $this->updateOAuth2('fusionauth', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update Keycloak (clientId + clientSecret + optional endpoint + optional realmName) - // ========================================================================= - - public function testUpdateOAuth2KeycloakAllowsOmittedEndpointWhenDisabled(): void - { - $response = $this->updateOAuth2('keycloak', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'realmName' => 'appwrite-realm', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('keycloak', $response['body']['$id']); - - // Cleanup - $this->updateOAuth2('keycloak', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'realmName' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2KeycloakEmptyEndpointRejectedWhenEnabling(): void - { - $response = $this->updateOAuth2('keycloak', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'endpoint' => '', - 'realmName' => 'appwrite-realm', - 'enabled' => true, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2KeycloakAllowsOmittedRealmNameWhenDisabled(): void - { - $response = $this->updateOAuth2('keycloak', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'endpoint' => 'keycloak.example.com', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('keycloak', $response['body']['$id']); - - // Cleanup - $this->updateOAuth2('keycloak', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'realmName' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2KeycloakEmptyRealmNameRejectedWhenEnabling(): void - { - $response = $this->updateOAuth2('keycloak', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'endpoint' => 'keycloak.example.com', - 'realmName' => '', - 'enabled' => true, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2Keycloak(): void - { - $response = $this->updateOAuth2('keycloak', [ - 'clientId' => 'appwrite-o0000000st-app', - 'clientSecret' => 'keycloak-secret', - 'endpoint' => 'keycloak.example.com', - 'realmName' => 'appwrite-realm', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('keycloak', $response['body']['$id']); - $this->assertSame('appwrite-o0000000st-app', $response['body']['clientId']); - $this->assertSame('keycloak.example.com', $response['body']['endpoint']); - $this->assertSame('appwrite-realm', $response['body']['realmName']); - - // Cleanup - $this->updateOAuth2('keycloak', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'realmName' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2KeycloakPartialPreservesSecret(): void - { - // The `clientSecret`, `endpoint`, and `realmName` live in the JSON - // blob and must survive when omitted on a subsequent call that only - // changes clientId. - $this->updateOAuth2('keycloak', [ - 'clientId' => 'keycloak-merge-client', - 'clientSecret' => 'keycloak-merge-secret', - 'endpoint' => 'merge.keycloak.com', - 'realmName' => 'merge-realm', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('keycloak', [ - 'clientId' => 'keycloak-rotated-client', - ]); - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('keycloak-rotated-client', $response['body']['clientId']); - $this->assertSame('merge.keycloak.com', $response['body']['endpoint']); - $this->assertSame('merge-realm', $response['body']['realmName']); - - // Confirm clientSecret survived the omitted-field merge by enabling - // without re-sending endpoint or realmName. - $enable = $this->updateOAuth2('keycloak', [ - 'enabled' => true, - ]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertTrue($enable['body']['enabled']); - - // Cleanup - $this->updateOAuth2('keycloak', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'realmName' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2KeycloakEnableAndReadBack(): void - { - $update = $this->updateOAuth2('keycloak', [ - 'clientId' => 'keycloak-enable-client', - 'clientSecret' => 'keycloak-enable-secret', - 'endpoint' => 'enable.keycloak.com', - 'realmName' => 'enable-realm', - 'enabled' => true, - ]); - - $this->assertSame(200, $update['headers']['status-code']); - $this->assertTrue($update['body']['enabled']); - - // GET must hide clientSecret while keeping clientId, endpoint, realmName. - $get = $this->getOAuth2Provider('keycloak'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('keycloak-enable-client', $get['body']['clientId']); - $this->assertSame('enable.keycloak.com', $get['body']['endpoint']); - $this->assertSame('enable-realm', $get['body']['realmName']); - $this->assertSame('', $get['body']['clientSecret']); - - // Cleanup - $this->updateOAuth2('keycloak', [ - 'clientId' => '', - 'clientSecret' => '', - 'endpoint' => '', - 'realmName' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update Microsoft (applicationId + applicationSecret + optional tenant) - // ========================================================================= - - public function testUpdateOAuth2MicrosoftAllowsOmittedTenantWhenDisabled(): void - { - $response = $this->updateOAuth2('microsoft', [ - 'applicationId' => 'whatever', - 'applicationSecret' => 'whatever', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('microsoft', $response['body']['$id']); - - // Cleanup - $this->updateOAuth2('microsoft', [ - 'applicationId' => '', - 'applicationSecret' => '', - 'tenant' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2MicrosoftEmptyTenantRejectedWhenEnabling(): void - { - $response = $this->updateOAuth2('microsoft', [ - 'applicationId' => 'whatever', - 'applicationSecret' => 'whatever', - 'tenant' => '', - 'enabled' => true, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2Microsoft(): void - { - $response = $this->updateOAuth2('microsoft', [ - 'applicationId' => '00001111-aaaa-2222-bbbb-3333cccc4444', - 'applicationSecret' => 'A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u', - 'tenant' => 'common', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('microsoft', $response['body']['$id']); - $this->assertSame('00001111-aaaa-2222-bbbb-3333cccc4444', $response['body']['applicationId']); - $this->assertSame('common', $response['body']['tenant']); - // Custom param names: applicationId/applicationSecret, not clientId/clientSecret. - $this->assertArrayNotHasKey('clientId', $response['body']); - $this->assertArrayNotHasKey('clientSecret', $response['body']); - - // Cleanup - $this->updateOAuth2('microsoft', [ - 'applicationId' => '', - 'applicationSecret' => '', - 'tenant' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2MicrosoftPartialPreservesSecret(): void - { - // Seed full credentials. - $this->updateOAuth2('microsoft', [ - 'applicationId' => 'seed-app-id', - 'applicationSecret' => 'seed-app-secret', - 'tenant' => 'common', - 'enabled' => false, - ]); - - // Patch with only a new applicationId, leaving applicationSecret and - // tenant omitted. The stored JSON values must not be wiped. - $response = $this->updateOAuth2('microsoft', [ - 'applicationId' => 'updated-app-id', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('updated-app-id', $response['body']['applicationId']); - $this->assertSame('common', $response['body']['tenant']); - - // Cleanup - $this->updateOAuth2('microsoft', [ - 'applicationId' => '', - 'applicationSecret' => '', - 'tenant' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2MicrosoftEnableAndReadBack(): void - { - $update = $this->updateOAuth2('microsoft', [ - 'applicationId' => 'microsoft-enable-app', - 'applicationSecret' => 'microsoft-enable-secret', - 'tenant' => 'common', - 'enabled' => true, - ]); - - $this->assertSame(200, $update['headers']['status-code']); - $this->assertTrue($update['body']['enabled']); - - // GET must hide applicationSecret while keeping applicationId/tenant. - $get = $this->getOAuth2Provider('microsoft'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('microsoft-enable-app', $get['body']['applicationId']); - $this->assertSame('common', $get['body']['tenant']); - $this->assertSame('', $get['body']['applicationSecret']); - - // Cleanup - $this->updateOAuth2('microsoft', [ - 'applicationId' => '', - 'applicationSecret' => '', - 'tenant' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update Gitlab (applicationId + secret + optional endpoint, custom names) - // ========================================================================= - - public function testUpdateOAuth2Gitlab(): void - { - $response = $this->updateOAuth2('gitlab', [ - 'applicationId' => 'd41ffe0000000000000000000000000000000000000000000000000000d5e252', - 'secret' => 'gloas-838cfa00', - 'endpoint' => 'https://gitlab.example.com', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('gitlab', $response['body']['$id']); - $this->assertSame('d41ffe0000000000000000000000000000000000000000000000000000d5e252', $response['body']['applicationId']); - $this->assertSame('https://gitlab.example.com', $response['body']['endpoint']); - // Custom names — the response model exposes `applicationId`/`secret`. - $this->assertArrayNotHasKey('clientId', $response['body']); - $this->assertArrayNotHasKey('clientSecret', $response['body']); - - // Cleanup - $this->updateOAuth2('gitlab', [ - 'applicationId' => '', - 'secret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2GitlabInvalidEndpoint(): void - { - $response = $this->updateOAuth2('gitlab', [ - 'applicationId' => 'whatever', - 'secret' => 'whatever', - 'endpoint' => 'not a url', - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2GitlabPartialEndpoint(): void - { - $this->updateOAuth2('gitlab', [ - 'applicationId' => 'gitlab-seed-app', - 'secret' => 'gitlab-seed-secret', - 'endpoint' => 'https://seed.gitlab.com', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('gitlab', [ - 'endpoint' => 'https://updated.gitlab.com', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('https://updated.gitlab.com', $response['body']['endpoint']); - $this->assertSame('gitlab-seed-app', $response['body']['applicationId']); - - // Cleanup - $this->updateOAuth2('gitlab', [ - 'applicationId' => '', - 'secret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2GitlabPartialPreservesEachField(): void - { - // testUpdateOAuth2GitlabPartialEndpoint covers patching only `endpoint`. - // Cover patching `secret` alone (must not wipe applicationId/endpoint) - // and `applicationId` alone (must not wipe the JSON-blob endpoint). - $this->updateOAuth2('gitlab', [ - 'applicationId' => 'gitlab-merge-app', - 'secret' => 'gitlab-merge-secret', - 'endpoint' => 'https://merge.gitlab.com', - 'enabled' => false, - ]); - - // Patch only `secret`. - $secretOnly = $this->updateOAuth2('gitlab', [ - 'secret' => 'gitlab-rotated-secret', - ]); - $this->assertSame(200, $secretOnly['headers']['status-code']); - $this->assertSame('gitlab-merge-app', $secretOnly['body']['applicationId']); - $this->assertSame('https://merge.gitlab.com', $secretOnly['body']['endpoint']); - - // Patch only `applicationId`. - $idOnly = $this->updateOAuth2('gitlab', [ - 'applicationId' => 'gitlab-rotated-app', - ]); - $this->assertSame(200, $idOnly['headers']['status-code']); - $this->assertSame('gitlab-rotated-app', $idOnly['body']['applicationId']); - $this->assertSame('https://merge.gitlab.com', $idOnly['body']['endpoint']); - - // Cleanup - $this->updateOAuth2('gitlab', [ - 'applicationId' => '', - 'secret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2GitlabEnableAndReadBack(): void - { - $update = $this->updateOAuth2('gitlab', [ - 'applicationId' => 'gitlab-enable-app', - 'secret' => 'gitlab-enable-secret', - 'endpoint' => 'https://enable.gitlab.com', - 'enabled' => true, - ]); - - $this->assertSame(200, $update['headers']['status-code']); - $this->assertTrue($update['body']['enabled']); - - // GET must hide `secret` while keeping applicationId and endpoint. - $get = $this->getOAuth2Provider('gitlab'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('gitlab-enable-app', $get['body']['applicationId']); - $this->assertSame('https://enable.gitlab.com', $get['body']['endpoint']); - $this->assertSame('', $get['body']['secret']); - - // Cleanup - $this->updateOAuth2('gitlab', [ - 'applicationId' => '', - 'secret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2GitlabEndpointAcceptsEmpty(): void - { - // The `endpoint` validator is `Nullable(URL(allowEmpty: true))`. Passing - // `''` must clear the stored value rather than 400 on URL validation. - $this->updateOAuth2('gitlab', [ - 'applicationId' => 'gitlab-clear-app', - 'secret' => 'gitlab-clear-secret', - 'endpoint' => 'https://before.gitlab.com', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('gitlab', [ - 'endpoint' => '', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('', $response['body']['endpoint']); - - // Cleanup - $this->updateOAuth2('gitlab', [ - 'applicationId' => '', - 'secret' => '', - 'endpoint' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update OIDC (clientId + secret + wellKnownURL or 3 discovery URLs) - // ========================================================================= - - public function testUpdateOAuth2OidcWithWellKnown(): void + public function testUpdateOAuth2OidcRejectsIncompleteDiscoveryConfig(): void { $response = $this->updateOAuth2('oidc', [ 'clientId' => 'oidc-client', 'clientSecret' => 'oidc-secret', - 'wellKnownURL' => 'https://idp.example.com/.well-known/openid-configuration', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('https://idp.example.com/.well-known/openid-configuration', $response['body']['wellKnownURL']); - $this->assertArrayHasKey('authorizationURL', $response['body']); - $this->assertArrayHasKey('tokenURL', $response['body']); - $this->assertArrayHasKey('userInfoURL', $response['body']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OidcWithDiscoveryURLs(): void - { - $response = $this->updateOAuth2('oidc', [ - 'clientId' => 'oidc-discovery', - 'clientSecret' => 'oidc-discovery-secret', - 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenURL' => 'https://idp.example.com/oauth2/token', - 'userInfoURL' => 'https://idp.example.com/oauth2/userinfo', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('https://idp.example.com/oauth2/authorize', $response['body']['authorizationURL']); - $this->assertSame('https://idp.example.com/oauth2/token', $response['body']['tokenURL']); - $this->assertSame('https://idp.example.com/oauth2/userinfo', $response['body']['userInfoURL']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OidcEnableMissingURLs(): void - { - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('oidc', [ - 'clientId' => 'oidc-no-urls', - 'clientSecret' => 'oidc-no-urls', + 'authorizationURL' => 'https://idp.example/oauth2/authorize', + 'userInfoURL' => 'https://idp.example/oauth2/userinfo', 'enabled' => true, ]); $this->assertSame(400, $response['headers']['status-code']); $this->assertSame('general_argument_invalid', $response['body']['type']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); } - public function testUpdateOAuth2OidcEnablePartialDiscoveryFails(): void + public function testUpdateOAuth2OktaRoundTrip(): void { - // Only authorization+token, missing userInfo — must fail to enable. - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('oidc', [ - 'clientId' => 'oidc-partial', - 'clientSecret' => 'oidc-partial-secret', - 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenURL' => 'https://idp.example.com/oauth2/token', - 'enabled' => true, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OidcEnableSucceedsWithWellKnown(): void - { - $update = $this->updateOAuth2('oidc', [ - 'clientId' => 'oidc-enable-client', - 'clientSecret' => 'oidc-enable-secret', - 'wellKnownURL' => 'https://idp.example.com/.well-known/openid-configuration', - 'enabled' => true, - ]); - - $this->assertSame(200, $update['headers']['status-code']); - $this->assertTrue($update['body']['enabled']); - - // GET must hide clientSecret while keeping clientId and the URL. - $get = $this->getOAuth2Provider('oidc'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('oidc-enable-client', $get['body']['clientId']); - $this->assertSame('https://idp.example.com/.well-known/openid-configuration', $get['body']['wellKnownURL']); - $this->assertSame('', $get['body']['clientSecret']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OidcEnableInSeparateRequestWithWellKnown(): void - { - // Configure URLs first with `enabled: false`. Then enable in a SECOND - // request that omits all URL fields. The merge-on-enable logic in - // Oidc::handle() must see the previously-stored wellKnownEndpoint and - // allow the toggle. This is the headline feature of the merge logic. - $this->updateOAuth2('oidc', [ - 'clientId' => 'oidc-split-wk-client', - 'clientSecret' => 'oidc-split-wk-secret', - 'wellKnownURL' => 'https://idp.example.com/.well-known/openid-configuration', - 'enabled' => false, - ]); - - $enable = $this->updateOAuth2('oidc', [ - 'enabled' => true, - ]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertTrue($enable['body']['enabled']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OidcEnableAcrossRequestsWithDiscoveryURLs(): void - { - // Reset to clean state — earlier tests in this section may have left - // partial URL state when running in any order. - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - - // Request 1: configure two of the three discovery URLs. - $this->updateOAuth2('oidc', [ - 'clientId' => 'oidc-split-discovery', - 'clientSecret' => 'oidc-split-discovery-secret', - 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenURL' => 'https://idp.example.com/oauth2/token', - 'enabled' => false, - ]); - - // Request 2: send only the third URL plus enable=true. The merged - // state must include the two stored URLs + the new one to satisfy - // the all-three-discovery-URLs branch of the enable check. - $enable = $this->updateOAuth2('oidc', [ - 'userInfoURL' => 'https://idp.example.com/oauth2/userinfo', - 'enabled' => true, - ]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertTrue($enable['body']['enabled']); - - // Confirm all three URLs ended up persisted (merge wrote the new - // userInfoURL while preserving the previously stored two). - $get = $this->getOAuth2Provider('oidc'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertSame('https://idp.example.com/oauth2/authorize', $get['body']['authorizationURL']); - $this->assertSame('https://idp.example.com/oauth2/token', $get['body']['tokenURL']); - $this->assertSame('https://idp.example.com/oauth2/userinfo', $get['body']['userInfoURL']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OidcEnableFailsAfterClearingWellKnown(): void - { - // Seed wellKnownURL only (no discovery URLs). - $this->updateOAuth2('oidc', [ - 'clientId' => 'oidc-clear-then-enable', - 'clientSecret' => 'oidc-clear-then-enable-secret', - 'wellKnownURL' => 'https://idp.example.com/.well-known/openid-configuration', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - - // Clear wellKnownURL and try to enable in the same request. Merge - // sees `wellKnown=''` (the cleared empty wins over the stored value - // because the new value is non-null) and no discovery URLs → 400. - // This is the inverse of testUpdateOAuth2OidcEnableInSeparateRequestWithWellKnown: - // confirms the merge correctly *replaces* with empty rather than - // falling back to the stored non-empty value. - $response = $this->updateOAuth2('oidc', [ - 'wellKnownURL' => '', - 'enabled' => true, - ]); - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OidcSwitchModesWellKnownToDiscovery(): void - { - // Configure with wellKnownURL, then switch to the three-discovery-URL - // mode in a single request: clear wellKnown, set the three URLs, - // enable. Merge sees wellKnown='' AND all three discovery URLs set → - // hasAllDiscovery branch passes. - $this->updateOAuth2('oidc', [ - 'clientId' => 'oidc-switch-client', - 'clientSecret' => 'oidc-switch-secret', - 'wellKnownURL' => 'https://idp.example.com/.well-known/openid-configuration', - 'enabled' => false, - ]); - - $switch = $this->updateOAuth2('oidc', [ - 'wellKnownURL' => '', - 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenURL' => 'https://idp.example.com/oauth2/token', - 'userInfoURL' => 'https://idp.example.com/oauth2/userinfo', - 'enabled' => true, - ]); - $this->assertSame(200, $switch['headers']['status-code']); - $this->assertTrue($switch['body']['enabled']); - $this->assertSame('', $switch['body']['wellKnownURL']); - $this->assertSame('https://idp.example.com/oauth2/authorize', $switch['body']['authorizationURL']); - $this->assertSame('https://idp.example.com/oauth2/token', $switch['body']['tokenURL']); - $this->assertSame('https://idp.example.com/oauth2/userinfo', $switch['body']['userInfoURL']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OidcURLsAcceptEmpty(): void - { - // All four URL fields use `Nullable(URL(allowEmpty: true))`. Passing `''` - // for each must clear them rather than 400 on URL validation. - $this->updateOAuth2('oidc', [ - 'clientId' => 'oidc-clear-client', - 'clientSecret' => 'oidc-clear-secret', - 'wellKnownURL' => 'https://idp.example.com/.well-known/openid-configuration', - 'authorizationURL' => 'https://idp.example.com/oauth2/authorize', - 'tokenURL' => 'https://idp.example.com/oauth2/token', - 'userInfoURL' => 'https://idp.example.com/oauth2/userinfo', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('oidc', [ - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('', $response['body']['wellKnownURL']); - $this->assertSame('', $response['body']['authorizationURL']); - $this->assertSame('', $response['body']['tokenURL']); - $this->assertSame('', $response['body']['userInfoURL']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OidcBackwardCompatibleResponseFormat(): void - { - // Reset to clean state - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'wellKnownURL' => '', - 'authorizationURL' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - - $headers = [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-response-format' => '1.9.3', - ]; - $headers = \array_merge($headers, $this->getHeaders()); - - // Update using OLD param names (aliases must still work) - $response = $this->client->call( - Client::METHOD_PATCH, - '/project/oauth2/oidc', - $headers, - [ - 'clientId' => 'oidc-compat-client', - 'clientSecret' => 'oidc-compat-secret', - 'tokenUrl' => 'https://idp.example.com/oauth2/token', - 'userInfoUrl' => 'https://idp.example.com/oauth2/userinfo', - 'enabled' => false, - ], - ); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertArrayHasKey('tokenUrl', $response['body']); - $this->assertArrayHasKey('userInfoUrl', $response['body']); - $this->assertArrayNotHasKey('tokenURL', $response['body']); - $this->assertArrayNotHasKey('userInfoURL', $response['body']); - $this->assertSame('https://idp.example.com/oauth2/token', $response['body']['tokenUrl']); - $this->assertSame('https://idp.example.com/oauth2/userinfo', $response['body']['userInfoUrl']); - - // GET with 1.9.3 format must also return old param names - $get = $this->client->call( - Client::METHOD_GET, - '/project/oauth2/oidc', - $headers, - ); - - $this->assertSame(200, $get['headers']['status-code']); - $this->assertArrayHasKey('tokenUrl', $get['body']); - $this->assertArrayHasKey('userInfoUrl', $get['body']); - $this->assertArrayNotHasKey('tokenURL', $get['body']); - $this->assertArrayNotHasKey('userInfoURL', $get['body']); - $this->assertSame('https://idp.example.com/oauth2/token', $get['body']['tokenUrl']); - $this->assertSame('https://idp.example.com/oauth2/userinfo', $get['body']['userInfoUrl']); - - // LIST with 1.9.3 format must also return old param names for OIDC - $list = $this->client->call( - Client::METHOD_GET, - '/project/oauth2', - $headers, - ); - - $this->assertSame(200, $list['headers']['status-code']); - $oidcEntry = null; - foreach ($list['body']['providers'] as $provider) { - if ($provider['$id'] === 'oidc') { - $oidcEntry = $provider; - break; - } - } - $this->assertNotNull($oidcEntry, 'OIDC provider missing from listOAuth2Providers response'); - $this->assertArrayHasKey('tokenUrl', $oidcEntry); - $this->assertArrayHasKey('userInfoUrl', $oidcEntry); - $this->assertArrayNotHasKey('tokenURL', $oidcEntry); - $this->assertArrayNotHasKey('userInfoURL', $oidcEntry); - $this->assertSame('https://idp.example.com/oauth2/token', $oidcEntry['tokenUrl']); - $this->assertSame('https://idp.example.com/oauth2/userinfo', $oidcEntry['userInfoUrl']); - - // Cleanup - $this->updateOAuth2('oidc', [ - 'clientId' => '', - 'clientSecret' => '', - 'tokenURL' => '', - 'userInfoURL' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update Okta (clientId + clientSecret + optional domain/authServer) - // ========================================================================= - - public function testUpdateOAuth2Okta(): void - { - $response = $this->updateOAuth2('okta', [ + $update = $this->updateOAuth2('okta', [ 'clientId' => '0oa00000000000000698', 'clientSecret' => 'okta-secret', 'domain' => 'trial-6400025.okta.com', 'authorizationServerId' => 'aus000000000000000h7z', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('okta', $response['body']['$id']); - $this->assertSame('0oa00000000000000698', $response['body']['clientId']); - $this->assertSame('trial-6400025.okta.com', $response['body']['domain']); - $this->assertSame('aus000000000000000h7z', $response['body']['authorizationServerId']); - - // Cleanup - $this->updateOAuth2('okta', [ - 'clientId' => '', - 'clientSecret' => '', - 'domain' => '', - 'authorizationServerId' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OktaInvalidDomain(): void - { - $response = $this->updateOAuth2('okta', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'domain' => 'https://trial-6400025.okta.com/', - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2OktaEnableRequiresDomain(): void - { - $this->updateOAuth2('okta', [ - 'clientId' => '', - 'clientSecret' => '', - 'domain' => '', - 'authorizationServerId' => '', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('okta', [ - 'clientId' => 'okta-no-domain', - 'clientSecret' => 'okta-no-domain-secret', - 'enabled' => true, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - - // Cleanup - $this->updateOAuth2('okta', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OktaEnableSucceedsWithDomain(): void - { - $update = $this->updateOAuth2('okta', [ - 'clientId' => 'okta-enable-client', - 'clientSecret' => 'okta-enable-secret', - 'domain' => 'enable.okta.com', - 'authorizationServerId' => 'aus000000000000000h7z', 'enabled' => true, ]); $this->assertSame(200, $update['headers']['status-code']); + $this->assertSame('okta', $update['body']['$id']); + $this->assertSame('0oa00000000000000698', $update['body']['clientId']); + $this->assertSame('trial-6400025.okta.com', $update['body']['domain']); + $this->assertSame('aus000000000000000h7z', $update['body']['authorizationServerId']); + $this->assertSame('', $update['body']['clientSecret']); $this->assertTrue($update['body']['enabled']); - - // GET must hide clientSecret while keeping clientId, domain and authServerId. - $get = $this->getOAuth2Provider('okta'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('okta-enable-client', $get['body']['clientId']); - $this->assertSame('enable.okta.com', $get['body']['domain']); - $this->assertSame('aus000000000000000h7z', $get['body']['authorizationServerId']); - $this->assertSame('', $get['body']['clientSecret']); - - // Cleanup - $this->updateOAuth2('okta', [ - 'clientId' => '', - 'clientSecret' => '', - 'domain' => '', - 'authorizationServerId' => '', - 'enabled' => false, - ]); } - public function testUpdateOAuth2OktaPartialPreservesEachField(): void + public function testUpdateOAuth2GoogleRoundTrip(): void { - // Okta has no field-by-field partial test in the existing suite. Cover - // each of `domain`, `authorizationServerId`, and `clientSecret` being - // patched alone — all three live in the same JSON blob. - $this->updateOAuth2('okta', [ - 'clientId' => 'okta-merge-client', - 'clientSecret' => 'okta-merge-secret', - 'domain' => 'merge.okta.com', - 'authorizationServerId' => 'aus000000000000merge', - 'enabled' => false, - ]); - - // Patch only `domain` — others must survive. - $domainOnly = $this->updateOAuth2('okta', [ - 'domain' => 'rotated.okta.com', - ]); - $this->assertSame(200, $domainOnly['headers']['status-code']); - $this->assertSame('rotated.okta.com', $domainOnly['body']['domain']); - $this->assertSame('okta-merge-client', $domainOnly['body']['clientId']); - $this->assertSame('aus000000000000merge', $domainOnly['body']['authorizationServerId']); - - // Patch only `authorizationServerId`. - $authServerOnly = $this->updateOAuth2('okta', [ - 'authorizationServerId' => 'aus000000000rotated00', - ]); - $this->assertSame(200, $authServerOnly['headers']['status-code']); - $this->assertSame('rotated.okta.com', $authServerOnly['body']['domain']); - $this->assertSame('aus000000000rotated00', $authServerOnly['body']['authorizationServerId']); - - // Patch only `clientSecret` — domain and authServerId in the JSON blob - // must survive. Confirm the rotated secret persisted by enabling. - $secretOnly = $this->updateOAuth2('okta', [ - 'clientSecret' => 'okta-rotated-secret', - ]); - $this->assertSame(200, $secretOnly['headers']['status-code']); - $this->assertSame('rotated.okta.com', $secretOnly['body']['domain']); - $this->assertSame('aus000000000rotated00', $secretOnly['body']['authorizationServerId']); - - $enable = $this->updateOAuth2('okta', ['enabled' => true]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertTrue($enable['body']['enabled']); - - // Cleanup - $this->updateOAuth2('okta', [ - 'clientId' => '', - 'clientSecret' => '', - 'domain' => '', - 'authorizationServerId' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OktaAuthServerIdAcceptsEmpty(): void - { - // `authorizationServerId` is `Nullable(Text(256, 0))`. Passing `''` - // must clear the stored value while leaving the rest of the JSON blob - // (clientSecret, oktaDomain) untouched. - $this->updateOAuth2('okta', [ - 'clientId' => 'okta-clear-auth-server', - 'clientSecret' => 'okta-clear-auth-server-secret', - 'domain' => 'authserver.okta.com', - 'authorizationServerId' => 'aus0000000000beforeauth', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('okta', [ - 'authorizationServerId' => '', - ]); - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('', $response['body']['authorizationServerId']); - // domain (also stored in the JSON blob) must NOT have been wiped. - $this->assertSame('authserver.okta.com', $response['body']['domain']); - - // Cleanup - $this->updateOAuth2('okta', [ - 'clientId' => '', - 'clientSecret' => '', - 'domain' => '', - 'authorizationServerId' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2OktaDomainAcceptsEmpty(): void - { - // The `domain` validator is `Nullable(Domain(allowEmpty: true))`. Passing - // `''` must clear the stored value rather than 400 on Domain validation. - $this->updateOAuth2('okta', [ - 'clientId' => 'okta-clear-client', - 'clientSecret' => 'okta-clear-secret', - 'domain' => 'before.okta.com', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('okta', [ - 'domain' => '', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('', $response['body']['domain']); - - // Cleanup - $this->updateOAuth2('okta', [ - 'clientId' => '', - 'clientSecret' => '', - 'domain' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update Dropbox (custom param names: appKey + appSecret) - // ========================================================================= - - public function testUpdateOAuth2DropboxFieldNames(): void - { - $response = $this->updateOAuth2('dropbox', [ - 'appKey' => 'jl000000000009t', - 'appSecret' => 'g200000000000vw', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('dropbox', $response['body']['$id']); - $this->assertSame('jl000000000009t', $response['body']['appKey']); - $this->assertArrayHasKey('appSecret', $response['body']); - $this->assertArrayNotHasKey('clientId', $response['body']); - $this->assertArrayNotHasKey('clientSecret', $response['body']); - - // GET enforces write-only on the secret regardless of the custom name. - $get = $this->getOAuth2Provider('dropbox'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertSame('jl000000000009t', $get['body']['appKey']); - $this->assertSame('', $get['body']['appSecret']); - - // Cleanup - $this->updateOAuth2('dropbox', [ - 'appKey' => '', - 'appSecret' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2DropboxPartial(): void - { - // Seed both fields, then patch only `appKey` and verify `appSecret` - // persists by enabling — Dropbox has no verifyCredentials() hook, so - // enabling succeeds purely from local state. - $this->updateOAuth2('dropbox', [ - 'appKey' => 'dropbox-seed-key', - 'appSecret' => 'dropbox-seed-secret', - 'enabled' => false, - ]); - - $response = $this->updateOAuth2('dropbox', [ - 'appKey' => 'dropbox-updated-key', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('dropbox-updated-key', $response['body']['appKey']); - - $enable = $this->updateOAuth2('dropbox', [ + $update = $this->updateOAuth2('google', [ + 'clientId' => 'google-client', + 'clientSecret' => 'google-secret', + 'prompt' => ['select_account'], 'enabled' => true, ]); - $this->assertSame(200, $enable['headers']['status-code']); - $this->assertSame(true, $enable['body']['enabled']); - // Cleanup - $this->updateOAuth2('dropbox', [ - 'appKey' => '', - 'appSecret' => '', - 'enabled' => false, - ]); + $this->assertSame(200, $update['headers']['status-code']); + $this->assertSame('google', $update['body']['$id']); + $this->assertSame('google-client', $update['body']['clientId']); + $this->assertSame(['select_account'], $update['body']['prompt']); + $this->assertSame('', $update['body']['clientSecret']); + $this->assertTrue($update['body']['enabled']); } - public function testUpdateOAuth2DropboxEnableAndReadBack(): void + public function testUpdateOAuth2DropboxCustomFieldRoundTrip(): void { $update = $this->updateOAuth2('dropbox', [ - 'appKey' => 'dropbox-enable-key', - 'appSecret' => 'dropbox-enable-secret', - 'enabled' => true, + 'appKey' => 'dropbox-app-key', + 'appSecret' => 'dropbox-app-secret', + 'enabled' => false, ]); $this->assertSame(200, $update['headers']['status-code']); - $this->assertTrue($update['body']['enabled']); - - // GET must hide `appSecret` while keeping `appKey`. - $get = $this->getOAuth2Provider('dropbox'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('dropbox-enable-key', $get['body']['appKey']); - $this->assertSame('', $get['body']['appSecret']); - - // Cleanup - $this->updateOAuth2('dropbox', [ - 'appKey' => '', - 'appSecret' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update Paypal Sandbox (inherits from Paypal — independent provider ID) - // ========================================================================= - - public function testUpdateOAuth2PaypalSandbox(): void - { - $response = $this->updateOAuth2('paypalSandbox', [ - 'clientId' => 'paypal-sandbox-client', - 'clientSecret' => 'paypal-sandbox-secret', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('paypalSandbox', $response['body']['$id']); - $this->assertSame('paypal-sandbox-client', $response['body']['clientId']); - - // Sandbox is independent of the regular paypal entry. - $regular = $this->getOAuth2Provider('paypal'); - $this->assertSame(200, $regular['headers']['status-code']); - $this->assertSame('paypal', $regular['body']['$id']); - $this->assertNotSame('paypal-sandbox-client', $regular['body']['clientId']); - - // Cleanup - $this->updateOAuth2('paypalSandbox', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2PaypalSandboxResponseModel(): void - { - // PaypalSandbox inherits from Paypal: param/response field is - // `secretKey` instead of `clientSecret`. A regression that adds the - // default `clientSecret` to the response model would leak the - // unwritten field; pin its absence on both PATCH and GET. - $update = $this->updateOAuth2('paypalSandbox', [ - 'clientId' => 'paypal-sandbox-shape', - 'secretKey' => 'paypal-sandbox-shape-secret', - 'enabled' => false, - ]); - $this->assertSame(200, $update['headers']['status-code']); - $this->assertArrayHasKey('secretKey', $update['body']); - $this->assertArrayNotHasKey('clientSecret', $update['body']); - - $get = $this->getOAuth2Provider('paypalSandbox'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertArrayHasKey('secretKey', $get['body']); - $this->assertArrayNotHasKey('clientSecret', $get['body']); - - // Cleanup - $this->updateOAuth2('paypalSandbox', [ - 'clientId' => '', - 'secretKey' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2PaypalDoesNotAffectSandbox(): void - { - // Reverse direction: writing to regular paypal must leave sandbox state intact. - $this->updateOAuth2('paypalSandbox', [ - 'clientId' => 'sandbox-untouched', - 'clientSecret' => 'sandbox-secret', - 'enabled' => false, - ]); - - $this->updateOAuth2('paypal', [ - 'clientId' => 'paypal-prod', - 'secretKey' => 'paypal-prod-secret', - 'enabled' => false, - ]); - - $sandbox = $this->getOAuth2Provider('paypalSandbox'); - $this->assertSame(200, $sandbox['headers']['status-code']); - $this->assertSame('sandbox-untouched', $sandbox['body']['clientId']); - - // Cleanup both - $this->updateOAuth2('paypal', [ - 'clientId' => '', - 'secretKey' => '', - 'enabled' => false, - ]); - $this->updateOAuth2('paypalSandbox', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update Tradeshift Sandbox (inherits from Tradeshift — independent provider ID) - // ========================================================================= - - public function testUpdateOAuth2TradeshiftBox(): void - { - $response = $this->updateOAuth2('tradeshiftBox', [ - 'oauth2ClientId' => 'tradeshift-sandbox-client', - 'oauth2ClientSecret' => 'tradeshift-sandbox-secret', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('tradeshiftBox', $response['body']['$id']); - $this->assertSame('tradeshift-sandbox-client', $response['body']['oauth2ClientId']); - - // Sandbox is independent of the regular tradeshift entry. - $regular = $this->getOAuth2Provider('tradeshift'); - $this->assertSame(200, $regular['headers']['status-code']); - $this->assertSame('tradeshift', $regular['body']['$id']); - $this->assertNotSame('tradeshift-sandbox-client', $regular['body']['oauth2ClientId']); - - // Cleanup - $this->updateOAuth2('tradeshiftBox', [ - 'oauth2ClientId' => '', - 'oauth2ClientSecret' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2TradeshiftBoxResponseModel(): void - { - // TradeshiftSandbox inherits from Tradeshift: both clientId AND - // clientSecret are renamed (oauth2ClientId / oauth2ClientSecret). - // Pin that the default field names are absent from PATCH and GET - // responses so a stray addition to the response model is caught. - $update = $this->updateOAuth2('tradeshiftBox', [ - 'oauth2ClientId' => 'tradeshift-box-shape', - 'oauth2ClientSecret' => 'tradeshift-box-shape-secret', - 'enabled' => false, - ]); - $this->assertSame(200, $update['headers']['status-code']); - $this->assertArrayHasKey('oauth2ClientId', $update['body']); - $this->assertArrayHasKey('oauth2ClientSecret', $update['body']); + $this->assertSame('dropbox', $update['body']['$id']); + $this->assertSame('dropbox-app-key', $update['body']['appKey']); + $this->assertSame('', $update['body']['appSecret']); $this->assertArrayNotHasKey('clientId', $update['body']); $this->assertArrayNotHasKey('clientSecret', $update['body']); - $get = $this->getOAuth2Provider('tradeshiftBox'); + $get = $this->getOAuth2Provider('dropbox'); $this->assertSame(200, $get['headers']['status-code']); - $this->assertArrayHasKey('oauth2ClientId', $get['body']); - $this->assertArrayHasKey('oauth2ClientSecret', $get['body']); - $this->assertArrayNotHasKey('clientId', $get['body']); - $this->assertArrayNotHasKey('clientSecret', $get['body']); - - // Cleanup - $this->updateOAuth2('tradeshiftBox', [ - 'oauth2ClientId' => '', - 'oauth2ClientSecret' => '', - 'enabled' => false, - ]); + $this->assertSame('dropbox-app-key', $get['body']['appKey']); + $this->assertSame('', $get['body']['appSecret']); } - public function testUpdateOAuth2TradeshiftDoesNotAffectSandbox(): void - { - // Reverse direction: writing to regular tradeshift must not touch sandbox state. - $this->updateOAuth2('tradeshiftBox', [ - 'oauth2ClientId' => 'tradeshift-sandbox-untouched', - 'oauth2ClientSecret' => 'tradeshift-sandbox-secret', - 'enabled' => false, - ]); - - $this->updateOAuth2('tradeshift', [ - 'oauth2ClientId' => 'tradeshift-prod', - 'oauth2ClientSecret' => 'tradeshift-prod-secret', - 'enabled' => false, - ]); - - $sandbox = $this->getOAuth2Provider('tradeshiftBox'); - $this->assertSame(200, $sandbox['headers']['status-code']); - $this->assertSame('tradeshift-sandbox-untouched', $sandbox['body']['oauth2ClientId']); - - // Cleanup both - $this->updateOAuth2('tradeshift', [ - 'oauth2ClientId' => '', - 'oauth2ClientSecret' => '', - 'enabled' => false, - ]); - $this->updateOAuth2('tradeshiftBox', [ - 'oauth2ClientId' => '', - 'oauth2ClientSecret' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Update Google (clientId + clientSecret + optional prompt) - // ========================================================================= - - /** - * Default prompt MUST run before any other Google test that sets a custom - * prompt value. The global resetProjectOAuth2() only clears Amazon state, - * so Google state leaks across tests in the same class. Running this first - * guarantees the stored JSON blob has no pre-existing "prompt" key. - */ - public function testUpdateOAuth2GoogleDefaultPrompt(): void - { - // When prompt is omitted and nothing is stored, the default is ['consent']. - $response = $this->updateOAuth2('google', [ - 'clientId' => 'google-default-client', - 'clientSecret' => 'google-default-secret', - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(['consent'], $response['body']['prompt']); - - // Cleanup - $this->updateOAuth2('google', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2Google(): void - { - $response = $this->updateOAuth2('google', [ - 'clientId' => '120000000095-92ifjb00000000000000000000g7ijfb.apps.googleusercontent.com', - 'clientSecret' => 'GOCSPX-2k8gsR0000000000000000VNahJj', - 'prompt' => ['select_account'], - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('google', $response['body']['$id']); - $this->assertSame('120000000095-92ifjb00000000000000000000g7ijfb.apps.googleusercontent.com', $response['body']['clientId']); - $this->assertSame(['select_account'], $response['body']['prompt']); - - // Cleanup - $this->updateOAuth2('google', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2GooglePartialPreservesPrompt(): void - { - // Seed clientSecret + prompt. - $this->updateOAuth2('google', [ - 'clientId' => 'google-seed-client', - 'clientSecret' => 'google-seed-secret', - 'prompt' => ['consent', 'select_account'], - 'enabled' => false, - ]); - - // Update only clientId. - $response = $this->updateOAuth2('google', [ - 'clientId' => 'google-rotated-client', - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame('google-rotated-client', $response['body']['clientId']); - $this->assertSame(['consent', 'select_account'], $response['body']['prompt']); - - // Cleanup - $this->updateOAuth2('google', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2GooglePromptNoneAloneRejected(): void - { - $response = $this->updateOAuth2('google', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'prompt' => ['none', 'consent'], - 'enabled' => false, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2GooglePromptEmptyArrayRejected(): void - { - $response = $this->updateOAuth2('google', [ - 'clientId' => 'whatever', - 'clientSecret' => 'whatever', - 'prompt' => [], - 'enabled' => false, - ]); - - $this->assertSame(400, $response['headers']['status-code']); - $this->assertSame('general_argument_invalid', $response['body']['type']); - } - - public function testUpdateOAuth2GooglePromptNoneAloneAccepted(): void - { - $response = $this->updateOAuth2('google', [ - 'clientId' => '120000000095-92ifjb00000000000000000000g7ijfb.apps.googleusercontent.com', - 'clientSecret' => 'GOCSPX-2k8gsR0000000000000000VNahJj', - 'prompt' => ['none'], - 'enabled' => false, - ]); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(['none'], $response['body']['prompt']); - - // Cleanup - $this->updateOAuth2('google', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - } - - public function testUpdateOAuth2GoogleEnableAndReadBack(): void - { - $update = $this->updateOAuth2('google', [ - 'clientId' => 'google-enable-client', - 'clientSecret' => 'google-enable-secret', - 'prompt' => ['select_account'], - 'enabled' => true, - ]); - - $this->assertSame(200, $update['headers']['status-code']); - $this->assertTrue($update['body']['enabled']); - - // GET must hide clientSecret while keeping clientId and prompt. - $get = $this->getOAuth2Provider('google'); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertTrue($get['body']['enabled']); - $this->assertSame('google-enable-client', $get['body']['clientId']); - $this->assertSame(['select_account'], $get['body']['prompt']); - $this->assertSame('', $get['body']['clientSecret']); - - // Cleanup - $this->updateOAuth2('google', [ - 'clientId' => '', - 'clientSecret' => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Smoke test: every plain (clientId + clientSecret) provider - // - // Ensures each provider's Update endpoint is wired up correctly: routing, - // provider class, response model and `$id`. Custom-shaped providers - // (apple, auth0, authentik, fusionauth, gitlab, keycloak, microsoft, oidc, - // okta, dropbox) and sandboxes (paypalSandbox, tradeshiftSandbox) have - // dedicated tests above. - // Github is excluded because its `verifyCredentials()` hook is exercised - // separately. - // ========================================================================= - - /** - * Provider, ID-field, secret-field. Many providers rename one or both of - * the two credential params (`clientId`/`clientSecret`) to match the - * upstream provider's terminology, so the smoke test parameterises both. - * - * @return array> - */ - public static function plainProviders(): array - { - return [ - 'discord' => ['discord', 'clientId', 'clientSecret'], - 'figma' => ['figma', 'clientId', 'clientSecret'], - 'dailymotion' => ['dailymotion', 'apiKey', 'apiSecret'], - 'bitbucket' => ['bitbucket', 'key', 'secret'], - 'bitly' => ['bitly', 'clientId', 'clientSecret'], - 'box' => ['box', 'clientId', 'clientSecret'], - 'autodesk' => ['autodesk', 'clientId', 'clientSecret'], - 'google' => ['google', 'clientId', 'clientSecret'], - 'zoom' => ['zoom', 'clientId', 'clientSecret'], - 'zoho' => ['zoho', 'clientId', 'clientSecret'], - 'yandex' => ['yandex', 'clientId', 'clientSecret'], - 'x' => ['x', 'customerKey', 'secretKey'], - 'wordpress' => ['wordpress', 'clientId', 'clientSecret'], - 'twitch' => ['twitch', 'clientId', 'clientSecret'], - 'stripe' => ['stripe', 'clientId', 'apiSecretKey'], - 'spotify' => ['spotify', 'clientId', 'clientSecret'], - 'slack' => ['slack', 'clientId', 'clientSecret'], - 'podio' => ['podio', 'clientId', 'clientSecret'], - 'notion' => ['notion', 'oauthClientId', 'oauthClientSecret'], - 'salesforce' => ['salesforce', 'customerKey', 'customerSecret'], - 'yahoo' => ['yahoo', 'clientId', 'clientSecret'], - 'linkedin' => ['linkedin', 'clientId', 'primaryClientSecret'], - 'disqus' => ['disqus', 'publicKey', 'secretKey'], - 'etsy' => ['etsy', 'keyString', 'sharedSecret'], - 'facebook' => ['facebook', 'appId', 'appSecret'], - 'tradeshift' => ['tradeshift', 'oauth2ClientId', 'oauth2ClientSecret'], - 'paypal' => ['paypal', 'clientId', 'secretKey'], - 'kick' => ['kick', 'clientId', 'clientSecret'], - ]; - } - - #[DataProvider('plainProviders')] - public function testUpdateOAuth2PlainProvider(string $providerId, string $idField, string $secretField): void - { - $clientId = $providerId . '-smoke-client'; - $clientSecret = $providerId . '-smoke-secret'; - - $update = $this->updateOAuth2($providerId, [ - $idField => $clientId, - $secretField => $clientSecret, - 'enabled' => false, - ]); - - $this->assertSame(200, $update['headers']['status-code']); - $this->assertSame($providerId, $update['body']['$id']); - $this->assertSame($clientId, $update['body'][$idField]); - $this->assertFalse($update['body']['enabled']); - - // GET round-trip — confirms the value actually persisted (catches a - // PATCH that only echoes input without writing) and that the secret - // is hidden on read. - $get = $this->getOAuth2Provider($providerId); - $this->assertSame(200, $get['headers']['status-code']); - $this->assertSame($providerId, $get['body']['$id']); - $this->assertSame($clientId, $get['body'][$idField]); - $this->assertSame('', $get['body'][$secretField]); - $this->assertFalse($get['body']['enabled']); - - // Cleanup - $this->updateOAuth2($providerId, [ - $idField => '', - $secretField => '', - 'enabled' => false, - ]); - } - - /** - * For providers that rename `clientId` / `clientSecret` to a custom field - * (e.g. `apiKey`/`apiSecret`, `customerKey`/`secretKey`, `oauthClientId`), - * the renamed field replaces the default — the response model must NOT - * also expose the default name. Catches a regression where adding a - * custom param name forgets to remove the default from the response. - */ - #[DataProvider('plainProviders')] - public function testUpdateOAuth2PlainProviderResponseDoesNotLeakDefaultNames(string $providerId, string $idField, string $secretField): void - { - if ($idField === 'clientId' && $secretField === 'clientSecret') { - // Default-named provider — nothing to leak. Avoids a no-op assertion. - $this->markTestSkipped("{$providerId} uses default field names."); - } - - $update = $this->updateOAuth2($providerId, [ - $idField => $providerId . '-leak-check-id', - $secretField => $providerId . '-leak-check-secret', - 'enabled' => false, - ]); - $this->assertSame(200, $update['headers']['status-code']); - - if ($idField !== 'clientId') { - $this->assertArrayNotHasKey('clientId', $update['body'], "PATCH response for {$providerId} leaks default `clientId` despite using `{$idField}`."); - } - if ($secretField !== 'clientSecret') { - $this->assertArrayNotHasKey('clientSecret', $update['body'], "PATCH response for {$providerId} leaks default `clientSecret` despite using `{$secretField}`."); - } - - $get = $this->getOAuth2Provider($providerId); - $this->assertSame(200, $get['headers']['status-code']); - if ($idField !== 'clientId') { - $this->assertArrayNotHasKey('clientId', $get['body'], "GET response for {$providerId} leaks default `clientId` despite using `{$idField}`."); - } - if ($secretField !== 'clientSecret') { - $this->assertArrayNotHasKey('clientSecret', $get['body'], "GET response for {$providerId} leaks default `clientSecret` despite using `{$secretField}`."); - } - - // Cleanup - $this->updateOAuth2($providerId, [ - $idField => '', - $secretField => '', - 'enabled' => false, - ]); - } - - // ========================================================================= - // Helpers - // ========================================================================= - /** * @param array $params */ diff --git a/tests/unit/Platform/Modules/Project/OAuth2/OAuth2ProviderTest.php b/tests/unit/Platform/Modules/Project/OAuth2/OAuth2ProviderTest.php new file mode 100644 index 0000000000..b8eb48f748 --- /dev/null +++ b/tests/unit/Platform/Modules/Project/OAuth2/OAuth2ProviderTest.php @@ -0,0 +1,593 @@ +assertSame($expected, $ids); + $this->assertArrayNotHasKey('mock', $actions); + $this->assertArrayNotHasKey('mock-unverified', $actions); + $this->assertSame(PaypalSandboxUpdate::class, $actions['paypalSandbox']); + $this->assertSame(TradeshiftSandboxUpdate::class, $actions['tradeshiftBox']); + + foreach ($actions as $providerId => $actionClass) { + $this->assertSame($providerId, $actionClass::getProviderId()); + } + } + + /** + * @param class-string $actionClass + * @param array $expectedIds + */ + #[DataProvider('providerParameters')] + public function testProviderParameterMetadata(string $actionClass, array $expectedIds): void + { + $parameters = $actionClass::getParameters(); + $ids = \array_column($parameters, '$id'); + + $this->assertSame($expectedIds, $ids); + + foreach ($parameters as $parameter) { + $this->assertArrayHasKey('$id', $parameter); + $this->assertArrayHasKey('name', $parameter); + $this->assertArrayHasKey('example', $parameter); + $this->assertArrayHasKey('hint', $parameter); + $this->assertNotSame('', $parameter['$id']); + $this->assertNotSame('', $parameter['name']); + } + } + + public static function providerParameters(): \Iterator + { + yield 'default provider' => [Base::getProviderActions()['amazon'], ['clientId', 'clientSecret']]; + yield 'custom id and secret names' => [DropboxUpdate::class, ['appKey', 'appSecret']]; + yield 'apple' => [AppleUpdate::class, ['serviceId', 'keyId', 'teamId', 'p8File']]; + yield 'auth0' => [Auth0Update::class, ['clientId', 'clientSecret', 'endpoint']]; + yield 'authentik' => [AuthentikUpdate::class, ['clientId', 'clientSecret', 'endpoint']]; + yield 'fusionauth' => [FusionAuthUpdate::class, ['clientId', 'clientSecret', 'endpoint']]; + yield 'gitlab' => [GitlabUpdate::class, ['applicationId', 'secret', 'endpoint']]; + yield 'google' => [GoogleUpdate::class, ['clientId', 'clientSecret', 'prompt']]; + yield 'keycloak' => [KeycloakUpdate::class, ['clientId', 'clientSecret', 'endpoint', 'realmName']]; + yield 'microsoft' => [MicrosoftUpdate::class, ['applicationId', 'applicationSecret', 'tenant']]; + yield 'oidc' => [OidcUpdate::class, ['clientId', 'clientSecret', 'wellKnownURL', 'authorizationURL', 'tokenURL', 'userInfoURL']]; + yield 'okta' => [OktaUpdate::class, ['clientId', 'clientSecret', 'domain', 'authorizationServerId']]; + } + + /** + * @param class-string $actionClass + */ + #[DataProvider('plainProviders')] + public function testPlainProviderReadResponsesUseProviderSpecificFieldNames( + string $providerId, + string $actionClass, + string $idField, + string $secretField + ): void { + $action = new $actionClass(); + $response = $action->buildReadResponse($this->project([ + $providerId . 'Enabled' => true, + $providerId . 'Appid' => 'stored-id', + $providerId . 'Secret' => 'stored-secret', + ])); + + $this->assertSame($providerId, $response->getAttribute('$id')); + $this->assertTrue($response->getAttribute('enabled')); + $this->assertSame('stored-id', $response->getAttribute($idField)); + $this->assertSame('', $response->getAttribute($secretField)); + + if ($idField !== 'clientId') { + $this->assertFalse($response->offsetExists('clientId')); + } + if ($secretField !== 'clientSecret') { + $this->assertFalse($response->offsetExists('clientSecret')); + } + } + + public static function plainProviders(): \Iterator + { + $actions = Base::getProviderActions(); + yield 'amazon' => ['amazon', $actions['amazon'], 'clientId', 'clientSecret']; + yield 'dailymotion' => ['dailymotion', $actions['dailymotion'], 'apiKey', 'apiSecret']; + yield 'bitbucket' => ['bitbucket', $actions['bitbucket'], 'key', 'secret']; + yield 'dropbox' => ['dropbox', DropboxUpdate::class, 'appKey', 'appSecret']; + yield 'etsy' => ['etsy', $actions['etsy'], 'keyString', 'sharedSecret']; + yield 'facebook' => ['facebook', $actions['facebook'], 'appId', 'appSecret']; + yield 'notion' => ['notion', $actions['notion'], 'oauthClientId', 'oauthClientSecret']; + yield 'paypal' => ['paypal', $actions['paypal'], 'clientId', 'secretKey']; + yield 'salesforce' => ['salesforce', $actions['salesforce'], 'customerKey', 'customerSecret']; + yield 'stripe' => ['stripe', $actions['stripe'], 'clientId', 'apiSecretKey']; + yield 'tradeshift' => ['tradeshift', $actions['tradeshift'], 'oauth2ClientId', 'oauth2ClientSecret']; + yield 'x' => ['x', $actions['x'], 'customerKey', 'secretKey']; + } + + public function testAppleReadResponseHidesP8FileAndExposesNonSecretFields(): void + { + $response = (new AppleUpdate())->buildReadResponse($this->project([ + 'appleEnabled' => true, + 'appleAppid' => 'ip.appwrite.app.web', + 'appleSecret' => \json_encode([ + 'p8' => 'private-key', + 'keyID' => 'KEY123', + 'teamID' => 'TEAM123', + ]), + ])); + + $this->assertSame('apple', $response->getAttribute('$id')); + $this->assertTrue($response->getAttribute('enabled')); + $this->assertSame('ip.appwrite.app.web', $response->getAttribute('serviceId')); + $this->assertSame('KEY123', $response->getAttribute('keyId')); + $this->assertSame('TEAM123', $response->getAttribute('teamId')); + $this->assertSame('', $response->getAttribute('p8File')); + $this->assertFalse($response->offsetExists('clientId')); + $this->assertFalse($response->offsetExists('clientSecret')); + } + + /** + * @param class-string $actionClass + * @param array $storedSecret + * @param array $expected + */ + #[DataProvider('jsonBackedReadResponses')] + public function testJsonBackedReadResponsesExposeOnlyNonSecretExtras( + string $providerId, + string $actionClass, + array $storedSecret, + array $expected + ): void { + $response = (new $actionClass())->buildReadResponse($this->project([ + $providerId . 'Enabled' => true, + $providerId . 'Appid' => 'stored-id', + $providerId . 'Secret' => \json_encode($storedSecret), + ])); + + $this->assertSame($providerId, $response->getAttribute('$id')); + $this->assertSame('stored-id', $response->getAttribute($actionClass::getClientIdParamName())); + $this->assertSame('', $response->getAttribute($actionClass::getClientSecretParamName())); + + foreach ($expected as $key => $value) { + $this->assertSame($value, $response->getAttribute($key)); + } + } + + public static function jsonBackedReadResponses(): \Iterator + { + yield 'auth0' => ['auth0', Auth0Update::class, ['clientSecret' => 'secret', 'auth0Domain' => 'example.us.auth0.com'], ['endpoint' => 'example.us.auth0.com']]; + yield 'authentik' => ['authentik', AuthentikUpdate::class, ['clientSecret' => 'secret', 'authentikDomain' => 'example.authentik.com'], ['endpoint' => 'example.authentik.com']]; + yield 'fusionauth' => ['fusionauth', FusionAuthUpdate::class, ['clientSecret' => 'secret', 'fusionAuthDomain' => 'example.fusionauth.io'], ['endpoint' => 'example.fusionauth.io']]; + yield 'gitlab' => ['gitlab', GitlabUpdate::class, ['clientSecret' => 'secret', 'endpoint' => 'https://gitlab.example.com'], ['endpoint' => 'https://gitlab.example.com']]; + yield 'google' => ['google', GoogleUpdate::class, ['clientSecret' => 'secret', 'prompt' => ['select_account']], ['prompt' => ['select_account']]]; + yield 'keycloak' => ['keycloak', KeycloakUpdate::class, ['clientSecret' => 'secret', 'keycloakDomain' => 'keycloak.example.com', 'keycloakRealm' => 'appwrite-realm'], ['endpoint' => 'keycloak.example.com', 'realmName' => 'appwrite-realm']]; + yield 'microsoft' => ['microsoft', MicrosoftUpdate::class, ['clientSecret' => 'secret', 'tenantID' => 'common'], ['tenant' => 'common']]; + yield 'oidc' => ['oidc', OidcUpdate::class, ['clientSecret' => 'secret', 'wellKnownEndpoint' => 'https://idp.example/.well-known/openid-configuration', 'authorizationEndpoint' => '', 'tokenEndpoint' => '', 'userInfoEndpoint' => ''], ['wellKnownURL' => 'https://idp.example/.well-known/openid-configuration', 'authorizationURL' => '', 'tokenURL' => '', 'userInfoURL' => '']]; + yield 'okta' => ['okta', OktaUpdate::class, ['clientSecret' => 'secret', 'oktaDomain' => 'trial-6400025.okta.com', 'authorizationServerId' => 'aus123'], ['domain' => 'trial-6400025.okta.com', 'authorizationServerId' => 'aus123']]; + } + + public function testInvalidStoredJsonReturnsEmptyExtras(): void + { + $response = (new Auth0Update())->buildReadResponse($this->project([ + 'auth0Enabled' => false, + 'auth0Appid' => 'stored-id', + 'auth0Secret' => '{not-json', + ])); + + $this->assertSame('stored-id', $response->getAttribute('clientId')); + $this->assertSame('', $response->getAttribute('clientSecret')); + $this->assertSame('', $response->getAttribute('endpoint')); + } + + public function testApplePartialUpdatesMergeStoredSecretFields(): void + { + $result = $this->runHandle( + new AppleUpdate(), + $this->project([ + 'appleEnabled' => false, + 'appleAppid' => 'ip.appwrite.app.seed', + 'appleSecret' => \json_encode([ + 'p8' => 'old-p8', + 'keyID' => 'OLDKEY', + 'teamID' => 'OLDTEAM', + ]), + ]), + [null, 'NEWKEY', null, null, false], + ); + + $stored = \json_decode($result['updatedProject']->getAttribute('oAuthProviders')['appleSecret'], true); + $this->assertSame('ip.appwrite.app.seed', $result['updatedProject']->getAttribute('oAuthProviders')['appleAppid']); + $this->assertSame('old-p8', $stored['p8']); + $this->assertSame('NEWKEY', $stored['keyID']); + $this->assertSame('OLDTEAM', $stored['teamID']); + $this->assertSame('NEWKEY', $result['response']->getAttribute('keyId')); + $this->assertSame('', $result['response']->getAttribute('p8File')); + } + + /** + * @param class-string $actionClass + * @param array $initialSecret + * @param array $args + * @param array $expectedSecret + * @param array $expectedResponse + */ + #[DataProvider('partialJsonMergeScenarios')] + public function testPartialJsonBackedUpdatesPreserveExistingFields( + string $providerId, + string $actionClass, + array $initialSecret, + array $args, + array $expectedSecret, + array $expectedResponse + ): void { + $result = $this->runHandle( + new $actionClass(), + $this->project([ + $providerId . 'Enabled' => false, + $providerId . 'Appid' => 'seed-id', + $providerId . 'Secret' => \json_encode($initialSecret), + ]), + $args, + ); + + $stored = \json_decode($result['updatedProject']->getAttribute('oAuthProviders')[$providerId . 'Secret'], true); + foreach ($expectedSecret as $key => $value) { + $this->assertSame($value, $stored[$key]); + } + + foreach ($expectedResponse as $key => $value) { + $this->assertSame($value, $result['response']->getAttribute($key)); + } + } + + public static function partialJsonMergeScenarios(): \Iterator + { + yield 'auth0 endpoint only' => [ + 'auth0', + Auth0Update::class, + ['clientSecret' => 'old-secret', 'auth0Domain' => 'old.us.auth0.com'], + [null, null, 'new.us.auth0.com', false], + ['clientSecret' => 'old-secret', 'auth0Domain' => 'new.us.auth0.com'], + ['clientId' => 'seed-id', 'clientSecret' => '', 'endpoint' => 'new.us.auth0.com'], + ]; + yield 'authentik client only' => [ + 'authentik', + AuthentikUpdate::class, + ['clientSecret' => 'old-secret', 'authentikDomain' => 'old.authentik.com'], + ['rotated-id', null, null, false], + ['clientSecret' => 'old-secret', 'authentikDomain' => 'old.authentik.com'], + ['clientId' => 'rotated-id', 'endpoint' => 'old.authentik.com'], + ]; + yield 'fusionauth secret only' => [ + 'fusionauth', + FusionAuthUpdate::class, + ['clientSecret' => 'old-secret', 'fusionAuthDomain' => 'old.fusionauth.io'], + [null, 'new-secret', null, false], + ['clientSecret' => 'new-secret', 'fusionAuthDomain' => 'old.fusionauth.io'], + ['clientId' => 'seed-id', 'endpoint' => 'old.fusionauth.io'], + ]; + yield 'gitlab endpoint only' => [ + 'gitlab', + GitlabUpdate::class, + ['clientSecret' => 'old-secret', 'endpoint' => 'https://old.gitlab.example'], + [null, null, 'https://new.gitlab.example', false], + ['clientSecret' => 'old-secret', 'endpoint' => 'https://new.gitlab.example'], + ['applicationId' => 'seed-id', 'endpoint' => 'https://new.gitlab.example'], + ]; + yield 'keycloak realm only' => [ + 'keycloak', + KeycloakUpdate::class, + ['clientSecret' => 'old-secret', 'keycloakDomain' => 'keycloak.example.com', 'keycloakRealm' => 'old-realm'], + [null, null, null, 'new-realm', false], + ['clientSecret' => 'old-secret', 'keycloakDomain' => 'keycloak.example.com', 'keycloakRealm' => 'new-realm'], + ['clientId' => 'seed-id', 'endpoint' => 'keycloak.example.com', 'realmName' => 'new-realm'], + ]; + yield 'microsoft tenant only' => [ + 'microsoft', + MicrosoftUpdate::class, + ['clientSecret' => 'old-secret', 'tenantID' => 'organizations'], + [null, null, 'common', false], + ['clientSecret' => 'old-secret', 'tenantID' => 'common'], + ['applicationId' => 'seed-id', 'tenant' => 'common'], + ]; + yield 'okta authorization server only' => [ + 'okta', + OktaUpdate::class, + ['clientSecret' => 'old-secret', 'oktaDomain' => 'trial-6400025.okta.com', 'authorizationServerId' => 'old-server'], + [null, null, null, 'new-server', false], + ['clientSecret' => 'old-secret', 'oktaDomain' => 'trial-6400025.okta.com', 'authorizationServerId' => 'new-server'], + ['clientId' => 'seed-id', 'domain' => 'trial-6400025.okta.com', 'authorizationServerId' => 'new-server'], + ]; + } + + public function testOidcAcceptsWellKnownMode(): void + { + $result = $this->runHandle(new OidcUpdate(), $this->project(), [ + 'oidc-client', + 'oidc-secret', + 'https://idp.example/.well-known/openid-configuration', + null, + null, + null, + true, + ]); + + $stored = \json_decode($result['updatedProject']->getAttribute('oAuthProviders')['oidcSecret'], true); + $this->assertSame('https://idp.example/.well-known/openid-configuration', $stored['wellKnownEndpoint']); + $this->assertTrue($result['response']->getAttribute('enabled')); + $this->assertSame('https://idp.example/.well-known/openid-configuration', $result['response']->getAttribute('wellKnownURL')); + } + + public function testOidcAcceptsDiscoveryUrlMode(): void + { + $result = $this->runHandle(new OidcUpdate(), $this->project(), [ + 'oidc-client', + 'oidc-secret', + null, + 'https://idp.example/oauth2/authorize', + 'https://idp.example/oauth2/token', + 'https://idp.example/oauth2/userinfo', + true, + ]); + + $stored = \json_decode($result['updatedProject']->getAttribute('oAuthProviders')['oidcSecret'], true); + $this->assertSame('https://idp.example/oauth2/authorize', $stored['authorizationEndpoint']); + $this->assertSame('https://idp.example/oauth2/token', $stored['tokenEndpoint']); + $this->assertSame('https://idp.example/oauth2/userinfo', $stored['userInfoEndpoint']); + $this->assertTrue($result['response']->getAttribute('enabled')); + } + + public function testOidcRejectsEnableWithIncompleteDiscoveryConfig(): void + { + $this->expectException(Exception::class); + + $this->runHandle( + new OidcUpdate(), + $this->project(), + [ + 'oidc-client', + 'oidc-secret', + null, + 'https://idp.example/oauth2/authorize', + null, + 'https://idp.example/oauth2/userinfo', + true, + ], + assertQueueParam: false, + ); + } + + public function testOidcCanSwitchFromWellKnownToDiscoveryMode(): void + { + $result = $this->runHandle( + new OidcUpdate(), + $this->project([ + 'oidcEnabled' => false, + 'oidcAppid' => 'oidc-client', + 'oidcSecret' => \json_encode([ + 'clientSecret' => 'oidc-secret', + 'wellKnownEndpoint' => 'https://old.example/.well-known/openid-configuration', + 'authorizationEndpoint' => '', + 'tokenEndpoint' => '', + 'userInfoEndpoint' => '', + ]), + ]), + [ + null, + null, + '', + 'https://idp.example/oauth2/authorize', + 'https://idp.example/oauth2/token', + 'https://idp.example/oauth2/userinfo', + true, + ], + ); + + $stored = \json_decode($result['updatedProject']->getAttribute('oAuthProviders')['oidcSecret'], true); + $this->assertSame('', $stored['wellKnownEndpoint']); + $this->assertSame('https://idp.example/oauth2/authorize', $stored['authorizationEndpoint']); + $this->assertTrue($result['response']->getAttribute('enabled')); + } + + public function testGooglePromptRulesAndBackwardCompatibleSecretStorage(): void + { + $result = $this->runHandle( + new GoogleUpdate(), + $this->project([ + 'googleEnabled' => false, + 'googleAppid' => 'google-client', + 'googleSecret' => 'legacy-plain-secret', + ]), + [null, null, ['none'], false], + ); + + $stored = \json_decode($result['updatedProject']->getAttribute('oAuthProviders')['googleSecret'], true); + $this->assertSame('legacy-plain-secret', $stored['clientSecret']); + $this->assertSame(['none'], $stored['prompt']); + $this->assertSame(['none'], $result['response']->getAttribute('prompt')); + } + + public function testGoogleRejectsEmptyPrompt(): void + { + $this->expectException(Exception::class); + + $this->runHandle( + new GoogleUpdate(), + $this->project(), + [ + 'google-client', + 'google-secret', + [], + false, + ], + assertQueueParam: false, + ); + } + + public function testGoogleRejectsNoneWithOtherPrompts(): void + { + $this->expectException(Exception::class); + + $this->runHandle( + new GoogleUpdate(), + $this->project(), + [ + 'google-client', + 'google-secret', + ['none', 'consent'], + false, + ], + assertQueueParam: false, + ); + } + + public function testOktaRequiresDomainWhenEnabling(): void + { + $this->expectException(Exception::class); + + $this->runHandle( + new OktaUpdate(), + $this->project(), + [ + 'okta-client', + 'okta-secret', + '', + null, + true, + ], + assertQueueParam: false, + ); + } + + public function testOktaCanEnableWithStoredDomain(): void + { + $result = $this->runHandle( + new OktaUpdate(), + $this->project([ + 'oktaEnabled' => false, + 'oktaAppid' => 'okta-client', + 'oktaSecret' => \json_encode([ + 'clientSecret' => 'okta-secret', + 'oktaDomain' => 'trial-6400025.okta.com', + 'authorizationServerId' => '', + ]), + ]), + [null, null, null, null, true], + ); + + $this->assertTrue($result['response']->getAttribute('enabled')); + $this->assertSame('trial-6400025.okta.com', $result['response']->getAttribute('domain')); + } + + /** + * @param array $oAuthProviders + */ + private function project(array $oAuthProviders = []): Document + { + return new Document([ + '$id' => 'project-test', + 'oAuthProviders' => $oAuthProviders, + ]); + } + + /** + * @param array $args + * @return array{updatedProject: Document, response: Document} + */ + private function runHandle(Base $action, Document $project, array $args, bool $assertQueueParam = true): array + { + $updatedProject = null; + $responseDocument = null; + + $dbForPlatform = $this->createStub(Database::class); + $dbForPlatform + ->method('updateDocument') + ->willReturnCallback(function (string $collection, string $id, Document $updates) use ($project, &$updatedProject): Document { + $this->assertSame('projects', $collection); + $this->assertSame('project-test', $id); + + $updatedProject = new Document($project->getArrayCopy()); + $updatedProject->setAttribute('oAuthProviders', $updates->getAttribute('oAuthProviders', [])); + + return $updatedProject; + }); + + $authorization = $this->createStub(Authorization::class); + $authorization + ->method('skip') + ->willReturnCallback(fn (callable $callback): mixed => $callback()); + + $response = $this->createStub(Response::class); + $response + ->method('dynamic') + ->willReturnCallback(function (Document $document) use (&$responseDocument): void { + $responseDocument = $document; + }); + + $queueForEvents = $this->getMockBuilder(QueueEvent::class) + ->disableOriginalConstructor() + ->onlyMethods(['setParam']) + ->getMock(); + $queueForEvents + ->expects($assertQueueParam ? $this->once() : $this->atMost(1)) + ->method('setParam') + ->with('providerId', $action::getProviderId()); + + $handle = [$action, 'handle']; + $this->assertIsCallable($handle); + $handle(...[ + ...$args, + $response, + $dbForPlatform, + $project, + $authorization, + $queueForEvents, + ]); + + $this->assertInstanceOf(Document::class, $updatedProject); + $this->assertInstanceOf(Document::class, $responseDocument); + + return [ + 'updatedProject' => $updatedProject, + 'response' => $responseDocument, + ]; + } +} From 77c50c591075e91f4b469083e1759f6c033d99ce Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 3 Jun 2026 16:40:05 +0530 Subject: [PATCH 16/19] feat: expose email metadata fields in user response model --- src/Appwrite/Utopia/Response/Model/User.php | 35 +++++++++++++++++++++ tests/e2e/Services/Account/AccountBase.php | 10 +++--- tests/e2e/Services/Users/UsersBase.php | 15 +++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index 01447ccfc2..b15baa98fb 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -108,6 +108,41 @@ class User extends Model 'default' => false, 'example' => true, ]) + ->addRule('emailCanonical', [ + 'type' => self::TYPE_STRING, + 'description' => 'Canonical form of the user email address.', + 'required' => false, + 'default' => '', + 'example' => 'john@appwrite.io', + ]) + ->addRule('emailIsFree', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether the user email is from a free email provider.', + 'required' => false, + 'default' => null, + 'example' => true, + ]) + ->addRule('emailIsDisposable', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether the user email is from a disposable email provider.', + 'required' => false, + 'default' => null, + 'example' => false, + ]) + ->addRule('emailIsCorporate', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether the user email is from a corporate domain.', + 'required' => false, + 'default' => null, + 'example' => false, + ]) + ->addRule('emailIsCanonical', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether the user email is in its canonical form.', + 'required' => false, + 'default' => null, + 'example' => true, + ]) ->addRule('phoneVerification', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Phone verification status.', diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 8b4dfd4e3e..c752a3bd5a 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -43,11 +43,11 @@ trait AccountBase $this->assertNotEmpty($response['body']['accessedAt']); $this->assertArrayHasKey('targets', $response['body']); $this->assertEquals($email, $response['body']['targets'][0]['identifier']); - $this->assertArrayNotHasKey('emailCanonical', $response['body']); - $this->assertArrayNotHasKey('emailIsFree', $response['body']); - $this->assertArrayNotHasKey('emailIsDisposable', $response['body']); - $this->assertArrayNotHasKey('emailIsCorporate', $response['body']); - $this->assertArrayNotHasKey('emailIsCanonical', $response['body']); + $this->assertArrayHasKey('emailCanonical', $response['body']); + $this->assertArrayHasKey('emailIsFree', $response['body']); + $this->assertArrayHasKey('emailIsDisposable', $response['body']); + $this->assertArrayHasKey('emailIsCorporate', $response['body']); + $this->assertArrayHasKey('emailIsCanonical', $response['body']); /** * Test for FAILURE diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index b06e2d88e1..828476ac07 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -337,6 +337,11 @@ trait UsersBase $this->assertEquals($body['status'], true); $this->assertGreaterThan('2000-01-01 00:00:00', $body['registration']); $this->assertEquals($body['labels'], []); + $this->assertArrayHasKey('emailCanonical', $body); + $this->assertArrayHasKey('emailIsFree', $body); + $this->assertArrayHasKey('emailIsDisposable', $body); + $this->assertArrayHasKey('emailIsCorporate', $body); + $this->assertArrayHasKey('emailIsCanonical', $body); /** * Test Create with Custom ID for SUCCESS @@ -751,6 +756,11 @@ trait UsersBase } } $this->assertNotNull($user1, 'user1 should exist in user list'); + $this->assertArrayHasKey('emailCanonical', $user1); + $this->assertArrayHasKey('emailIsFree', $user1); + $this->assertArrayHasKey('emailIsDisposable', $user1); + $this->assertArrayHasKey('emailIsCorporate', $user1); + $this->assertArrayHasKey('emailIsCanonical', $user1); // This test ensures that by default, endpoints dont support select queries // If we add select query to this endpoint, you will need to remove this test @@ -1092,6 +1102,11 @@ trait UsersBase $this->assertNotEmpty($user['body']['email']); $this->assertEquals($user['body']['status'], true); $this->assertGreaterThan('2000-01-01 00:00:00', $user['body']['registration']); + $this->assertArrayHasKey('emailCanonical', $user['body']); + $this->assertArrayHasKey('emailIsFree', $user['body']); + $this->assertArrayHasKey('emailIsDisposable', $user['body']); + $this->assertArrayHasKey('emailIsCorporate', $user['body']); + $this->assertArrayHasKey('emailIsCanonical', $user['body']); $sessions = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/sessions', array_merge([ 'content-type' => 'application/json', From 62c52efdbcc55b64f335dca819cac8cd3451fe53 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Wed, 3 Jun 2026 17:03:11 +0530 Subject: [PATCH 17/19] fix: add email metadata fields to Account response model --- .../Utopia/Response/Model/Account.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Appwrite/Utopia/Response/Model/Account.php b/src/Appwrite/Utopia/Response/Model/Account.php index aaaf501a88..befa88a181 100644 --- a/src/Appwrite/Utopia/Response/Model/Account.php +++ b/src/Appwrite/Utopia/Response/Model/Account.php @@ -78,6 +78,41 @@ class Account extends Model 'default' => false, 'example' => true, ]) + ->addRule('emailCanonical', [ + 'type' => self::TYPE_STRING, + 'description' => 'Canonical form of the user email address.', + 'required' => false, + 'default' => '', + 'example' => 'john@appwrite.io', + ]) + ->addRule('emailIsFree', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether the user email is from a free email provider.', + 'required' => false, + 'default' => null, + 'example' => true, + ]) + ->addRule('emailIsDisposable', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether the user email is from a disposable email provider.', + 'required' => false, + 'default' => null, + 'example' => false, + ]) + ->addRule('emailIsCorporate', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether the user email is from a corporate domain.', + 'required' => false, + 'default' => null, + 'example' => false, + ]) + ->addRule('emailIsCanonical', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether the user email is in its canonical form.', + 'required' => false, + 'default' => null, + 'example' => true, + ]) ->addRule('phoneVerification', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Phone verification status.', From 99ae69bdc3a4122d2f21665c6cdeac88ae4eae31 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 19:44:00 +0530 Subject: [PATCH 18/19] test: assert exact values for email metadata fields in account and user tests --- tests/e2e/Services/Account/AccountBase.php | 10 +++++----- tests/e2e/Services/Users/UsersBase.php | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index c752a3bd5a..0f55f9dc0d 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -43,11 +43,11 @@ trait AccountBase $this->assertNotEmpty($response['body']['accessedAt']); $this->assertArrayHasKey('targets', $response['body']); $this->assertEquals($email, $response['body']['targets'][0]['identifier']); - $this->assertArrayHasKey('emailCanonical', $response['body']); - $this->assertArrayHasKey('emailIsFree', $response['body']); - $this->assertArrayHasKey('emailIsDisposable', $response['body']); - $this->assertArrayHasKey('emailIsCorporate', $response['body']); - $this->assertArrayHasKey('emailIsCanonical', $response['body']); + $this->assertEquals($email, $response['body']['emailCanonical']); + $this->assertEquals(false, $response['body']['emailIsFree']); + $this->assertEquals(false, $response['body']['emailIsDisposable']); + $this->assertEquals(true, $response['body']['emailIsCorporate']); + $this->assertEquals(true, $response['body']['emailIsCanonical']); /** * Test for FAILURE diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 828476ac07..eeadbfa925 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -337,11 +337,11 @@ trait UsersBase $this->assertEquals($body['status'], true); $this->assertGreaterThan('2000-01-01 00:00:00', $body['registration']); $this->assertEquals($body['labels'], []); - $this->assertArrayHasKey('emailCanonical', $body); - $this->assertArrayHasKey('emailIsFree', $body); - $this->assertArrayHasKey('emailIsDisposable', $body); - $this->assertArrayHasKey('emailIsCorporate', $body); - $this->assertArrayHasKey('emailIsCanonical', $body); + $this->assertEquals('cristiano.ronaldo@manchester-united.co.uk', $body['emailCanonical']); + $this->assertEquals(false, $body['emailIsFree']); + $this->assertEquals(false, $body['emailIsDisposable']); + $this->assertEquals(true, $body['emailIsCorporate']); + $this->assertEquals(true, $body['emailIsCanonical']); /** * Test Create with Custom ID for SUCCESS From 6aa9b80e366e05a0ba2dbedfcfad734500b60f47 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 20:34:37 +0530 Subject: [PATCH 19/19] fix: correct emailIsCorporate example value and relax localhost.test domain assertions --- src/Appwrite/Utopia/Response/Model/Account.php | 2 +- src/Appwrite/Utopia/Response/Model/User.php | 2 +- tests/e2e/Services/Account/AccountBase.php | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/Account.php b/src/Appwrite/Utopia/Response/Model/Account.php index befa88a181..fb03bdb155 100644 --- a/src/Appwrite/Utopia/Response/Model/Account.php +++ b/src/Appwrite/Utopia/Response/Model/Account.php @@ -104,7 +104,7 @@ class Account extends Model 'description' => 'Whether the user email is from a corporate domain.', 'required' => false, 'default' => null, - 'example' => false, + 'example' => true, ]) ->addRule('emailIsCanonical', [ 'type' => self::TYPE_BOOLEAN, diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index b15baa98fb..f255519bfd 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -134,7 +134,7 @@ class User extends Model 'description' => 'Whether the user email is from a corporate domain.', 'required' => false, 'default' => null, - 'example' => false, + 'example' => true, ]) ->addRule('emailIsCanonical', [ 'type' => self::TYPE_BOOLEAN, diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 0f55f9dc0d..1804e621de 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -44,10 +44,10 @@ trait AccountBase $this->assertArrayHasKey('targets', $response['body']); $this->assertEquals($email, $response['body']['targets'][0]['identifier']); $this->assertEquals($email, $response['body']['emailCanonical']); - $this->assertEquals(false, $response['body']['emailIsFree']); - $this->assertEquals(false, $response['body']['emailIsDisposable']); - $this->assertEquals(true, $response['body']['emailIsCorporate']); - $this->assertEquals(true, $response['body']['emailIsCanonical']); + $this->assertIsBool($response['body']['emailIsFree']); + $this->assertIsBool($response['body']['emailIsDisposable']); + $this->assertIsBool($response['body']['emailIsCorporate']); + $this->assertIsBool($response['body']['emailIsCanonical']); /** * Test for FAILURE