From e33f8026e6a01409032c9a10da2c3ed5e69cd79b Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 8 Apr 2026 17:00:32 +0400 Subject: [PATCH 01/16] Add project password policy settings --- app/controllers/api/account.php | 6 +- app/controllers/api/projects.php | 200 ++++++++++++++++ app/controllers/api/users.php | 4 +- .../update-auth-password-policy-lowercase.md | 1 + .../update-auth-password-policy-min-length.md | 1 + .../update-auth-password-policy-number.md | 1 + ...pdate-auth-password-policy-special-char.md | 1 + .../update-auth-password-policy-uppercase.md | 1 + .../Auth/Validator/PasswordDictionary.php | 8 +- .../Auth/Validator/PasswordPolicy.php | 89 +++++++ .../Modules/Projects/Http/Projects/Create.php | 7 + .../Utopia/Response/Model/Project.php | 36 +++ .../Projects/ProjectsConsoleClientTest.php | 223 ++++++++++++++++++ .../Auth/Validator/PasswordPolicyTest.php | 48 ++++ 14 files changed, 617 insertions(+), 9 deletions(-) create mode 100644 docs/references/projects/update-auth-password-policy-lowercase.md create mode 100644 docs/references/projects/update-auth-password-policy-min-length.md create mode 100644 docs/references/projects/update-auth-password-policy-number.md create mode 100644 docs/references/projects/update-auth-password-policy-special-char.md create mode 100644 docs/references/projects/update-auth-password-policy-uppercase.md create mode 100644 src/Appwrite/Auth/Validator/PasswordPolicy.php create mode 100644 tests/unit/Auth/Validator/PasswordPolicyTest.php diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 8eb49ea27b..7ab7c44e7e 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -394,7 +394,7 @@ Http::post('/v1/account') ->label('abuse-limit', 10) ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', '', new EmailValidator(), 'User email.') - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false, false, $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('request') ->inject('response') @@ -3378,7 +3378,7 @@ Http::patch('/v1/account/password') contentType: ContentType::JSON )) ->label('abuse-limit', 10) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false, false, $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) ->param('oldPassword', '', new Password(), 'Current user password. Must be at least 8 chars.', true) ->inject('response') ->inject('user') @@ -3988,7 +3988,7 @@ Http::put('/v1/account/recovery') ->label('abuse-key', 'url:{url},userId:{param-userId}') ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) ->param('secret', '', new Text(256), 'Valid reset token.') - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false, false, $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('user') ->inject('dbForProject') diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index dac6ed456a..6b77acab0f 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -555,6 +555,206 @@ Http::patch('/v1/projects/:projectId/auth/password-history') $response->dynamic($project, Response::MODEL_PROJECT); }); +Http::patch('/v1/projects/:projectId/auth/password-policy/min-length') + ->desc('Update the minimum password length requirement.') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk', new Method( + namespace: 'projects', + group: 'auth', + name: 'updateAuthPasswordPolicyMinLength', + description: '/docs/references/projects/update-auth-password-policy-min-length.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ) + ] + )) + ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) + ->param('minLength', 8, new Range(8, 256), 'Set the minimum password length. Value must be between 8 and 256. Default is 8.') + ->inject('response') + ->inject('dbForPlatform') + ->action(function (string $projectId, int $minLength, Response $response, Database $dbForPlatform) { + + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $auths = $project->getAttribute('auths', []); + $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ + 'minLength' => $minLength, + ]); + + $dbForPlatform->updateDocument('projects', $project->getId(), $project + ->setAttribute('auths', $auths)); + + $response->dynamic($project, Response::MODEL_PROJECT); + }); + +Http::patch('/v1/projects/:projectId/auth/password-policy/uppercase') + ->desc('Update the uppercase password requirement.') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk', new Method( + namespace: 'projects', + group: 'auth', + name: 'updateAuthPasswordPolicyUppercase', + description: '/docs/references/projects/update-auth-password-policy-uppercase.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ) + ] + )) + ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) + ->param('enabled', false, new Boolean(false), 'Set whether or not passwords must include at least one uppercase letter. Default is false.') + ->inject('response') + ->inject('dbForPlatform') + ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { + + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $auths = $project->getAttribute('auths', []); + $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ + 'requireUppercase' => $enabled, + ]); + + $dbForPlatform->updateDocument('projects', $project->getId(), $project + ->setAttribute('auths', $auths)); + + $response->dynamic($project, Response::MODEL_PROJECT); + }); + +Http::patch('/v1/projects/:projectId/auth/password-policy/lowercase') + ->desc('Update the lowercase password requirement.') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk', new Method( + namespace: 'projects', + group: 'auth', + name: 'updateAuthPasswordPolicyLowercase', + description: '/docs/references/projects/update-auth-password-policy-lowercase.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ) + ] + )) + ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) + ->param('enabled', false, new Boolean(false), 'Set whether or not passwords must include at least one lowercase letter. Default is false.') + ->inject('response') + ->inject('dbForPlatform') + ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { + + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $auths = $project->getAttribute('auths', []); + $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ + 'requireLowercase' => $enabled, + ]); + + $dbForPlatform->updateDocument('projects', $project->getId(), $project + ->setAttribute('auths', $auths)); + + $response->dynamic($project, Response::MODEL_PROJECT); + }); + +Http::patch('/v1/projects/:projectId/auth/password-policy/number') + ->desc('Update the numeric password requirement.') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk', new Method( + namespace: 'projects', + group: 'auth', + name: 'updateAuthPasswordPolicyNumber', + description: '/docs/references/projects/update-auth-password-policy-number.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ) + ] + )) + ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) + ->param('enabled', false, new Boolean(false), 'Set whether or not passwords must include at least one number. Default is false.') + ->inject('response') + ->inject('dbForPlatform') + ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { + + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $auths = $project->getAttribute('auths', []); + $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ + 'requireNumber' => $enabled, + ]); + + $dbForPlatform->updateDocument('projects', $project->getId(), $project + ->setAttribute('auths', $auths)); + + $response->dynamic($project, Response::MODEL_PROJECT); + }); + +Http::patch('/v1/projects/:projectId/auth/password-policy/special-char') + ->desc('Update the special character password requirement.') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk', new Method( + namespace: 'projects', + group: 'auth', + name: 'updateAuthPasswordPolicySpecialChar', + description: '/docs/references/projects/update-auth-password-policy-special-char.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ) + ] + )) + ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) + ->param('enabled', false, new Boolean(false), 'Set whether or not passwords must include at least one special character. Default is false.') + ->inject('response') + ->inject('dbForPlatform') + ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { + + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $auths = $project->getAttribute('auths', []); + $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ + 'requireSpecialChar' => $enabled, + ]); + + $dbForPlatform->updateDocument('projects', $project->getId(), $project + ->setAttribute('auths', $auths)); + + $response->dynamic($project, Response::MODEL_PROJECT); + }); + Http::patch('/v1/projects/:projectId/auth/password-dictionary') ->desc('Update authentication password dictionary status. Use this endpoint to enable or disable the dicitonary check for user password') ->groups(['api', 'projects']) diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 51fc3d03c7..b7990b1eac 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -278,7 +278,7 @@ Http::post('/v1/users') ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', null, new Nullable(new EmailValidator()), 'User email.', true) ->param('phone', null, new Nullable(new Phone()), 'Phone number. Format this number with a leading \'+\' and a country code, e.g., +16175551212.', true) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false), 'Plain text user password. Must be at least 8 chars.', true, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false, false, $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'Plain text user password. Must be at least 8 chars.', true, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('response') ->inject('project') @@ -1395,7 +1395,7 @@ Http::patch('/v1/users/:userId/password') ] )) ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, allowEmpty: true), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, allowEmpty: true, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('project') ->inject('dbForProject') diff --git a/docs/references/projects/update-auth-password-policy-lowercase.md b/docs/references/projects/update-auth-password-policy-lowercase.md new file mode 100644 index 0000000000..139930d20e --- /dev/null +++ b/docs/references/projects/update-auth-password-policy-lowercase.md @@ -0,0 +1 @@ +Update whether authentication passwords must include at least one lowercase letter. diff --git a/docs/references/projects/update-auth-password-policy-min-length.md b/docs/references/projects/update-auth-password-policy-min-length.md new file mode 100644 index 0000000000..9a01d51543 --- /dev/null +++ b/docs/references/projects/update-auth-password-policy-min-length.md @@ -0,0 +1 @@ +Update the minimum authentication password length requirement. diff --git a/docs/references/projects/update-auth-password-policy-number.md b/docs/references/projects/update-auth-password-policy-number.md new file mode 100644 index 0000000000..fe7866fb88 --- /dev/null +++ b/docs/references/projects/update-auth-password-policy-number.md @@ -0,0 +1 @@ +Update whether authentication passwords must include at least one number. diff --git a/docs/references/projects/update-auth-password-policy-special-char.md b/docs/references/projects/update-auth-password-policy-special-char.md new file mode 100644 index 0000000000..7c1b718252 --- /dev/null +++ b/docs/references/projects/update-auth-password-policy-special-char.md @@ -0,0 +1 @@ +Update whether authentication passwords must include at least one special character. diff --git a/docs/references/projects/update-auth-password-policy-uppercase.md b/docs/references/projects/update-auth-password-policy-uppercase.md new file mode 100644 index 0000000000..a64ab65d0a --- /dev/null +++ b/docs/references/projects/update-auth-password-policy-uppercase.md @@ -0,0 +1 @@ +Update whether authentication passwords must include at least one uppercase letter. diff --git a/src/Appwrite/Auth/Validator/PasswordDictionary.php b/src/Appwrite/Auth/Validator/PasswordDictionary.php index 99a6c81525..290ca5766b 100644 --- a/src/Appwrite/Auth/Validator/PasswordDictionary.php +++ b/src/Appwrite/Auth/Validator/PasswordDictionary.php @@ -7,14 +7,14 @@ namespace Appwrite\Auth\Validator; * * Validates user password string */ -class PasswordDictionary extends Password +class PasswordDictionary extends PasswordPolicy { protected array $dictionary; protected bool $enabled; - public function __construct(array $dictionary, bool $enabled = false, bool $allowEmpty = false) + public function __construct(array $dictionary, bool $enabled = false, bool $allowEmpty = false, array $policy = []) { - parent::__construct($allowEmpty); + parent::__construct($policy, $allowEmpty); $this->dictionary = $dictionary; $this->enabled = $enabled; } @@ -28,7 +28,7 @@ class PasswordDictionary extends Password */ public function getDescription(): string { - return 'Password must be between 8 and 265 characters long, and should not be one of the commonly used password.'; + return parent::getDescription() . ' It should not be one of the commonly used passwords.'; } /** diff --git a/src/Appwrite/Auth/Validator/PasswordPolicy.php b/src/Appwrite/Auth/Validator/PasswordPolicy.php new file mode 100644 index 0000000000..6fdb11d15a --- /dev/null +++ b/src/Appwrite/Auth/Validator/PasswordPolicy.php @@ -0,0 +1,89 @@ +minLength = $policy['minLength'] ?? 8; + $this->requireUppercase = $policy['requireUppercase'] ?? false; + $this->requireLowercase = $policy['requireLowercase'] ?? false; + $this->requireNumber = $policy['requireNumber'] ?? false; + $this->requireSpecialChar = $policy['requireSpecialChar'] ?? false; + } + + public function getDescription(): string + { + $requirements = [ + 'between ' . $this->minLength . ' and 256 characters long', + ]; + + if ($this->requireUppercase) { + $requirements[] = 'include an uppercase letter'; + } + + if ($this->requireLowercase) { + $requirements[] = 'include a lowercase letter'; + } + + if ($this->requireNumber) { + $requirements[] = 'include a number'; + } + + if ($this->requireSpecialChar) { + $requirements[] = 'include a special character'; + } + + return 'Password must be ' . \implode(', ', $requirements) . '.'; + } + + /** + * @param mixed $value + */ + public function isValid($value): bool + { + if (!parent::isValid($value)) { + return false; + } + + if ($this->allowEmpty && \strlen($value) === 0) { + return true; + } + + if (\strlen($value) < $this->minLength) { + return false; + } + + if ($this->requireUppercase && !\preg_match('/[A-Z]/', $value)) { + return false; + } + + if ($this->requireLowercase && !\preg_match('/[a-z]/', $value)) { + return false; + } + + if ($this->requireNumber && !\preg_match('/\d/', $value)) { + return false; + } + + if ($this->requireSpecialChar && !\preg_match("/[!\"#$%&'()*+,\-.\/:;<=>?@[\\\\\]^_`{|}~]/", $value)) { + return false; + } + + return true; + } +} diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index 9070962e7d..d43fe3e071 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -110,6 +110,13 @@ class Create extends Action $auths = [ 'limit' => 0, 'maxSessions' => APP_LIMIT_USER_SESSIONS_DEFAULT, + 'passwordPolicy' => [ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ], 'passwordHistory' => 0, 'passwordDictionary' => false, 'duration' => TOKEN_EXPIRATION_LOGIN_LONG, diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index 1ef73aa769..4001d61fbf 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -120,6 +120,36 @@ class Project extends Model 'default' => 0, 'example' => 5, ]) + ->addRule('authPasswordPolicyMinLength', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Minimum password length required for user passwords.', + 'default' => 8, + 'example' => 12, + ]) + ->addRule('authPasswordPolicyRequireUppercase', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether or not passwords must include at least one uppercase letter.', + 'default' => false, + 'example' => true, + ]) + ->addRule('authPasswordPolicyRequireLowercase', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether or not passwords must include at least one lowercase letter.', + 'default' => false, + 'example' => true, + ]) + ->addRule('authPasswordPolicyRequireNumber', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether or not passwords must include at least one number.', + 'default' => false, + 'example' => true, + ]) + ->addRule('authPasswordPolicyRequireSpecialChar', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether or not passwords must include at least one special character.', + 'default' => false, + 'example' => true, + ]) ->addRule('authPasswordDictionary', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether or not to check user\'s password against most commonly used passwords.', @@ -426,12 +456,18 @@ class Project extends Model } $authValues = $document->getAttribute('auths', []); + $passwordPolicy = $authValues['passwordPolicy'] ?? []; $auth = Config::getParam('auth', []); $document->setAttribute('authLimit', $authValues['limit'] ?? 0); $document->setAttribute('authDuration', $authValues['duration'] ?? TOKEN_EXPIRATION_LOGIN_LONG); $document->setAttribute('authSessionsLimit', $authValues['maxSessions'] ?? APP_LIMIT_USER_SESSIONS_DEFAULT); $document->setAttribute('authPasswordHistory', $authValues['passwordHistory'] ?? 0); + $document->setAttribute('authPasswordPolicyMinLength', $passwordPolicy['minLength'] ?? 8); + $document->setAttribute('authPasswordPolicyRequireUppercase', $passwordPolicy['requireUppercase'] ?? false); + $document->setAttribute('authPasswordPolicyRequireLowercase', $passwordPolicy['requireLowercase'] ?? false); + $document->setAttribute('authPasswordPolicyRequireNumber', $passwordPolicy['requireNumber'] ?? false); + $document->setAttribute('authPasswordPolicyRequireSpecialChar', $passwordPolicy['requireSpecialChar'] ?? false); $document->setAttribute('authPasswordDictionary', $authValues['passwordDictionary'] ?? false); $document->setAttribute('authPersonalDataCheck', $authValues['personalDataCheck'] ?? false); $document->setAttribute('authDisposableEmails', $authValues['disposableEmails'] ?? false); diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index e0f94b64cc..8e0cf1f87e 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2006,6 +2006,229 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(0, $response['body']['authPasswordHistory']); } + public function testUpdateProjectAuthPasswordPolicy(): void + { + $data = $this->setupProjectData(); + $id = $data['projectId']; + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/min-length', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'minLength' => 7, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/min-length', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'minLength' => 12, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/uppercase', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/lowercase', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/number', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/special-char', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(12, $response['body']['authPasswordPolicyMinLength']); + $this->assertEquals(true, $response['body']['authPasswordPolicyRequireUppercase']); + $this->assertEquals(true, $response['body']['authPasswordPolicyRequireLowercase']); + $this->assertEquals(true, $response['body']['authPasswordPolicyRequireNumber']); + $this->assertEquals(true, $response['body']['authPasswordPolicyRequireSpecialChar']); + + $weakPassword = 'password123!'; + $validPassword = 'Password123!'; + $email = uniqid() . 'user@localhost.test'; + + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'userId' => ID::unique(), + 'email' => uniqid() . 'weak-account@localhost.test', + 'password' => $weakPassword, + 'name' => 'Weak Account', + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/users', array_merge($this->getHeaders(), [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ]), [ + 'userId' => ID::unique(), + 'email' => uniqid() . 'weak-user@localhost.test', + 'password' => $weakPassword, + 'name' => 'Weak User', + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'userId' => ID::unique(), + 'email' => $email, + 'password' => $validPassword, + 'name' => 'Password Policy User', + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $userId = $response['body']['$id']; + + $session = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ], [ + 'email' => $email, + 'password' => $validPassword, + ]); + + $this->assertEquals(201, $session['headers']['status-code']); + $session = $session['cookies']['a_session_' . $id]; + + $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'cookie' => 'a_session_' . $id . '=' . $session, + ]), [ + 'oldPassword' => $validPassword, + 'password' => $weakPassword, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/account/recovery', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'email' => $email, + 'url' => 'http://localhost/recovery', + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + $lastEmail = $this->getLastEmailByAddress($email, function ($email) { + $this->assertStringContainsString('Password Reset', $email['subject']); + }); + $tokens = $this->extractQueryParamsFromEmailLink($lastEmail['html']); + + $response = $this->client->call(Client::METHOD_PUT, '/account/recovery', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'userId' => $userId, + 'secret' => $tokens['secret'], + 'password' => $weakPassword, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $headers = array_merge($this->getHeaders(), [ + 'x-appwrite-mode' => 'admin', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]); + + $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/password', $headers, [ + 'password' => $weakPassword, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/min-length', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'minLength' => 8, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/uppercase', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/lowercase', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/number', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/special-char', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(8, $response['body']['authPasswordPolicyMinLength']); + $this->assertEquals(false, $response['body']['authPasswordPolicyRequireUppercase']); + $this->assertEquals(false, $response['body']['authPasswordPolicyRequireLowercase']); + $this->assertEquals(false, $response['body']['authPasswordPolicyRequireNumber']); + $this->assertEquals(false, $response['body']['authPasswordPolicyRequireSpecialChar']); + } + #[Group('smtpAndTemplates')] #[Group('projectsCRUD')] public function testUpdateMockNumbers(): void diff --git a/tests/unit/Auth/Validator/PasswordPolicyTest.php b/tests/unit/Auth/Validator/PasswordPolicyTest.php new file mode 100644 index 0000000000..a342455f61 --- /dev/null +++ b/tests/unit/Auth/Validator/PasswordPolicyTest.php @@ -0,0 +1,48 @@ +assertFalse($validator->isValid('1234567')); + $this->assertTrue($validator->isValid('password')); + } + + public function testConfiguredPolicy(): void + { + $validator = new PasswordPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ]); + + $this->assertFalse($validator->isValid('Password1!')); + $this->assertFalse($validator->isValid('password123!')); + $this->assertFalse($validator->isValid('PASSWORD123!')); + $this->assertFalse($validator->isValid('PasswordOnly!')); + $this->assertFalse($validator->isValid('Password1234')); + $this->assertTrue($validator->isValid('Password123!')); + } + + public function testAllowEmpty(): void + { + $validator = new PasswordPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ], true); + + $this->assertTrue($validator->isValid('')); + } +} From 4f65f8878935713ea04d0699972e1ee74e61f659 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 9 Apr 2026 11:40:07 +0400 Subject: [PATCH 02/16] Use named password validator arguments --- app/controllers/api/account.php | 6 +++--- app/controllers/api/users.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 7ab7c44e7e..1a7a512a0b 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -394,7 +394,7 @@ Http::post('/v1/account') ->label('abuse-limit', 10) ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', '', new EmailValidator(), 'User email.') - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false, false, $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('request') ->inject('response') @@ -3378,7 +3378,7 @@ Http::patch('/v1/account/password') contentType: ContentType::JSON )) ->label('abuse-limit', 10) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false, false, $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) ->param('oldPassword', '', new Password(), 'Current user password. Must be at least 8 chars.', true) ->inject('response') ->inject('user') @@ -3988,7 +3988,7 @@ Http::put('/v1/account/recovery') ->label('abuse-key', 'url:{url},userId:{param-userId}') ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) ->param('secret', '', new Text(256), 'Valid reset token.') - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false, false, $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('user') ->inject('dbForProject') diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index b7990b1eac..2153599da2 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -278,7 +278,7 @@ Http::post('/v1/users') ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', null, new Nullable(new EmailValidator()), 'User email.', true) ->param('phone', null, new Nullable(new Phone()), 'Phone number. Format this number with a leading \'+\' and a country code, e.g., +16175551212.', true) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, $project->getAttribute('auths', [])['passwordDictionary'] ?? false, false, $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'Plain text user password. Must be at least 8 chars.', true, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'Plain text user password. Must be at least 8 chars.', true, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('response') ->inject('project') From 23b0aa2f7038da774092c78af269396919728bf2 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 21 May 2026 19:22:09 +0400 Subject: [PATCH 03/16] Adapt password policy to project policies API --- app/controllers/api/projects.php | 553 ------------------ app/init/models.php | 2 + .../Project/Http/Project/Policies/Get.php | 16 +- .../Policies/PasswordPolicy/Update.php | 99 ++++ .../Project/Http/Project/Policies/XList.php | 9 + .../Modules/Project/Services/Http.php | 2 + src/Appwrite/Utopia/Response.php | 1 + .../Utopia/Response/Model/PolicyList.php | 3 +- .../Response/Model/PolicyPasswordPolicy.php | 59 ++ tests/e2e/Services/Project/PoliciesBase.php | 129 +++- .../Projects/ProjectsConsoleClientTest.php | 96 +-- 11 files changed, 332 insertions(+), 637 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPolicy/Update.php create mode 100644 src/Appwrite/Utopia/Response/Model/PolicyPasswordPolicy.php diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 2fa5ce97f0..8ab30fac99 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -2,9 +2,6 @@ use Appwrite\Auth\Validator\MockNumber; use Appwrite\Extend\Exception; -use Appwrite\SDK\AuthType; -use Appwrite\SDK\Method; -use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response; use Utopia\Config\Config; use Utopia\Database\Database; @@ -15,7 +12,6 @@ use Utopia\System\System; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; -use Utopia\Validator\Range; use Utopia\Validator\Text; use Utopia\Validator\WhiteList; @@ -67,555 +63,6 @@ Http::patch('/v1/projects/:projectId/oauth2') $response->dynamic($project, Response::MODEL_PROJECT); }); -Http::patch('/v1/projects/:projectId/auth/session-alerts') - ->desc('Update project sessions emails') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateSessionAlerts', - description: '/docs/references/projects/update-session-alerts.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('alerts', false, new Boolean(true), 'Set to true to enable session emails.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, bool $alerts, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['sessionAlerts'] = $alerts; - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/memberships-privacy') - ->desc('Update project memberships privacy attributes') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateMembershipsPrivacy', - description: '/docs/references/projects/update-memberships-privacy.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('userName', true, new Boolean(true), 'Set to true to show userName to members of a team.') - ->param('userEmail', true, new Boolean(true), 'Set to true to show email to members of a team.') - ->param('mfa', true, new Boolean(true), 'Set to true to show mfa to members of a team.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, bool $userName, bool $userEmail, bool $mfa, Response $response, Database $dbForPlatform) { - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - - $auths['membershipsUserName'] = $userName; - $auths['membershipsUserEmail'] = $userEmail; - $auths['membershipsMfa'] = $mfa; - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/limit') - ->desc('Update project users limit') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthLimit', - description: '/docs/references/projects/update-auth-limit.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('limit', false, new Range(0, APP_LIMIT_USERS), 'Set the max number of users allowed in this project. Use 0 for unlimited.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, int $limit, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['limit'] = $limit; - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/duration') - ->desc('Update project authentication duration') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthDuration', - description: '/docs/references/projects/update-auth-duration.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('duration', 31536000, new Range(0, 31536000), 'Project session length in seconds. Max length: 31536000 seconds.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, int $duration, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['duration'] = $duration; - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/:method') - ->desc('Update project auth method status. Use this endpoint to enable or disable a given auth method for this project.') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthStatus', - description: '/docs/references/projects/update-auth-status.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('method', '', new WhiteList(\array_keys(Config::getParam('auth')), true), 'Auth Method. Possible values: ' . implode(',', \array_keys(Config::getParam('auth'))), false) - ->param('status', false, new Boolean(true), 'Set the status of this auth method.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, string $method, bool $status, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - $auth = Config::getParam('auth')[$method] ?? []; - $authKey = $auth['key'] ?? ''; - $status = ($status === '1' || $status === 'true' || $status === 1 || $status === true); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths[$authKey] = $status; - - $project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/password-history') - ->desc('Update authentication password history. Use this endpoint to set the number of password history to save and 0 to disable password history.') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthPasswordHistory', - description: '/docs/references/projects/update-auth-password-history.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('limit', 0, new Range(0, APP_LIMIT_USER_PASSWORD_HISTORY), 'Set the max number of passwords to store in user history. User can\'t choose a new password that is already stored in the password history list. Max number of passwords allowed in history is' . APP_LIMIT_USER_PASSWORD_HISTORY . '. Default value is 0') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, int $limit, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['passwordHistory'] = $limit; - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/password-policy/min-length') - ->desc('Update the minimum password length requirement.') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthPasswordPolicyMinLength', - description: '/docs/references/projects/update-auth-password-policy-min-length.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('minLength', 8, new Range(8, 256), 'Set the minimum password length. Value must be between 8 and 256. Default is 8.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, int $minLength, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ - 'minLength' => $minLength, - ]); - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/password-policy/uppercase') - ->desc('Update the uppercase password requirement.') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthPasswordPolicyUppercase', - description: '/docs/references/projects/update-auth-password-policy-uppercase.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('enabled', false, new Boolean(false), 'Set whether or not passwords must include at least one uppercase letter. Default is false.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ - 'requireUppercase' => $enabled, - ]); - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/password-policy/lowercase') - ->desc('Update the lowercase password requirement.') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthPasswordPolicyLowercase', - description: '/docs/references/projects/update-auth-password-policy-lowercase.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('enabled', false, new Boolean(false), 'Set whether or not passwords must include at least one lowercase letter. Default is false.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ - 'requireLowercase' => $enabled, - ]); - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/password-policy/number') - ->desc('Update the numeric password requirement.') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthPasswordPolicyNumber', - description: '/docs/references/projects/update-auth-password-policy-number.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('enabled', false, new Boolean(false), 'Set whether or not passwords must include at least one number. Default is false.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ - 'requireNumber' => $enabled, - ]); - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/password-policy/special-char') - ->desc('Update the special character password requirement.') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthPasswordPolicySpecialChar', - description: '/docs/references/projects/update-auth-password-policy-special-char.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('enabled', false, new Boolean(false), 'Set whether or not passwords must include at least one special character. Default is false.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['passwordPolicy'] = \array_merge($auths['passwordPolicy'] ?? [], [ - 'requireSpecialChar' => $enabled, - ]); - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/password-dictionary') - ->desc('Update authentication password dictionary status. Use this endpoint to enable or disable the dicitonary check for user password') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthPasswordDictionary', - description: '/docs/references/projects/update-auth-password-dictionary.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('enabled', false, new Boolean(false), 'Set whether or not to enable checking user\'s password against most commonly used passwords. Default is false.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['passwordDictionary'] = $enabled; - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/personal-data') - ->desc('Update personal data check') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updatePersonalDataCheck', - description: '/docs/references/projects/update-personal-data-check.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('enabled', false, new Boolean(false), 'Set whether or not to check a password for similarity with personal data. Default is false.') - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, bool $enabled, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['personalDataCheck'] = $enabled; - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - -Http::patch('/v1/projects/:projectId/auth/max-sessions') - ->desc('Update project user sessions limit') - ->groups(['api', 'projects']) - ->label('scope', 'projects.write') - ->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateAuthSessionsLimit', - description: '/docs/references/projects/update-auth-sessions-limit.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] - )) - ->param('projectId', '', fn (Database $dbForPlatform) => new UID($dbForPlatform->getAdapter()->getMaxUIDLength()), 'Project unique ID.', false, ['dbForPlatform']) - ->param('limit', false, new Range(1, APP_LIMIT_USER_SESSIONS_MAX), 'Set the max number of users allowed in this project. Value allowed is between 1-' . APP_LIMIT_USER_SESSIONS_MAX . '. Default is ' . APP_LIMIT_USER_SESSIONS_DEFAULT) - ->inject('response') - ->inject('dbForPlatform') - ->action(function (string $projectId, int $limit, Response $response, Database $dbForPlatform) { - - $project = $dbForPlatform->getDocument('projects', $projectId); - - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } - - $auths = $project->getAttribute('auths', []); - $auths['maxSessions'] = $limit; - - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); - - $response->dynamic($project, Response::MODEL_PROJECT); - }); - // Backwards compatibility Http::patch('/v1/projects/:projectId/auth/mock-numbers') ->desc('Update the mock numbers for the project') diff --git a/app/init/models.php b/app/init/models.php index 08ebc3af23..22ccd73c9d 100644 --- a/app/init/models.php +++ b/app/init/models.php @@ -167,6 +167,7 @@ use Appwrite\Utopia\Response\Model\PolicyList; use Appwrite\Utopia\Response\Model\PolicyMembershipPrivacy; use Appwrite\Utopia\Response\Model\PolicyPasswordDictionary; use Appwrite\Utopia\Response\Model\PolicyPasswordHistory; +use Appwrite\Utopia\Response\Model\PolicyPasswordPolicy; use Appwrite\Utopia\Response\Model\PolicyPasswordPersonalData; use Appwrite\Utopia\Response\Model\PolicySessionAlert; use Appwrite\Utopia\Response\Model\PolicySessionDuration; @@ -460,6 +461,7 @@ Response::setModel(new OAuth2Microsoft()); Response::setModel(new OAuth2ProviderList()); Response::setModel(new PolicyPasswordDictionary()); Response::setModel(new PolicyPasswordHistory()); +Response::setModel(new PolicyPasswordPolicy()); Response::setModel(new PolicyPasswordPersonalData()); Response::setModel(new PolicySessionAlert()); Response::setModel(new PolicySessionDuration()); 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 21342332d9..8d3653c5b3 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php @@ -42,6 +42,7 @@ class Get extends Action model: [ Response::MODEL_POLICY_PASSWORD_DICTIONARY, Response::MODEL_POLICY_PASSWORD_HISTORY, + Response::MODEL_POLICY_PASSWORD_POLICY, Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA, Response::MODEL_POLICY_SESSION_ALERT, Response::MODEL_POLICY_SESSION_DURATION, @@ -56,6 +57,7 @@ class Get extends Action ->param('policyId', '', new WhiteList([ 'password-dictionary', 'password-history', + 'password-policy', 'password-personal-data', 'session-alert', 'session-duration', @@ -63,7 +65,7 @@ class Get extends Action 'session-limit', 'user-limit', 'membership-privacy', - ], true), 'Policy ID. Can be one of: password-dictionary, password-history, password-personal-data, session-alert, session-duration, session-invalidation, session-limit, user-limit, membership-privacy.') + ], true), 'Policy ID. Can be one of: password-dictionary, password-history, password-policy, password-personal-data, session-alert, session-duration, session-invalidation, session-limit, user-limit, membership-privacy.') ->inject('response') ->inject('project') ->callback($this->action(...)); @@ -91,6 +93,18 @@ class Get extends Action ]), Response::MODEL_POLICY_PASSWORD_HISTORY, ], + 'password-policy' => [ + new Document(\array_merge([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ], $auths['passwordPolicy'] ?? [], [ + '$id' => 'password-policy', + ])), + Response::MODEL_POLICY_PASSWORD_POLICY, + ], 'password-personal-data' => [ new Document([ '$id' => 'password-personal-data', diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPolicy/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPolicy/Update.php new file mode 100644 index 0000000000..eefee954fc --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPolicy/Update.php @@ -0,0 +1,99 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/project/policies/password-policy') + ->desc('Update password policy') + ->groups(['api', 'project']) + ->label('scope', ['policies.write', 'project.policies.write']) + ->label('event', 'projects.[projectId].policies.[policy].update') + ->label('audits.event', 'projects.[projectId].policies.[policy].update') + ->label('audits.resource', 'project/{response.$id}') + ->label('sdk', new Method( + namespace: 'project', + group: 'policies', + name: 'updatePasswordPolicy', + description: <<param('minLength', 8, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.') + ->param('requireUppercase', false, new Boolean(), 'Whether passwords must include at least one uppercase letter.') + ->param('requireLowercase', false, new Boolean(), 'Whether passwords must include at least one lowercase letter.') + ->param('requireNumber', false, new Boolean(), 'Whether passwords must include at least one number.') + ->param('requireSpecialChar', false, new Boolean(), 'Whether passwords must include at least one special character.') + ->inject('response') + ->inject('dbForPlatform') + ->inject('project') + ->inject('authorization') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action( + int $minLength, + bool $requireUppercase, + bool $requireLowercase, + bool $requireNumber, + bool $requireSpecialChar, + Response $response, + Database $dbForPlatform, + Document $project, + Authorization $authorization, + Event $queueForEvents, + ): void { + $auths = $project->getAttribute('auths', []); + $auths['passwordPolicy'] = [ + 'minLength' => $minLength, + 'requireUppercase' => $requireUppercase, + 'requireLowercase' => $requireLowercase, + 'requireNumber' => $requireNumber, + 'requireSpecialChar' => $requireSpecialChar, + ]; + + $updates = new Document([ + 'auths' => $auths, + ]); + + $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + + $queueForEvents + ->setParam('projectId', $project->getId()) + ->setParam('policy', 'password-policy'); + + $response->dynamic($project, Response::MODEL_PROJECT); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php index 3020fa79dd..9b6c5c4100 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php @@ -82,6 +82,15 @@ class XList extends Action '$id' => 'password-history', 'total' => $auths['passwordHistory'] ?? 0, ]), + new Document(\array_merge([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ], $auths['passwordPolicy'] ?? [], [ + '$id' => 'password-policy', + ])), new Document([ '$id' => 'password-personal-data', 'enabled' => $auths['personalDataCheck'] ?? false, diff --git a/src/Appwrite/Platform/Modules/Project/Services/Http.php b/src/Appwrite/Platform/Modules/Project/Services/Http.php index 3fe9f63d9e..54a6b27317 100644 --- a/src/Appwrite/Platform/Modules/Project/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Project/Services/Http.php @@ -79,6 +79,7 @@ use Appwrite\Platform\Modules\Project\Http\Project\Policies\Get as GetPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\MembershipPrivacy\Update as UpdateMembershipPrivacyPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordDictionary\Update as UpdatePasswordDictionaryPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordHistory\Update as UpdatePasswordHistoryPolicy; +use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPolicy\Update as UpdatePasswordPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPersonalData\Update as UpdatePasswordPersonalDataPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionAlert\Update as UpdateSessionAlertPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionDuration\Update as UpdateSessionDurationPolicy; @@ -168,6 +169,7 @@ class Http extends Service $this->addAction(UpdateMembershipPrivacyPolicy::getName(), new UpdateMembershipPrivacyPolicy()); $this->addAction(UpdatePasswordDictionaryPolicy::getName(), new UpdatePasswordDictionaryPolicy()); $this->addAction(UpdatePasswordHistoryPolicy::getName(), new UpdatePasswordHistoryPolicy()); + $this->addAction(UpdatePasswordPolicy::getName(), new UpdatePasswordPolicy()); $this->addAction(UpdatePasswordPersonalDataPolicy::getName(), new UpdatePasswordPersonalDataPolicy()); $this->addAction(UpdateSessionAlertPolicy::getName(), new UpdateSessionAlertPolicy()); $this->addAction(UpdateSessionDurationPolicy::getName(), new UpdateSessionDurationPolicy()); diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 66e4a5f4ae..97d6ed5b61 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -267,6 +267,7 @@ class Response extends SwooleResponse public const MODEL_POLICY_LIST = 'policyList'; public const MODEL_POLICY_PASSWORD_DICTIONARY = 'policyPasswordDictionary'; public const MODEL_POLICY_PASSWORD_HISTORY = 'policyPasswordHistory'; + public const MODEL_POLICY_PASSWORD_POLICY = 'policyPasswordPolicy'; public const MODEL_POLICY_PASSWORD_PERSONAL_DATA = 'policyPasswordPersonalData'; public const MODEL_POLICY_SESSION_ALERT = 'policySessionAlert'; public const MODEL_POLICY_SESSION_DURATION = 'policySessionDuration'; diff --git a/src/Appwrite/Utopia/Response/Model/PolicyList.php b/src/Appwrite/Utopia/Response/Model/PolicyList.php index 09548fedcf..3db06d62e1 100644 --- a/src/Appwrite/Utopia/Response/Model/PolicyList.php +++ b/src/Appwrite/Utopia/Response/Model/PolicyList.php @@ -14,12 +14,13 @@ class PolicyList extends Model 'type' => self::TYPE_INTEGER, 'description' => 'Total number of policies in the given project.', 'default' => 0, - 'example' => 9, + 'example' => 10, ]) ->addRule('policies', [ 'type' => [ Response::MODEL_POLICY_PASSWORD_DICTIONARY, Response::MODEL_POLICY_PASSWORD_HISTORY, + Response::MODEL_POLICY_PASSWORD_POLICY, Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA, Response::MODEL_POLICY_SESSION_ALERT, Response::MODEL_POLICY_SESSION_DURATION, diff --git a/src/Appwrite/Utopia/Response/Model/PolicyPasswordPolicy.php b/src/Appwrite/Utopia/Response/Model/PolicyPasswordPolicy.php new file mode 100644 index 0000000000..f8378cd26d --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/PolicyPasswordPolicy.php @@ -0,0 +1,59 @@ + 'password-policy', + ]; + + public function __construct() + { + parent::__construct(); + + $this + ->addRule('minLength', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Minimum password length required for user passwords.', + 'default' => 8, + 'example' => 12, + ]) + ->addRule('requireUppercase', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether passwords must include at least one uppercase letter.', + 'default' => false, + 'example' => true, + ]) + ->addRule('requireLowercase', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether passwords must include at least one lowercase letter.', + 'default' => false, + 'example' => true, + ]) + ->addRule('requireNumber', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether passwords must include at least one number.', + 'default' => false, + 'example' => true, + ]) + ->addRule('requireSpecialChar', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether passwords must include at least one special character.', + 'default' => false, + 'example' => true, + ]); + } + + public function getName(): string + { + return 'Policy Password Policy'; + } + + public function getType(): string + { + return Response::MODEL_POLICY_PASSWORD_POLICY; + } +} diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 43c09b55c3..0b4824c604 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -16,6 +16,7 @@ trait PoliciesBase $expectedFields = [ 'password-dictionary' => ['enabled'], 'password-history' => ['total'], + 'password-policy' => ['minLength', 'requireUppercase', 'requireLowercase', 'requireNumber', 'requireSpecialChar'], 'password-personal-data' => ['enabled'], 'session-alert' => ['enabled'], 'session-duration' => ['duration'], @@ -60,6 +61,13 @@ trait PoliciesBase { $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); + $this->updatePasswordPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ]); $this->updateSessionDurationPolicy(3600); $this->updateMembershipPrivacyPolicy([ 'userId' => true, @@ -71,6 +79,7 @@ trait PoliciesBase $passwordDictionary = $this->getPolicy('password-dictionary'); $passwordHistory = $this->getPolicy('password-history'); + $passwordPolicy = $this->getPolicy('password-policy'); $sessionDuration = $this->getPolicy('session-duration'); $membershipPrivacy = $this->getPolicy('membership-privacy'); @@ -80,6 +89,13 @@ trait PoliciesBase $this->assertSame(200, $passwordHistory['headers']['status-code']); $this->assertSame(5, $passwordHistory['body']['total']); + $this->assertSame(200, $passwordPolicy['headers']['status-code']); + $this->assertSame(12, $passwordPolicy['body']['minLength']); + $this->assertSame(true, $passwordPolicy['body']['requireUppercase']); + $this->assertSame(true, $passwordPolicy['body']['requireLowercase']); + $this->assertSame(true, $passwordPolicy['body']['requireNumber']); + $this->assertSame(true, $passwordPolicy['body']['requireSpecialChar']); + $this->assertSame(200, $sessionDuration['headers']['status-code']); $this->assertSame(3600, $sessionDuration['body']['duration']); @@ -93,6 +109,13 @@ trait PoliciesBase // Cleanup $this->updatePasswordDictionaryPolicy(false); $this->updatePasswordHistoryPolicy(null); + $this->updatePasswordPolicy([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ]); $this->updateSessionDurationPolicy(31536000); $this->updateMembershipPrivacyPolicy([ 'userId' => false, @@ -130,13 +153,14 @@ trait PoliciesBase $this->assertArrayHasKey('total', $response['body']); $this->assertIsArray($response['body']['policies']); $this->assertIsInt($response['body']['total']); - $this->assertSame(9, $response['body']['total']); - $this->assertCount(9, $response['body']['policies']); + $this->assertSame(10, $response['body']['total']); + $this->assertCount(10, $response['body']['policies']); $policyIds = \array_column($response['body']['policies'], '$id'); $this->assertContains('password-dictionary', $policyIds); $this->assertContains('password-history', $policyIds); + $this->assertContains('password-policy', $policyIds); $this->assertContains('password-personal-data', $policyIds); $this->assertContains('session-alert', $policyIds); $this->assertContains('session-duration', $policyIds); @@ -163,6 +187,11 @@ trait PoliciesBase $this->assertArrayHasKey('enabled', $byId['password-dictionary']); $this->assertArrayHasKey('total', $byId['password-history']); + $this->assertArrayHasKey('minLength', $byId['password-policy']); + $this->assertArrayHasKey('requireUppercase', $byId['password-policy']); + $this->assertArrayHasKey('requireLowercase', $byId['password-policy']); + $this->assertArrayHasKey('requireNumber', $byId['password-policy']); + $this->assertArrayHasKey('requireSpecialChar', $byId['password-policy']); $this->assertArrayHasKey('enabled', $byId['password-personal-data']); $this->assertArrayHasKey('enabled', $byId['session-alert']); $this->assertArrayHasKey('duration', $byId['session-duration']); @@ -180,6 +209,13 @@ trait PoliciesBase { $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); + $this->updatePasswordPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ]); $this->updateSessionDurationPolicy(3600); $this->updateMembershipPrivacyPolicy([ 'userId' => true, @@ -200,6 +236,11 @@ trait PoliciesBase $this->assertSame(true, $byId['password-dictionary']['enabled']); $this->assertSame(5, $byId['password-history']['total']); + $this->assertSame(12, $byId['password-policy']['minLength']); + $this->assertSame(true, $byId['password-policy']['requireUppercase']); + $this->assertSame(true, $byId['password-policy']['requireLowercase']); + $this->assertSame(true, $byId['password-policy']['requireNumber']); + $this->assertSame(true, $byId['password-policy']['requireSpecialChar']); $this->assertSame(3600, $byId['session-duration']['duration']); $this->assertSame(true, $byId['membership-privacy']['userId']); $this->assertSame(true, $byId['membership-privacy']['userEmail']); @@ -210,6 +251,13 @@ trait PoliciesBase // Cleanup $this->updatePasswordDictionaryPolicy(false); $this->updatePasswordHistoryPolicy(null); + $this->updatePasswordPolicy([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ]); $this->updateSessionDurationPolicy(31536000); $this->updateMembershipPrivacyPolicy([ 'userId' => false, @@ -226,7 +274,7 @@ trait PoliciesBase $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(0, $response['body']['total']); - $this->assertCount(9, $response['body']['policies']); + $this->assertCount(10, $response['body']['policies']); } public function testListPoliciesWithLimit(): void @@ -237,7 +285,7 @@ trait PoliciesBase $this->assertSame(200, $response['headers']['status-code']); $this->assertCount(1, $response['body']['policies']); - $this->assertSame(9, $response['body']['total']); + $this->assertSame(10, $response['body']['total']); } public function testListPoliciesWithOffset(): void @@ -425,6 +473,71 @@ trait PoliciesBase $this->assertSame(401, $response['headers']['status-code']); } + // ========================================================================= + // Password Policy + // ========================================================================= + + public function testUpdatePasswordPolicy(): void + { + $response = $this->updatePasswordPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ]); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame(12, $response['body']['authPasswordPolicyMinLength']); + $this->assertSame(true, $response['body']['authPasswordPolicyRequireUppercase']); + $this->assertSame(true, $response['body']['authPasswordPolicyRequireLowercase']); + $this->assertSame(true, $response['body']['authPasswordPolicyRequireNumber']); + $this->assertSame(true, $response['body']['authPasswordPolicyRequireSpecialChar']); + + $policy = $this->getPolicy('password-policy'); + $this->assertSame(200, $policy['headers']['status-code']); + $this->assertSame(12, $policy['body']['minLength']); + $this->assertSame(true, $policy['body']['requireUppercase']); + $this->assertSame(true, $policy['body']['requireLowercase']); + $this->assertSame(true, $policy['body']['requireNumber']); + $this->assertSame(true, $policy['body']['requireSpecialChar']); + + // Cleanup + $this->updatePasswordPolicy([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ]); + } + + public function testUpdatePasswordPolicyBelowMinLength(): void + { + $response = $this->updatePasswordPolicy([ + 'minLength' => 7, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ]); + + $this->assertSame(400, $response['headers']['status-code']); + } + + public function testUpdatePasswordPolicyWithoutAuth(): void + { + $response = $this->updatePasswordPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ], false); + + $this->assertSame(401, $response['headers']['status-code']); + } + // ========================================================================= // Password Personal Data Policy // ========================================================================= @@ -1134,6 +1247,14 @@ trait PoliciesBase ]); } + /** + * @param array $params + */ + protected function updatePasswordPolicy(array $params, bool $authenticated = true): mixed + { + return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-policy', $this->buildHeaders($authenticated), $params); + } + protected function updatePasswordPersonalDataPolicy(bool $enabled, bool $authenticated = true): mixed { return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-personal-data', $this->buildHeaders($authenticated), [ diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 82755d9d73..c2b422fb7b 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2911,56 +2911,28 @@ class ProjectsConsoleClientTest extends Scope $data = $this->setupProjectData(); $id = $data['projectId']; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/min-length', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-policy', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'minLength' => 7, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, ]); $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/min-length', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-policy', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'minLength' => 12, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/uppercase', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'enabled' => true, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/lowercase', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'enabled' => true, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/number', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'enabled' => true, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/special-char', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'enabled' => true, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -3078,47 +3050,15 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/min-length', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-policy', array_merge([ 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-project' => $id, ], $this->getHeaders()), [ 'minLength' => 8, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/uppercase', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'enabled' => false, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/lowercase', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'enabled' => false, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/number', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'enabled' => false, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-policy/special-char', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'enabled' => false, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, ]); $this->assertEquals(200, $response['headers']['status-code']); From 77456155a2ceac18ed0f522e4d82bc32f876e77f Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 21 May 2026 19:52:23 +0400 Subject: [PATCH 04/16] Fix policy CI failures --- app/init/constants.php | 1 + app/init/models.php | 2 +- src/Appwrite/Platform/Modules/Project/Services/Http.php | 2 +- src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php | 2 +- src/Appwrite/Utopia/Response/Model/Project.php | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/init/constants.php b/app/init/constants.php index b271b56a14..84b7ea46cd 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -37,6 +37,7 @@ const APP_LIMIT_COMPRESSION = 20_000_000; //20MB const APP_LIMIT_ARRAY_PARAMS_SIZE = 100; // Default maximum of how many elements can there be in API parameter that expects array value const APP_LIMIT_ARRAY_LABELS_SIZE = 1000; // Default maximum of how many labels elements can there be in API parameter that expects array value const APP_LIMIT_ARRAY_ELEMENT_SIZE = 4096; // Default maximum length of element in array parameter represented by maximum URL length. +const APP_LIMIT_USER_SESSIONS_DEFAULT = 10; // Default maximum sessions allowed per user const APP_LIMIT_SUBQUERY = 1000; const APP_LIMIT_SUBSCRIBERS_SUBQUERY = 1_000_000; const APP_LIMIT_WRITE_RATE_DEFAULT = 60; // Default maximum write rate per rate period diff --git a/app/init/models.php b/app/init/models.php index 22ccd73c9d..5c9e6a604b 100644 --- a/app/init/models.php +++ b/app/init/models.php @@ -167,8 +167,8 @@ use Appwrite\Utopia\Response\Model\PolicyList; use Appwrite\Utopia\Response\Model\PolicyMembershipPrivacy; use Appwrite\Utopia\Response\Model\PolicyPasswordDictionary; use Appwrite\Utopia\Response\Model\PolicyPasswordHistory; -use Appwrite\Utopia\Response\Model\PolicyPasswordPolicy; use Appwrite\Utopia\Response\Model\PolicyPasswordPersonalData; +use Appwrite\Utopia\Response\Model\PolicyPasswordPolicy; use Appwrite\Utopia\Response\Model\PolicySessionAlert; use Appwrite\Utopia\Response\Model\PolicySessionDuration; use Appwrite\Utopia\Response\Model\PolicySessionInvalidation; diff --git a/src/Appwrite/Platform/Modules/Project/Services/Http.php b/src/Appwrite/Platform/Modules/Project/Services/Http.php index 54a6b27317..967610ad0a 100644 --- a/src/Appwrite/Platform/Modules/Project/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Project/Services/Http.php @@ -79,8 +79,8 @@ use Appwrite\Platform\Modules\Project\Http\Project\Policies\Get as GetPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\MembershipPrivacy\Update as UpdateMembershipPrivacyPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordDictionary\Update as UpdatePasswordDictionaryPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordHistory\Update as UpdatePasswordHistoryPolicy; -use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPolicy\Update as UpdatePasswordPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPersonalData\Update as UpdatePasswordPersonalDataPolicy; +use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPolicy\Update as UpdatePasswordPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionAlert\Update as UpdateSessionAlertPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionDuration\Update as UpdateSessionDurationPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionInvalidation\Update as UpdateSessionInvalidationPolicy; diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index f94669597b..252e5d8dbd 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -81,7 +81,7 @@ class Create extends Action $auth = Config::getParam('auth', []); $auths = [ 'limit' => 0, - 'maxSessions' => APP_LIMIT_USER_SESSIONS_DEFAULT, + 'maxSessions' => \APP_LIMIT_USER_SESSIONS_DEFAULT, 'passwordPolicy' => [ 'minLength' => 8, 'requireUppercase' => false, diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index 286edc935e..c3797eade2 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -523,7 +523,7 @@ class Project extends Model $document->setAttribute('authLimit', $authValues['limit'] ?? 0); $document->setAttribute('authDuration', $authValues['duration'] ?? TOKEN_EXPIRATION_LOGIN_LONG); - $document->setAttribute('authSessionsLimit', $authValues['maxSessions'] ?? APP_LIMIT_USER_SESSIONS_DEFAULT); + $document->setAttribute('authSessionsLimit', $authValues['maxSessions'] ?? \APP_LIMIT_USER_SESSIONS_DEFAULT); $document->setAttribute('authPasswordHistory', $authValues['passwordHistory'] ?? 0); $document->setAttribute('authPasswordPolicyMinLength', $passwordPolicy['minLength'] ?? 8); $document->setAttribute('authPasswordPolicyRequireUppercase', $passwordPolicy['requireUppercase'] ?? false); From daaed8ff500ba16c773de99d06b4d0ce709a599a Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 21 May 2026 20:10:13 +0400 Subject: [PATCH 05/16] Address password policy review --- app/init/constants.php | 1 - src/Appwrite/Auth/Validator/PasswordPolicy.php | 2 +- src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php | 2 +- src/Appwrite/Utopia/Response/Model/Project.php | 2 +- tests/unit/Auth/Validator/PasswordPolicyTest.php | 1 + 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/init/constants.php b/app/init/constants.php index 84b7ea46cd..b271b56a14 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -37,7 +37,6 @@ const APP_LIMIT_COMPRESSION = 20_000_000; //20MB const APP_LIMIT_ARRAY_PARAMS_SIZE = 100; // Default maximum of how many elements can there be in API parameter that expects array value const APP_LIMIT_ARRAY_LABELS_SIZE = 1000; // Default maximum of how many labels elements can there be in API parameter that expects array value const APP_LIMIT_ARRAY_ELEMENT_SIZE = 4096; // Default maximum length of element in array parameter represented by maximum URL length. -const APP_LIMIT_USER_SESSIONS_DEFAULT = 10; // Default maximum sessions allowed per user const APP_LIMIT_SUBQUERY = 1000; const APP_LIMIT_SUBSCRIBERS_SUBQUERY = 1_000_000; const APP_LIMIT_WRITE_RATE_DEFAULT = 60; // Default maximum write rate per rate period diff --git a/src/Appwrite/Auth/Validator/PasswordPolicy.php b/src/Appwrite/Auth/Validator/PasswordPolicy.php index 6fdb11d15a..e39b0b07ab 100644 --- a/src/Appwrite/Auth/Validator/PasswordPolicy.php +++ b/src/Appwrite/Auth/Validator/PasswordPolicy.php @@ -80,7 +80,7 @@ class PasswordPolicy extends Password return false; } - if ($this->requireSpecialChar && !\preg_match("/[!\"#$%&'()*+,\-.\/:;<=>?@[\\\\\]^_`{|}~]/", $value)) { + if ($this->requireSpecialChar && !\preg_match('/[^\p{L}\p{N}\s]/u', $value)) { return false; } diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index 252e5d8dbd..e3a9be3711 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -81,7 +81,7 @@ class Create extends Action $auth = Config::getParam('auth', []); $auths = [ 'limit' => 0, - 'maxSessions' => \APP_LIMIT_USER_SESSIONS_DEFAULT, + 'maxSessions' => 0, 'passwordPolicy' => [ 'minLength' => 8, 'requireUppercase' => false, diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index c3797eade2..f13def6a36 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -523,7 +523,7 @@ class Project extends Model $document->setAttribute('authLimit', $authValues['limit'] ?? 0); $document->setAttribute('authDuration', $authValues['duration'] ?? TOKEN_EXPIRATION_LOGIN_LONG); - $document->setAttribute('authSessionsLimit', $authValues['maxSessions'] ?? \APP_LIMIT_USER_SESSIONS_DEFAULT); + $document->setAttribute('authSessionsLimit', $authValues['maxSessions'] ?? 0); $document->setAttribute('authPasswordHistory', $authValues['passwordHistory'] ?? 0); $document->setAttribute('authPasswordPolicyMinLength', $passwordPolicy['minLength'] ?? 8); $document->setAttribute('authPasswordPolicyRequireUppercase', $passwordPolicy['requireUppercase'] ?? false); diff --git a/tests/unit/Auth/Validator/PasswordPolicyTest.php b/tests/unit/Auth/Validator/PasswordPolicyTest.php index a342455f61..048a1d3f60 100644 --- a/tests/unit/Auth/Validator/PasswordPolicyTest.php +++ b/tests/unit/Auth/Validator/PasswordPolicyTest.php @@ -31,6 +31,7 @@ class PasswordPolicyTest extends TestCase $this->assertFalse($validator->isValid('PasswordOnly!')); $this->assertFalse($validator->isValid('Password1234')); $this->assertTrue($validator->isValid('Password123!')); + $this->assertTrue($validator->isValid('Password123€')); } public function testAllowEmpty(): void From f021bd402d619cdb4cd205948cdf911f972a9036 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 21 May 2026 20:21:12 +0400 Subject: [PATCH 06/16] Rename password policy to password strength --- app/controllers/api/account.php | 6 +- app/controllers/api/users.php | 4 +- app/init/models.php | 4 +- .../Auth/Validator/PasswordDictionary.php | 2 +- ...asswordPolicy.php => PasswordStrength.php} | 4 +- .../Project/Http/Project/Policies/Get.php | 14 +-- .../Update.php | 62 ++++++---- .../Project/Http/Project/Policies/XList.php | 4 +- .../Modules/Project/Services/Http.php | 4 +- .../Modules/Projects/Http/Projects/Create.php | 2 +- src/Appwrite/Utopia/Response.php | 2 +- .../Utopia/Response/Model/PolicyList.php | 2 +- ...dPolicy.php => PolicyPasswordStrength.php} | 8 +- .../Utopia/Response/Model/Project.php | 22 ++-- tests/e2e/Services/Project/PoliciesBase.php | 111 ++++++++++++------ .../Projects/ProjectsConsoleClientTest.php | 30 ++--- ...olicyTest.php => PasswordStrengthTest.php} | 10 +- 17 files changed, 170 insertions(+), 121 deletions(-) rename src/Appwrite/Auth/Validator/{PasswordPolicy.php => PasswordStrength.php} (97%) rename src/Appwrite/Platform/Modules/Project/Http/Project/Policies/{PasswordPolicy => PasswordStrength}/Update.php (53%) rename src/Appwrite/Utopia/Response/Model/{PolicyPasswordPolicy.php => PolicyPasswordStrength.php} (89%) rename tests/unit/Auth/Validator/{PasswordPolicyTest.php => PasswordStrengthTest.php} (85%) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index f764dd9fec..9cb5dad8e8 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -254,7 +254,7 @@ Http::post('/v1/account') ->label('abuse-limit', 10) ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', '', new EmailValidator(), 'User email.') - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('request') ->inject('response') @@ -3269,7 +3269,7 @@ Http::patch('/v1/account/password') contentType: ContentType::JSON )) ->label('abuse-limit', 10) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) ->param('oldPassword', '', new Password(), 'Current user password. Must be at least 8 chars.', true) ->inject('response') ->inject('user') @@ -3886,7 +3886,7 @@ Http::put('/v1/account/recovery') ->label('abuse-key', 'url:{url},userId:{param-userId}') ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) ->param('secret', '', new Text(256), 'Valid reset token.') - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('user') ->inject('dbForProject') diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 1e4c8391a1..a94a9307ab 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -279,7 +279,7 @@ Http::post('/v1/users') ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', null, new Nullable(new EmailValidator()), 'User email.', true) ->param('phone', null, new Nullable(new Phone()), 'Phone number. Format this number with a leading \'+\' and a country code, e.g., +16175551212.', true) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'Plain text user password. Must be at least 8 chars.', true, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'Plain text user password. Must be at least 8 chars.', true, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('response') ->inject('project') @@ -1398,7 +1398,7 @@ Http::patch('/v1/users/:userId/password') ] )) ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, allowEmpty: true, policy: $project->getAttribute('auths', [])['passwordPolicy'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, allowEmpty: true, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('project') ->inject('dbForProject') diff --git a/app/init/models.php b/app/init/models.php index 5c9e6a604b..d0f665bb4e 100644 --- a/app/init/models.php +++ b/app/init/models.php @@ -168,7 +168,7 @@ use Appwrite\Utopia\Response\Model\PolicyMembershipPrivacy; use Appwrite\Utopia\Response\Model\PolicyPasswordDictionary; use Appwrite\Utopia\Response\Model\PolicyPasswordHistory; use Appwrite\Utopia\Response\Model\PolicyPasswordPersonalData; -use Appwrite\Utopia\Response\Model\PolicyPasswordPolicy; +use Appwrite\Utopia\Response\Model\PolicyPasswordStrength; use Appwrite\Utopia\Response\Model\PolicySessionAlert; use Appwrite\Utopia\Response\Model\PolicySessionDuration; use Appwrite\Utopia\Response\Model\PolicySessionInvalidation; @@ -461,7 +461,7 @@ Response::setModel(new OAuth2Microsoft()); Response::setModel(new OAuth2ProviderList()); Response::setModel(new PolicyPasswordDictionary()); Response::setModel(new PolicyPasswordHistory()); -Response::setModel(new PolicyPasswordPolicy()); +Response::setModel(new PolicyPasswordStrength()); Response::setModel(new PolicyPasswordPersonalData()); Response::setModel(new PolicySessionAlert()); Response::setModel(new PolicySessionDuration()); diff --git a/src/Appwrite/Auth/Validator/PasswordDictionary.php b/src/Appwrite/Auth/Validator/PasswordDictionary.php index 290ca5766b..59a8d2f3a6 100644 --- a/src/Appwrite/Auth/Validator/PasswordDictionary.php +++ b/src/Appwrite/Auth/Validator/PasswordDictionary.php @@ -7,7 +7,7 @@ namespace Appwrite\Auth\Validator; * * Validates user password string */ -class PasswordDictionary extends PasswordPolicy +class PasswordDictionary extends PasswordStrength { protected array $dictionary; protected bool $enabled; diff --git a/src/Appwrite/Auth/Validator/PasswordPolicy.php b/src/Appwrite/Auth/Validator/PasswordStrength.php similarity index 97% rename from src/Appwrite/Auth/Validator/PasswordPolicy.php rename to src/Appwrite/Auth/Validator/PasswordStrength.php index e39b0b07ab..fc4d3cfd82 100644 --- a/src/Appwrite/Auth/Validator/PasswordPolicy.php +++ b/src/Appwrite/Auth/Validator/PasswordStrength.php @@ -3,11 +3,11 @@ namespace Appwrite\Auth\Validator; /** - * PasswordPolicy. + * PasswordStrength. * * Validates password complexity rules. */ -class PasswordPolicy extends Password +class PasswordStrength extends Password { protected int $minLength; protected bool $requireUppercase; 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 8d3653c5b3..a6491b1b15 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php @@ -42,7 +42,7 @@ class Get extends Action model: [ Response::MODEL_POLICY_PASSWORD_DICTIONARY, Response::MODEL_POLICY_PASSWORD_HISTORY, - Response::MODEL_POLICY_PASSWORD_POLICY, + Response::MODEL_POLICY_PASSWORD_STRENGTH, Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA, Response::MODEL_POLICY_SESSION_ALERT, Response::MODEL_POLICY_SESSION_DURATION, @@ -57,7 +57,7 @@ class Get extends Action ->param('policyId', '', new WhiteList([ 'password-dictionary', 'password-history', - 'password-policy', + 'password-strength', 'password-personal-data', 'session-alert', 'session-duration', @@ -65,7 +65,7 @@ class Get extends Action 'session-limit', 'user-limit', 'membership-privacy', - ], true), 'Policy ID. Can be one of: password-dictionary, password-history, password-policy, password-personal-data, session-alert, session-duration, session-invalidation, session-limit, user-limit, membership-privacy.') + ], true), 'Policy ID. Can be one of: password-dictionary, password-history, password-strength, password-personal-data, session-alert, session-duration, session-invalidation, session-limit, user-limit, membership-privacy.') ->inject('response') ->inject('project') ->callback($this->action(...)); @@ -93,17 +93,17 @@ class Get extends Action ]), Response::MODEL_POLICY_PASSWORD_HISTORY, ], - 'password-policy' => [ + 'password-strength' => [ new Document(\array_merge([ 'minLength' => 8, 'requireUppercase' => false, 'requireLowercase' => false, 'requireNumber' => false, 'requireSpecialChar' => false, - ], $auths['passwordPolicy'] ?? [], [ - '$id' => 'password-policy', + ], $auths['passwordStrength'] ?? [], [ + '$id' => 'password-strength', ])), - Response::MODEL_POLICY_PASSWORD_POLICY, + Response::MODEL_POLICY_PASSWORD_STRENGTH, ], 'password-personal-data' => [ new Document([ diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPolicy/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php similarity index 53% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPolicy/Update.php rename to src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index eefee954fc..53b82426a8 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordPolicy/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/project/policies/password-policy') - ->desc('Update password policy') + ->setHttpPath('/v1/project/policies/password-strength') + ->desc('Update password strength policy') ->groups(['api', 'project']) ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') @@ -38,7 +38,7 @@ class Update extends Action ->label('sdk', new Method( namespace: 'project', group: 'policies', - name: 'updatePasswordPolicy', + name: 'updatePasswordStrength', description: <<param('minLength', 8, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.') - ->param('requireUppercase', false, new Boolean(), 'Whether passwords must include at least one uppercase letter.') - ->param('requireLowercase', false, new Boolean(), 'Whether passwords must include at least one lowercase letter.') - ->param('requireNumber', false, new Boolean(), 'Whether passwords must include at least one number.') - ->param('requireSpecialChar', false, new Boolean(), 'Whether passwords must include at least one special character.') + ->param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) + ->param('requireUppercase', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.', optional: true) + ->param('requireLowercase', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.', optional: true) + ->param('requireNumber', null, new Boolean(), 'Whether passwords must include at least one number.', optional: true) + ->param('requireSpecialChar', null, new Boolean(), 'Whether passwords must include at least one special character.', optional: true) ->inject('response') ->inject('dbForPlatform') ->inject('project') @@ -64,11 +64,11 @@ class Update extends Action } public function action( - int $minLength, - bool $requireUppercase, - bool $requireLowercase, - bool $requireNumber, - bool $requireSpecialChar, + ?int $minLength, + ?bool $requireUppercase, + ?bool $requireLowercase, + ?bool $requireNumber, + ?bool $requireSpecialChar, Response $response, Database $dbForPlatform, Document $project, @@ -76,13 +76,29 @@ class Update extends Action Event $queueForEvents, ): void { $auths = $project->getAttribute('auths', []); - $auths['passwordPolicy'] = [ - 'minLength' => $minLength, - 'requireUppercase' => $requireUppercase, - 'requireLowercase' => $requireLowercase, - 'requireNumber' => $requireNumber, - 'requireSpecialChar' => $requireSpecialChar, - ]; + $auths['passwordStrength'] = \array_merge([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ], $auths['passwordStrength'] ?? []); + + if ($minLength !== null) { + $auths['passwordStrength']['minLength'] = $minLength; + } + if ($requireUppercase !== null) { + $auths['passwordStrength']['requireUppercase'] = $requireUppercase; + } + if ($requireLowercase !== null) { + $auths['passwordStrength']['requireLowercase'] = $requireLowercase; + } + if ($requireNumber !== null) { + $auths['passwordStrength']['requireNumber'] = $requireNumber; + } + if ($requireSpecialChar !== null) { + $auths['passwordStrength']['requireSpecialChar'] = $requireSpecialChar; + } $updates = new Document([ 'auths' => $auths, @@ -92,7 +108,7 @@ class Update extends Action $queueForEvents ->setParam('projectId', $project->getId()) - ->setParam('policy', 'password-policy'); + ->setParam('policy', 'password-strength'); $response->dynamic($project, Response::MODEL_PROJECT); } diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php index 9b6c5c4100..83f60ced7d 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php @@ -88,8 +88,8 @@ class XList extends Action 'requireLowercase' => false, 'requireNumber' => false, 'requireSpecialChar' => false, - ], $auths['passwordPolicy'] ?? [], [ - '$id' => 'password-policy', + ], $auths['passwordStrength'] ?? [], [ + '$id' => 'password-strength', ])), new Document([ '$id' => 'password-personal-data', diff --git a/src/Appwrite/Platform/Modules/Project/Services/Http.php b/src/Appwrite/Platform/Modules/Project/Services/Http.php index 967610ad0a..a8eec3abd0 100644 --- a/src/Appwrite/Platform/Modules/Project/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Project/Services/Http.php @@ -80,7 +80,7 @@ use Appwrite\Platform\Modules\Project\Http\Project\Policies\MembershipPrivacy\Up use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordDictionary\Update as UpdatePasswordDictionaryPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordHistory\Update as UpdatePasswordHistoryPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPersonalData\Update as UpdatePasswordPersonalDataPolicy; -use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPolicy\Update as UpdatePasswordPolicy; +use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\Update as UpdatePasswordStrengthPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionAlert\Update as UpdateSessionAlertPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionDuration\Update as UpdateSessionDurationPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionInvalidation\Update as UpdateSessionInvalidationPolicy; @@ -169,7 +169,7 @@ class Http extends Service $this->addAction(UpdateMembershipPrivacyPolicy::getName(), new UpdateMembershipPrivacyPolicy()); $this->addAction(UpdatePasswordDictionaryPolicy::getName(), new UpdatePasswordDictionaryPolicy()); $this->addAction(UpdatePasswordHistoryPolicy::getName(), new UpdatePasswordHistoryPolicy()); - $this->addAction(UpdatePasswordPolicy::getName(), new UpdatePasswordPolicy()); + $this->addAction(UpdatePasswordStrengthPolicy::getName(), new UpdatePasswordStrengthPolicy()); $this->addAction(UpdatePasswordPersonalDataPolicy::getName(), new UpdatePasswordPersonalDataPolicy()); $this->addAction(UpdateSessionAlertPolicy::getName(), new UpdateSessionAlertPolicy()); $this->addAction(UpdateSessionDurationPolicy::getName(), new UpdateSessionDurationPolicy()); diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index e3a9be3711..82d89c903f 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -82,7 +82,7 @@ class Create extends Action $auths = [ 'limit' => 0, 'maxSessions' => 0, - 'passwordPolicy' => [ + 'passwordStrength' => [ 'minLength' => 8, 'requireUppercase' => false, 'requireLowercase' => false, diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 97d6ed5b61..bd4427d710 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -267,7 +267,7 @@ class Response extends SwooleResponse public const MODEL_POLICY_LIST = 'policyList'; public const MODEL_POLICY_PASSWORD_DICTIONARY = 'policyPasswordDictionary'; public const MODEL_POLICY_PASSWORD_HISTORY = 'policyPasswordHistory'; - public const MODEL_POLICY_PASSWORD_POLICY = 'policyPasswordPolicy'; + public const MODEL_POLICY_PASSWORD_STRENGTH = 'policyPasswordStrength'; public const MODEL_POLICY_PASSWORD_PERSONAL_DATA = 'policyPasswordPersonalData'; public const MODEL_POLICY_SESSION_ALERT = 'policySessionAlert'; public const MODEL_POLICY_SESSION_DURATION = 'policySessionDuration'; diff --git a/src/Appwrite/Utopia/Response/Model/PolicyList.php b/src/Appwrite/Utopia/Response/Model/PolicyList.php index 3db06d62e1..ac67023b0b 100644 --- a/src/Appwrite/Utopia/Response/Model/PolicyList.php +++ b/src/Appwrite/Utopia/Response/Model/PolicyList.php @@ -20,7 +20,7 @@ class PolicyList extends Model 'type' => [ Response::MODEL_POLICY_PASSWORD_DICTIONARY, Response::MODEL_POLICY_PASSWORD_HISTORY, - Response::MODEL_POLICY_PASSWORD_POLICY, + Response::MODEL_POLICY_PASSWORD_STRENGTH, Response::MODEL_POLICY_PASSWORD_PERSONAL_DATA, Response::MODEL_POLICY_SESSION_ALERT, Response::MODEL_POLICY_SESSION_DURATION, diff --git a/src/Appwrite/Utopia/Response/Model/PolicyPasswordPolicy.php b/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php similarity index 89% rename from src/Appwrite/Utopia/Response/Model/PolicyPasswordPolicy.php rename to src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php index f8378cd26d..356f6313ba 100644 --- a/src/Appwrite/Utopia/Response/Model/PolicyPasswordPolicy.php +++ b/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php @@ -4,10 +4,10 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; -class PolicyPasswordPolicy extends PolicyBase +class PolicyPasswordStrength extends PolicyBase { public array $conditions = [ - '$id' => 'password-policy', + '$id' => 'password-strength', ]; public function __construct() @@ -49,11 +49,11 @@ class PolicyPasswordPolicy extends PolicyBase public function getName(): string { - return 'Policy Password Policy'; + return 'Policy Password Strength'; } public function getType(): string { - return Response::MODEL_POLICY_PASSWORD_POLICY; + return Response::MODEL_POLICY_PASSWORD_STRENGTH; } } diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index f13def6a36..5907a9aaca 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -115,31 +115,31 @@ class Project extends Model 'default' => 0, 'example' => 5, ]) - ->addRule('authPasswordPolicyMinLength', [ + ->addRule('authPasswordStrengthMinLength', [ 'type' => self::TYPE_INTEGER, 'description' => 'Minimum password length required for user passwords.', 'default' => 8, 'example' => 12, ]) - ->addRule('authPasswordPolicyRequireUppercase', [ + ->addRule('authPasswordStrengthRequireUppercase', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether or not passwords must include at least one uppercase letter.', 'default' => false, 'example' => true, ]) - ->addRule('authPasswordPolicyRequireLowercase', [ + ->addRule('authPasswordStrengthRequireLowercase', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether or not passwords must include at least one lowercase letter.', 'default' => false, 'example' => true, ]) - ->addRule('authPasswordPolicyRequireNumber', [ + ->addRule('authPasswordStrengthRequireNumber', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether or not passwords must include at least one number.', 'default' => false, 'example' => true, ]) - ->addRule('authPasswordPolicyRequireSpecialChar', [ + ->addRule('authPasswordStrengthRequireSpecialChar', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether or not passwords must include at least one special character.', 'default' => false, @@ -519,17 +519,17 @@ class Project extends Model } $authValues = $document->getAttribute('auths', []); - $passwordPolicy = $authValues['passwordPolicy'] ?? []; + $passwordStrength = $authValues['passwordStrength'] ?? []; $document->setAttribute('authLimit', $authValues['limit'] ?? 0); $document->setAttribute('authDuration', $authValues['duration'] ?? TOKEN_EXPIRATION_LOGIN_LONG); $document->setAttribute('authSessionsLimit', $authValues['maxSessions'] ?? 0); $document->setAttribute('authPasswordHistory', $authValues['passwordHistory'] ?? 0); - $document->setAttribute('authPasswordPolicyMinLength', $passwordPolicy['minLength'] ?? 8); - $document->setAttribute('authPasswordPolicyRequireUppercase', $passwordPolicy['requireUppercase'] ?? false); - $document->setAttribute('authPasswordPolicyRequireLowercase', $passwordPolicy['requireLowercase'] ?? false); - $document->setAttribute('authPasswordPolicyRequireNumber', $passwordPolicy['requireNumber'] ?? false); - $document->setAttribute('authPasswordPolicyRequireSpecialChar', $passwordPolicy['requireSpecialChar'] ?? false); + $document->setAttribute('authPasswordStrengthMinLength', $passwordStrength['minLength'] ?? 8); + $document->setAttribute('authPasswordStrengthRequireUppercase', $passwordStrength['requireUppercase'] ?? false); + $document->setAttribute('authPasswordStrengthRequireLowercase', $passwordStrength['requireLowercase'] ?? false); + $document->setAttribute('authPasswordStrengthRequireNumber', $passwordStrength['requireNumber'] ?? false); + $document->setAttribute('authPasswordStrengthRequireSpecialChar', $passwordStrength['requireSpecialChar'] ?? false); $document->setAttribute('authPasswordDictionary', $authValues['passwordDictionary'] ?? false); $document->setAttribute('authPersonalDataCheck', $authValues['personalDataCheck'] ?? false); $document->setAttribute('authDisposableEmails', $authValues['disposableEmails'] ?? false); diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 0b4824c604..bb62e72c69 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -16,7 +16,7 @@ trait PoliciesBase $expectedFields = [ 'password-dictionary' => ['enabled'], 'password-history' => ['total'], - 'password-policy' => ['minLength', 'requireUppercase', 'requireLowercase', 'requireNumber', 'requireSpecialChar'], + 'password-strength' => ['minLength', 'requireUppercase', 'requireLowercase', 'requireNumber', 'requireSpecialChar'], 'password-personal-data' => ['enabled'], 'session-alert' => ['enabled'], 'session-duration' => ['duration'], @@ -61,7 +61,7 @@ trait PoliciesBase { $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); - $this->updatePasswordPolicy([ + $this->updatePasswordStrengthPolicy([ 'minLength' => 12, 'requireUppercase' => true, 'requireLowercase' => true, @@ -79,7 +79,7 @@ trait PoliciesBase $passwordDictionary = $this->getPolicy('password-dictionary'); $passwordHistory = $this->getPolicy('password-history'); - $passwordPolicy = $this->getPolicy('password-policy'); + $passwordStrength = $this->getPolicy('password-strength'); $sessionDuration = $this->getPolicy('session-duration'); $membershipPrivacy = $this->getPolicy('membership-privacy'); @@ -89,12 +89,12 @@ trait PoliciesBase $this->assertSame(200, $passwordHistory['headers']['status-code']); $this->assertSame(5, $passwordHistory['body']['total']); - $this->assertSame(200, $passwordPolicy['headers']['status-code']); - $this->assertSame(12, $passwordPolicy['body']['minLength']); - $this->assertSame(true, $passwordPolicy['body']['requireUppercase']); - $this->assertSame(true, $passwordPolicy['body']['requireLowercase']); - $this->assertSame(true, $passwordPolicy['body']['requireNumber']); - $this->assertSame(true, $passwordPolicy['body']['requireSpecialChar']); + $this->assertSame(200, $passwordStrength['headers']['status-code']); + $this->assertSame(12, $passwordStrength['body']['minLength']); + $this->assertSame(true, $passwordStrength['body']['requireUppercase']); + $this->assertSame(true, $passwordStrength['body']['requireLowercase']); + $this->assertSame(true, $passwordStrength['body']['requireNumber']); + $this->assertSame(true, $passwordStrength['body']['requireSpecialChar']); $this->assertSame(200, $sessionDuration['headers']['status-code']); $this->assertSame(3600, $sessionDuration['body']['duration']); @@ -109,7 +109,7 @@ trait PoliciesBase // Cleanup $this->updatePasswordDictionaryPolicy(false); $this->updatePasswordHistoryPolicy(null); - $this->updatePasswordPolicy([ + $this->updatePasswordStrengthPolicy([ 'minLength' => 8, 'requireUppercase' => false, 'requireLowercase' => false, @@ -160,7 +160,7 @@ trait PoliciesBase $this->assertContains('password-dictionary', $policyIds); $this->assertContains('password-history', $policyIds); - $this->assertContains('password-policy', $policyIds); + $this->assertContains('password-strength', $policyIds); $this->assertContains('password-personal-data', $policyIds); $this->assertContains('session-alert', $policyIds); $this->assertContains('session-duration', $policyIds); @@ -187,11 +187,11 @@ trait PoliciesBase $this->assertArrayHasKey('enabled', $byId['password-dictionary']); $this->assertArrayHasKey('total', $byId['password-history']); - $this->assertArrayHasKey('minLength', $byId['password-policy']); - $this->assertArrayHasKey('requireUppercase', $byId['password-policy']); - $this->assertArrayHasKey('requireLowercase', $byId['password-policy']); - $this->assertArrayHasKey('requireNumber', $byId['password-policy']); - $this->assertArrayHasKey('requireSpecialChar', $byId['password-policy']); + $this->assertArrayHasKey('minLength', $byId['password-strength']); + $this->assertArrayHasKey('requireUppercase', $byId['password-strength']); + $this->assertArrayHasKey('requireLowercase', $byId['password-strength']); + $this->assertArrayHasKey('requireNumber', $byId['password-strength']); + $this->assertArrayHasKey('requireSpecialChar', $byId['password-strength']); $this->assertArrayHasKey('enabled', $byId['password-personal-data']); $this->assertArrayHasKey('enabled', $byId['session-alert']); $this->assertArrayHasKey('duration', $byId['session-duration']); @@ -209,7 +209,7 @@ trait PoliciesBase { $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); - $this->updatePasswordPolicy([ + $this->updatePasswordStrengthPolicy([ 'minLength' => 12, 'requireUppercase' => true, 'requireLowercase' => true, @@ -236,11 +236,11 @@ trait PoliciesBase $this->assertSame(true, $byId['password-dictionary']['enabled']); $this->assertSame(5, $byId['password-history']['total']); - $this->assertSame(12, $byId['password-policy']['minLength']); - $this->assertSame(true, $byId['password-policy']['requireUppercase']); - $this->assertSame(true, $byId['password-policy']['requireLowercase']); - $this->assertSame(true, $byId['password-policy']['requireNumber']); - $this->assertSame(true, $byId['password-policy']['requireSpecialChar']); + $this->assertSame(12, $byId['password-strength']['minLength']); + $this->assertSame(true, $byId['password-strength']['requireUppercase']); + $this->assertSame(true, $byId['password-strength']['requireLowercase']); + $this->assertSame(true, $byId['password-strength']['requireNumber']); + $this->assertSame(true, $byId['password-strength']['requireSpecialChar']); $this->assertSame(3600, $byId['session-duration']['duration']); $this->assertSame(true, $byId['membership-privacy']['userId']); $this->assertSame(true, $byId['membership-privacy']['userEmail']); @@ -251,7 +251,7 @@ trait PoliciesBase // Cleanup $this->updatePasswordDictionaryPolicy(false); $this->updatePasswordHistoryPolicy(null); - $this->updatePasswordPolicy([ + $this->updatePasswordStrengthPolicy([ 'minLength' => 8, 'requireUppercase' => false, 'requireLowercase' => false, @@ -474,12 +474,12 @@ trait PoliciesBase } // ========================================================================= - // Password Policy + // Password Strength // ========================================================================= - public function testUpdatePasswordPolicy(): void + public function testUpdatePasswordStrengthPolicy(): void { - $response = $this->updatePasswordPolicy([ + $response = $this->updatePasswordStrengthPolicy([ 'minLength' => 12, 'requireUppercase' => true, 'requireLowercase' => true, @@ -488,13 +488,13 @@ trait PoliciesBase ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(12, $response['body']['authPasswordPolicyMinLength']); - $this->assertSame(true, $response['body']['authPasswordPolicyRequireUppercase']); - $this->assertSame(true, $response['body']['authPasswordPolicyRequireLowercase']); - $this->assertSame(true, $response['body']['authPasswordPolicyRequireNumber']); - $this->assertSame(true, $response['body']['authPasswordPolicyRequireSpecialChar']); + $this->assertSame(12, $response['body']['authPasswordStrengthMinLength']); + $this->assertSame(true, $response['body']['authPasswordStrengthRequireUppercase']); + $this->assertSame(true, $response['body']['authPasswordStrengthRequireLowercase']); + $this->assertSame(true, $response['body']['authPasswordStrengthRequireNumber']); + $this->assertSame(true, $response['body']['authPasswordStrengthRequireSpecialChar']); - $policy = $this->getPolicy('password-policy'); + $policy = $this->getPolicy('password-strength'); $this->assertSame(200, $policy['headers']['status-code']); $this->assertSame(12, $policy['body']['minLength']); $this->assertSame(true, $policy['body']['requireUppercase']); @@ -503,7 +503,7 @@ trait PoliciesBase $this->assertSame(true, $policy['body']['requireSpecialChar']); // Cleanup - $this->updatePasswordPolicy([ + $this->updatePasswordStrengthPolicy([ 'minLength' => 8, 'requireUppercase' => false, 'requireLowercase' => false, @@ -512,9 +512,42 @@ trait PoliciesBase ]); } - public function testUpdatePasswordPolicyBelowMinLength(): void + public function testUpdatePasswordStrengthPolicyPartial(): void { - $response = $this->updatePasswordPolicy([ + $response = $this->updatePasswordStrengthPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ]); + + $this->assertSame(200, $response['headers']['status-code']); + + $response = $this->updatePasswordStrengthPolicy([ + 'requireLowercase' => false, + ]); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame(12, $response['body']['authPasswordStrengthMinLength']); + $this->assertSame(true, $response['body']['authPasswordStrengthRequireUppercase']); + $this->assertSame(false, $response['body']['authPasswordStrengthRequireLowercase']); + $this->assertSame(true, $response['body']['authPasswordStrengthRequireNumber']); + $this->assertSame(true, $response['body']['authPasswordStrengthRequireSpecialChar']); + + // Cleanup + $this->updatePasswordStrengthPolicy([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ]); + } + + public function testUpdatePasswordStrengthPolicyBelowMinLength(): void + { + $response = $this->updatePasswordStrengthPolicy([ 'minLength' => 7, 'requireUppercase' => false, 'requireLowercase' => false, @@ -525,9 +558,9 @@ trait PoliciesBase $this->assertSame(400, $response['headers']['status-code']); } - public function testUpdatePasswordPolicyWithoutAuth(): void + public function testUpdatePasswordStrengthPolicyWithoutAuth(): void { - $response = $this->updatePasswordPolicy([ + $response = $this->updatePasswordStrengthPolicy([ 'minLength' => 12, 'requireUppercase' => true, 'requireLowercase' => true, @@ -1250,9 +1283,9 @@ trait PoliciesBase /** * @param array $params */ - protected function updatePasswordPolicy(array $params, bool $authenticated = true): mixed + protected function updatePasswordStrengthPolicy(array $params, bool $authenticated = true): mixed { - return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-policy', $this->buildHeaders($authenticated), $params); + return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders($authenticated), $params); } protected function updatePasswordPersonalDataPolicy(bool $enabled, bool $authenticated = true): mixed diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index c2b422fb7b..99de990170 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2906,12 +2906,12 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(0, $response['body']['authPasswordHistory']); } - public function testUpdateProjectAuthPasswordPolicy(): void + public function testUpdateProjectAuthPasswordStrength(): void { $data = $this->setupProjectData(); $id = $data['projectId']; - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-policy', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, ], $this->getHeaders()), [ @@ -2924,7 +2924,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-policy', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, ], $this->getHeaders()), [ @@ -2936,11 +2936,11 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(12, $response['body']['authPasswordPolicyMinLength']); - $this->assertEquals(true, $response['body']['authPasswordPolicyRequireUppercase']); - $this->assertEquals(true, $response['body']['authPasswordPolicyRequireLowercase']); - $this->assertEquals(true, $response['body']['authPasswordPolicyRequireNumber']); - $this->assertEquals(true, $response['body']['authPasswordPolicyRequireSpecialChar']); + $this->assertEquals(12, $response['body']['authPasswordStrengthMinLength']); + $this->assertEquals(true, $response['body']['authPasswordStrengthRequireUppercase']); + $this->assertEquals(true, $response['body']['authPasswordStrengthRequireLowercase']); + $this->assertEquals(true, $response['body']['authPasswordStrengthRequireNumber']); + $this->assertEquals(true, $response['body']['authPasswordStrengthRequireSpecialChar']); $weakPassword = 'password123!'; $validPassword = 'Password123!'; @@ -2980,7 +2980,7 @@ class ProjectsConsoleClientTest extends Scope 'userId' => ID::unique(), 'email' => $email, 'password' => $validPassword, - 'name' => 'Password Policy User', + 'name' => 'Password Strength User', ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -3050,7 +3050,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-policy', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, ], $this->getHeaders()), [ @@ -3062,11 +3062,11 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(8, $response['body']['authPasswordPolicyMinLength']); - $this->assertEquals(false, $response['body']['authPasswordPolicyRequireUppercase']); - $this->assertEquals(false, $response['body']['authPasswordPolicyRequireLowercase']); - $this->assertEquals(false, $response['body']['authPasswordPolicyRequireNumber']); - $this->assertEquals(false, $response['body']['authPasswordPolicyRequireSpecialChar']); + $this->assertEquals(8, $response['body']['authPasswordStrengthMinLength']); + $this->assertEquals(false, $response['body']['authPasswordStrengthRequireUppercase']); + $this->assertEquals(false, $response['body']['authPasswordStrengthRequireLowercase']); + $this->assertEquals(false, $response['body']['authPasswordStrengthRequireNumber']); + $this->assertEquals(false, $response['body']['authPasswordStrengthRequireSpecialChar']); } #[Group('smtpAndTemplates')] diff --git a/tests/unit/Auth/Validator/PasswordPolicyTest.php b/tests/unit/Auth/Validator/PasswordStrengthTest.php similarity index 85% rename from tests/unit/Auth/Validator/PasswordPolicyTest.php rename to tests/unit/Auth/Validator/PasswordStrengthTest.php index 048a1d3f60..042d853653 100644 --- a/tests/unit/Auth/Validator/PasswordPolicyTest.php +++ b/tests/unit/Auth/Validator/PasswordStrengthTest.php @@ -2,14 +2,14 @@ namespace Tests\Unit\Auth\Validator; -use Appwrite\Auth\Validator\PasswordPolicy; +use Appwrite\Auth\Validator\PasswordStrength; use PHPUnit\Framework\TestCase; -class PasswordPolicyTest extends TestCase +class PasswordStrengthTest extends TestCase { public function testDefaultPolicy(): void { - $validator = new PasswordPolicy(); + $validator = new PasswordStrength(); $this->assertFalse($validator->isValid('1234567')); $this->assertTrue($validator->isValid('password')); @@ -17,7 +17,7 @@ class PasswordPolicyTest extends TestCase public function testConfiguredPolicy(): void { - $validator = new PasswordPolicy([ + $validator = new PasswordStrength([ 'minLength' => 12, 'requireUppercase' => true, 'requireLowercase' => true, @@ -36,7 +36,7 @@ class PasswordPolicyTest extends TestCase public function testAllowEmpty(): void { - $validator = new PasswordPolicy([ + $validator = new PasswordStrength([ 'minLength' => 12, 'requireUppercase' => true, 'requireLowercase' => true, From 38f80db9925ef5f2e5eb954060c529c7e3f494fe Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 21 May 2026 20:54:07 +0400 Subject: [PATCH 07/16] Clean up password strength policy docs --- .../update-auth-password-policy-lowercase.md | 1 - .../update-auth-password-policy-min-length.md | 1 - .../update-auth-password-policy-number.md | 1 - .../update-auth-password-policy-special-char.md | 1 - .../update-auth-password-policy-uppercase.md | 1 - .../projects/update-auth-password-strength.md | 1 + src/Appwrite/Utopia/Response/Model/Project.php | 12 ------------ .../Services/Project/ProjectConsoleClientTest.php | 15 +-------------- 8 files changed, 2 insertions(+), 31 deletions(-) delete mode 100644 docs/references/projects/update-auth-password-policy-lowercase.md delete mode 100644 docs/references/projects/update-auth-password-policy-min-length.md delete mode 100644 docs/references/projects/update-auth-password-policy-number.md delete mode 100644 docs/references/projects/update-auth-password-policy-special-char.md delete mode 100644 docs/references/projects/update-auth-password-policy-uppercase.md create mode 100644 docs/references/projects/update-auth-password-strength.md diff --git a/docs/references/projects/update-auth-password-policy-lowercase.md b/docs/references/projects/update-auth-password-policy-lowercase.md deleted file mode 100644 index 139930d20e..0000000000 --- a/docs/references/projects/update-auth-password-policy-lowercase.md +++ /dev/null @@ -1 +0,0 @@ -Update whether authentication passwords must include at least one lowercase letter. diff --git a/docs/references/projects/update-auth-password-policy-min-length.md b/docs/references/projects/update-auth-password-policy-min-length.md deleted file mode 100644 index 9a01d51543..0000000000 --- a/docs/references/projects/update-auth-password-policy-min-length.md +++ /dev/null @@ -1 +0,0 @@ -Update the minimum authentication password length requirement. diff --git a/docs/references/projects/update-auth-password-policy-number.md b/docs/references/projects/update-auth-password-policy-number.md deleted file mode 100644 index fe7866fb88..0000000000 --- a/docs/references/projects/update-auth-password-policy-number.md +++ /dev/null @@ -1 +0,0 @@ -Update whether authentication passwords must include at least one number. diff --git a/docs/references/projects/update-auth-password-policy-special-char.md b/docs/references/projects/update-auth-password-policy-special-char.md deleted file mode 100644 index 7c1b718252..0000000000 --- a/docs/references/projects/update-auth-password-policy-special-char.md +++ /dev/null @@ -1 +0,0 @@ -Update whether authentication passwords must include at least one special character. diff --git a/docs/references/projects/update-auth-password-policy-uppercase.md b/docs/references/projects/update-auth-password-policy-uppercase.md deleted file mode 100644 index a64ab65d0a..0000000000 --- a/docs/references/projects/update-auth-password-policy-uppercase.md +++ /dev/null @@ -1 +0,0 @@ -Update whether authentication passwords must include at least one uppercase letter. diff --git a/docs/references/projects/update-auth-password-strength.md b/docs/references/projects/update-auth-password-strength.md new file mode 100644 index 0000000000..ad7ff46b57 --- /dev/null +++ b/docs/references/projects/update-auth-password-strength.md @@ -0,0 +1 @@ +Update the authentication password strength requirements. diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index 5907a9aaca..1619c8ab16 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -43,18 +43,6 @@ class Project extends Model 'default' => '', 'example' => '1592981250', ]) - ->addRule('logo', [ - 'type' => self::TYPE_STRING, - 'description' => 'Project logo file ID.', - 'default' => '', - 'example' => '5f5c451b403cb', - ]) - ->addRule('url', [ - 'type' => self::TYPE_STRING, - 'description' => 'Project website URL.', - 'default' => '', - 'example' => '5f5c451b403cb', - ]) ->addRule('legalName', [ 'type' => self::TYPE_STRING, 'description' => 'Company legal name.', diff --git a/tests/e2e/Services/Project/ProjectConsoleClientTest.php b/tests/e2e/Services/Project/ProjectConsoleClientTest.php index a4c8b73efc..9e44f91122 100644 --- a/tests/e2e/Services/Project/ProjectConsoleClientTest.php +++ b/tests/e2e/Services/Project/ProjectConsoleClientTest.php @@ -114,23 +114,10 @@ class ProjectConsoleClientTest extends Scope $this->assertSame(0, $response['body']['pingCount']); $this->assertSame('', $response['body']['pingedAt']); - // Ensure old flattened fields are not present + // Ensure old unsupported fields are not present $this->assertArrayNotHasKey('description', $response['body']); $this->assertArrayNotHasKey('logo', $response['body']); $this->assertArrayNotHasKey('url', $response['body']); - $this->assertArrayNotHasKey('authDuration', $response['body']); - $this->assertArrayNotHasKey('authLimit', $response['body']); - $this->assertArrayNotHasKey('authSessionsLimit', $response['body']); - $this->assertArrayNotHasKey('authPasswordHistory', $response['body']); - $this->assertArrayNotHasKey('authPasswordDictionary', $response['body']); - $this->assertArrayNotHasKey('authPersonalDataCheck', $response['body']); - $this->assertArrayNotHasKey('authDisposableEmails', $response['body']); - $this->assertArrayNotHasKey('authCanonicalEmails', $response['body']); - $this->assertArrayNotHasKey('authFreeEmails', $response['body']); - $this->assertArrayNotHasKey('oAuthProviders', $response['body']); - $this->assertArrayNotHasKey('platforms', $response['body']); - $this->assertArrayNotHasKey('webhooks', $response['body']); - $this->assertArrayNotHasKey('keys', $response['body']); } protected function createTeam(string $name): array From 7b27bab9bdf6cf0bf2e1a286114a8cc65dd5d953 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 21 May 2026 21:15:14 +0400 Subject: [PATCH 08/16] Split password strength policy endpoints --- ...pdate-auth-password-strength-min-length.md | 1 + ...uth-password-strength-require-lowercase.md | 1 + ...e-auth-password-strength-require-number.md | 1 + ...-password-strength-require-special-char.md | 1 + ...uth-password-strength-require-uppercase.md | 1 + .../projects/update-auth-password-strength.md | 1 - .../{ => MinLength}/Update.php | 54 +- .../RequireLowercase/Update.php | 89 + .../PasswordStrength/RequireNumber/Update.php | 89 + .../RequireSpecialChar/Update.php | 89 + .../RequireUppercase/Update.php | 89 + .../Modules/Project/Services/Http.php | 204 +-- tests/e2e/Services/Project/PoliciesBase.php | 179 +- .../Projects/ProjectsConsoleClientTest.php | 1560 +++++++++-------- 14 files changed, 1383 insertions(+), 976 deletions(-) create mode 100644 docs/references/projects/update-auth-password-strength-min-length.md create mode 100644 docs/references/projects/update-auth-password-strength-require-lowercase.md create mode 100644 docs/references/projects/update-auth-password-strength-require-number.md create mode 100644 docs/references/projects/update-auth-password-strength-require-special-char.md create mode 100644 docs/references/projects/update-auth-password-strength-require-uppercase.md delete mode 100644 docs/references/projects/update-auth-password-strength.md rename src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/{ => MinLength}/Update.php (58%) create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php create mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php diff --git a/docs/references/projects/update-auth-password-strength-min-length.md b/docs/references/projects/update-auth-password-strength-min-length.md new file mode 100644 index 0000000000..f6c2beef25 --- /dev/null +++ b/docs/references/projects/update-auth-password-strength-min-length.md @@ -0,0 +1 @@ +Update the minimum authentication password strength length requirement. diff --git a/docs/references/projects/update-auth-password-strength-require-lowercase.md b/docs/references/projects/update-auth-password-strength-require-lowercase.md new file mode 100644 index 0000000000..b7e5dc4c74 --- /dev/null +++ b/docs/references/projects/update-auth-password-strength-require-lowercase.md @@ -0,0 +1 @@ +Update whether authentication password strength requires at least one lowercase letter. diff --git a/docs/references/projects/update-auth-password-strength-require-number.md b/docs/references/projects/update-auth-password-strength-require-number.md new file mode 100644 index 0000000000..6cccb19b88 --- /dev/null +++ b/docs/references/projects/update-auth-password-strength-require-number.md @@ -0,0 +1 @@ +Update whether authentication password strength requires at least one number. diff --git a/docs/references/projects/update-auth-password-strength-require-special-char.md b/docs/references/projects/update-auth-password-strength-require-special-char.md new file mode 100644 index 0000000000..9ed6073d18 --- /dev/null +++ b/docs/references/projects/update-auth-password-strength-require-special-char.md @@ -0,0 +1 @@ +Update whether authentication password strength requires at least one special character. diff --git a/docs/references/projects/update-auth-password-strength-require-uppercase.md b/docs/references/projects/update-auth-password-strength-require-uppercase.md new file mode 100644 index 0000000000..3535258de5 --- /dev/null +++ b/docs/references/projects/update-auth-password-strength-require-uppercase.md @@ -0,0 +1 @@ +Update whether authentication password strength requires at least one uppercase letter. diff --git a/docs/references/projects/update-auth-password-strength.md b/docs/references/projects/update-auth-password-strength.md deleted file mode 100644 index ad7ff46b57..0000000000 --- a/docs/references/projects/update-auth-password-strength.md +++ /dev/null @@ -1 +0,0 @@ -Update the authentication password strength requirements. diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/MinLength/Update.php similarity index 58% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php rename to src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/MinLength/Update.php index 53b82426a8..2e7a6242bc 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/MinLength/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/project/policies/password-strength') - ->desc('Update password strength policy') + ->setHttpPath('/v1/project/policies/password-strength/min-length') + ->desc('Update password strength minimum length') ->groups(['api', 'project']) ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') @@ -38,23 +37,19 @@ class Update extends Action ->label('sdk', new Method( namespace: 'project', group: 'policies', - name: 'updatePasswordStrength', - description: <<param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) - ->param('requireUppercase', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.', optional: true) - ->param('requireLowercase', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.', optional: true) - ->param('requireNumber', null, new Boolean(), 'Whether passwords must include at least one number.', optional: true) - ->param('requireSpecialChar', null, new Boolean(), 'Whether passwords must include at least one special character.', optional: true) + ->param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.') ->inject('response') ->inject('dbForPlatform') ->inject('project') @@ -64,11 +59,7 @@ class Update extends Action } public function action( - ?int $minLength, - ?bool $requireUppercase, - ?bool $requireLowercase, - ?bool $requireNumber, - ?bool $requireSpecialChar, + int $minLength, Response $response, Database $dbForPlatform, Document $project, @@ -83,32 +74,15 @@ class Update extends Action 'requireNumber' => false, 'requireSpecialChar' => false, ], $auths['passwordStrength'] ?? []); + $auths['passwordStrength']['minLength'] = $minLength; - if ($minLength !== null) { - $auths['passwordStrength']['minLength'] = $minLength; - } - if ($requireUppercase !== null) { - $auths['passwordStrength']['requireUppercase'] = $requireUppercase; - } - if ($requireLowercase !== null) { - $auths['passwordStrength']['requireLowercase'] = $requireLowercase; - } - if ($requireNumber !== null) { - $auths['passwordStrength']['requireNumber'] = $requireNumber; - } - if ($requireSpecialChar !== null) { - $auths['passwordStrength']['requireSpecialChar'] = $requireSpecialChar; - } - - $updates = new Document([ + $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ 'auths' => $auths, - ]); - - $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), $updates)); + ]))); $queueForEvents ->setParam('projectId', $project->getId()) - ->setParam('policy', 'password-strength'); + ->setParam('policy', 'password-strength.min-length'); $response->dynamic($project, Response::MODEL_PROJECT); } diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php new file mode 100644 index 0000000000..359c6e0e43 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php @@ -0,0 +1,89 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/project/policies/password-strength/require-lowercase') + ->desc('Update password strength lowercase requirement') + ->groups(['api', 'project']) + ->label('scope', ['policies.write', 'project.policies.write']) + ->label('event', 'projects.[projectId].policies.[policy].update') + ->label('audits.event', 'projects.[projectId].policies.[policy].update') + ->label('audits.resource', 'project/{response.$id}') + ->label('sdk', new Method( + namespace: 'project', + group: 'policies', + name: 'updatePasswordStrengthRequireLowercase', + description: <<<'EOT' + Update whether passwords must include at least one lowercase letter. + EOT, + auth: [AuthType::ADMIN, AuthType::KEY], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ), + ], + )) + ->param('enabled', null, new Boolean, 'Whether passwords must include at least one lowercase letter.') + ->inject('response') + ->inject('dbForPlatform') + ->inject('project') + ->inject('authorization') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action( + bool $enabled, + Response $response, + Database $dbForPlatform, + Document $project, + Authorization $authorization, + Event $queueForEvents, + ): void { + $auths = $project->getAttribute('auths', []); + $auths['passwordStrength'] = \array_merge([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ], $auths['passwordStrength'] ?? []); + $auths['passwordStrength']['requireLowercase'] = $enabled; + + $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ + 'auths' => $auths, + ]))); + + $queueForEvents + ->setParam('projectId', $project->getId()) + ->setParam('policy', 'password-strength.require-lowercase'); + + $response->dynamic($project, Response::MODEL_PROJECT); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php new file mode 100644 index 0000000000..4077df3257 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php @@ -0,0 +1,89 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/project/policies/password-strength/require-number') + ->desc('Update password strength number requirement') + ->groups(['api', 'project']) + ->label('scope', ['policies.write', 'project.policies.write']) + ->label('event', 'projects.[projectId].policies.[policy].update') + ->label('audits.event', 'projects.[projectId].policies.[policy].update') + ->label('audits.resource', 'project/{response.$id}') + ->label('sdk', new Method( + namespace: 'project', + group: 'policies', + name: 'updatePasswordStrengthRequireNumber', + description: <<<'EOT' + Update whether passwords must include at least one number. + EOT, + auth: [AuthType::ADMIN, AuthType::KEY], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ), + ], + )) + ->param('enabled', null, new Boolean, 'Whether passwords must include at least one number.') + ->inject('response') + ->inject('dbForPlatform') + ->inject('project') + ->inject('authorization') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action( + bool $enabled, + Response $response, + Database $dbForPlatform, + Document $project, + Authorization $authorization, + Event $queueForEvents, + ): void { + $auths = $project->getAttribute('auths', []); + $auths['passwordStrength'] = \array_merge([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ], $auths['passwordStrength'] ?? []); + $auths['passwordStrength']['requireNumber'] = $enabled; + + $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ + 'auths' => $auths, + ]))); + + $queueForEvents + ->setParam('projectId', $project->getId()) + ->setParam('policy', 'password-strength.require-number'); + + $response->dynamic($project, Response::MODEL_PROJECT); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php new file mode 100644 index 0000000000..a83575ec13 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php @@ -0,0 +1,89 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/project/policies/password-strength/require-special-char') + ->desc('Update password strength special character requirement') + ->groups(['api', 'project']) + ->label('scope', ['policies.write', 'project.policies.write']) + ->label('event', 'projects.[projectId].policies.[policy].update') + ->label('audits.event', 'projects.[projectId].policies.[policy].update') + ->label('audits.resource', 'project/{response.$id}') + ->label('sdk', new Method( + namespace: 'project', + group: 'policies', + name: 'updatePasswordStrengthRequireSpecialChar', + description: <<<'EOT' + Update whether passwords must include at least one special character. + EOT, + auth: [AuthType::ADMIN, AuthType::KEY], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ), + ], + )) + ->param('enabled', null, new Boolean, 'Whether passwords must include at least one special character.') + ->inject('response') + ->inject('dbForPlatform') + ->inject('project') + ->inject('authorization') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action( + bool $enabled, + Response $response, + Database $dbForPlatform, + Document $project, + Authorization $authorization, + Event $queueForEvents, + ): void { + $auths = $project->getAttribute('auths', []); + $auths['passwordStrength'] = \array_merge([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ], $auths['passwordStrength'] ?? []); + $auths['passwordStrength']['requireSpecialChar'] = $enabled; + + $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ + 'auths' => $auths, + ]))); + + $queueForEvents + ->setParam('projectId', $project->getId()) + ->setParam('policy', 'password-strength.require-special-char'); + + $response->dynamic($project, Response::MODEL_PROJECT); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php new file mode 100644 index 0000000000..906c52d54d --- /dev/null +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php @@ -0,0 +1,89 @@ +setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) + ->setHttpPath('/v1/project/policies/password-strength/require-uppercase') + ->desc('Update password strength uppercase requirement') + ->groups(['api', 'project']) + ->label('scope', ['policies.write', 'project.policies.write']) + ->label('event', 'projects.[projectId].policies.[policy].update') + ->label('audits.event', 'projects.[projectId].policies.[policy].update') + ->label('audits.resource', 'project/{response.$id}') + ->label('sdk', new Method( + namespace: 'project', + group: 'policies', + name: 'updatePasswordStrengthRequireUppercase', + description: <<<'EOT' + Update whether passwords must include at least one uppercase letter. + EOT, + auth: [AuthType::ADMIN, AuthType::KEY], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ), + ], + )) + ->param('enabled', null, new Boolean, 'Whether passwords must include at least one uppercase letter.') + ->inject('response') + ->inject('dbForPlatform') + ->inject('project') + ->inject('authorization') + ->inject('queueForEvents') + ->callback($this->action(...)); + } + + public function action( + bool $enabled, + Response $response, + Database $dbForPlatform, + Document $project, + Authorization $authorization, + Event $queueForEvents, + ): void { + $auths = $project->getAttribute('auths', []); + $auths['passwordStrength'] = \array_merge([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ], $auths['passwordStrength'] ?? []); + $auths['passwordStrength']['requireUppercase'] = $enabled; + + $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ + 'auths' => $auths, + ]))); + + $queueForEvents + ->setParam('projectId', $project->getId()) + ->setParam('policy', 'password-strength.require-uppercase'); + + $response->dynamic($project, Response::MODEL_PROJECT); + } +} diff --git a/src/Appwrite/Platform/Modules/Project/Services/Http.php b/src/Appwrite/Platform/Modules/Project/Services/Http.php index a8eec3abd0..eefb4d770a 100644 --- a/src/Appwrite/Platform/Modules/Project/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Project/Services/Http.php @@ -80,7 +80,11 @@ use Appwrite\Platform\Modules\Project\Http\Project\Policies\MembershipPrivacy\Up use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordDictionary\Update as UpdatePasswordDictionaryPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordHistory\Update as UpdatePasswordHistoryPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPersonalData\Update as UpdatePasswordPersonalDataPolicy; -use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\Update as UpdatePasswordStrengthPolicy; +use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\MinLength\Update as UpdatePasswordStrengthMinLengthPolicy; +use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\RequireLowercase\Update as UpdatePasswordStrengthRequireLowercasePolicy; +use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\RequireNumber\Update as UpdatePasswordStrengthRequireNumberPolicy; +use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\RequireSpecialChar\Update as UpdatePasswordStrengthRequireSpecialCharPolicy; +use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\RequireUppercase\Update as UpdatePasswordStrengthRequireUppercasePolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionAlert\Update as UpdateSessionAlertPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionDuration\Update as UpdateSessionDurationPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionInvalidation\Update as UpdateSessionInvalidationPolicy; @@ -108,122 +112,126 @@ class Http extends Service $this->type = Service::TYPE_HTTP; // Hooks - $this->addAction(Init::getName(), new Init()); + $this->addAction(Init::getName(), new Init); // Project - $this->addAction(DeleteProject::getName(), new DeleteProject()); - $this->addAction(GetProject::getName(), new GetProject()); - $this->addAction(UpdateProjectLabels::getName(), new UpdateProjectLabels()); - $this->addAction(UpdateProjectProtocol::getName(), new UpdateProjectProtocol()); - $this->addAction(UpdateProjectService::getName(), new UpdateProjectService()); + $this->addAction(DeleteProject::getName(), new DeleteProject); + $this->addAction(GetProject::getName(), new GetProject); + $this->addAction(UpdateProjectLabels::getName(), new UpdateProjectLabels); + $this->addAction(UpdateProjectProtocol::getName(), new UpdateProjectProtocol); + $this->addAction(UpdateProjectService::getName(), new UpdateProjectService); // SMTP - $this->addAction(UpdateSMTP::getName(), new UpdateSMTP()); - $this->addAction(CreateSMTPTest::getName(), new CreateSMTPTest()); + $this->addAction(UpdateSMTP::getName(), new UpdateSMTP); + $this->addAction(CreateSMTPTest::getName(), new CreateSMTPTest); // Templates - $this->addAction(ListTemplates::getName(), new ListTemplates()); - $this->addAction(GetTemplate::getName(), new GetTemplate()); - $this->addAction(UpdateTemplate::getName(), new UpdateTemplate()); + $this->addAction(ListTemplates::getName(), new ListTemplates); + $this->addAction(GetTemplate::getName(), new GetTemplate); + $this->addAction(UpdateTemplate::getName(), new UpdateTemplate); // Variables - $this->addAction(CreateVariable::getName(), new CreateVariable()); - $this->addAction(ListVariables::getName(), new ListVariables()); - $this->addAction(GetVariable::getName(), new GetVariable()); - $this->addAction(DeleteVariable::getName(), new DeleteVariable()); - $this->addAction(UpdateVariable::getName(), new UpdateVariable()); + $this->addAction(CreateVariable::getName(), new CreateVariable); + $this->addAction(ListVariables::getName(), new ListVariables); + $this->addAction(GetVariable::getName(), new GetVariable); + $this->addAction(DeleteVariable::getName(), new DeleteVariable); + $this->addAction(UpdateVariable::getName(), new UpdateVariable); // Keys - $this->addAction(CreateKey::getName(), new CreateKey()); - $this->addAction(CreateEphemeralKey::getName(), new CreateEphemeralKey()); - $this->addAction(ListKeys::getName(), new ListKeys()); - $this->addAction(GetKey::getName(), new GetKey()); - $this->addAction(DeleteKey::getName(), new DeleteKey()); - $this->addAction(UpdateKey::getName(), new UpdateKey()); + $this->addAction(CreateKey::getName(), new CreateKey); + $this->addAction(CreateEphemeralKey::getName(), new CreateEphemeralKey); + $this->addAction(ListKeys::getName(), new ListKeys); + $this->addAction(GetKey::getName(), new GetKey); + $this->addAction(DeleteKey::getName(), new DeleteKey); + $this->addAction(UpdateKey::getName(), new UpdateKey); // Platforms - $this->addAction(ListPlatforms::getName(), new ListPlatforms()); - $this->addAction(GetPlatform::getName(), new GetPlatform()); - $this->addAction(CreateWebPlatform::getName(), new CreateWebPlatform()); - $this->addAction(CreateApplePlatform::getName(), new CreateApplePlatform()); - $this->addAction(CreateAndroidPlatform::getName(), new CreateAndroidPlatform()); - $this->addAction(CreateWindowsPlatform::getName(), new CreateWindowsPlatform()); - $this->addAction(CreateLinuxPlatform::getName(), new CreateLinuxPlatform()); - $this->addAction(UpdateWebPlatform::getName(), new UpdateWebPlatform()); - $this->addAction(UpdateApplePlatform::getName(), new UpdateApplePlatform()); - $this->addAction(UpdateAndroidPlatform::getName(), new UpdateAndroidPlatform()); - $this->addAction(UpdateWindowsPlatform::getName(), new UpdateWindowsPlatform()); - $this->addAction(UpdateLinuxPlatform::getName(), new UpdateLinuxPlatform()); - $this->addAction(DeletePlatform::getName(), new DeletePlatform()); + $this->addAction(ListPlatforms::getName(), new ListPlatforms); + $this->addAction(GetPlatform::getName(), new GetPlatform); + $this->addAction(CreateWebPlatform::getName(), new CreateWebPlatform); + $this->addAction(CreateApplePlatform::getName(), new CreateApplePlatform); + $this->addAction(CreateAndroidPlatform::getName(), new CreateAndroidPlatform); + $this->addAction(CreateWindowsPlatform::getName(), new CreateWindowsPlatform); + $this->addAction(CreateLinuxPlatform::getName(), new CreateLinuxPlatform); + $this->addAction(UpdateWebPlatform::getName(), new UpdateWebPlatform); + $this->addAction(UpdateApplePlatform::getName(), new UpdateApplePlatform); + $this->addAction(UpdateAndroidPlatform::getName(), new UpdateAndroidPlatform); + $this->addAction(UpdateWindowsPlatform::getName(), new UpdateWindowsPlatform); + $this->addAction(UpdateLinuxPlatform::getName(), new UpdateLinuxPlatform); + $this->addAction(DeletePlatform::getName(), new DeletePlatform); // Mock Phones - $this->addAction(CreateMockPhone::getName(), new CreateMockPhone()); - $this->addAction(ListMockPhones::getName(), new ListMockPhones()); - $this->addAction(GetMockPhone::getName(), new GetMockPhone()); - $this->addAction(UpdateMockPhone::getName(), new UpdateMockPhone()); - $this->addAction(DeleteMockPhone::getName(), new DeleteMockPhone()); + $this->addAction(CreateMockPhone::getName(), new CreateMockPhone); + $this->addAction(ListMockPhones::getName(), new ListMockPhones); + $this->addAction(GetMockPhone::getName(), new GetMockPhone); + $this->addAction(UpdateMockPhone::getName(), new UpdateMockPhone); + $this->addAction(DeleteMockPhone::getName(), new DeleteMockPhone); // Policies - $this->addAction(ListPolicies::getName(), new ListPolicies()); - $this->addAction(GetPolicy::getName(), new GetPolicy()); - $this->addAction(UpdateMembershipPrivacyPolicy::getName(), new UpdateMembershipPrivacyPolicy()); - $this->addAction(UpdatePasswordDictionaryPolicy::getName(), new UpdatePasswordDictionaryPolicy()); - $this->addAction(UpdatePasswordHistoryPolicy::getName(), new UpdatePasswordHistoryPolicy()); - $this->addAction(UpdatePasswordStrengthPolicy::getName(), new UpdatePasswordStrengthPolicy()); - $this->addAction(UpdatePasswordPersonalDataPolicy::getName(), new UpdatePasswordPersonalDataPolicy()); - $this->addAction(UpdateSessionAlertPolicy::getName(), new UpdateSessionAlertPolicy()); - $this->addAction(UpdateSessionDurationPolicy::getName(), new UpdateSessionDurationPolicy()); - $this->addAction(UpdateSessionInvalidationPolicy::getName(), new UpdateSessionInvalidationPolicy()); - $this->addAction(UpdateSessionLimitPolicy::getName(), new UpdateSessionLimitPolicy()); - $this->addAction(UpdateUserLimitPolicy::getName(), new UpdateUserLimitPolicy()); + $this->addAction(ListPolicies::getName(), new ListPolicies); + $this->addAction(GetPolicy::getName(), new GetPolicy); + $this->addAction(UpdateMembershipPrivacyPolicy::getName(), new UpdateMembershipPrivacyPolicy); + $this->addAction(UpdatePasswordDictionaryPolicy::getName(), new UpdatePasswordDictionaryPolicy); + $this->addAction(UpdatePasswordHistoryPolicy::getName(), new UpdatePasswordHistoryPolicy); + $this->addAction(UpdatePasswordStrengthMinLengthPolicy::getName(), new UpdatePasswordStrengthMinLengthPolicy); + $this->addAction(UpdatePasswordStrengthRequireUppercasePolicy::getName(), new UpdatePasswordStrengthRequireUppercasePolicy); + $this->addAction(UpdatePasswordStrengthRequireLowercasePolicy::getName(), new UpdatePasswordStrengthRequireLowercasePolicy); + $this->addAction(UpdatePasswordStrengthRequireNumberPolicy::getName(), new UpdatePasswordStrengthRequireNumberPolicy); + $this->addAction(UpdatePasswordStrengthRequireSpecialCharPolicy::getName(), new UpdatePasswordStrengthRequireSpecialCharPolicy); + $this->addAction(UpdatePasswordPersonalDataPolicy::getName(), new UpdatePasswordPersonalDataPolicy); + $this->addAction(UpdateSessionAlertPolicy::getName(), new UpdateSessionAlertPolicy); + $this->addAction(UpdateSessionDurationPolicy::getName(), new UpdateSessionDurationPolicy); + $this->addAction(UpdateSessionInvalidationPolicy::getName(), new UpdateSessionInvalidationPolicy); + $this->addAction(UpdateSessionLimitPolicy::getName(), new UpdateSessionLimitPolicy); + $this->addAction(UpdateUserLimitPolicy::getName(), new UpdateUserLimitPolicy); // Auth Methods - $this->addAction(UpdateAuthMethod::getName(), new UpdateAuthMethod()); + $this->addAction(UpdateAuthMethod::getName(), new UpdateAuthMethod); // OAuth2 - $this->addAction(ListOAuth2Providers::getName(), new ListOAuth2Providers()); - $this->addAction(GetOAuth2Provider::getName(), new GetOAuth2Provider()); - $this->addAction(UpdateOAuth2GitHub::getName(), new UpdateOAuth2GitHub()); - $this->addAction(UpdateOAuth2Discord::getName(), new UpdateOAuth2Discord()); - $this->addAction(UpdateOAuth2Figma::getName(), new UpdateOAuth2Figma()); - $this->addAction(UpdateOAuth2Dropbox::getName(), new UpdateOAuth2Dropbox()); - $this->addAction(UpdateOAuth2Dailymotion::getName(), new UpdateOAuth2Dailymotion()); - $this->addAction(UpdateOAuth2Bitbucket::getName(), new UpdateOAuth2Bitbucket()); - $this->addAction(UpdateOAuth2Bitly::getName(), new UpdateOAuth2Bitly()); - $this->addAction(UpdateOAuth2Box::getName(), new UpdateOAuth2Box()); - $this->addAction(UpdateOAuth2Autodesk::getName(), new UpdateOAuth2Autodesk()); - $this->addAction(UpdateOAuth2Google::getName(), new UpdateOAuth2Google()); - $this->addAction(UpdateOAuth2Zoom::getName(), new UpdateOAuth2Zoom()); - $this->addAction(UpdateOAuth2Zoho::getName(), new UpdateOAuth2Zoho()); - $this->addAction(UpdateOAuth2Yandex::getName(), new UpdateOAuth2Yandex()); - $this->addAction(UpdateOAuth2X::getName(), new UpdateOAuth2X()); - $this->addAction(UpdateOAuth2WordPress::getName(), new UpdateOAuth2WordPress()); - $this->addAction(UpdateOAuth2Twitch::getName(), new UpdateOAuth2Twitch()); - $this->addAction(UpdateOAuth2Stripe::getName(), new UpdateOAuth2Stripe()); - $this->addAction(UpdateOAuth2Spotify::getName(), new UpdateOAuth2Spotify()); - $this->addAction(UpdateOAuth2Slack::getName(), new UpdateOAuth2Slack()); - $this->addAction(UpdateOAuth2Podio::getName(), new UpdateOAuth2Podio()); - $this->addAction(UpdateOAuth2Notion::getName(), new UpdateOAuth2Notion()); - $this->addAction(UpdateOAuth2Salesforce::getName(), new UpdateOAuth2Salesforce()); - $this->addAction(UpdateOAuth2Yahoo::getName(), new UpdateOAuth2Yahoo()); - $this->addAction(UpdateOAuth2Linkedin::getName(), new UpdateOAuth2Linkedin()); - $this->addAction(UpdateOAuth2Disqus::getName(), new UpdateOAuth2Disqus()); - $this->addAction(UpdateOAuth2Amazon::getName(), new UpdateOAuth2Amazon()); - $this->addAction(UpdateOAuth2Etsy::getName(), new UpdateOAuth2Etsy()); - $this->addAction(UpdateOAuth2Facebook::getName(), new UpdateOAuth2Facebook()); - $this->addAction(UpdateOAuth2Tradeshift::getName(), new UpdateOAuth2Tradeshift()); - $this->addAction(UpdateOAuth2TradeshiftSandbox::getName(), new UpdateOAuth2TradeshiftSandbox()); - $this->addAction(UpdateOAuth2Paypal::getName(), new UpdateOAuth2Paypal()); - $this->addAction(UpdateOAuth2PaypalSandbox::getName(), new UpdateOAuth2PaypalSandbox()); - $this->addAction(UpdateOAuth2Gitlab::getName(), new UpdateOAuth2Gitlab()); - $this->addAction(UpdateOAuth2Authentik::getName(), new UpdateOAuth2Authentik()); - $this->addAction(UpdateOAuth2Auth0::getName(), new UpdateOAuth2Auth0()); - $this->addAction(UpdateOAuth2FusionAuth::getName(), new UpdateOAuth2FusionAuth()); - $this->addAction(UpdateOAuth2Keycloak::getName(), new UpdateOAuth2Keycloak()); - $this->addAction(UpdateOAuth2Oidc::getName(), new UpdateOAuth2Oidc()); - $this->addAction(UpdateOAuth2Okta::getName(), new UpdateOAuth2Okta()); - $this->addAction(UpdateOAuth2Kick::getName(), new UpdateOAuth2Kick()); - $this->addAction(UpdateOAuth2Apple::getName(), new UpdateOAuth2Apple()); - $this->addAction(UpdateOAuth2Microsoft::getName(), new UpdateOAuth2Microsoft()); + $this->addAction(ListOAuth2Providers::getName(), new ListOAuth2Providers); + $this->addAction(GetOAuth2Provider::getName(), new GetOAuth2Provider); + $this->addAction(UpdateOAuth2GitHub::getName(), new UpdateOAuth2GitHub); + $this->addAction(UpdateOAuth2Discord::getName(), new UpdateOAuth2Discord); + $this->addAction(UpdateOAuth2Figma::getName(), new UpdateOAuth2Figma); + $this->addAction(UpdateOAuth2Dropbox::getName(), new UpdateOAuth2Dropbox); + $this->addAction(UpdateOAuth2Dailymotion::getName(), new UpdateOAuth2Dailymotion); + $this->addAction(UpdateOAuth2Bitbucket::getName(), new UpdateOAuth2Bitbucket); + $this->addAction(UpdateOAuth2Bitly::getName(), new UpdateOAuth2Bitly); + $this->addAction(UpdateOAuth2Box::getName(), new UpdateOAuth2Box); + $this->addAction(UpdateOAuth2Autodesk::getName(), new UpdateOAuth2Autodesk); + $this->addAction(UpdateOAuth2Google::getName(), new UpdateOAuth2Google); + $this->addAction(UpdateOAuth2Zoom::getName(), new UpdateOAuth2Zoom); + $this->addAction(UpdateOAuth2Zoho::getName(), new UpdateOAuth2Zoho); + $this->addAction(UpdateOAuth2Yandex::getName(), new UpdateOAuth2Yandex); + $this->addAction(UpdateOAuth2X::getName(), new UpdateOAuth2X); + $this->addAction(UpdateOAuth2WordPress::getName(), new UpdateOAuth2WordPress); + $this->addAction(UpdateOAuth2Twitch::getName(), new UpdateOAuth2Twitch); + $this->addAction(UpdateOAuth2Stripe::getName(), new UpdateOAuth2Stripe); + $this->addAction(UpdateOAuth2Spotify::getName(), new UpdateOAuth2Spotify); + $this->addAction(UpdateOAuth2Slack::getName(), new UpdateOAuth2Slack); + $this->addAction(UpdateOAuth2Podio::getName(), new UpdateOAuth2Podio); + $this->addAction(UpdateOAuth2Notion::getName(), new UpdateOAuth2Notion); + $this->addAction(UpdateOAuth2Salesforce::getName(), new UpdateOAuth2Salesforce); + $this->addAction(UpdateOAuth2Yahoo::getName(), new UpdateOAuth2Yahoo); + $this->addAction(UpdateOAuth2Linkedin::getName(), new UpdateOAuth2Linkedin); + $this->addAction(UpdateOAuth2Disqus::getName(), new UpdateOAuth2Disqus); + $this->addAction(UpdateOAuth2Amazon::getName(), new UpdateOAuth2Amazon); + $this->addAction(UpdateOAuth2Etsy::getName(), new UpdateOAuth2Etsy); + $this->addAction(UpdateOAuth2Facebook::getName(), new UpdateOAuth2Facebook); + $this->addAction(UpdateOAuth2Tradeshift::getName(), new UpdateOAuth2Tradeshift); + $this->addAction(UpdateOAuth2TradeshiftSandbox::getName(), new UpdateOAuth2TradeshiftSandbox); + $this->addAction(UpdateOAuth2Paypal::getName(), new UpdateOAuth2Paypal); + $this->addAction(UpdateOAuth2PaypalSandbox::getName(), new UpdateOAuth2PaypalSandbox); + $this->addAction(UpdateOAuth2Gitlab::getName(), new UpdateOAuth2Gitlab); + $this->addAction(UpdateOAuth2Authentik::getName(), new UpdateOAuth2Authentik); + $this->addAction(UpdateOAuth2Auth0::getName(), new UpdateOAuth2Auth0); + $this->addAction(UpdateOAuth2FusionAuth::getName(), new UpdateOAuth2FusionAuth); + $this->addAction(UpdateOAuth2Keycloak::getName(), new UpdateOAuth2Keycloak); + $this->addAction(UpdateOAuth2Oidc::getName(), new UpdateOAuth2Oidc); + $this->addAction(UpdateOAuth2Okta::getName(), new UpdateOAuth2Okta); + $this->addAction(UpdateOAuth2Kick::getName(), new UpdateOAuth2Kick); + $this->addAction(UpdateOAuth2Apple::getName(), new UpdateOAuth2Apple); + $this->addAction(UpdateOAuth2Microsoft::getName(), new UpdateOAuth2Microsoft); } } diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index bb62e72c69..80edad2e65 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -61,13 +61,11 @@ trait PoliciesBase { $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); - $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, - ]); + $this->updatePasswordStrengthMinLengthPolicy(12); + $this->updatePasswordStrengthRequireUppercasePolicy(true); + $this->updatePasswordStrengthRequireLowercasePolicy(true); + $this->updatePasswordStrengthRequireNumberPolicy(true); + $this->updatePasswordStrengthRequireSpecialCharPolicy(true); $this->updateSessionDurationPolicy(3600); $this->updateMembershipPrivacyPolicy([ 'userId' => true, @@ -109,13 +107,7 @@ trait PoliciesBase // Cleanup $this->updatePasswordDictionaryPolicy(false); $this->updatePasswordHistoryPolicy(null); - $this->updatePasswordStrengthPolicy([ - 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, - ]); + $this->resetPasswordStrengthPolicy(); $this->updateSessionDurationPolicy(31536000); $this->updateMembershipPrivacyPolicy([ 'userId' => false, @@ -209,13 +201,11 @@ trait PoliciesBase { $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); - $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, - ]); + $this->updatePasswordStrengthMinLengthPolicy(12); + $this->updatePasswordStrengthRequireUppercasePolicy(true); + $this->updatePasswordStrengthRequireLowercasePolicy(true); + $this->updatePasswordStrengthRequireNumberPolicy(true); + $this->updatePasswordStrengthRequireSpecialCharPolicy(true); $this->updateSessionDurationPolicy(3600); $this->updateMembershipPrivacyPolicy([ 'userId' => true, @@ -251,13 +241,7 @@ trait PoliciesBase // Cleanup $this->updatePasswordDictionaryPolicy(false); $this->updatePasswordHistoryPolicy(null); - $this->updatePasswordStrengthPolicy([ - 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, - ]); + $this->resetPasswordStrengthPolicy(); $this->updateSessionDurationPolicy(31536000); $this->updateMembershipPrivacyPolicy([ 'userId' => false, @@ -479,13 +463,19 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicy(): void { - $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, - ]); + $response = $this->updatePasswordStrengthMinLengthPolicy(12); + $this->assertSame(200, $response['headers']['status-code']); + + $response = $this->updatePasswordStrengthRequireUppercasePolicy(true); + $this->assertSame(200, $response['headers']['status-code']); + + $response = $this->updatePasswordStrengthRequireLowercasePolicy(true); + $this->assertSame(200, $response['headers']['status-code']); + + $response = $this->updatePasswordStrengthRequireNumberPolicy(true); + $this->assertSame(200, $response['headers']['status-code']); + + $response = $this->updatePasswordStrengthRequireSpecialCharPolicy(true); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(12, $response['body']['authPasswordStrengthMinLength']); @@ -503,30 +493,28 @@ trait PoliciesBase $this->assertSame(true, $policy['body']['requireSpecialChar']); // Cleanup - $this->updatePasswordStrengthPolicy([ - 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, - ]); + $this->resetPasswordStrengthPolicy(); } - public function testUpdatePasswordStrengthPolicyPartial(): void + public function testUpdatePasswordStrengthPolicyOptionPreservesOtherOptions(): void { - $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, - ]); + $response = $this->updatePasswordStrengthMinLengthPolicy(12); + $this->assertSame(200, $response['headers']['status-code']); + + $response = $this->updatePasswordStrengthRequireUppercasePolicy(true); + $this->assertSame(200, $response['headers']['status-code']); + + $response = $this->updatePasswordStrengthRequireLowercasePolicy(true); + $this->assertSame(200, $response['headers']['status-code']); + + $response = $this->updatePasswordStrengthRequireNumberPolicy(true); + $this->assertSame(200, $response['headers']['status-code']); + + $response = $this->updatePasswordStrengthRequireSpecialCharPolicy(true); $this->assertSame(200, $response['headers']['status-code']); - $response = $this->updatePasswordStrengthPolicy([ - 'requireLowercase' => false, - ]); + $response = $this->updatePasswordStrengthRequireLowercasePolicy(false); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(12, $response['body']['authPasswordStrengthMinLength']); @@ -536,37 +524,28 @@ trait PoliciesBase $this->assertSame(true, $response['body']['authPasswordStrengthRequireSpecialChar']); // Cleanup - $this->updatePasswordStrengthPolicy([ - 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, - ]); + $this->resetPasswordStrengthPolicy(); } public function testUpdatePasswordStrengthPolicyBelowMinLength(): void { - $response = $this->updatePasswordStrengthPolicy([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', $this->buildHeaders(), [ 'minLength' => 7, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, ]); $this->assertSame(400, $response['headers']['status-code']); } + public function testUpdatePasswordStrengthPolicyMissingParam(): void + { + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-uppercase', $this->buildHeaders(), []); + + $this->assertSame(400, $response['headers']['status-code']); + } + public function testUpdatePasswordStrengthPolicyWithoutAuth(): void { - $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, - ], false); + $response = $this->updatePasswordStrengthMinLengthPolicy(12, false); $this->assertSame(401, $response['headers']['status-code']); } @@ -1123,7 +1102,7 @@ trait PoliciesBase if ($otherParam === $param) { continue; } - $this->assertSame(true, $response['body'][$otherAttribute], $otherAttribute . ' should be untouched while only ' . $param . ' was updated'); + $this->assertSame(true, $response['body'][$otherAttribute], $otherAttribute.' should be untouched while only '.$param.' was updated'); } // Restore the field before the next iteration @@ -1238,10 +1217,10 @@ trait PoliciesBase protected function getProjectDocument(): array { - return $this->client->call(Client::METHOD_GET, '/projects/' . $this->getProject()['$id'], [ + return $this->client->call(Client::METHOD_GET, '/projects/'.$this->getProject()['$id'], [ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], 'x-appwrite-response-format' => '1.9.4', ]); } @@ -1263,7 +1242,7 @@ trait PoliciesBase protected function getPolicy(string $policyId, bool $authenticated = true): mixed { - return $this->client->call(Client::METHOD_GET, '/project/policies/' . $policyId, $this->buildHeaders($authenticated)); + return $this->client->call(Client::METHOD_GET, '/project/policies/'.$policyId, $this->buildHeaders($authenticated)); } protected function updatePasswordDictionaryPolicy(bool $enabled, bool $authenticated = true): mixed @@ -1280,12 +1259,48 @@ trait PoliciesBase ]); } - /** - * @param array $params - */ - protected function updatePasswordStrengthPolicy(array $params, bool $authenticated = true): mixed + protected function updatePasswordStrengthMinLengthPolicy(int $minLength, bool $authenticated = true): mixed { - return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders($authenticated), $params); + return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', $this->buildHeaders($authenticated), [ + 'minLength' => $minLength, + ]); + } + + protected function updatePasswordStrengthRequireUppercasePolicy(bool $enabled, bool $authenticated = true): mixed + { + return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-uppercase', $this->buildHeaders($authenticated), [ + 'enabled' => $enabled, + ]); + } + + protected function updatePasswordStrengthRequireLowercasePolicy(bool $enabled, bool $authenticated = true): mixed + { + return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-lowercase', $this->buildHeaders($authenticated), [ + 'enabled' => $enabled, + ]); + } + + protected function updatePasswordStrengthRequireNumberPolicy(bool $enabled, bool $authenticated = true): mixed + { + return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-number', $this->buildHeaders($authenticated), [ + 'enabled' => $enabled, + ]); + } + + protected function updatePasswordStrengthRequireSpecialCharPolicy(bool $enabled, bool $authenticated = true): mixed + { + return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-special-char', $this->buildHeaders($authenticated), [ + 'enabled' => $enabled, + ]); + } + + protected function resetPasswordStrengthPolicy(): void + { + $this->updatePasswordStrengthMinLengthPolicy(8); + $this->updatePasswordStrengthRequireUppercasePolicy(false); + $this->updatePasswordStrengthRequireLowercasePolicy(false); + $this->updatePasswordStrengthRequireNumberPolicy(false); + $this->updatePasswordStrengthRequireSpecialCharPolicy(false); } protected function updatePasswordPersonalDataPolicy(bool $enabled, bool $authenticated = true): mixed @@ -1331,7 +1346,7 @@ trait PoliciesBase } /** - * @param array $params + * @param array $params */ protected function updateMembershipPrivacyPolicy(array $params, bool $authenticated = true): mixed { diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 99de990170..85c4b5d4e0 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -19,14 +19,14 @@ use Utopia\System\System; class ProjectsConsoleClientTest extends Scope { - use ProjectsBase; - use ProjectConsole; - use SideClient; use Async; + use ProjectConsole; + use ProjectsBase; + use SideClient; #[Group('smtpAndTemplates')] #[Group('projectsCRUD')] - public function testCreateProject(): void + public function test_create_project(): void { /** * Test for SUCCESS @@ -46,12 +46,12 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-response-format' => '1.9.4' + 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -96,7 +96,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => '', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -108,13 +108,13 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'projectId' => ID::unique(), 'name' => 'Project Test', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(401, $response['headers']['status-code']); } - public function testDeleteProjectWithMultiDB(): void + public function test_delete_project_with_multi_db(): void { // Create a team and project $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -136,7 +136,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'MultiDB Project', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -156,7 +156,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $database['headers']['status-code']); $databaseId = $database['body']['$id']; - $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', $projectAdminHeaders, [ + $collection = $this->client->call(Client::METHOD_POST, '/databases/'.$databaseId.'/collections', $projectAdminHeaders, [ 'collectionId' => ID::unique(), 'name' => 'Legacy Collection', 'documentSecurity' => true, @@ -174,7 +174,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $documentsDb['headers']['status-code']); $documentsDbId = $documentsDb['body']['$id']; - $documentsCollection = $this->client->call(Client::METHOD_POST, '/documentsdb/' . $documentsDbId . '/collections', $projectAdminHeaders, [ + $documentsCollection = $this->client->call(Client::METHOD_POST, '/documentsdb/'.$documentsDbId.'/collections', $projectAdminHeaders, [ 'collectionId' => ID::unique(), 'name' => 'Documents Collection', 'documentSecurity' => true, @@ -192,7 +192,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $vectorDb['headers']['status-code']); $vectorDbId = $vectorDb['body']['$id']; - $vectorCollection = $this->client->call(Client::METHOD_POST, '/vectorsdb/' . $vectorDbId . '/collections', $projectAdminHeaders, [ + $vectorCollection = $this->client->call(Client::METHOD_POST, '/vectorsdb/'.$vectorDbId.'/collections', $projectAdminHeaders, [ 'collectionId' => ID::unique(), 'name' => 'Vector Collection', 'dimension' => 3, @@ -204,7 +204,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $vectorCollection['headers']['status-code']); // Delete project - $delete = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ + $delete = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -212,7 +212,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $delete['headers']['status-code']); // Ensure project is gone - $getProject = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ + $getProject = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -221,7 +221,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $getProject['headers']['status-code']); } - public function testCreateDuplicateProject(): void + public function test_create_duplicate_project(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -245,7 +245,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => $projectId, 'name' => 'Original Project', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -261,7 +261,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => $projectId, 'name' => 'Project Duplicate', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(409, $response['headers']['status-code']); @@ -270,7 +270,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('projectsCRUD')] - public function testTransferProjectTeam() + public function test_transfer_project_team() { /** * Test for SUCCESS @@ -324,7 +324,7 @@ class ProjectsConsoleClientTest extends Scope $projectId = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/team', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/team', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -339,7 +339,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('projectsCRUD')] - public function testListProject(): void + public function test_list_project(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -347,7 +347,6 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -366,7 +365,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders(), [ - 'search' => $id + 'search' => $id, ])); $this->assertEquals(200, $response['headers']['status-code']); @@ -378,7 +377,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders(), [ - 'search' => 'Project Test' + 'search' => 'Project Test', ])); $this->assertEquals($response['headers']['status-code'], 200); @@ -408,7 +407,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test 2', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -530,7 +529,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('projectsCRUD')] - public function testListProjectsQuerySelect(): void + public function test_list_projects_query_select(): void { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', @@ -551,7 +550,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Query Select Test Project', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -593,7 +592,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-response-format' => '1.9.4' + 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ 'queries' => [ Query::select(['$id', 'name', 'teamId', 'description', '$createdAt', '$updatedAt'])->toString(), @@ -789,7 +788,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `queries` param: Invalid query: Attribute not found in schema: invalidAttribute', $response['body']['message']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -797,7 +796,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } - public function testGetProject(): void + public function test_get_project(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -828,7 +827,7 @@ class ProjectsConsoleClientTest extends Scope 'legalState' => 'Custom state', 'legalCity' => 'Košice', 'legalAddress' => 'Main street 32', - 'legalTaxId' => 'TAXID_123456' + 'legalTaxId' => 'TAXID_123456', ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -875,7 +874,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'number' => '+421123456789', - 'otp' => '123456' + 'otp' => '123456', ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -885,12 +884,12 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'labels' => ['custom1', 'custom2'] + 'labels' => ['custom1', 'custom2'], ]); $this->assertEquals(200, $response['headers']['status-code']); // Create dev keys - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ 'content-type' => 'application/json', ], $this->getHeaders()), [ 'name' => 'Custom key 1', @@ -898,11 +897,11 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(201, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ 'content-type' => 'application/json', ], $this->getHeaders()), [ 'name' => 'Custom key 2', - 'expire' => '2099-05-07 11:23:30.713' + 'expire' => '2099-05-07 11:23:30.713', ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -912,7 +911,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'number' => '+420987654321', - 'otp' => '654321' + 'otp' => '654321', ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -922,7 +921,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'duration' => 135 + 'duration' => 135, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -931,7 +930,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'total' => 54 + 'total' => 54, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -940,7 +939,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'total' => 7 + 'total' => 7, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -949,7 +948,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'total' => 9 + 'total' => 9, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -958,7 +957,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => true + 'enabled' => true, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -967,7 +966,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => true + 'enabled' => true, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -976,7 +975,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => true + 'enabled' => true, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -998,7 +997,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => true + 'enabled' => true, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1019,7 +1018,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $webhook['headers']['status-code']); // Create API key - $key = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $key = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1030,7 +1029,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $key['headers']['status-code']); // Create platform - $platform = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $platform = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1056,7 +1055,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1263,7 +1262,7 @@ class ProjectsConsoleClientTest extends Scope 'authPhone', ]; foreach ($authsKeys as $authsKey) { - $this->assertTrue($response['body'][$authsKey], 'Auth method should be enabled: ' . $authsKey); + $this->assertTrue($response['body'][$authsKey], 'Auth method should be enabled: '.$authsKey); } $serviceKeys = [ @@ -1286,7 +1285,7 @@ class ProjectsConsoleClientTest extends Scope 'serviceStatusForMessaging', ]; foreach ($serviceKeys as $serviceKey) { - $this->assertTrue($response['body'][$serviceKey], 'Service should be enabled: ' . $serviceKey); + $this->assertTrue($response['body'][$serviceKey], 'Service should be enabled: '.$serviceKey); } $protocolKeys = [ @@ -1295,7 +1294,7 @@ class ProjectsConsoleClientTest extends Scope 'protocolStatusForWebsocket', ]; foreach ($protocolKeys as $protocolKey) { - $this->assertTrue($response['body'][$protocolKey], 'Protocol should be enabled: ' . $protocolKey); + $this->assertTrue($response['body'][$protocolKey], 'Protocol should be enabled: '.$protocolKey); } // Ensure booleans can be falsy @@ -1305,7 +1304,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => false + 'enabled' => false, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1314,7 +1313,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => false + 'enabled' => false, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1323,7 +1322,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => false + 'enabled' => false, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1345,7 +1344,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => false + 'enabled' => false, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1355,7 +1354,7 @@ class ProjectsConsoleClientTest extends Scope foreach ($authMethods as $authMethod) { $response = $this->client->call( Client::METHOD_PATCH, - '/project/auth-methods/' . $authMethod, + '/project/auth-methods/'.$authMethod, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, @@ -1372,7 +1371,7 @@ class ProjectsConsoleClientTest extends Scope foreach ($protocols as $protocol) { $response = $this->client->call( Client::METHOD_PATCH, - '/project/protocols/' . $protocol, + '/project/protocols/'.$protocol, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, @@ -1408,7 +1407,7 @@ class ProjectsConsoleClientTest extends Scope foreach ($services as $service) { $response = $this->client->call( Client::METHOD_PATCH, - '/project/services/' . $service, + '/project/services/'.$service, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, @@ -1441,7 +1440,7 @@ class ProjectsConsoleClientTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1475,7 +1474,7 @@ class ProjectsConsoleClientTest extends Scope 'authPhone', ]; foreach ($authsKeys as $authsKey) { - $this->assertFalse($response['body'][$authsKey], 'Auth method should be disabled: ' . $authsKey); + $this->assertFalse($response['body'][$authsKey], 'Auth method should be disabled: '.$authsKey); } $serviceKeys = [ @@ -1498,7 +1497,7 @@ class ProjectsConsoleClientTest extends Scope 'serviceStatusForMessaging', ]; foreach ($serviceKeys as $serviceKey) { - $this->assertFalse($response['body'][$serviceKey], 'Service should be disabled: ' . $serviceKey); + $this->assertFalse($response['body'][$serviceKey], 'Service should be disabled: '.$serviceKey); } $protocolKeys = [ @@ -1507,7 +1506,7 @@ class ProjectsConsoleClientTest extends Scope 'protocolStatusForWebsocket', ]; foreach ($protocolKeys as $protocolKey) { - $this->assertFalse($response['body'][$protocolKey], 'Protocol should be disabled: ' . $protocolKey); + $this->assertFalse($response['body'][$protocolKey], 'Protocol should be disabled: '.$protocolKey); } /** @@ -1531,14 +1530,14 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function testGetProjectUsage(): void + public function test_get_project_usage(): void { $this->markTestIncomplete( 'This test is failing right now due to functions collection.' ); } - public function testUpdateProject(): void + public function test_update_project(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -1561,7 +1560,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -1570,7 +1569,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1604,19 +1603,19 @@ class ProjectsConsoleClientTest extends Scope } #[Group('smtpAndTemplates')] - public function testUpdateProjectSMTP(): void + public function test_update_project_smtp(): void { $data = $this->setupProjectData(); $id = $data['projectId']; - $smtpHost = System::getEnv('_APP_SMTP_HOST', "maildev"); - $smtpPort = intval(System::getEnv('_APP_SMTP_PORT', "1025")); + $smtpHost = System::getEnv('_APP_SMTP_HOST', 'maildev'); + $smtpPort = intval(System::getEnv('_APP_SMTP_PORT', '1025')); $smtpUsername = System::getEnv('_APP_SMTP_USERNAME', 'user'); $smtpPassword = System::getEnv('_APP_SMTP_PASSWORD', 'password'); /** * Test for SUCCESS: Valid Credentials */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/smtp', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1642,7 +1641,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('', $response['body']['smtpSecure']); // Check the project - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1662,7 +1661,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE: Invalid Credentials */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/smtp', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1682,10 +1681,10 @@ class ProjectsConsoleClientTest extends Scope } #[Group('smtpAndTemplates')] - public function testCreateProjectSMTPTests(): void + public function test_create_project_smtp_tests(): void { - $smtpHost = System::getEnv('_APP_SMTP_HOST', "maildev"); - $smtpPort = intval(System::getEnv('_APP_SMTP_PORT', "1025")); + $smtpHost = System::getEnv('_APP_SMTP_HOST', 'maildev'); + $smtpPort = intval(System::getEnv('_APP_SMTP_PORT', '1025')); $smtpUsername = System::getEnv('_APP_SMTP_USERNAME', 'user'); $smtpPassword = System::getEnv('_APP_SMTP_PASSWORD', 'password'); @@ -1710,13 +1709,13 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/smtp/tests', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1749,7 +1748,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsStringIgnoringCase('251 Little Falls Drive', $email1['html']); $this->assertEquals('custommailer@appwrite.io', $email2['from'][0]['address']); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/smtp/tests', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1765,7 +1764,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/smtp/tests', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1783,13 +1782,13 @@ class ProjectsConsoleClientTest extends Scope } #[Group('smtpAndTemplates')] - public function testUpdateTemplates(): void + public function test_update_templates(): void { $data = $this->setupProjectData(); $id = $data['projectId']; /** Get Default Email Template */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/email/verification/en-us', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/templates/email/verification/en-us', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1805,10 +1804,10 @@ class ProjectsConsoleClientTest extends Scope $projectWithoutSmtp = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'Project Without SMTP', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectWithoutSmtp . '/templates/email/verification/en-us', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectWithoutSmtp.'/templates/email/verification/en-us', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1826,7 +1825,7 @@ class ProjectsConsoleClientTest extends Scope $smtpPort = 1025; $smtpUsername = 'user'; $smtpPassword = 'password'; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/smtp', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1842,7 +1841,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); /** Update Email template */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/templates/email/verification/en-us', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/templates/email/verification/en-us', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1862,7 +1861,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('Please verify your email {{url}}', $response['body']['message']); /** Get Updated Email Template */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/email/verification/en-us', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/templates/email/verification/en-us', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1878,7 +1877,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('smtpAndTemplates')] - public function testSessionAlertLocaleFallback(): void + public function test_session_alert_locale_fallback(): void { $smtpHost = 'maildev'; $smtpPort = 1025; @@ -1911,7 +1910,7 @@ class ProjectsConsoleClientTest extends Scope $projectId = $project['body']['$id']; /** Configure custom SMTP pointing to maildev */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/smtp', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/smtp', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1932,7 +1931,7 @@ class ProjectsConsoleClientTest extends Scope * default locale (en), which is the same slot used as the system-wide * fallback when a session's locale has no dedicated template. */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/templates/email', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/templates/email', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1951,7 +1950,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('fallback@appwrite.io', $response['body']['senderEmail']); /** Set custom sessionAlert template for Slovak locale */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/templates/email', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/templates/email', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1970,7 +1969,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('sk@appwrite.io', $response['body']['senderEmail']); /** Enable session alerts */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/auth/session-alerts', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/auth/session-alerts', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1980,7 +1979,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); /** Verify alerts are enabled */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1989,7 +1988,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertTrue($response['body']['authSessionAlerts']); /** Create user (email + password) in the project */ - $userEmail = 'session-alert-' . uniqid() . '@appwrite.io'; + $userEmail = 'session-alert-'.uniqid().'@appwrite.io'; $password = 'password'; $response = $this->client->call(Client::METHOD_POST, '/account', [ 'origin' => 'http://localhost', @@ -2083,27 +2082,27 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString('Slovak sign-in alert body', $lastEmail['html']); /** Cleanup — delete the project */ - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); /** Cleanup — delete the team */ - $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); } - public function testUpdateProjectAuthDuration(): void + public function test_update_project_auth_duration(): void { $data = $this->setupProjectData(); $id = $data['projectId']; // Check defaults - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2115,7 +2114,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/duration', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2139,7 +2138,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $projectId, ], $this->getHeaders()), [ 'userId' => 'unique()', - 'email' => 'test' . rand(0, 9999) . '@example.com', + 'email' => 'test'.rand(0, 9999).'@example.com', 'password' => 'password', 'name' => 'Test User', ]); @@ -2183,7 +2182,7 @@ class ProjectsConsoleClientTest extends Scope }, timeoutMs: 15 * 1000); // Set session duration to 10min - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/duration', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2204,7 +2203,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(401, $response['headers']['status-code']); // Return project back to normal - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/duration', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2216,7 +2215,7 @@ class ProjectsConsoleClientTest extends Scope $projectId = $response['body']['$id']; // Check project is back to normal - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2226,7 +2225,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(TOKEN_EXPIRATION_LOGIN_LONG, $response['body']['authDuration']); // 1 Year } - public function testUpdateProjectInvalidateSessions(): void + public function test_update_project_invalidate_sessions(): void { // Create a team for the test project $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -2248,14 +2247,14 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Session Invalidation Test Project', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; // Check defaults - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2264,7 +2263,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertTrue($response['body']['authInvalidateSessions']); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/session-invalidation', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/session-invalidation', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2273,7 +2272,7 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertFalse($response['body']['authInvalidateSessions']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2282,7 +2281,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertFalse($response['body']['authInvalidateSessions']); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/session-invalidation', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/session-invalidation', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2291,7 +2290,7 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertTrue($response['body']['authInvalidateSessions']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2301,7 +2300,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertTrue($response['body']['authInvalidateSessions']); } - public function testUpdateProjectOAuth(): void + public function test_update_project_o_auth(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -2324,33 +2323,33 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; - $providers = require(__DIR__ . '/../../../../app/config/oAuthProviders.php'); + $providers = require __DIR__.'/../../../../app/config/oAuthProviders.php'; /** * Test for SUCCESS */ foreach ($providers as $key => $provider) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/oauth2', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ 'provider' => $key, - 'appId' => 'AppId-' . ucfirst($key), - 'secret' => 'Secret-' . ucfirst($key), + 'appId' => 'AppId-'.ucfirst($key), + 'secret' => 'Secret-'.ucfirst($key), ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); } - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -2364,7 +2363,7 @@ class ProjectsConsoleClientTest extends Scope $asserted = false; foreach ($response['body']['oAuthProviders'] as $responseProvider) { if ($responseProvider['key'] === $key) { - $this->assertEquals('AppId-' . ucfirst($key), $responseProvider['appId']); + $this->assertEquals('AppId-'.ucfirst($key), $responseProvider['appId']); $this->assertEmpty($responseProvider['secret']); $this->assertFalse($responseProvider['enabled']); $asserted = true; @@ -2378,13 +2377,13 @@ class ProjectsConsoleClientTest extends Scope // Enable providers $i = 0; foreach ($providers as $key => $provider) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/oauth2', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ 'provider' => $key, - 'enabled' => $i === 0 ? false : true // On first provider, test enabled=false + 'enabled' => $i === 0 ? false : true, // On first provider, test enabled=false ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -2393,7 +2392,7 @@ class ProjectsConsoleClientTest extends Scope $i++; } - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -2423,7 +2422,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/oauth2', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -2436,7 +2435,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function testUpdateProjectAuthStatus(): void + public function test_update_project_auth_status(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -2459,14 +2458,14 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; - $auth = require(__DIR__ . '/../../../../app/config/auth.php'); - $originalEmail = uniqid() . 'user@localhost.test'; + $auth = require __DIR__.'/../../../../app/config/auth.php'; + $originalEmail = uniqid().'user@localhost.test'; $originalPassword = 'password'; $originalName = 'User Name'; @@ -2490,13 +2489,13 @@ class ProjectsConsoleClientTest extends Scope 'password' => $originalPassword, ]); - $session = $response['cookies']['a_session_' . $id]; + $session = $response['cookies']['a_session_'.$id]; /** * Test for SUCCESS */ foreach ($auth as $index => $method) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/' . $index, array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/'.$index, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2507,7 +2506,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -2515,10 +2514,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['auth' . ucfirst($method['key'])]); + $this->assertEquals(false, $response['body']['auth'.ucfirst($method['key'])]); } - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $password = 'password'; $name = 'User Name'; @@ -2541,25 +2540,25 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_' . $id . '=' . $session, + 'cookie' => 'a_session_'.$id.'='.$session, ]), [ 'teamId' => ID::unique(), - 'name' => 'Arsenal' + 'name' => 'Arsenal', ]); $this->assertEquals(201, $response['headers']['status-code']); $teamUid = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_' . $id . '=' . $session, + 'cookie' => 'a_session_'.$id.'='.$session, ]), [ 'email' => $email, 'name' => 'Friend User', 'roles' => ['admin', 'editor'], - 'url' => 'http://localhost:5000/join-us#title' + 'url' => 'http://localhost:5000/join-us#title', ]); $this->assertEquals($response['headers']['status-code'], 501); @@ -2567,7 +2566,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/jwt', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_' . $id . '=' . $session, + 'cookie' => 'a_session_'.$id.'='.$session, ])); $this->assertEquals($response['headers']['status-code'], 501); @@ -2594,7 +2593,7 @@ class ProjectsConsoleClientTest extends Scope // Cleanup foreach ($auth as $index => $method) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/' . $index, array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/'.$index, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2604,7 +2603,7 @@ class ProjectsConsoleClientTest extends Scope } } - public function testUpdateProjectAuthLimit(): void + public function test_update_project_auth_limit(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -2612,7 +2611,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/limit', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/limit', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2623,7 +2622,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $password = 'password'; $name = 'User Name'; @@ -2655,10 +2654,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $team['headers']['status-code']); $teamId = $team['body']['$id']; - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; // Creating A User Using Team membership - $response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamId . '/memberships', array_merge($this->getHeaders(), [ + $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamId.'/memberships', array_merge($this->getHeaders(), [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $id, @@ -2671,7 +2670,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ 'origin' => 'http://localhost', @@ -2687,11 +2686,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(Exception::USER_COUNT_EXCEEDED, $response['body']['type']); $this->assertEquals(400, $response['headers']['status-code']); - /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/limit', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/limit', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2702,7 +2700,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ 'origin' => 'http://localhost', @@ -2718,18 +2716,18 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($response['headers']['status-code'], 201); } - public function testUpdateProjectAuthSessionsLimit(): void + public function test_update_project_auth_sessions_limit(): void { $id = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testUpdateProjectAuthSessionsLimit', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/max-sessions', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2741,7 +2739,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertNotEmpty($response['body']['$id']); $this->assertEquals(1, $response['body']['authSessionsLimit']); - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $password = 'password'; $name = 'User Name'; @@ -2779,7 +2777,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $latestSessionId = $response['body']['$id']; - $sessionCookie = 'a_session_' . $id . '=' . ($response['cookies']['a_session_' . $id] ?? ''); + $sessionCookie = 'a_session_'.$id.'='.($response['cookies']['a_session_'.$id] ?? ''); // Small delay for shutdown hook to complete \usleep(500_000); @@ -2801,7 +2799,7 @@ class ProjectsConsoleClientTest extends Scope /** * Reset Limit */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/max-sessions', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2812,7 +2810,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); } - public function testUpdateProjectAuthPasswordHistory(): void + public function test_update_project_auth_password_history(): void { $data = $this->setupProjectWithAuthLimit(); $id = $data['projectId']; @@ -2820,7 +2818,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for Success */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-history', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2831,8 +2829,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['authPasswordHistory']); - - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $password = 'password'; $name = 'User Name'; @@ -2864,13 +2861,13 @@ class ProjectsConsoleClientTest extends Scope 'password' => $password, ]); $this->assertEquals(201, $session['headers']['status-code']); - $session = $session['cookies']['a_session_' . $id]; + $session = $session['cookies']['a_session_'.$id]; $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_' . $id . '=' . $session, + 'cookie' => 'a_session_'.$id.'='.$session, ]), [ 'oldPassword' => $password, 'password' => $password, @@ -2884,17 +2881,16 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]); - $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/password', $headers, [ + $response = $this->client->call(Client::METHOD_PATCH, '/users/'.$userId.'/password', $headers, [ 'password' => $password, ]); $this->assertEquals(400, $response['headers']['status-code']); - /** * Reset */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-history', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2906,33 +2902,67 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(0, $response['body']['authPasswordHistory']); } - public function testUpdateProjectAuthPasswordStrength(): void + public function test_update_project_auth_password_strength(): void { $data = $this->setupProjectData(); $id = $data['projectId']; - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'minLength' => 7, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, ]); $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-uppercase', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'enabled' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-lowercase', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'enabled' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-number', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'enabled' => true, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-special-char', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'enabled' => true, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -2944,7 +2974,7 @@ class ProjectsConsoleClientTest extends Scope $weakPassword = 'password123!'; $validPassword = 'Password123!'; - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ 'origin' => 'http://localhost', @@ -2952,7 +2982,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]), [ 'userId' => ID::unique(), - 'email' => uniqid() . 'weak-account@localhost.test', + 'email' => uniqid().'weak-account@localhost.test', 'password' => $weakPassword, 'name' => 'Weak Account', ]); @@ -2965,7 +2995,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ]), [ 'userId' => ID::unique(), - 'email' => uniqid() . 'weak-user@localhost.test', + 'email' => uniqid().'weak-user@localhost.test', 'password' => $weakPassword, 'name' => 'Weak User', ]); @@ -2996,13 +3026,13 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(201, $session['headers']['status-code']); - $session = $session['cookies']['a_session_' . $id]; + $session = $session['cookies']['a_session_'.$id]; $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_' . $id . '=' . $session, + 'cookie' => 'a_session_'.$id.'='.$session, ]), [ 'oldPassword' => $validPassword, 'password' => $weakPassword, @@ -3044,21 +3074,58 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]); - $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/password', $headers, [ + $response = $this->client->call(Client::METHOD_PATCH, '/users/'.$userId.'/password', $headers, [ 'password' => $weakPassword, ]); $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-uppercase', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'enabled' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-lowercase', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'enabled' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-number', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'enabled' => false, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-special-char', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'enabled' => false, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -3071,7 +3138,7 @@ class ProjectsConsoleClientTest extends Scope #[Group('smtpAndTemplates')] #[Group('projectsCRUD')] - public function testUpdateMockNumbers(): void + public function test_update_mock_numbers(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -3081,7 +3148,7 @@ class ProjectsConsoleClientTest extends Scope */ /** Trying to pass an empty body to the endpoint */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3091,21 +3158,21 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('Param "numbers" is not optional.', $response['body']['message']); /** Trying to pass body with incorrect structure */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ 'numbers' => [ 'phone' => '+1655513432', - 'otp' => '123456' - ] + 'otp' => '123456', + ], ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid payload structure. Please check the "phone" and "otp" fields', $response['body']['message']); /** Trying to pass an OTP longer than 6 characters*/ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3113,15 +3180,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '12345678' - ] - ] + 'otp' => '12345678', + ], + ], ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid OTP. Please make sure the OTP is a 6 digit number', $response['body']['message']); /** Trying to pass an OTP shorter than 6 characters*/ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3129,15 +3196,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '123' - ] - ] + 'otp' => '123', + ], + ], ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid OTP. Please make sure the OTP is a 6 digit number', $response['body']['message']); /** Trying to pass an OTP with non numeric characters */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3145,15 +3212,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '123re2' - ] - ] + 'otp' => '123re2', + ], + ], ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid OTP. Please make sure the OTP is a 6 digit number', $response['body']['message']); /** Trying to pass an invalid phone number */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3161,15 +3228,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '1655234', - 'otp' => '123456' - ] - ] + 'otp' => '123456', + ], + ], ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Phone number must start with a \'+\' can have a maximum of fifteen digits.', $response['body']['message']); /** Trying to pass a number longer than 15 digits */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3177,15 +3244,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1234567890987654', - 'otp' => '123456' - ] - ] + 'otp' => '123456', + ], + ], ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Phone number must start with a \'+\' can have a maximum of fifteen digits.', $response['body']['message']); /** Trying to pass duplicate numbers */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3193,13 +3260,13 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '123456' + 'otp' => '123456', ], [ 'phone' => '+1655513432', - 'otp' => '123456' - ] - ] + 'otp' => '123456', + ], + ], ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Duplicate phone numbers are not allowed.', $response['body']['message']); @@ -3208,17 +3275,17 @@ class ProjectsConsoleClientTest extends Scope for ($i = 0; $i < 11; $i++) { $numbers[] = [ 'phone' => '+1655513432', - 'otp' => '123456' + 'otp' => '123456', ]; } /** Trying to pass more than 10 values */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ - 'numbers' => $numbers + 'numbers' => $numbers, ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -3227,16 +3294,16 @@ class ProjectsConsoleClientTest extends Scope /** * Test for success */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ - 'numbers' => [] + 'numbers' => [], ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3244,9 +3311,9 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '123456' - ] - ] + 'otp' => '123456', + ], + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -3283,7 +3350,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); } - public function testUpdateProjectAuthPasswordDictionary(): void + public function test_update_project_auth_password_dictionary(): void { $data = $this->setupProjectWithAuthLimit(); $id = $data['projectId']; @@ -3304,7 +3371,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]), [ 'userId' => ID::unique(), - 'email' => uniqid() . 'user@localhost.test', + 'email' => uniqid().'user@localhost.test', 'password' => $password, 'name' => $name, ]); @@ -3320,7 +3387,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ]), [ 'userId' => ID::unique(), - 'email' => uniqid() . 'user@localhost.test', + 'email' => uniqid().'user@localhost.test', 'password' => 'password', 'name' => 'Cristiano Ronaldo', ]); @@ -3329,7 +3396,7 @@ class ProjectsConsoleClientTest extends Scope /** * Enable Disctionary */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-dictionary', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-dictionary', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3349,7 +3416,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]), [ 'userId' => ID::unique(), - 'email' => uniqid() . 'user@localhost.test', + 'email' => uniqid().'user@localhost.test', 'password' => $password, 'name' => $name, ]); @@ -3365,7 +3432,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ]), [ 'userId' => ID::unique(), - 'email' => uniqid() . 'user@localhost.test', + 'email' => uniqid().'user@localhost.test', 'password' => 'password', 'name' => 'Cristiano Ronaldo', ]); @@ -3377,17 +3444,16 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]); - $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/password', $headers, [ + $response = $this->client->call(Client::METHOD_PATCH, '/users/'.$userId.'/password', $headers, [ 'password' => $password, ]); $this->assertEquals(400, $response['headers']['status-code']); - /** * Reset */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-history', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3401,7 +3467,7 @@ class ProjectsConsoleClientTest extends Scope /** * Reset */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-dictionary', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-dictionary', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3413,7 +3479,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(false, $response['body']['authPasswordDictionary']); } - public function testUpdateDisallowPersonalData(): void + public function test_update_disallow_personal_data(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -3421,7 +3487,7 @@ class ProjectsConsoleClientTest extends Scope /** * Enable Disallowing of Personal Data */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/personal-data', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/personal-data', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3435,7 +3501,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for failure */ - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $password = 'password'; $name = 'username'; $userId = ID::unique(); @@ -3448,7 +3514,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $email, 'password' => $email, 'name' => $name, - 'userId' => $userId + 'userId' => $userId, ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -3463,7 +3529,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $email, 'password' => $name, 'name' => $name, - 'userId' => $userId + 'userId' => $userId, ]); $phone = '+123456789'; @@ -3476,7 +3542,7 @@ class ProjectsConsoleClientTest extends Scope 'password' => $phone, 'name' => $name, 'userId' => $userId, - 'phone' => $phone + 'phone' => $phone, ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -3484,7 +3550,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(Exception::USER_PASSWORD_PERSONAL_DATA, $response['body']['type']); /** Test for success */ - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $password = 'password'; $name = 'username'; $userId = ID::unique(); @@ -3496,7 +3562,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $email, 'password' => $password, 'name' => $name, - 'userId' => $userId + 'userId' => $userId, ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -3507,14 +3573,14 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ]), [ // Empty password - 'email' => uniqid() . 'user@localhost.test', + 'email' => uniqid().'user@localhost.test', 'name' => 'User', 'userId' => ID::unique(), ]); $this->assertEquals(201, $response['headers']['status-code']); - $email = uniqid() . 'user@localhost.test'; + $email = uniqid().'user@localhost.test'; $userId = ID::unique(); $response = $this->client->call(Client::METHOD_POST, '/users', array_merge($this->getHeaders(), [ 'content-type' => 'application/json', @@ -3525,16 +3591,15 @@ class ProjectsConsoleClientTest extends Scope 'password' => $password, 'name' => $name, 'userId' => $userId, - 'phone' => $phone + 'phone' => $phone, ]); $this->assertEquals(201, $response['headers']['status-code']); - /** * Reset */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/personal-data', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/personal-data', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3546,12 +3611,12 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(false, $response['body']['authPersonalDataCheck']); } - public function testUpdateProjectApiStatus(): void + public function test_update_project_api_status(): void { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'teamId' => ID::unique(), 'name' => 'Project Test', @@ -3564,12 +3629,12 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -3583,11 +3648,11 @@ class ProjectsConsoleClientTest extends Scope */ foreach ($protocols as $key) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/api', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'api' => $key, 'status' => false, @@ -3596,16 +3661,16 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['protocolStatusFor' . ucfirst($key)]); + $this->assertEquals(false, $response['body']['protocolStatusFor'.ucfirst($key)]); } /** @@ -3613,11 +3678,11 @@ class ProjectsConsoleClientTest extends Scope */ foreach ($protocols as $key) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/api', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'api' => $key, 'status' => true, @@ -3626,25 +3691,25 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(true, $response['body']['protocolStatusFor' . ucfirst($key)]); + $this->assertEquals(true, $response['body']['protocolStatusFor'.ucfirst($key)]); } } - public function testUpdateProjectApiStatusRealtimeBackwardsCompat(): void + public function test_update_project_api_status_realtime_backwards_compat(): void { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'teamId' => ID::unique(), 'name' => 'Project Test', @@ -3656,12 +3721,12 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -3671,11 +3736,11 @@ class ProjectsConsoleClientTest extends Scope /** * Test that "realtime" gets renamed to "websocket" via request filter */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/api', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'api' => 'realtime', 'status' => false, @@ -3683,22 +3748,22 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(false, $response['body']['protocolStatusForWebsocket']); // Re-enable via old "realtime" name - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/api', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'api' => 'realtime', 'status' => true, @@ -3706,23 +3771,23 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(true, $response['body']['protocolStatusForWebsocket']); } - public function testUpdateProjectServiceStatusAdmin(): array + public function test_update_project_service_status_admin(): array { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'teamId' => ID::unique(), 'name' => 'Project Test', @@ -3734,35 +3799,35 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $project['headers']['status-code']); $this->assertNotEmpty($project['body']['$id']); $id = $project['body']['$id']; - $services = require(__DIR__ . '/../../../../app/config/services.php'); + $services = require __DIR__.'/../../../../app/config/services.php'; /** * Test for Disabled */ foreach ($services as $service) { - if (!$service['optional']) { + if (! $service['optional']) { continue; } $key = $service['key'] ?? ''; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'service' => $key, 'status' => false, @@ -3771,41 +3836,40 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]); + $this->assertEquals(false, $response['body']['serviceStatusFor'.ucfirst($key)]); } /** * Admin request must succeed */ - $response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', // 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $id, - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], - 'x-appwrite-mode' => 'admin' + 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'x-appwrite-mode' => 'admin', ])); $this->assertEquals(200, $response['headers']['status-code']); foreach ($services as $service) { - if (!$service['optional']) { + if (! $service['optional']) { continue; } $key = $service['key'] ?? ''; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service/', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', @@ -3818,28 +3882,28 @@ class ProjectsConsoleClientTest extends Scope return ['projectId' => $id]; } - public function testUpdateProjectServiceStatus(): void + public function test_update_project_service_status(): void { $data = $this->setupProjectWithServicesDisabled(); $id = $data['projectId']; - $services = require(__DIR__ . '/../../../../app/config/services.php'); + $services = require __DIR__.'/../../../../app/config/services.php'; /** * Test for Disabled */ foreach ($services as $service) { - if (!$service['optional']) { + if (! $service['optional']) { continue; } $key = $service['key'] ?? ''; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'service' => $key, 'status' => false, @@ -3848,16 +3912,16 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]); + $this->assertEquals(false, $response['body']['serviceStatusFor'.ucfirst($key)]); } /** @@ -3876,7 +3940,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]), [ 'teamId' => ID::unique(), - 'name' => 'Arsenal' + 'name' => 'Arsenal', ]); $this->assertEquals(403, $response['headers']['status-code']); @@ -3884,7 +3948,7 @@ class ProjectsConsoleClientTest extends Scope // Cleanup foreach ($services as $service) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service/', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', @@ -3895,28 +3959,28 @@ class ProjectsConsoleClientTest extends Scope } } - public function testUpdateProjectServiceStatusServer(): void + public function test_update_project_service_status_server(): void { $data = $this->setupProjectWithServicesDisabled(); $id = $data['projectId']; - $services = require(__DIR__ . '/../../../../app/config/services.php'); + $services = require __DIR__.'/../../../../app/config/services.php'; /** * Test for Disabled */ foreach ($services as $service) { - if (!$service['optional']) { + if (! $service['optional']) { continue; } $key = $service['key'] ?? ''; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'service' => $key, 'status' => false, @@ -3925,23 +3989,23 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]); + $this->assertEquals(false, $response['body']['serviceStatusFor'.ucfirst($key)]); } // Create API Key - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), [ 'keyId' => ID::unique(), 'name' => 'Key Test', @@ -3960,7 +4024,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-key' => $keySecret, - 'x-sdk-name' => 'python' + 'x-sdk-name' => 'python', ])); $this->assertEquals(200, $response['headers']['status-code']); @@ -3969,19 +4033,19 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-key' => $keySecret, - 'x-sdk-name' => 'php' + 'x-sdk-name' => 'php', ]), [ 'teamId' => ID::unique(), - 'name' => 'Arsenal' + 'name' => 'Arsenal', ]); $this->assertEquals(201, $response['headers']['status-code']); /** Check that the API key has been updated */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), []); $this->assertEquals(200, $response['headers']['status-code']); @@ -3994,16 +4058,16 @@ class ProjectsConsoleClientTest extends Scope // Cleanup - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/'.$keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'cookie' => 'a_session_console='.$this->getRoot()['session'], ]), []); $this->assertEquals(204, $response['headers']['status-code']); foreach ($services as $service) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service/', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', @@ -4014,7 +4078,7 @@ class ProjectsConsoleClientTest extends Scope } } - public function testCreateProjectWebhook(): void + public function test_create_project_webhook(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -4022,7 +4086,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'webhookId' => 'unique()', 'name' => 'Webhook Test', @@ -4049,7 +4113,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'webhookId' => 'unique()', 'name' => 'Webhook Test', @@ -4065,7 +4129,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'webhookId' => 'unique()', 'name' => 'Webhook Test', @@ -4076,7 +4140,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function testListProjectWebhook(): void + public function test_list_project_webhook(): void { $data = $this->setupProjectWithWebhook(); $id = $data['projectId']; @@ -4084,7 +4148,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); @@ -4096,16 +4160,16 @@ class ProjectsConsoleClientTest extends Scope */ } - public function testGetProjectWebhook(): void + public function test_get_project_webhook(): void { $data = $this->setupProjectWithWebhook(); $id = $data['projectId']; $webhookId = $data['webhookId']; - $response = $this->client->call(Client::METHOD_GET, '/webhooks/' . $webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/webhooks/'.$webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); @@ -4124,22 +4188,22 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/webhooks/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), []); $this->assertEquals(404, $response['headers']['status-code']); } - public function testUpdateProjectWebhook(): void + public function test_update_project_webhook(): void { $data = $this->setupProjectWithWebhook(); $id = $data['projectId']; $webhookId = $data['webhookId']; - $response = $this->client->call(Client::METHOD_PUT, '/webhooks/' . $webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/webhooks/'.$webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'name' => 'Webhook Test Update', 'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'], @@ -4161,10 +4225,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('', $response['body']['authUsername']); $this->assertEquals('', $response['body']['authPassword']); - $response = $this->client->call(Client::METHOD_GET, '/webhooks/' . $webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/webhooks/'.$webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); @@ -4184,10 +4248,10 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PUT, '/webhooks/' . $webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/webhooks/'.$webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'name' => 'Webhook Test Update', 'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.unknown'], @@ -4197,10 +4261,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PUT, '/webhooks/' . $webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/webhooks/'.$webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'name' => 'Webhook Test Update', 'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'], @@ -4210,10 +4274,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PUT, '/webhooks/' . $webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/webhooks/'.$webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'name' => 'Webhook Test Update', 'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'], @@ -4223,17 +4287,17 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function testUpdateProjectWebhookSignature(): void + public function test_update_project_webhook_signature(): void { $data = $this->setupProjectWithWebhook(); $id = $data['projectId']; $webhookId = $data['webhookId']; $signatureKey = $data['signatureKey']; - $response = $this->client->call(Client::METHOD_PATCH, '/webhooks/' . $webhookId . '/secret', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/webhooks/'.$webhookId.'/secret', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); @@ -4241,7 +4305,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertNotEquals($signatureKey, $response['body']['secret']); } - public function testDeleteProjectWebhook(): void + public function test_delete_project_webhook(): void { // Create a fresh project with webhook for deletion test $projectData = $this->setupProjectData(); @@ -4251,7 +4315,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'webhookId' => 'unique()', 'name' => 'Webhook To Delete', @@ -4265,19 +4329,19 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $webhookId = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_DELETE, '/webhooks/' . $webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/webhooks/'.$webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), []); $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/webhooks/' . $webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/webhooks/'.$webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), []); $this->assertEquals(404, $response['headers']['status-code']); @@ -4288,7 +4352,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_DELETE, '/webhooks/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), []); $this->assertEquals(404, $response['headers']['status-code']); @@ -4296,12 +4360,12 @@ class ProjectsConsoleClientTest extends Scope // Keys - public function testCreateProjectKey(): void + public function test_create_project_key(): void { $data = $this->setupProjectData(); $id = $data['projectId']; - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4324,7 +4388,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS without key ID */ - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4339,8 +4403,8 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS with custom ID */ - $customKeyId = \uniqid() . 'custom-id'; - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $customKeyId = \uniqid().'custom-id'; + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4355,7 +4419,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE with custom ID */ - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4369,7 +4433,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS with magic string ID */ - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4384,13 +4448,13 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, [ 'keyId' => $response['body']['$id'], - 'secret' => $response['body']['secret'] + 'secret' => $response['body']['secret'], ]); /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4402,15 +4466,14 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - - public function testListProjectKey(): void + public function test_list_project_key(): void { $data = $this->setupProjectWithKey(); $id = $data['projectId']; /** Create a second key with an expiry for query testing */ - $expireDate = DateTime::addSeconds(new \DateTime(), 3600); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $expireDate = DateTime::addSeconds(new \DateTime, 3600); + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4424,7 +4487,7 @@ class ProjectsConsoleClientTest extends Scope $key2Id = $response['body']['$id']; /** List all keys (no queries) — count depends on how many test methods ran before this in the same worker */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4435,13 +4498,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertCount($totalKeys, $response['body']['keys']); /** List keys with limit */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::limit(1)->toString(), - ] + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -4449,13 +4512,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($totalKeys, $response['body']['total']); /** List keys with offset */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::offset(1)->toString(), - ] + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -4463,13 +4526,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($totalKeys, $response['body']['total']); /** List keys with cursor after */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::cursorAfter(new Document(['$id' => $data['keyId']]))->toString(), - ] + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -4477,26 +4540,26 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($totalKeys, $response['body']['total']); /** List keys filtering by expire (lessThan now — should match none) */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::lessThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString(), - ] + Query::lessThan('expire', (new \DateTime)->format('Y-m-d H:i:s'))->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(0, $response['body']['total']); /** List keys filtering by expire (greaterThan now — should match the key with expiry) */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::greaterThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString(), - ] + Query::greaterThan('expire', (new \DateTime)->format('Y-m-d H:i:s'))->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -4508,38 +4571,37 @@ class ProjectsConsoleClientTest extends Scope */ /** Test invalid query attribute */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::equal('secret', ['test'])->toString(), - ] + ], ]); $this->assertEquals(400, $response['headers']['status-code']); /** Test invalid cursor */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::cursorAfter(new Document(['$id' => 'invalid']))->toString(), - ] + ], ]); $this->assertEquals(400, $response['headers']['status-code']); } - - public function testGetProjectKey(): void + public function test_get_project_key(): void { $data = $this->setupProjectWithKey(); $id = $data['projectId']; $keyId = $data['keyId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4560,7 +4622,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/error', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4568,7 +4630,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function testValidateProjectKey(): void + public function test_validate_project_key(): void { $data = $this->setupProjectData(); $projectId = $data['projectId']; @@ -4579,20 +4641,20 @@ class ProjectsConsoleClientTest extends Scope */ // Expiring key - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'keyId' => ID::unique(), 'name' => 'Key Test', 'scopes' => ['users.write'], - 'expire' => DateTime::addSeconds(new \DateTime(), 3600), + 'expire' => DateTime::addSeconds(new \DateTime, 3600), ]); $response = $this->client->call(Client::METHOD_POST, '/users', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'] + 'x-appwrite-key' => $response['body']['secret'], ], [ 'userId' => ID::unique(), ]); @@ -4600,7 +4662,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); // No expiry - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4613,7 +4675,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/health', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'] + 'x-appwrite-key' => $response['body']['secret'], ], []); $this->assertEquals(200, $response['headers']['status-code']); @@ -4623,20 +4685,20 @@ class ProjectsConsoleClientTest extends Scope */ // Expired key - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'keyId' => ID::unique(), 'name' => 'Key Test', 'scopes' => ['health.read'], - 'expire' => DateTime::addSeconds(new \DateTime(), -3600), + 'expire' => DateTime::addSeconds(new \DateTime, -3600), ]); $response = $this->client->call(Client::METHOD_GET, '/health', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'] + 'x-appwrite-key' => $response['body']['secret'], ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -4659,26 +4721,26 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, "/storage/buckets/{$bucketId}/files", [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => 'invalid-key' + 'x-appwrite-key' => 'invalid-key', ]); $this->assertEquals(401, $response['headers']['status-code']); // Invalid scopes - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'keyId' => ID::unique(), 'name' => 'Key Test', 'scopes' => ['teams.read'], - 'expire' => DateTime::addSeconds(new \DateTime(), 3600), + 'expire' => DateTime::addSeconds(new \DateTime, 3600), ]); $response = $this->client->call(Client::METHOD_GET, '/users', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'] + 'x-appwrite-key' => $response['body']['secret'], ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -4692,46 +4754,45 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test 2', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $response['headers']['status-code']); $project2Id = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$project2Id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'keyId' => ID::unique(), 'name' => 'Key Test', 'scopes' => ['health.read'], - 'expire' => DateTime::addSeconds(new \DateTime(), 3600), + 'expire' => DateTime::addSeconds(new \DateTime, 3600), ]); $response = $this->client->call(Client::METHOD_GET, '/health', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'] + 'x-appwrite-key' => $response['body']['secret'], ]); $this->assertEquals(401, $response['headers']['status-code']); } - - public function testUpdateProjectKey(): void + public function test_update_project_key(): void { $data = $this->setupProjectWithKey(); $id = $data['projectId']; $keyId = $data['keyId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/keys/' . $keyId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/keys/'.$keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Key Test Update', 'scopes' => ['users.read', 'users.write', 'collections.read', 'tables.read'], - 'expire' => DateTime::addSeconds(new \DateTime(), 360), + 'expire' => DateTime::addSeconds(new \DateTime, 360), ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -4748,7 +4809,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertArrayHasKey('accessedAt', $response['body']); $this->assertEmpty($response['body']['accessedAt']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4770,7 +4831,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/keys/' . $keyId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/keys/'.$keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4781,13 +4842,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function testDeleteProjectKey(): void + public function test_delete_project_key(): void { // Create a fresh key for deletion testing (cannot use cached key) $projectData = $this->setupProjectData(); $id = $projectData['projectId']; - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4799,7 +4860,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $keyId = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/'.$keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4807,7 +4868,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4817,7 +4878,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/error', array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4825,7 +4886,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function testCreateProjectKeyOutdated(): void + public function test_create_project_key_outdated(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -4834,13 +4895,13 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'projectId' => $id + 'projectId' => $id, ]); $this->assertEquals(201, $response['headers']['status-code']); $this->assertContains('users.read', $response['body']['scopes']); $this->assertNotEmpty($response['body']['secret']); - $this->assertStringStartsNotWith(API_KEY_STANDARD . '_', $response['body']['secret']); + $this->assertStringStartsNotWith(API_KEY_STANDARD.'_', $response['body']['secret']); $keyId = $response['body']['$id']; $secret = $response['body']['secret']; @@ -4848,12 +4909,12 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/users', [ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-key' => $secret + 'x-appwrite-key' => $secret, ], []); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/'.$keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4864,13 +4925,13 @@ class ProjectsConsoleClientTest extends Scope // JWT Keys - public function testJWTKey(): void + public function test_jwt_key(): void { $data = $this->setupProjectData(); $id = $data['projectId']; // Create JWT key - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/jwts', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/jwts', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.2', @@ -4919,12 +4980,12 @@ class ProjectsConsoleClientTest extends Scope // Platforms - public function testCreateProjectPlatform(): void + public function test_create_project_platform(): void { $data = $this->setupProjectData(); $id = $data['projectId']; - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4944,7 +5005,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformWebId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4964,7 +5025,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformFultteriOSId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4984,7 +5045,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformFultterAndroidId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5004,7 +5065,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformFultterWebId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5024,7 +5085,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformAppleIosId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5044,7 +5105,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformAppleMacOsId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5064,7 +5125,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformAppleWatchOsId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5087,7 +5148,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5100,13 +5161,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function testListProjectPlatform(): void + public function test_list_project_platform(): void { $data = $this->setupProjectWithPlatform(); $id = $data['projectId']; $this->assertEventually(function () use ($id) { - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5123,14 +5184,14 @@ class ProjectsConsoleClientTest extends Scope */ } - public function testGetProjectPlatform(): void + public function test_get_project_platform(): void { $data = $this->setupProjectWithPlatform(); $id = $data['projectId']; $platformWebId = $data['platformWebId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5147,7 +5208,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultteriOSId = $data['platformFultteriOSId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultteriOSId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5164,7 +5225,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterAndroidId = $data['platformFultterAndroidId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultterAndroidId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5181,7 +5242,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterWebId = $data['platformFultterWebId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultterWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5198,7 +5259,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleIosId = $data['platformAppleIosId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleIosId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5215,7 +5276,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleMacOsId = $data['platformAppleMacOsId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleMacOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5232,7 +5293,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleWatchOsId = $data['platformAppleWatchOsId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleWatchOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5249,7 +5310,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleTvOsId = $data['platformAppleTvOsId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleTvOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5267,7 +5328,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/error', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5276,14 +5337,14 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function testUpdateProjectPlatform(): void + public function test_update_project_platform(): void { $data = $this->setupProjectWithPlatform(); $id = $data['projectId']; $platformWebId = $data['platformWebId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5303,7 +5364,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultteriOSId = $data['platformFultteriOSId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformFultteriOSId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5323,7 +5384,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterAndroidId = $data['platformFultterAndroidId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformFultterAndroidId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5343,7 +5404,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterWebId = $data['platformFultterWebId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformFultterWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5363,7 +5424,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleIosId = $data['platformAppleIosId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformAppleIosId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5383,7 +5444,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleMacOsId = $data['platformAppleMacOsId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformAppleMacOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5403,7 +5464,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleWatchOsId = $data['platformAppleWatchOsId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformAppleWatchOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5423,7 +5484,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleTvOsId = $data['platformAppleTvOsId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformAppleTvOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5444,7 +5505,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/error', array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5456,14 +5517,14 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function testDeleteProjectPlatform(): void + public function test_delete_project_platform(): void { // Create a fresh project with platforms for deletion testing (cannot use cached platforms) $projectData = $this->setupProjectData(); $id = $projectData['projectId']; // Create web platform - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5476,7 +5537,7 @@ class ProjectsConsoleClientTest extends Scope $platformWebId = $response['body']['$id']; // Create flutter-ios platform - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5489,7 +5550,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultteriOSId = $response['body']['$id']; // Create flutter-android platform - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5502,7 +5563,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterAndroidId = $response['body']['$id']; // Create flutter-web platform - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5515,7 +5576,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterWebId = $response['body']['$id']; // Create apple-ios platform - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5528,7 +5589,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleIosId = $response['body']['$id']; // Create apple-macos platform - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5541,7 +5602,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleMacOsId = $response['body']['$id']; // Create apple-watchos platform - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5554,7 +5615,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleWatchOsId = $response['body']['$id']; // Create apple-tvos platform - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5566,7 +5627,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $platformAppleTvOsId = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5575,7 +5636,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5583,7 +5644,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformFultteriOSId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5592,7 +5653,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultteriOSId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5600,7 +5661,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformFultterAndroidId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5609,7 +5670,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultterAndroidId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5617,7 +5678,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformFultterWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5626,7 +5687,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultterWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5634,7 +5695,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformAppleIosId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5643,7 +5704,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleIosId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5651,7 +5712,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformAppleMacOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5660,7 +5721,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleMacOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5668,7 +5729,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformAppleWatchOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5677,7 +5738,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleWatchOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5685,7 +5746,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformAppleTvOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5694,7 +5755,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleTvOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5708,13 +5769,13 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_DELETE, '/webhooks/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin' + 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), []); $this->assertEquals(404, $response['headers']['status-code']); } - public function testDeleteProject(): array + public function test_delete_project(): array { $data = []; @@ -5741,7 +5802,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Amazing Project', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -5752,14 +5813,14 @@ class ProjectsConsoleClientTest extends Scope $projectId = $project['body']['$id']; // Ensure I can get both team and project - $team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([ + $team = $this->client->call(Client::METHOD_GET, '/teams/'.$teamId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(200, $team['headers']['status-code']); - $project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ + $project = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -5768,7 +5829,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $project['headers']['status-code']); // Delete Project - $project = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ + $project = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -5776,14 +5837,14 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $project['headers']['status-code']); // Ensure I can get team but not a project - $team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([ + $team = $this->client->call(Client::METHOD_GET, '/teams/'.$teamId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(200, $team['headers']['status-code']); - $project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ + $project = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -5794,7 +5855,7 @@ class ProjectsConsoleClientTest extends Scope return $data; } - public function testDeleteSharedProject(): void + public function test_delete_shared_project(): void { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', @@ -5815,7 +5876,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Amazing Project 1', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $project2 = $this->client->call(Client::METHOD_POST, '/projects', array_merge([ @@ -5826,14 +5887,14 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Amazing Project 2', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $project1Id = $project1['body']['$id']; $project2Id = $project2['body']['$id']; // Create user in each project - $key1 = $this->client->call(Client::METHOD_POST, '/projects/' . $project1Id . '/keys', array_merge([ + $key1 = $this->client->call(Client::METHOD_POST, '/projects/'.$project1Id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -5854,7 +5915,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $user1['headers']['status-code']); - $key2 = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', array_merge([ + $key2 = $this->client->call(Client::METHOD_POST, '/projects/'.$project2Id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -5876,7 +5937,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $user2['headers']['status-code']); // Delete project 1 - $project1 = $this->client->call(Client::METHOD_DELETE, '/projects/' . $project1Id, array_merge([ + $project1 = $this->client->call(Client::METHOD_DELETE, '/projects/'.$project1Id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -5885,7 +5946,7 @@ class ProjectsConsoleClientTest extends Scope // Ensure project 2 user is still there $this->assertEventually(function () use ($user2, $project2Id, $key2) { - $response = $this->client->call(Client::METHOD_GET, '/users/' . $user2['body']['$id'], [ + $response = $this->client->call(Client::METHOD_GET, '/users/'.$user2['body']['$id'], [ 'content-type' => 'application/json', 'x-appwrite-project' => $project2Id, 'x-appwrite-key' => $key2['body']['secret'], @@ -5901,13 +5962,13 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-key' => $key2['body']['secret'], ], [ 'userId' => ID::unique(), - 'email' => 'test3@appwrite.io' + 'email' => 'test3@appwrite.io', ]); $this->assertEquals(201, $user3['headers']['status-code']); } - public function testCreateProjectVariable(): void + public function test_create_project_variable(): void { $data = $this->setupProjectData(); @@ -5922,7 +5983,7 @@ class ProjectsConsoleClientTest extends Scope 'variableId' => 'unique()', 'key' => 'APP_TEST_CREATE', 'value' => 'TESTINGVALUE', - 'secret' => false + 'secret' => false, ]); $this->assertEquals(201, $variable['headers']['status-code']); @@ -5939,7 +6000,7 @@ class ProjectsConsoleClientTest extends Scope 'variableId' => 'unique()', 'key' => 'APP_TEST_CREATE_1', 'value' => 'TESTINGVALUE_1', - 'secret' => true + 'secret' => true, ]); $this->assertEquals(201, $variable['headers']['status-code']); @@ -5957,7 +6018,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'variableId' => 'unique()', 'key' => 'APP_TEST_CREATE', - 'value' => 'ANOTHERTESTINGVALUE' + 'value' => 'ANOTHERTESTINGVALUE', ]); $this->assertEquals(409, $variable['headers']['status-code']); @@ -5969,8 +6030,8 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'variableId' => 'unique()', - 'key' => str_repeat("A", 256), - 'value' => 'TESTINGVALUE' + 'key' => str_repeat('A', 256), + 'value' => 'TESTINGVALUE', ]); $this->assertEquals(400, $variable['headers']['status-code']); @@ -5983,20 +6044,19 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'variableId' => 'unique()', 'key' => 'LONGKEY', - 'value' => str_repeat("#", 8193), + 'value' => str_repeat('#', 8193), ]); $this->assertEquals(400, $variable['headers']['status-code']); } - public function testListVariables(): void + public function test_list_variables(): void { $data = $this->setupProjectWithVariable(); /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/project/variables', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], @@ -6008,38 +6068,37 @@ class ProjectsConsoleClientTest extends Scope $this->assertGreaterThanOrEqual(2, $response['body']['total']); } - public function testGetVariable(): void + public function test_get_variable(): void { $data = $this->setupProjectWithVariable(); /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['variableId'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/project/variables/'.$data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals("APP_TEST", $response['body']['key']); - $this->assertEquals("TESTINGVALUE", $response['body']['value']); + $this->assertEquals('APP_TEST', $response['body']['key']); + $this->assertEquals('TESTINGVALUE', $response['body']['value']); - $response = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['secretVariableId'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/project/variables/'.$data['secretVariableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals("APP_TEST_1", $response['body']['key']); + $this->assertEquals('APP_TEST_1', $response['body']['key']); $this->assertEmpty($response['body']['value']); $this->assertTrue($response['body']['secret']); /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/project/variables/NON_EXISTING_VARIABLE', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], @@ -6049,60 +6108,59 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function testUpdateVariable(): void + public function test_update_variable(): void { $data = $this->setupProjectWithVariable(); /** * Test for SUCCESS */ - - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => 'APP_TEST_UPDATE', - 'value' => 'TESTINGVALUEUPDATED' + 'value' => 'TESTINGVALUEUPDATED', ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals("APP_TEST_UPDATE", $response['body']['key']); - $this->assertEquals("TESTINGVALUEUPDATED", $response['body']['value']); + $this->assertEquals('APP_TEST_UPDATE', $response['body']['key']); + $this->assertEquals('TESTINGVALUEUPDATED', $response['body']['value']); - $variable = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['variableId'], array_merge([ + $variable = $this->client->call(Client::METHOD_GET, '/project/variables/'.$data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); $this->assertEquals(200, $variable['headers']['status-code']); - $this->assertEquals("APP_TEST_UPDATE", $variable['body']['key']); - $this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']); + $this->assertEquals('APP_TEST_UPDATE', $variable['body']['key']); + $this->assertEquals('TESTINGVALUEUPDATED', $variable['body']['value']); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['secretVariableId'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['secretVariableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => 'APP_TEST_UPDATE_1', - 'value' => 'TESTINGVALUEUPDATED_1' + 'value' => 'TESTINGVALUEUPDATED_1', ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals("APP_TEST_UPDATE_1", $response['body']['key']); + $this->assertEquals('APP_TEST_UPDATE_1', $response['body']['key']); $this->assertEmpty($response['body']['value']); - $variable = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['secretVariableId'], array_merge([ + $variable = $this->client->call(Client::METHOD_GET, '/project/variables/'.$data['secretVariableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); $this->assertEquals(200, $variable['headers']['status-code']); - $this->assertEquals("APP_TEST_UPDATE_1", $variable['body']['key']); + $this->assertEquals('APP_TEST_UPDATE_1', $variable['body']['key']); $this->assertEmpty($variable['body']['value']); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['secretVariableId'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['secretVariableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', @@ -6124,15 +6182,15 @@ class ProjectsConsoleClientTest extends Scope $this->assertGreaterThanOrEqual(2, count($response['body']['variables'])); // Verify our updated variables exist (may not be at specific positions) $variableKeys = array_column($response['body']['variables'], 'key'); - $this->assertContains("APP_TEST_UPDATE", $variableKeys); - $this->assertContains("APP_TEST_UPDATE_1", $variableKeys); + $this->assertContains('APP_TEST_UPDATE', $variableKeys); + $this->assertContains('APP_TEST_UPDATE_1', $variableKeys); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'value' => 'TESTINGVALUEUPDATED_2' + 'value' => 'TESTINGVALUEUPDATED_2', ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -6142,7 +6200,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', @@ -6150,26 +6208,26 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $longKey = str_repeat("A", 256); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + $longKey = str_repeat('A', 256); + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => $longKey, - 'value' => 'TESTINGVALUEUPDATED' + 'value' => 'TESTINGVALUEUPDATED', ]); $this->assertEquals(400, $response['headers']['status-code']); - $longValue = str_repeat("#", 8193); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ + $longValue = str_repeat('#', 8193); + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => 'APP_TEST_UPDATE', - 'value' => $longValue + 'value' => $longValue, ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -6180,13 +6238,13 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => 'APP_TEST_UPDATE', - 'value' => 'TESTINGVALUEUPDATED' + 'value' => 'TESTINGVALUEUPDATED', ]); $this->assertEquals(404, $response['headers']['status-code']); } - public function testDeleteVariable(): void + public function test_delete_variable(): void { // Create a fresh project with variables for deletion testing $projectData = $this->setupProjectData(); @@ -6200,7 +6258,7 @@ class ProjectsConsoleClientTest extends Scope 'variableId' => 'unique()', 'key' => 'APP_TEST_DELETE', 'value' => 'TESTINGVALUE', - 'secret' => false + 'secret' => false, ]); $this->assertEquals(201, $variable['headers']['status-code']); @@ -6215,7 +6273,7 @@ class ProjectsConsoleClientTest extends Scope 'variableId' => 'unique()', 'key' => 'APP_TEST_DELETE_1', 'value' => 'TESTINGVALUE_1', - 'secret' => true + 'secret' => true, ]); $this->assertEquals(201, $variable['headers']['status-code']); @@ -6224,8 +6282,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - - $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/' . $variableId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/'.$variableId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectData['projectId'], 'x-appwrite-mode' => 'admin', @@ -6233,7 +6290,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/' . $secretVariableId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/'.$secretVariableId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectData['projectId'], 'x-appwrite-mode' => 'admin', @@ -6257,7 +6314,6 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/NON_EXISTING_VARIABLE', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectData['projectId'], @@ -6270,9 +6326,8 @@ class ProjectsConsoleClientTest extends Scope /** * Devkeys Tests starts here ------------------------------------------------ */ - #[Group('abuseEnabled')] - public function testCreateProjectDevKey(): void + public function test_create_project_dev_key(): void { /** * Test for SUCCESS @@ -6280,15 +6335,15 @@ class ProjectsConsoleClientTest extends Scope $id = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testCreateProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -6299,12 +6354,12 @@ class ProjectsConsoleClientTest extends Scope $this->assertEmpty($response['body']['accessedAt']); /** Create a second dev key */ - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -6319,19 +6374,18 @@ class ProjectsConsoleClientTest extends Scope */ /** TEST expiry date is required */ - $res = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ + $res = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'name' => 'Key Test' + 'name' => 'Key Test', ]); $this->assertEquals(400, $res['headers']['status-code']); } - #[Group('abuseEnabled')] - public function testListProjectDevKey(): void + public function test_list_project_dev_key(): void { /** * Test for SUCCESS @@ -6339,25 +6393,25 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testListProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); /** Create devKey 1 */ $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); /** Create devKey 2 */ $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); /** List all dev keys */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6366,20 +6420,20 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(2, $response['body']['total']); /** List dev keys with limit */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::limit(1)->toString() - ] + Query::limit(1)->toString(), + ], ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); /** List dev keys with search */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -6390,11 +6444,11 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('Dev Key Test', $response['body']['devKeys'][1]['name']); /** List dev keys with querying `expire` */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::lessThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString()] + 'queries' => [Query::lessThan('expire', (new \DateTime)->format('Y-m-d H:i:s'))->toString()], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -6405,22 +6459,21 @@ class ProjectsConsoleClientTest extends Scope */ /** Test for search with invalid query */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::search('name', 'Invalid')->toString() - ] + Query::search('name', 'Invalid')->toString(), + ], ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `queries` param: Invalid query: Attribute not found in schema: name', $response['body']['message']); } - #[Group('abuseEnabled')] - public function testGetProjectDevKey(): void + public function test_get_project_dev_key(): void { /** * Test for SUCCESS @@ -6428,16 +6481,16 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testGetProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6453,7 +6506,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/error', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6462,7 +6515,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('abuseEnabled')] - public function testGetDevKeyWithSdks(): void + public function test_get_dev_key_with_sdks(): void { /** * Test for SUCCESS @@ -6470,13 +6523,13 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testGetDevKeyWithSdks', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); /** Use dev key with python sdk */ @@ -6484,10 +6537,10 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-dev-key' => $devKey['secret'], - 'x-sdk-name' => 'python' + 'x-sdk-name' => 'python', ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(401, $res['headers']['status-code']); @@ -6496,15 +6549,15 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-dev-key' => $devKey['secret'], - 'x-sdk-name' => 'php' + 'x-sdk-name' => 'php', ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(401, $res['headers']['status-code']); /** Get the dev key */ - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6517,7 +6570,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('abuseEnabled')] - public function testNoHostValidationWithDevKey(): void + public function test_no_host_validation_with_dev_key(): void { /** * Test for SUCCESS @@ -6525,20 +6578,20 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testNoHostValidationWithDevKey', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); $provider = 'mock'; $appId = '1'; $secret = '123456'; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/oauth2', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -6551,23 +6604,23 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); /** Test oauth2 and get invalid `success` URL */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, ], [ 'success' => 'https://example.com', - 'failure' => 'https://example.com' + 'failure' => 'https://example.com', ]); $this->assertEquals(400, $response['headers']['status-code']); /** Test oauth2 with devKey and now flow works with untrusted URL too */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'] + 'x-appwrite-dev-key' => $devKey['secret'], ], [ 'success' => 'https://example.com', - 'failure' => 'https://example.com' + 'failure' => 'https://example.com', ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); @@ -6575,8 +6628,7 @@ class ProjectsConsoleClientTest extends Scope $location = $response['headers']['location']; - - $locationClient = new Client(); + $locationClient = new Client; $locationClient->setEndpoint(''); $locationClient->addHeader('x-appwrite-dev-key', $devKey['secret']); @@ -6601,27 +6653,27 @@ class ProjectsConsoleClientTest extends Scope $this->assertSame('https://example.com/#', $response['headers']['location']); /** Ensure any hostname is allowed */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-dev-key' => $devKey['secret'], 'origin' => '', - 'referer' => 'https://domain-without-rule.com' + 'referer' => 'https://domain-without-rule.com', ], [ 'success' => 'https://domain-without-rule.com', - 'failure' => 'https://domain-without-rule.com' + 'failure' => 'https://domain-without-rule.com', ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-dev-key' => $devKey['secret'], 'referer' => '', - 'origin' => 'https://domain-without-rule.com' + 'origin' => 'https://domain-without-rule.com', ], [ 'success' => 'https://domain-without-rule.com', - 'failure' => 'https://domain-without-rule.com' + 'failure' => 'https://domain-without-rule.com', ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); @@ -6640,7 +6692,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'] + 'x-appwrite-dev-key' => $devKey['secret'], ], [ 'userId' => ID::unique(), 'email' => 'user@appwrite.io', @@ -6649,13 +6701,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); } - public function testRuleOAuthRedirect(): void + public function test_rule_o_auth_redirect(): void { // Prepare project $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testRuleOAuthRedirect', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $provider = 'mock'; @@ -6663,7 +6715,7 @@ class ProjectsConsoleClientTest extends Scope $secret = '123456'; // Prepare OAuth provider - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/oauth2', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -6676,31 +6728,31 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); // Prepare rule. In reality this is site rule, but for testing, API rule is enough, and faster to prepare - $domain = \uniqid() . '-with-rule.custom.localhost'; + $domain = \uniqid().'-with-rule.custom.localhost'; $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'domain' => $domain + 'domain' => $domain, ]); $this->assertEquals(201, $rule['headers']['status-code']); // Ensure unknown domain cannot be redirect URL - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'referer' => 'https://' . $domain, + 'referer' => 'https://'.$domain, 'origin' => '', ], [ 'success' => 'https://domain-without-rule.com', - 'failure' => 'https://domain-without-rule.com' + 'failure' => 'https://domain-without-rule.com', ], followRedirects: false); $this->assertEquals(400, $response['headers']['status-code']); // Also ensure final step blocks unknown redirect URL - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider . '/redirect', [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider.'/redirect', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'origin' => '', @@ -6709,7 +6761,7 @@ class ProjectsConsoleClientTest extends Scope 'code' => 'any-code', 'state' => \json_encode([ 'success' => 'https://domain-without-rule.com', - 'failure' => 'https://domain-without-rule.com' + 'failure' => 'https://domain-without-rule.com', ]), 'error' => '', 'error_description' => '', @@ -6718,19 +6770,19 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString('project_invalid_success_url', $response['body']); // Ensure rule's domain can be redirect URL - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'referer' => 'https://' . $domain, + 'referer' => 'https://'.$domain, 'origin' => '', ], [ - 'success' => 'https://' . $domain, - 'failure' => 'https://' . $domain + 'success' => 'https://'.$domain, + 'failure' => 'https://'.$domain, ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); // Also ensure final step allows redirect URL - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider . '/redirect', [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider.'/redirect', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'origin' => '', @@ -6738,20 +6790,20 @@ class ProjectsConsoleClientTest extends Scope ], [ 'code' => 'any-code', 'state' => \json_encode([ - 'success' => 'https://' . $domain, - 'failure' => 'https://' . $domain + 'success' => 'https://'.$domain, + 'failure' => 'https://'.$domain, ]), 'error' => '', 'error_deescription' => '', ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); - $this->assertStringContainsString('https://' . $domain, $response['headers']['location']); + $this->assertStringContainsString('https://'.$domain, $response['headers']['location']); // Ensure unknown domain cannot be redirect URL $response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'referer' => 'https://' . $domain, + 'referer' => 'https://'.$domain, 'origin' => '', ], [ 'userId' => ID::unique(), @@ -6764,23 +6816,23 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'referer' => 'https://' . $domain, + 'referer' => 'https://'.$domain, 'origin' => '', ], [ 'userId' => ID::unique(), 'email' => 'user@appwrite.io', - 'url' => 'https://' . $domain, + 'url' => 'https://'.$domain, ]); $this->assertEquals(201, $response['headers']['status-code']); } - public function testOAuthRedirectWithCustomSchemeState(): void + public function test_o_auth_redirect_with_custom_scheme_state(): void { // Prepare project $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testOAuthRedirectWithCustomSchemeState', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $provider = 'mock'; @@ -6788,7 +6840,7 @@ class ProjectsConsoleClientTest extends Scope $secret = '123456'; // Prepare OAuth provider - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/oauth2', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -6800,13 +6852,13 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $scheme = 'appwrite-callback-' . $projectId; + $scheme = 'appwrite-callback-'.$projectId; $state = \json_encode([ - 'success' => $scheme . ':///', - 'failure' => $scheme . ':///' + 'success' => $scheme.':///', + 'failure' => $scheme.':///', ]); - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider . '/redirect', [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider.'/redirect', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'origin' => '', @@ -6819,12 +6871,12 @@ class ProjectsConsoleClientTest extends Scope ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); - $this->assertStringStartsWith($scheme . '://', $response['headers']['location']); + $this->assertStringStartsWith($scheme.'://', $response['headers']['location']); $this->assertStringContainsString('error=', $response['headers']['location']); } #[Group('abuseEnabled')] - public function testCorsWithDevKey(): void + public function test_cors_with_dev_key(): void { /** * Test for SUCCESS @@ -6832,13 +6884,13 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testCorsWithDevKey', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); $origin = 'http://example.com'; @@ -6852,7 +6904,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $projectId, ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(403, $response['headers']['status-code']); @@ -6860,7 +6912,6 @@ class ProjectsConsoleClientTest extends Scope // you should not return a fallback origin for a disallowed host $this->assertNull($response['headers']['access-control-allow-origin'] ?? null); - /** * Test CORS with Dev Key (should bypass origin check) */ @@ -6868,17 +6919,17 @@ class ProjectsConsoleClientTest extends Scope 'origin' => $origin, 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'] + 'x-appwrite-dev-key' => $devKey['secret'], ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(401, $response['headers']['status-code']); $this->assertEquals($origin, $response['headers']['access-control-allow-origin'] ?? null); } - public function testConsoleCorsWithTrustedProject(): void + public function test_console_cors_with_trusted_project(): void { $trustedProjectIds = ['trusted-project', 'another-trusted-project']; // Set in env variable @@ -6890,17 +6941,17 @@ class ProjectsConsoleClientTest extends Scope $this->setupProject([ 'projectId' => $projectId, 'name' => 'Trusted project', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); // Add domain to trusted project; API for simplicity, in real work this will be site - $domain = \uniqid() . '.custom.localhost'; + $domain = \uniqid().'.custom.localhost'; $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'domain' => $domain + 'domain' => $domain, ]); $this->assertEquals(201, $rule['headers']['status-code']); @@ -6914,7 +6965,7 @@ class ProjectsConsoleClientTest extends Scope [ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', - 'origin' => 'http://' . $domain + 'origin' => 'http://'.$domain, ] ) ); @@ -6922,7 +6973,7 @@ class ProjectsConsoleClientTest extends Scope if (\in_array($projectId, $trustedProjectIds)) { // Trusted projects can $this->assertEquals(200, $currencies['headers']['status-code']); - $this->assertSame('http://' . $domain, $currencies['headers']['access-control-allow-origin']); + $this->assertSame('http://'.$domain, $currencies['headers']['access-control-allow-origin']); } else { // Untrusted projects cannot $this->assertEquals(403, $currencies['headers']['status-code']); @@ -6930,7 +6981,7 @@ class ProjectsConsoleClientTest extends Scope } } finally { // Cleanup - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6941,7 +6992,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('abuseEnabled')] - public function testNoRateLimitWithDevKey(): void + public function test_no_rate_limit_with_dev_key(): void { /** * Test for SUCCESS @@ -6949,13 +7000,13 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testNoRateLimitWithDevKey', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); /** @@ -6967,7 +7018,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $projectId, ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -6977,7 +7028,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $projectId, ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(429, $response['headers']['status-code']); @@ -6985,31 +7036,31 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'] + 'x-appwrite-dev-key' => $devKey['secret'], ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(401, $response['headers']['status-code']); /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), -3600), + 'expire' => DateTime::addSeconds(new \DateTime, -3600), ]); $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $response['body']['secret'] + 'x-appwrite-dev-key' => $response['body']['secret'], ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(429, $response['headers']['status-code']); @@ -7019,16 +7070,16 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test Expire 5 seconds', - 'expire' => DateTime::addSeconds(new \DateTime(), 5) + 'expire' => DateTime::addSeconds(new \DateTime, 5), ]); $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'] + 'x-appwrite-dev-key' => $devKey['secret'], ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -7036,36 +7087,36 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'] + 'x-appwrite-dev-key' => $devKey['secret'], ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(429, $response['headers']['status-code']); }, 15_000, 500); } #[Group('abuseEnabled')] - public function testUpdateProjectDevKey(): void + public function test_update_project_dev_key(): void { $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testUpdateProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); - $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Key Test Update', - 'expire' => DateTime::addSeconds(new \DateTime(), 360), + 'expire' => DateTime::addSeconds(new \DateTime, 360), ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -7075,7 +7126,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertArrayHasKey('accessedAt', $response['body']); $this->assertEmpty($response['body']['accessedAt']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -7089,21 +7140,21 @@ class ProjectsConsoleClientTest extends Scope } #[Group('abuseEnabled')] - public function testDeleteProjectDevKey(): void + public function test_delete_project_dev_key(): void { $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testDeleteProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000) + 'expire' => DateTime::addSeconds(new \DateTime, 36000), ]); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -7117,14 +7168,14 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'] + 'x-appwrite-dev-key' => $devKey['secret'], ], [ 'email' => 'user@appwrite.io', - 'password' => 'password' + 'password' => 'password', ]); $this->assertEquals(429, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -7134,7 +7185,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId . '/dev-keys/error', array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId.'/dev-keys/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -7145,8 +7196,7 @@ class ProjectsConsoleClientTest extends Scope /** * Devkeys Tests ends here ------------------------------------------------ */ - - public function testProjectLabels(): void + public function test_project_labels(): void { // Setup: Prepare team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -7169,7 +7219,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Test project - Labels 1', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -7178,11 +7228,11 @@ class ProjectsConsoleClientTest extends Scope $projectId = $project['body']['$id']; // Apply labels - $project = $this->client->call(Client::METHOD_PUT, '/projects/' . $projectId . '/labels', array_merge([ + $project = $this->client->call(Client::METHOD_PUT, '/projects/'.$projectId.'/labels', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'labels' => ['vip', 'imagine', 'blocked'] + 'labels' => ['vip', 'imagine', 'blocked'], ]); $this->assertEquals(200, $project['headers']['status-code']); @@ -7193,11 +7243,11 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('blocked', $project['body']['labels'][2]); // Update labels - $project = $this->client->call(Client::METHOD_PUT, '/projects/' . $projectId . '/labels', array_merge([ + $project = $this->client->call(Client::METHOD_PUT, '/projects/'.$projectId.'/labels', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'labels' => ['nonvip', 'imagine'] + 'labels' => ['nonvip', 'imagine'], ]); $this->assertEquals(200, $project['headers']['status-code']); $this->assertIsArray($project['body']['labels']); @@ -7213,7 +7263,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['nonvip'])->toString(), - ] + ], ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7226,7 +7276,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['vip'])->toString(), - ] + ], ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(0, $projects['body']['total']); @@ -7238,7 +7288,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['imagine'])->toString(), - ] + ], ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7251,7 +7301,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['nonvip', 'imagine'])->toString(), - ] + ], ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7266,7 +7316,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Test project - Labels 2', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default') + 'region' => System::getEnv('_APP_REGION', 'default'), ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -7274,11 +7324,11 @@ class ProjectsConsoleClientTest extends Scope $this->assertCount(0, $project['body']['labels']); $projectId2 = $project['body']['$id']; - $project = $this->client->call(Client::METHOD_PUT, '/projects/' . $projectId2 . '/labels', array_merge([ + $project = $this->client->call(Client::METHOD_PUT, '/projects/'.$projectId2.'/labels', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'labels' => ['vip', 'imagine'] + 'labels' => ['vip', 'imagine'], ]); $this->assertEquals(200, $project['headers']['status-code']); $this->assertIsArray($project['body']['labels']); @@ -7294,7 +7344,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['imagine'])->toString(), - ] + ], ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(2, $projects['body']['total']); @@ -7309,7 +7359,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['vip'])->toString(), - ] + ], ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7324,7 +7374,7 @@ class ProjectsConsoleClientTest extends Scope 'queries' => [ Query::contains('labels', ['vip'])->toString(), Query::contains('labels', ['imagine'])->toString(), - ] + ], ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7338,7 +7388,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['vip', 'imagine'])->toString(), - ] + ], ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(2, $projects['body']['total']); @@ -7346,21 +7396,21 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($projectId2, $projects['body']['projects'][1]['$id']); // Cleanup - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId2, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId2, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -7369,7 +7419,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('ciIgnore')] - public function testProjectSpecificPermissionsForListProjects(): void + public function test_project_specific_permissions_for_list_projects(): void { $teamId = ID::unique(); $projectIdA = $this->setupProject([ @@ -7381,23 +7431,23 @@ class ProjectsConsoleClientTest extends Scope 'name' => 'Project Test B', ], $teamId, false); - $testUserEmail = 'test-' . ID::unique() . '@localhost.test'; + $testUserEmail = 'test-'.ID::unique().'@localhost.test'; $testUserName = 'Test User'; - [ 'membershipId' => $testUserMembershipId ] = $this->setupUserMembership([ + ['membershipId' => $testUserMembershipId] = $this->setupUserMembership([ 'teamId' => $teamId, 'email' => $testUserEmail, 'name' => $testUserName, - 'roles' => ["owner"], + 'roles' => ['owner'], ]); $testCases = [ [ - 'roles' => ["owner"], + 'roles' => ['owner'], 'successProjectIds' => [$projectIdA, $projectIdB], ], [ - 'roles' => ["developer"], + 'roles' => ['developer'], 'successProjectIds' => [$projectIdA, $projectIdB], ], [ @@ -7417,9 +7467,9 @@ class ProjectsConsoleClientTest extends Scope 'successProjectIds' => [$projectIdB], ], [ - 'roles' => ["developer", "project-$projectIdA-owner"], + 'roles' => ['developer', "project-$projectIdA-owner"], 'successProjectIds' => [$projectIdA, $projectIdB], - ] + ], ]; // Setup session @@ -7431,7 +7481,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $testUserEmail, 'password' => 'password', ]); - $token = $session['cookies']['a_session_' . $this->getProject()['$id']]; + $token = $session['cookies']['a_session_'.$this->getProject()['$id']]; foreach ($testCases as $testCase) { $this->updateMembershipRole($teamId, $testUserMembershipId, $testCase['roles']); @@ -7441,7 +7491,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, + 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -7456,7 +7506,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('ciIgnore')] - public function testProjectSpecificPermissionsForUpdateProject(): void + public function test_project_specific_permissions_for_update_project(): void { $teamId = ID::unique(); $projectIdA = $this->setupProject([ @@ -7468,24 +7518,24 @@ class ProjectsConsoleClientTest extends Scope 'name' => 'Project Test B', ], $teamId, false); - $testUserEmail = 'test-' . ID::unique() . '@localhost.test'; + $testUserEmail = 'test-'.ID::unique().'@localhost.test'; $testUserName = 'Test User'; - [ 'membershipId' => $testUserMembershipId ] = $this->setupUserMembership([ + ['membershipId' => $testUserMembershipId] = $this->setupUserMembership([ 'teamId' => $teamId, 'email' => $testUserEmail, 'name' => $testUserName, - 'roles' => ["owner"], + 'roles' => ['owner'], ]); $testCases = [ [ - 'roles' => ["owner"], + 'roles' => ['owner'], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], ], [ - 'roles' => ["developer"], + 'roles' => ['developer'], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], ], @@ -7510,10 +7560,10 @@ class ProjectsConsoleClientTest extends Scope 'failureProjectIds' => [$projectIdA], ], [ - 'roles' => ["developer", "project-$projectIdA-owner"], + 'roles' => ['developer', "project-$projectIdA-owner"], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], - ] + ], ]; // Setup session @@ -7525,20 +7575,20 @@ class ProjectsConsoleClientTest extends Scope 'email' => $testUserEmail, 'password' => 'password', ]); - $token = $session['cookies']['a_session_' . $this->getProject()['$id']]; + $token = $session['cookies']['a_session_'.$this->getProject()['$id']]; foreach ($testCases as $testCase) { $this->updateMembershipRole($teamId, $testUserMembershipId, $testCase['roles']); foreach ($testCase['successProjectIds'] as $projectId) { - $newProjectName = 'Updated Project Name ' . ID::unique(); + $newProjectName = 'Updated Project Name '.ID::unique(); // Success: User should be able to update the project they have access to. - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId, [ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId, [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, + 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, ], [ 'name' => $newProjectName, ]); @@ -7548,14 +7598,14 @@ class ProjectsConsoleClientTest extends Scope } foreach ($testCase['failureProjectIds'] as $projectId) { - $newProjectName = 'Updated Project Name ' . ID::unique(); + $newProjectName = 'Updated Project Name '.ID::unique(); // Failure: User should not be able to update the project they do not have access to. - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId, [ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId, [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, + 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, ], [ 'name' => $newProjectName, ]); @@ -7565,7 +7615,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('ciIgnore')] - public function testProjectSpecificPermissionsForDeleteProject(): void + public function test_project_specific_permissions_for_delete_project(): void { $teamId = ID::unique(); $projectIdA = $this->setupProject([ @@ -7589,24 +7639,24 @@ class ProjectsConsoleClientTest extends Scope 'name' => 'Project Test E', ], $teamId, false); - $testUserEmail = 'test-' . ID::unique() . '@localhost.test'; + $testUserEmail = 'test-'.ID::unique().'@localhost.test'; $testUserName = 'Test User'; - [ 'membershipId' => $testUserMembershipId ] = $this->setupUserMembership([ + ['membershipId' => $testUserMembershipId] = $this->setupUserMembership([ 'teamId' => $teamId, 'email' => $testUserEmail, 'name' => $testUserName, - 'roles' => ["owner"], + 'roles' => ['owner'], ]); $testCases = [ [ - 'roles' => ["owner"], + 'roles' => ['owner'], 'successProjectIds' => [$projectIdA], 'failureProjectIds' => [], ], [ - 'roles' => ["developer"], + 'roles' => ['developer'], 'successProjectIds' => [$projectIdB, $projectIdC], 'failureProjectIds' => [], ], @@ -7631,29 +7681,29 @@ class ProjectsConsoleClientTest extends Scope 'email' => $testUserEmail, 'password' => 'password', ]); - $token = $session['cookies']['a_session_' . $this->getProject()['$id']]; + $token = $session['cookies']['a_session_'.$this->getProject()['$id']]; foreach ($testCases as $testCase) { $this->updateMembershipRole($teamId, $testUserMembershipId, $testCase['roles']); foreach ($testCase['successProjectIds'] as $projectId) { // Success: User should be able to delete the project they have access to. - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, [ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, + 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, ]); $this->assertEquals(204, $response['headers']['status-code']); } foreach ($testCase['failureProjectIds'] as $projectId) { // Failure: User should not be able to delete the project they do not have access to. - $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, [ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, + 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, ]); $this->assertTrue($response['headers']['status-code'] === 401 || $response['headers']['status-code'] === 404); } @@ -7664,7 +7714,7 @@ class ProjectsConsoleClientTest extends Scope * Test project specific permissions for project resources, in this case 'function variables'. */ #[Group('ciIgnore')] - public function testProjectSpecificPermissionsForProjectResources(): void + public function test_project_specific_permissions_for_project_resources(): void { $teamId = ID::unique(); $projectIdA = $this->setupProject([ @@ -7676,24 +7726,24 @@ class ProjectsConsoleClientTest extends Scope 'name' => 'Project Test B', ], $teamId, false); - $testUserEmail = 'test-' . ID::unique() . '@localhost.test'; + $testUserEmail = 'test-'.ID::unique().'@localhost.test'; $testUserName = 'Test User'; - [ 'membershipId' => $testUserMembershipId ] = $this->setupUserMembership([ + ['membershipId' => $testUserMembershipId] = $this->setupUserMembership([ 'teamId' => $teamId, 'email' => $testUserEmail, 'name' => $testUserName, - 'roles' => ["owner"], + 'roles' => ['owner'], ]); $testCases = [ [ - 'roles' => ["owner"], + 'roles' => ['owner'], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], ], [ - 'roles' => ["developer"], + 'roles' => ['developer'], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], ], @@ -7718,10 +7768,10 @@ class ProjectsConsoleClientTest extends Scope 'failureProjectIds' => [$projectIdA], ], [ - 'roles' => ["developer", "project-$projectIdA-owner"], + 'roles' => ['developer', "project-$projectIdA-owner"], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], - ] + ], ]; // Setup session @@ -7733,7 +7783,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $testUserEmail, 'password' => 'password', ]); - $token = $session['cookies']['a_session_' . $this->getProject()['$id']]; + $token = $session['cookies']['a_session_'.$this->getProject()['$id']]; // Setup functions $functionId = ID::unique(); @@ -7745,37 +7795,37 @@ class ProjectsConsoleClientTest extends Scope foreach ($testCase['successProjectIds'] as $projectId) { $variableId = ID::unique(); - $response = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', [ + $response = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/variables', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-mode' => 'admin', - 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, + 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, ], [ 'variableId' => $variableId, - 'key' => 'APP_TEST_' . $variableId, + 'key' => 'APP_TEST_'.$variableId, 'value' => 'TESTINGVALUE', - 'secret' => false + 'secret' => false, ]); $this->assertEquals(201, $response['headers']['status-code']); - $this->assertEquals('APP_TEST_' . $variableId, $response['body']['key']); + $this->assertEquals('APP_TEST_'.$variableId, $response['body']['key']); $this->assertEquals('TESTINGVALUE', $response['body']['value']); } foreach ($testCase['failureProjectIds'] as $projectId) { $variableId = ID::unique(); - $response = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', [ + $response = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/variables', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-mode' => 'admin', - 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, + 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, ], [ 'variableId' => $variableId, - 'key' => 'APP_TEST_' . $variableId, + 'key' => 'APP_TEST_'.$variableId, 'value' => 'TESTINGVALUE', - 'secret' => false + 'secret' => false, ]); $this->assertTrue($response['headers']['status-code'] === 401 || $response['headers']['status-code'] === 404); @@ -7783,7 +7833,7 @@ class ProjectsConsoleClientTest extends Scope } } - public function testPasswordRecoveryUrlParams(): void + public function test_password_recovery_url_params(): void { // With search params $url = 'http://localhost/auth/signin?id=abcd1234&tenant=efgh5678&domain=example.com&referred=0'; @@ -7813,9 +7863,9 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString($url, $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); - $expectedUrl = $url . "&userId=" . $userId . "&secret="; + $expectedUrl = $url.'&userId='.$userId.'&secret='; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); @@ -7845,9 +7895,9 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString($url, $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); - $expectedUrl = $url . "&userId=" . $userId . "&secret="; + $expectedUrl = $url.'&userId='.$userId.'&secret='; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); @@ -7874,12 +7924,12 @@ class ProjectsConsoleClientTest extends Scope $userId = $response['body']['userId']; $lastEmail = $this->getLastEmailByAddress($userEmail, function ($email) use ($url, $userId) { - $this->assertStringContainsString($url . '?userId=' . $userId, $email['html'] ?? ''); + $this->assertStringContainsString($url.'?userId='.$userId, $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); - $expectedUrl = $url . "?userId=" . $userId . "&secret="; + $expectedUrl = $url.'?userId='.$userId.'&secret='; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); @@ -7906,12 +7956,12 @@ class ProjectsConsoleClientTest extends Scope $userId = $response['body']['userId']; $lastEmail = $this->getLastEmailByAddress($userEmail, function ($email) use ($url, $userId) { - $this->assertStringContainsString($url . '?userId=' . $userId, $email['html'] ?? ''); + $this->assertStringContainsString($url.'?userId='.$userId, $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); - $expectedUrl = $url . "?userId=" . $userId . "&secret="; + $expectedUrl = $url.'?userId='.$userId.'&secret='; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); @@ -7941,7 +7991,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString('INJECTED', $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); $this->assertStringContainsString('INJECTED', $lastEmail['html']); $this->assertStringContainsString('

', $lastEmail['html']); @@ -7949,7 +7999,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString('">', $lastEmail['html']); $this->assertStringContainsString('', $lastEmail['html']); - $expectedUrl = $url . "?userId=" . $userId . "&secret="; + $expectedUrl = $url.'?userId='.$userId.'&secret='; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); } From 6ab4564db43f7768f60ada7c02e363d6e557c256 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Fri, 22 May 2026 12:52:14 +0400 Subject: [PATCH 09/16] chore: formatter --- .../RequireLowercase/Update.php | 2 +- .../PasswordStrength/RequireNumber/Update.php | 2 +- .../RequireSpecialChar/Update.php | 2 +- .../RequireUppercase/Update.php | 2 +- .../Modules/Project/Services/Http.php | 202 +++++++++--------- .../Projects/ProjectsConsoleClientTest.php | 48 ++--- 6 files changed, 129 insertions(+), 129 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php index 359c6e0e43..07c391d832 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php @@ -49,7 +49,7 @@ class Update extends Action ), ], )) - ->param('enabled', null, new Boolean, 'Whether passwords must include at least one lowercase letter.') + ->param('enabled', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.') ->inject('response') ->inject('dbForPlatform') ->inject('project') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php index 4077df3257..6869a355ed 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php @@ -49,7 +49,7 @@ class Update extends Action ), ], )) - ->param('enabled', null, new Boolean, 'Whether passwords must include at least one number.') + ->param('enabled', null, new Boolean(), 'Whether passwords must include at least one number.') ->inject('response') ->inject('dbForPlatform') ->inject('project') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php index a83575ec13..6f70bdb38f 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php @@ -49,7 +49,7 @@ class Update extends Action ), ], )) - ->param('enabled', null, new Boolean, 'Whether passwords must include at least one special character.') + ->param('enabled', null, new Boolean(), 'Whether passwords must include at least one special character.') ->inject('response') ->inject('dbForPlatform') ->inject('project') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php index 906c52d54d..adc93bcdbc 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php @@ -49,7 +49,7 @@ class Update extends Action ), ], )) - ->param('enabled', null, new Boolean, 'Whether passwords must include at least one uppercase letter.') + ->param('enabled', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.') ->inject('response') ->inject('dbForPlatform') ->inject('project') diff --git a/src/Appwrite/Platform/Modules/Project/Services/Http.php b/src/Appwrite/Platform/Modules/Project/Services/Http.php index eefb4d770a..7940e5b506 100644 --- a/src/Appwrite/Platform/Modules/Project/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Project/Services/Http.php @@ -112,126 +112,126 @@ class Http extends Service $this->type = Service::TYPE_HTTP; // Hooks - $this->addAction(Init::getName(), new Init); + $this->addAction(Init::getName(), new Init()); // Project - $this->addAction(DeleteProject::getName(), new DeleteProject); - $this->addAction(GetProject::getName(), new GetProject); - $this->addAction(UpdateProjectLabels::getName(), new UpdateProjectLabels); - $this->addAction(UpdateProjectProtocol::getName(), new UpdateProjectProtocol); - $this->addAction(UpdateProjectService::getName(), new UpdateProjectService); + $this->addAction(DeleteProject::getName(), new DeleteProject()); + $this->addAction(GetProject::getName(), new GetProject()); + $this->addAction(UpdateProjectLabels::getName(), new UpdateProjectLabels()); + $this->addAction(UpdateProjectProtocol::getName(), new UpdateProjectProtocol()); + $this->addAction(UpdateProjectService::getName(), new UpdateProjectService()); // SMTP - $this->addAction(UpdateSMTP::getName(), new UpdateSMTP); - $this->addAction(CreateSMTPTest::getName(), new CreateSMTPTest); + $this->addAction(UpdateSMTP::getName(), new UpdateSMTP()); + $this->addAction(CreateSMTPTest::getName(), new CreateSMTPTest()); // Templates - $this->addAction(ListTemplates::getName(), new ListTemplates); - $this->addAction(GetTemplate::getName(), new GetTemplate); - $this->addAction(UpdateTemplate::getName(), new UpdateTemplate); + $this->addAction(ListTemplates::getName(), new ListTemplates()); + $this->addAction(GetTemplate::getName(), new GetTemplate()); + $this->addAction(UpdateTemplate::getName(), new UpdateTemplate()); // Variables - $this->addAction(CreateVariable::getName(), new CreateVariable); - $this->addAction(ListVariables::getName(), new ListVariables); - $this->addAction(GetVariable::getName(), new GetVariable); - $this->addAction(DeleteVariable::getName(), new DeleteVariable); - $this->addAction(UpdateVariable::getName(), new UpdateVariable); + $this->addAction(CreateVariable::getName(), new CreateVariable()); + $this->addAction(ListVariables::getName(), new ListVariables()); + $this->addAction(GetVariable::getName(), new GetVariable()); + $this->addAction(DeleteVariable::getName(), new DeleteVariable()); + $this->addAction(UpdateVariable::getName(), new UpdateVariable()); // Keys - $this->addAction(CreateKey::getName(), new CreateKey); - $this->addAction(CreateEphemeralKey::getName(), new CreateEphemeralKey); - $this->addAction(ListKeys::getName(), new ListKeys); - $this->addAction(GetKey::getName(), new GetKey); - $this->addAction(DeleteKey::getName(), new DeleteKey); - $this->addAction(UpdateKey::getName(), new UpdateKey); + $this->addAction(CreateKey::getName(), new CreateKey()); + $this->addAction(CreateEphemeralKey::getName(), new CreateEphemeralKey()); + $this->addAction(ListKeys::getName(), new ListKeys()); + $this->addAction(GetKey::getName(), new GetKey()); + $this->addAction(DeleteKey::getName(), new DeleteKey()); + $this->addAction(UpdateKey::getName(), new UpdateKey()); // Platforms - $this->addAction(ListPlatforms::getName(), new ListPlatforms); - $this->addAction(GetPlatform::getName(), new GetPlatform); - $this->addAction(CreateWebPlatform::getName(), new CreateWebPlatform); - $this->addAction(CreateApplePlatform::getName(), new CreateApplePlatform); - $this->addAction(CreateAndroidPlatform::getName(), new CreateAndroidPlatform); - $this->addAction(CreateWindowsPlatform::getName(), new CreateWindowsPlatform); - $this->addAction(CreateLinuxPlatform::getName(), new CreateLinuxPlatform); - $this->addAction(UpdateWebPlatform::getName(), new UpdateWebPlatform); - $this->addAction(UpdateApplePlatform::getName(), new UpdateApplePlatform); - $this->addAction(UpdateAndroidPlatform::getName(), new UpdateAndroidPlatform); - $this->addAction(UpdateWindowsPlatform::getName(), new UpdateWindowsPlatform); - $this->addAction(UpdateLinuxPlatform::getName(), new UpdateLinuxPlatform); - $this->addAction(DeletePlatform::getName(), new DeletePlatform); + $this->addAction(ListPlatforms::getName(), new ListPlatforms()); + $this->addAction(GetPlatform::getName(), new GetPlatform()); + $this->addAction(CreateWebPlatform::getName(), new CreateWebPlatform()); + $this->addAction(CreateApplePlatform::getName(), new CreateApplePlatform()); + $this->addAction(CreateAndroidPlatform::getName(), new CreateAndroidPlatform()); + $this->addAction(CreateWindowsPlatform::getName(), new CreateWindowsPlatform()); + $this->addAction(CreateLinuxPlatform::getName(), new CreateLinuxPlatform()); + $this->addAction(UpdateWebPlatform::getName(), new UpdateWebPlatform()); + $this->addAction(UpdateApplePlatform::getName(), new UpdateApplePlatform()); + $this->addAction(UpdateAndroidPlatform::getName(), new UpdateAndroidPlatform()); + $this->addAction(UpdateWindowsPlatform::getName(), new UpdateWindowsPlatform()); + $this->addAction(UpdateLinuxPlatform::getName(), new UpdateLinuxPlatform()); + $this->addAction(DeletePlatform::getName(), new DeletePlatform()); // Mock Phones - $this->addAction(CreateMockPhone::getName(), new CreateMockPhone); - $this->addAction(ListMockPhones::getName(), new ListMockPhones); - $this->addAction(GetMockPhone::getName(), new GetMockPhone); - $this->addAction(UpdateMockPhone::getName(), new UpdateMockPhone); - $this->addAction(DeleteMockPhone::getName(), new DeleteMockPhone); + $this->addAction(CreateMockPhone::getName(), new CreateMockPhone()); + $this->addAction(ListMockPhones::getName(), new ListMockPhones()); + $this->addAction(GetMockPhone::getName(), new GetMockPhone()); + $this->addAction(UpdateMockPhone::getName(), new UpdateMockPhone()); + $this->addAction(DeleteMockPhone::getName(), new DeleteMockPhone()); // Policies - $this->addAction(ListPolicies::getName(), new ListPolicies); - $this->addAction(GetPolicy::getName(), new GetPolicy); - $this->addAction(UpdateMembershipPrivacyPolicy::getName(), new UpdateMembershipPrivacyPolicy); - $this->addAction(UpdatePasswordDictionaryPolicy::getName(), new UpdatePasswordDictionaryPolicy); - $this->addAction(UpdatePasswordHistoryPolicy::getName(), new UpdatePasswordHistoryPolicy); - $this->addAction(UpdatePasswordStrengthMinLengthPolicy::getName(), new UpdatePasswordStrengthMinLengthPolicy); - $this->addAction(UpdatePasswordStrengthRequireUppercasePolicy::getName(), new UpdatePasswordStrengthRequireUppercasePolicy); - $this->addAction(UpdatePasswordStrengthRequireLowercasePolicy::getName(), new UpdatePasswordStrengthRequireLowercasePolicy); - $this->addAction(UpdatePasswordStrengthRequireNumberPolicy::getName(), new UpdatePasswordStrengthRequireNumberPolicy); - $this->addAction(UpdatePasswordStrengthRequireSpecialCharPolicy::getName(), new UpdatePasswordStrengthRequireSpecialCharPolicy); - $this->addAction(UpdatePasswordPersonalDataPolicy::getName(), new UpdatePasswordPersonalDataPolicy); - $this->addAction(UpdateSessionAlertPolicy::getName(), new UpdateSessionAlertPolicy); - $this->addAction(UpdateSessionDurationPolicy::getName(), new UpdateSessionDurationPolicy); - $this->addAction(UpdateSessionInvalidationPolicy::getName(), new UpdateSessionInvalidationPolicy); - $this->addAction(UpdateSessionLimitPolicy::getName(), new UpdateSessionLimitPolicy); - $this->addAction(UpdateUserLimitPolicy::getName(), new UpdateUserLimitPolicy); + $this->addAction(ListPolicies::getName(), new ListPolicies()); + $this->addAction(GetPolicy::getName(), new GetPolicy()); + $this->addAction(UpdateMembershipPrivacyPolicy::getName(), new UpdateMembershipPrivacyPolicy()); + $this->addAction(UpdatePasswordDictionaryPolicy::getName(), new UpdatePasswordDictionaryPolicy()); + $this->addAction(UpdatePasswordHistoryPolicy::getName(), new UpdatePasswordHistoryPolicy()); + $this->addAction(UpdatePasswordStrengthMinLengthPolicy::getName(), new UpdatePasswordStrengthMinLengthPolicy()); + $this->addAction(UpdatePasswordStrengthRequireUppercasePolicy::getName(), new UpdatePasswordStrengthRequireUppercasePolicy()); + $this->addAction(UpdatePasswordStrengthRequireLowercasePolicy::getName(), new UpdatePasswordStrengthRequireLowercasePolicy()); + $this->addAction(UpdatePasswordStrengthRequireNumberPolicy::getName(), new UpdatePasswordStrengthRequireNumberPolicy()); + $this->addAction(UpdatePasswordStrengthRequireSpecialCharPolicy::getName(), new UpdatePasswordStrengthRequireSpecialCharPolicy()); + $this->addAction(UpdatePasswordPersonalDataPolicy::getName(), new UpdatePasswordPersonalDataPolicy()); + $this->addAction(UpdateSessionAlertPolicy::getName(), new UpdateSessionAlertPolicy()); + $this->addAction(UpdateSessionDurationPolicy::getName(), new UpdateSessionDurationPolicy()); + $this->addAction(UpdateSessionInvalidationPolicy::getName(), new UpdateSessionInvalidationPolicy()); + $this->addAction(UpdateSessionLimitPolicy::getName(), new UpdateSessionLimitPolicy()); + $this->addAction(UpdateUserLimitPolicy::getName(), new UpdateUserLimitPolicy()); // Auth Methods - $this->addAction(UpdateAuthMethod::getName(), new UpdateAuthMethod); + $this->addAction(UpdateAuthMethod::getName(), new UpdateAuthMethod()); // OAuth2 - $this->addAction(ListOAuth2Providers::getName(), new ListOAuth2Providers); - $this->addAction(GetOAuth2Provider::getName(), new GetOAuth2Provider); - $this->addAction(UpdateOAuth2GitHub::getName(), new UpdateOAuth2GitHub); - $this->addAction(UpdateOAuth2Discord::getName(), new UpdateOAuth2Discord); - $this->addAction(UpdateOAuth2Figma::getName(), new UpdateOAuth2Figma); - $this->addAction(UpdateOAuth2Dropbox::getName(), new UpdateOAuth2Dropbox); - $this->addAction(UpdateOAuth2Dailymotion::getName(), new UpdateOAuth2Dailymotion); - $this->addAction(UpdateOAuth2Bitbucket::getName(), new UpdateOAuth2Bitbucket); - $this->addAction(UpdateOAuth2Bitly::getName(), new UpdateOAuth2Bitly); - $this->addAction(UpdateOAuth2Box::getName(), new UpdateOAuth2Box); - $this->addAction(UpdateOAuth2Autodesk::getName(), new UpdateOAuth2Autodesk); - $this->addAction(UpdateOAuth2Google::getName(), new UpdateOAuth2Google); - $this->addAction(UpdateOAuth2Zoom::getName(), new UpdateOAuth2Zoom); - $this->addAction(UpdateOAuth2Zoho::getName(), new UpdateOAuth2Zoho); - $this->addAction(UpdateOAuth2Yandex::getName(), new UpdateOAuth2Yandex); - $this->addAction(UpdateOAuth2X::getName(), new UpdateOAuth2X); - $this->addAction(UpdateOAuth2WordPress::getName(), new UpdateOAuth2WordPress); - $this->addAction(UpdateOAuth2Twitch::getName(), new UpdateOAuth2Twitch); - $this->addAction(UpdateOAuth2Stripe::getName(), new UpdateOAuth2Stripe); - $this->addAction(UpdateOAuth2Spotify::getName(), new UpdateOAuth2Spotify); - $this->addAction(UpdateOAuth2Slack::getName(), new UpdateOAuth2Slack); - $this->addAction(UpdateOAuth2Podio::getName(), new UpdateOAuth2Podio); - $this->addAction(UpdateOAuth2Notion::getName(), new UpdateOAuth2Notion); - $this->addAction(UpdateOAuth2Salesforce::getName(), new UpdateOAuth2Salesforce); - $this->addAction(UpdateOAuth2Yahoo::getName(), new UpdateOAuth2Yahoo); - $this->addAction(UpdateOAuth2Linkedin::getName(), new UpdateOAuth2Linkedin); - $this->addAction(UpdateOAuth2Disqus::getName(), new UpdateOAuth2Disqus); - $this->addAction(UpdateOAuth2Amazon::getName(), new UpdateOAuth2Amazon); - $this->addAction(UpdateOAuth2Etsy::getName(), new UpdateOAuth2Etsy); - $this->addAction(UpdateOAuth2Facebook::getName(), new UpdateOAuth2Facebook); - $this->addAction(UpdateOAuth2Tradeshift::getName(), new UpdateOAuth2Tradeshift); - $this->addAction(UpdateOAuth2TradeshiftSandbox::getName(), new UpdateOAuth2TradeshiftSandbox); - $this->addAction(UpdateOAuth2Paypal::getName(), new UpdateOAuth2Paypal); - $this->addAction(UpdateOAuth2PaypalSandbox::getName(), new UpdateOAuth2PaypalSandbox); - $this->addAction(UpdateOAuth2Gitlab::getName(), new UpdateOAuth2Gitlab); - $this->addAction(UpdateOAuth2Authentik::getName(), new UpdateOAuth2Authentik); - $this->addAction(UpdateOAuth2Auth0::getName(), new UpdateOAuth2Auth0); - $this->addAction(UpdateOAuth2FusionAuth::getName(), new UpdateOAuth2FusionAuth); - $this->addAction(UpdateOAuth2Keycloak::getName(), new UpdateOAuth2Keycloak); - $this->addAction(UpdateOAuth2Oidc::getName(), new UpdateOAuth2Oidc); - $this->addAction(UpdateOAuth2Okta::getName(), new UpdateOAuth2Okta); - $this->addAction(UpdateOAuth2Kick::getName(), new UpdateOAuth2Kick); - $this->addAction(UpdateOAuth2Apple::getName(), new UpdateOAuth2Apple); - $this->addAction(UpdateOAuth2Microsoft::getName(), new UpdateOAuth2Microsoft); + $this->addAction(ListOAuth2Providers::getName(), new ListOAuth2Providers()); + $this->addAction(GetOAuth2Provider::getName(), new GetOAuth2Provider()); + $this->addAction(UpdateOAuth2GitHub::getName(), new UpdateOAuth2GitHub()); + $this->addAction(UpdateOAuth2Discord::getName(), new UpdateOAuth2Discord()); + $this->addAction(UpdateOAuth2Figma::getName(), new UpdateOAuth2Figma()); + $this->addAction(UpdateOAuth2Dropbox::getName(), new UpdateOAuth2Dropbox()); + $this->addAction(UpdateOAuth2Dailymotion::getName(), new UpdateOAuth2Dailymotion()); + $this->addAction(UpdateOAuth2Bitbucket::getName(), new UpdateOAuth2Bitbucket()); + $this->addAction(UpdateOAuth2Bitly::getName(), new UpdateOAuth2Bitly()); + $this->addAction(UpdateOAuth2Box::getName(), new UpdateOAuth2Box()); + $this->addAction(UpdateOAuth2Autodesk::getName(), new UpdateOAuth2Autodesk()); + $this->addAction(UpdateOAuth2Google::getName(), new UpdateOAuth2Google()); + $this->addAction(UpdateOAuth2Zoom::getName(), new UpdateOAuth2Zoom()); + $this->addAction(UpdateOAuth2Zoho::getName(), new UpdateOAuth2Zoho()); + $this->addAction(UpdateOAuth2Yandex::getName(), new UpdateOAuth2Yandex()); + $this->addAction(UpdateOAuth2X::getName(), new UpdateOAuth2X()); + $this->addAction(UpdateOAuth2WordPress::getName(), new UpdateOAuth2WordPress()); + $this->addAction(UpdateOAuth2Twitch::getName(), new UpdateOAuth2Twitch()); + $this->addAction(UpdateOAuth2Stripe::getName(), new UpdateOAuth2Stripe()); + $this->addAction(UpdateOAuth2Spotify::getName(), new UpdateOAuth2Spotify()); + $this->addAction(UpdateOAuth2Slack::getName(), new UpdateOAuth2Slack()); + $this->addAction(UpdateOAuth2Podio::getName(), new UpdateOAuth2Podio()); + $this->addAction(UpdateOAuth2Notion::getName(), new UpdateOAuth2Notion()); + $this->addAction(UpdateOAuth2Salesforce::getName(), new UpdateOAuth2Salesforce()); + $this->addAction(UpdateOAuth2Yahoo::getName(), new UpdateOAuth2Yahoo()); + $this->addAction(UpdateOAuth2Linkedin::getName(), new UpdateOAuth2Linkedin()); + $this->addAction(UpdateOAuth2Disqus::getName(), new UpdateOAuth2Disqus()); + $this->addAction(UpdateOAuth2Amazon::getName(), new UpdateOAuth2Amazon()); + $this->addAction(UpdateOAuth2Etsy::getName(), new UpdateOAuth2Etsy()); + $this->addAction(UpdateOAuth2Facebook::getName(), new UpdateOAuth2Facebook()); + $this->addAction(UpdateOAuth2Tradeshift::getName(), new UpdateOAuth2Tradeshift()); + $this->addAction(UpdateOAuth2TradeshiftSandbox::getName(), new UpdateOAuth2TradeshiftSandbox()); + $this->addAction(UpdateOAuth2Paypal::getName(), new UpdateOAuth2Paypal()); + $this->addAction(UpdateOAuth2PaypalSandbox::getName(), new UpdateOAuth2PaypalSandbox()); + $this->addAction(UpdateOAuth2Gitlab::getName(), new UpdateOAuth2Gitlab()); + $this->addAction(UpdateOAuth2Authentik::getName(), new UpdateOAuth2Authentik()); + $this->addAction(UpdateOAuth2Auth0::getName(), new UpdateOAuth2Auth0()); + $this->addAction(UpdateOAuth2FusionAuth::getName(), new UpdateOAuth2FusionAuth()); + $this->addAction(UpdateOAuth2Keycloak::getName(), new UpdateOAuth2Keycloak()); + $this->addAction(UpdateOAuth2Oidc::getName(), new UpdateOAuth2Oidc()); + $this->addAction(UpdateOAuth2Okta::getName(), new UpdateOAuth2Okta()); + $this->addAction(UpdateOAuth2Kick::getName(), new UpdateOAuth2Kick()); + $this->addAction(UpdateOAuth2Apple::getName(), new UpdateOAuth2Apple()); + $this->addAction(UpdateOAuth2Microsoft::getName(), new UpdateOAuth2Microsoft()); } } diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 85c4b5d4e0..dba60c6dcb 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -4472,7 +4472,7 @@ class ProjectsConsoleClientTest extends Scope $id = $data['projectId']; /** Create a second key with an expiry for query testing */ - $expireDate = DateTime::addSeconds(new \DateTime, 3600); + $expireDate = DateTime::addSeconds(new \DateTime(), 3600); $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -4545,7 +4545,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::lessThan('expire', (new \DateTime)->format('Y-m-d H:i:s'))->toString(), + Query::lessThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString(), ], ]); @@ -4558,7 +4558,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::greaterThan('expire', (new \DateTime)->format('Y-m-d H:i:s'))->toString(), + Query::greaterThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString(), ], ]); @@ -4648,7 +4648,7 @@ class ProjectsConsoleClientTest extends Scope 'keyId' => ID::unique(), 'name' => 'Key Test', 'scopes' => ['users.write'], - 'expire' => DateTime::addSeconds(new \DateTime, 3600), + 'expire' => DateTime::addSeconds(new \DateTime(), 3600), ]); $response = $this->client->call(Client::METHOD_POST, '/users', [ @@ -4692,7 +4692,7 @@ class ProjectsConsoleClientTest extends Scope 'keyId' => ID::unique(), 'name' => 'Key Test', 'scopes' => ['health.read'], - 'expire' => DateTime::addSeconds(new \DateTime, -3600), + 'expire' => DateTime::addSeconds(new \DateTime(), -3600), ]); $response = $this->client->call(Client::METHOD_GET, '/health', [ @@ -4734,7 +4734,7 @@ class ProjectsConsoleClientTest extends Scope 'keyId' => ID::unique(), 'name' => 'Key Test', 'scopes' => ['teams.read'], - 'expire' => DateTime::addSeconds(new \DateTime, 3600), + 'expire' => DateTime::addSeconds(new \DateTime(), 3600), ]); $response = $this->client->call(Client::METHOD_GET, '/users', [ @@ -4768,7 +4768,7 @@ class ProjectsConsoleClientTest extends Scope 'keyId' => ID::unique(), 'name' => 'Key Test', 'scopes' => ['health.read'], - 'expire' => DateTime::addSeconds(new \DateTime, 3600), + 'expire' => DateTime::addSeconds(new \DateTime(), 3600), ]); $response = $this->client->call(Client::METHOD_GET, '/health', [ @@ -4792,7 +4792,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'name' => 'Key Test Update', 'scopes' => ['users.read', 'users.write', 'collections.read', 'tables.read'], - 'expire' => DateTime::addSeconds(new \DateTime, 360), + 'expire' => DateTime::addSeconds(new \DateTime(), 360), ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -6343,7 +6343,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -6359,7 +6359,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -6400,14 +6400,14 @@ class ProjectsConsoleClientTest extends Scope $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); /** Create devKey 2 */ $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); /** List all dev keys */ @@ -6448,7 +6448,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::lessThan('expire', (new \DateTime)->format('Y-m-d H:i:s'))->toString()], + 'queries' => [Query::lessThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString()], ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -6487,7 +6487,7 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ @@ -6529,7 +6529,7 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); /** Use dev key with python sdk */ @@ -6584,7 +6584,7 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); $provider = 'mock'; @@ -6628,7 +6628,7 @@ class ProjectsConsoleClientTest extends Scope $location = $response['headers']['location']; - $locationClient = new Client; + $locationClient = new Client(); $locationClient->setEndpoint(''); $locationClient->addHeader('x-appwrite-dev-key', $devKey['secret']); @@ -6890,7 +6890,7 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); $origin = 'http://example.com'; @@ -7006,7 +7006,7 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); /** @@ -7051,7 +7051,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, -3600), + 'expire' => DateTime::addSeconds(new \DateTime(), -3600), ]); $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ @@ -7070,7 +7070,7 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test Expire 5 seconds', - 'expire' => DateTime::addSeconds(new \DateTime, 5), + 'expire' => DateTime::addSeconds(new \DateTime(), 5), ]); $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ @@ -7108,7 +7108,7 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ @@ -7116,7 +7116,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Key Test Update', - 'expire' => DateTime::addSeconds(new \DateTime, 360), + 'expire' => DateTime::addSeconds(new \DateTime(), 360), ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -7151,7 +7151,7 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime, 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000), ]); $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ From 1eba33574a61b424644559db7e8d00a542714311 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 1 Jun 2026 14:26:17 +0400 Subject: [PATCH 10/16] Update password strength policy endpoint --- ...pdate-auth-password-strength-min-length.md | 1 - ...uth-password-strength-require-lowercase.md | 1 - ...e-auth-password-strength-require-number.md | 1 - ...-password-strength-require-special-char.md | 1 - ...uth-password-strength-require-uppercase.md | 1 - .../projects/update-auth-password-strength.md | 1 + .../RequireLowercase/Update.php | 89 ------------ .../PasswordStrength/RequireNumber/Update.php | 89 ------------ .../RequireSpecialChar/Update.php | 89 ------------ .../RequireUppercase/Update.php | 89 ------------ .../{MinLength => }/Update.php | 44 ++++-- .../Modules/Project/Services/Http.php | 12 +- tests/e2e/Services/Project/PoliciesBase.php | 136 ++++++++---------- .../Projects/ProjectsConsoleClientTest.php | 87 ++--------- 14 files changed, 106 insertions(+), 535 deletions(-) delete mode 100644 docs/references/projects/update-auth-password-strength-min-length.md delete mode 100644 docs/references/projects/update-auth-password-strength-require-lowercase.md delete mode 100644 docs/references/projects/update-auth-password-strength-require-number.md delete mode 100644 docs/references/projects/update-auth-password-strength-require-special-char.md delete mode 100644 docs/references/projects/update-auth-password-strength-require-uppercase.md create mode 100644 docs/references/projects/update-auth-password-strength.md delete mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php delete mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php delete mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php delete mode 100644 src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php rename src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/{MinLength => }/Update.php (61%) diff --git a/docs/references/projects/update-auth-password-strength-min-length.md b/docs/references/projects/update-auth-password-strength-min-length.md deleted file mode 100644 index f6c2beef25..0000000000 --- a/docs/references/projects/update-auth-password-strength-min-length.md +++ /dev/null @@ -1 +0,0 @@ -Update the minimum authentication password strength length requirement. diff --git a/docs/references/projects/update-auth-password-strength-require-lowercase.md b/docs/references/projects/update-auth-password-strength-require-lowercase.md deleted file mode 100644 index b7e5dc4c74..0000000000 --- a/docs/references/projects/update-auth-password-strength-require-lowercase.md +++ /dev/null @@ -1 +0,0 @@ -Update whether authentication password strength requires at least one lowercase letter. diff --git a/docs/references/projects/update-auth-password-strength-require-number.md b/docs/references/projects/update-auth-password-strength-require-number.md deleted file mode 100644 index 6cccb19b88..0000000000 --- a/docs/references/projects/update-auth-password-strength-require-number.md +++ /dev/null @@ -1 +0,0 @@ -Update whether authentication password strength requires at least one number. diff --git a/docs/references/projects/update-auth-password-strength-require-special-char.md b/docs/references/projects/update-auth-password-strength-require-special-char.md deleted file mode 100644 index 9ed6073d18..0000000000 --- a/docs/references/projects/update-auth-password-strength-require-special-char.md +++ /dev/null @@ -1 +0,0 @@ -Update whether authentication password strength requires at least one special character. diff --git a/docs/references/projects/update-auth-password-strength-require-uppercase.md b/docs/references/projects/update-auth-password-strength-require-uppercase.md deleted file mode 100644 index 3535258de5..0000000000 --- a/docs/references/projects/update-auth-password-strength-require-uppercase.md +++ /dev/null @@ -1 +0,0 @@ -Update whether authentication password strength requires at least one uppercase letter. diff --git a/docs/references/projects/update-auth-password-strength.md b/docs/references/projects/update-auth-password-strength.md new file mode 100644 index 0000000000..ad7ff46b57 --- /dev/null +++ b/docs/references/projects/update-auth-password-strength.md @@ -0,0 +1 @@ +Update the authentication password strength requirements. diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php deleted file mode 100644 index 07c391d832..0000000000 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireLowercase/Update.php +++ /dev/null @@ -1,89 +0,0 @@ -setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/project/policies/password-strength/require-lowercase') - ->desc('Update password strength lowercase requirement') - ->groups(['api', 'project']) - ->label('scope', ['policies.write', 'project.policies.write']) - ->label('event', 'projects.[projectId].policies.[policy].update') - ->label('audits.event', 'projects.[projectId].policies.[policy].update') - ->label('audits.resource', 'project/{response.$id}') - ->label('sdk', new Method( - namespace: 'project', - group: 'policies', - name: 'updatePasswordStrengthRequireLowercase', - description: <<<'EOT' - Update whether passwords must include at least one lowercase letter. - EOT, - auth: [AuthType::ADMIN, AuthType::KEY], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ), - ], - )) - ->param('enabled', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.') - ->inject('response') - ->inject('dbForPlatform') - ->inject('project') - ->inject('authorization') - ->inject('queueForEvents') - ->callback($this->action(...)); - } - - public function action( - bool $enabled, - Response $response, - Database $dbForPlatform, - Document $project, - Authorization $authorization, - Event $queueForEvents, - ): void { - $auths = $project->getAttribute('auths', []); - $auths['passwordStrength'] = \array_merge([ - 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, - ], $auths['passwordStrength'] ?? []); - $auths['passwordStrength']['requireLowercase'] = $enabled; - - $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ - 'auths' => $auths, - ]))); - - $queueForEvents - ->setParam('projectId', $project->getId()) - ->setParam('policy', 'password-strength.require-lowercase'); - - $response->dynamic($project, Response::MODEL_PROJECT); - } -} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php deleted file mode 100644 index 6869a355ed..0000000000 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireNumber/Update.php +++ /dev/null @@ -1,89 +0,0 @@ -setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/project/policies/password-strength/require-number') - ->desc('Update password strength number requirement') - ->groups(['api', 'project']) - ->label('scope', ['policies.write', 'project.policies.write']) - ->label('event', 'projects.[projectId].policies.[policy].update') - ->label('audits.event', 'projects.[projectId].policies.[policy].update') - ->label('audits.resource', 'project/{response.$id}') - ->label('sdk', new Method( - namespace: 'project', - group: 'policies', - name: 'updatePasswordStrengthRequireNumber', - description: <<<'EOT' - Update whether passwords must include at least one number. - EOT, - auth: [AuthType::ADMIN, AuthType::KEY], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ), - ], - )) - ->param('enabled', null, new Boolean(), 'Whether passwords must include at least one number.') - ->inject('response') - ->inject('dbForPlatform') - ->inject('project') - ->inject('authorization') - ->inject('queueForEvents') - ->callback($this->action(...)); - } - - public function action( - bool $enabled, - Response $response, - Database $dbForPlatform, - Document $project, - Authorization $authorization, - Event $queueForEvents, - ): void { - $auths = $project->getAttribute('auths', []); - $auths['passwordStrength'] = \array_merge([ - 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, - ], $auths['passwordStrength'] ?? []); - $auths['passwordStrength']['requireNumber'] = $enabled; - - $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ - 'auths' => $auths, - ]))); - - $queueForEvents - ->setParam('projectId', $project->getId()) - ->setParam('policy', 'password-strength.require-number'); - - $response->dynamic($project, Response::MODEL_PROJECT); - } -} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php deleted file mode 100644 index 6f70bdb38f..0000000000 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireSpecialChar/Update.php +++ /dev/null @@ -1,89 +0,0 @@ -setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/project/policies/password-strength/require-special-char') - ->desc('Update password strength special character requirement') - ->groups(['api', 'project']) - ->label('scope', ['policies.write', 'project.policies.write']) - ->label('event', 'projects.[projectId].policies.[policy].update') - ->label('audits.event', 'projects.[projectId].policies.[policy].update') - ->label('audits.resource', 'project/{response.$id}') - ->label('sdk', new Method( - namespace: 'project', - group: 'policies', - name: 'updatePasswordStrengthRequireSpecialChar', - description: <<<'EOT' - Update whether passwords must include at least one special character. - EOT, - auth: [AuthType::ADMIN, AuthType::KEY], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ), - ], - )) - ->param('enabled', null, new Boolean(), 'Whether passwords must include at least one special character.') - ->inject('response') - ->inject('dbForPlatform') - ->inject('project') - ->inject('authorization') - ->inject('queueForEvents') - ->callback($this->action(...)); - } - - public function action( - bool $enabled, - Response $response, - Database $dbForPlatform, - Document $project, - Authorization $authorization, - Event $queueForEvents, - ): void { - $auths = $project->getAttribute('auths', []); - $auths['passwordStrength'] = \array_merge([ - 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, - ], $auths['passwordStrength'] ?? []); - $auths['passwordStrength']['requireSpecialChar'] = $enabled; - - $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ - 'auths' => $auths, - ]))); - - $queueForEvents - ->setParam('projectId', $project->getId()) - ->setParam('policy', 'password-strength.require-special-char'); - - $response->dynamic($project, Response::MODEL_PROJECT); - } -} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php deleted file mode 100644 index adc93bcdbc..0000000000 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/RequireUppercase/Update.php +++ /dev/null @@ -1,89 +0,0 @@ -setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/project/policies/password-strength/require-uppercase') - ->desc('Update password strength uppercase requirement') - ->groups(['api', 'project']) - ->label('scope', ['policies.write', 'project.policies.write']) - ->label('event', 'projects.[projectId].policies.[policy].update') - ->label('audits.event', 'projects.[projectId].policies.[policy].update') - ->label('audits.resource', 'project/{response.$id}') - ->label('sdk', new Method( - namespace: 'project', - group: 'policies', - name: 'updatePasswordStrengthRequireUppercase', - description: <<<'EOT' - Update whether passwords must include at least one uppercase letter. - EOT, - auth: [AuthType::ADMIN, AuthType::KEY], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ), - ], - )) - ->param('enabled', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.') - ->inject('response') - ->inject('dbForPlatform') - ->inject('project') - ->inject('authorization') - ->inject('queueForEvents') - ->callback($this->action(...)); - } - - public function action( - bool $enabled, - Response $response, - Database $dbForPlatform, - Document $project, - Authorization $authorization, - Event $queueForEvents, - ): void { - $auths = $project->getAttribute('auths', []); - $auths['passwordStrength'] = \array_merge([ - 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, - ], $auths['passwordStrength'] ?? []); - $auths['passwordStrength']['requireUppercase'] = $enabled; - - $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ - 'auths' => $auths, - ]))); - - $queueForEvents - ->setParam('projectId', $project->getId()) - ->setParam('policy', 'password-strength.require-uppercase'); - - $response->dynamic($project, Response::MODEL_PROJECT); - } -} diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/MinLength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php similarity index 61% rename from src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/MinLength/Update.php rename to src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index 2e7a6242bc..cce5e6adb5 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/MinLength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -1,6 +1,6 @@ setHttpMethod(Action::HTTP_REQUEST_METHOD_PATCH) - ->setHttpPath('/v1/project/policies/password-strength/min-length') - ->desc('Update password strength minimum length') + ->setHttpPath('/v1/project/policies/password-strength') + ->desc('Update password strength policy') ->groups(['api', 'project']) ->label('scope', ['policies.write', 'project.policies.write']) ->label('event', 'projects.[projectId].policies.[policy].update') @@ -37,9 +38,9 @@ class Update extends Action ->label('sdk', new Method( namespace: 'project', group: 'policies', - name: 'updatePasswordStrengthMinLength', + name: 'updatePasswordStrengthPolicy', description: <<<'EOT' - Update the minimum password length required for users in the project. + Update the password strength requirements for users in the project. EOT, auth: [AuthType::ADMIN, AuthType::KEY], responses: [ @@ -49,7 +50,11 @@ class Update extends Action ), ], )) - ->param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.') + ->param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) + ->param('requireUppercase', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.', optional: true) + ->param('requireLowercase', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.', optional: true) + ->param('requireNumber', null, new Boolean(), 'Whether passwords must include at least one number.', optional: true) + ->param('requireSpecialChar', null, new Boolean(), 'Whether passwords must include at least one special character.', optional: true) ->inject('response') ->inject('dbForPlatform') ->inject('project') @@ -59,7 +64,11 @@ class Update extends Action } public function action( - int $minLength, + ?int $minLength, + ?bool $requireUppercase, + ?bool $requireLowercase, + ?bool $requireNumber, + ?bool $requireSpecialChar, Response $response, Database $dbForPlatform, Document $project, @@ -74,7 +83,22 @@ class Update extends Action 'requireNumber' => false, 'requireSpecialChar' => false, ], $auths['passwordStrength'] ?? []); - $auths['passwordStrength']['minLength'] = $minLength; + + if ($minLength !== null) { + $auths['passwordStrength']['minLength'] = $minLength; + } + if ($requireUppercase !== null) { + $auths['passwordStrength']['requireUppercase'] = $requireUppercase; + } + if ($requireLowercase !== null) { + $auths['passwordStrength']['requireLowercase'] = $requireLowercase; + } + if ($requireNumber !== null) { + $auths['passwordStrength']['requireNumber'] = $requireNumber; + } + if ($requireSpecialChar !== null) { + $auths['passwordStrength']['requireSpecialChar'] = $requireSpecialChar; + } $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ 'auths' => $auths, @@ -82,7 +106,7 @@ class Update extends Action $queueForEvents ->setParam('projectId', $project->getId()) - ->setParam('policy', 'password-strength.min-length'); + ->setParam('policy', 'password-strength'); $response->dynamic($project, Response::MODEL_PROJECT); } diff --git a/src/Appwrite/Platform/Modules/Project/Services/Http.php b/src/Appwrite/Platform/Modules/Project/Services/Http.php index 7940e5b506..a8eec3abd0 100644 --- a/src/Appwrite/Platform/Modules/Project/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Project/Services/Http.php @@ -80,11 +80,7 @@ use Appwrite\Platform\Modules\Project\Http\Project\Policies\MembershipPrivacy\Up use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordDictionary\Update as UpdatePasswordDictionaryPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordHistory\Update as UpdatePasswordHistoryPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordPersonalData\Update as UpdatePasswordPersonalDataPolicy; -use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\MinLength\Update as UpdatePasswordStrengthMinLengthPolicy; -use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\RequireLowercase\Update as UpdatePasswordStrengthRequireLowercasePolicy; -use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\RequireNumber\Update as UpdatePasswordStrengthRequireNumberPolicy; -use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\RequireSpecialChar\Update as UpdatePasswordStrengthRequireSpecialCharPolicy; -use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\RequireUppercase\Update as UpdatePasswordStrengthRequireUppercasePolicy; +use Appwrite\Platform\Modules\Project\Http\Project\Policies\PasswordStrength\Update as UpdatePasswordStrengthPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionAlert\Update as UpdateSessionAlertPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionDuration\Update as UpdateSessionDurationPolicy; use Appwrite\Platform\Modules\Project\Http\Project\Policies\SessionInvalidation\Update as UpdateSessionInvalidationPolicy; @@ -173,11 +169,7 @@ class Http extends Service $this->addAction(UpdateMembershipPrivacyPolicy::getName(), new UpdateMembershipPrivacyPolicy()); $this->addAction(UpdatePasswordDictionaryPolicy::getName(), new UpdatePasswordDictionaryPolicy()); $this->addAction(UpdatePasswordHistoryPolicy::getName(), new UpdatePasswordHistoryPolicy()); - $this->addAction(UpdatePasswordStrengthMinLengthPolicy::getName(), new UpdatePasswordStrengthMinLengthPolicy()); - $this->addAction(UpdatePasswordStrengthRequireUppercasePolicy::getName(), new UpdatePasswordStrengthRequireUppercasePolicy()); - $this->addAction(UpdatePasswordStrengthRequireLowercasePolicy::getName(), new UpdatePasswordStrengthRequireLowercasePolicy()); - $this->addAction(UpdatePasswordStrengthRequireNumberPolicy::getName(), new UpdatePasswordStrengthRequireNumberPolicy()); - $this->addAction(UpdatePasswordStrengthRequireSpecialCharPolicy::getName(), new UpdatePasswordStrengthRequireSpecialCharPolicy()); + $this->addAction(UpdatePasswordStrengthPolicy::getName(), new UpdatePasswordStrengthPolicy()); $this->addAction(UpdatePasswordPersonalDataPolicy::getName(), new UpdatePasswordPersonalDataPolicy()); $this->addAction(UpdateSessionAlertPolicy::getName(), new UpdateSessionAlertPolicy()); $this->addAction(UpdateSessionDurationPolicy::getName(), new UpdateSessionDurationPolicy()); diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 80edad2e65..eef86174fe 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -61,11 +61,13 @@ trait PoliciesBase { $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); - $this->updatePasswordStrengthMinLengthPolicy(12); - $this->updatePasswordStrengthRequireUppercasePolicy(true); - $this->updatePasswordStrengthRequireLowercasePolicy(true); - $this->updatePasswordStrengthRequireNumberPolicy(true); - $this->updatePasswordStrengthRequireSpecialCharPolicy(true); + $this->updatePasswordStrengthPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ]); $this->updateSessionDurationPolicy(3600); $this->updateMembershipPrivacyPolicy([ 'userId' => true, @@ -201,11 +203,13 @@ trait PoliciesBase { $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); - $this->updatePasswordStrengthMinLengthPolicy(12); - $this->updatePasswordStrengthRequireUppercasePolicy(true); - $this->updatePasswordStrengthRequireLowercasePolicy(true); - $this->updatePasswordStrengthRequireNumberPolicy(true); - $this->updatePasswordStrengthRequireSpecialCharPolicy(true); + $this->updatePasswordStrengthPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ]); $this->updateSessionDurationPolicy(3600); $this->updateMembershipPrivacyPolicy([ 'userId' => true, @@ -463,19 +467,13 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicy(): void { - $response = $this->updatePasswordStrengthMinLengthPolicy(12); - $this->assertSame(200, $response['headers']['status-code']); - - $response = $this->updatePasswordStrengthRequireUppercasePolicy(true); - $this->assertSame(200, $response['headers']['status-code']); - - $response = $this->updatePasswordStrengthRequireLowercasePolicy(true); - $this->assertSame(200, $response['headers']['status-code']); - - $response = $this->updatePasswordStrengthRequireNumberPolicy(true); - $this->assertSame(200, $response['headers']['status-code']); - - $response = $this->updatePasswordStrengthRequireSpecialCharPolicy(true); + $response = $this->updatePasswordStrengthPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(12, $response['body']['authPasswordStrengthMinLength']); @@ -498,23 +496,19 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicyOptionPreservesOtherOptions(): void { - $response = $this->updatePasswordStrengthMinLengthPolicy(12); - $this->assertSame(200, $response['headers']['status-code']); - - $response = $this->updatePasswordStrengthRequireUppercasePolicy(true); - $this->assertSame(200, $response['headers']['status-code']); - - $response = $this->updatePasswordStrengthRequireLowercasePolicy(true); - $this->assertSame(200, $response['headers']['status-code']); - - $response = $this->updatePasswordStrengthRequireNumberPolicy(true); - $this->assertSame(200, $response['headers']['status-code']); - - $response = $this->updatePasswordStrengthRequireSpecialCharPolicy(true); + $response = $this->updatePasswordStrengthPolicy([ + 'minLength' => 12, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, + ]); $this->assertSame(200, $response['headers']['status-code']); - $response = $this->updatePasswordStrengthRequireLowercasePolicy(false); + $response = $this->updatePasswordStrengthPolicy([ + 'requireLowercase' => false, + ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(12, $response['body']['authPasswordStrengthMinLength']); @@ -529,23 +523,32 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicyBelowMinLength(): void { - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', $this->buildHeaders(), [ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders(), [ 'minLength' => 7, ]); $this->assertSame(400, $response['headers']['status-code']); } - public function testUpdatePasswordStrengthPolicyMissingParam(): void + public function testUpdatePasswordStrengthPolicyEmptyBody(): void { - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-uppercase', $this->buildHeaders(), []); + $this->resetPasswordStrengthPolicy(); - $this->assertSame(400, $response['headers']['status-code']); + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders(), []); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame(8, $response['body']['authPasswordStrengthMinLength']); + $this->assertSame(false, $response['body']['authPasswordStrengthRequireUppercase']); + $this->assertSame(false, $response['body']['authPasswordStrengthRequireLowercase']); + $this->assertSame(false, $response['body']['authPasswordStrengthRequireNumber']); + $this->assertSame(false, $response['body']['authPasswordStrengthRequireSpecialChar']); } public function testUpdatePasswordStrengthPolicyWithoutAuth(): void { - $response = $this->updatePasswordStrengthMinLengthPolicy(12, false); + $response = $this->updatePasswordStrengthPolicy([ + 'minLength' => 12, + ], false); $this->assertSame(401, $response['headers']['status-code']); } @@ -1259,48 +1262,23 @@ trait PoliciesBase ]); } - protected function updatePasswordStrengthMinLengthPolicy(int $minLength, bool $authenticated = true): mixed + /** + * @param array $params + */ + protected function updatePasswordStrengthPolicy(array $params, bool $authenticated = true): mixed { - return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', $this->buildHeaders($authenticated), [ - 'minLength' => $minLength, - ]); - } - - protected function updatePasswordStrengthRequireUppercasePolicy(bool $enabled, bool $authenticated = true): mixed - { - return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-uppercase', $this->buildHeaders($authenticated), [ - 'enabled' => $enabled, - ]); - } - - protected function updatePasswordStrengthRequireLowercasePolicy(bool $enabled, bool $authenticated = true): mixed - { - return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-lowercase', $this->buildHeaders($authenticated), [ - 'enabled' => $enabled, - ]); - } - - protected function updatePasswordStrengthRequireNumberPolicy(bool $enabled, bool $authenticated = true): mixed - { - return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-number', $this->buildHeaders($authenticated), [ - 'enabled' => $enabled, - ]); - } - - protected function updatePasswordStrengthRequireSpecialCharPolicy(bool $enabled, bool $authenticated = true): mixed - { - return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-special-char', $this->buildHeaders($authenticated), [ - 'enabled' => $enabled, - ]); + return $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders($authenticated), $params); } protected function resetPasswordStrengthPolicy(): void { - $this->updatePasswordStrengthMinLengthPolicy(8); - $this->updatePasswordStrengthRequireUppercasePolicy(false); - $this->updatePasswordStrengthRequireLowercasePolicy(false); - $this->updatePasswordStrengthRequireNumberPolicy(false); - $this->updatePasswordStrengthRequireSpecialCharPolicy(false); + $this->updatePasswordStrengthPolicy([ + 'minLength' => 8, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, + ]); } protected function updatePasswordPersonalDataPolicy(bool $enabled, bool $authenticated = true): mixed diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index dba60c6dcb..dd45f5e6fd 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2907,7 +2907,7 @@ class ProjectsConsoleClientTest extends Scope $data = $this->setupProjectData(); $id = $data['projectId']; - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', @@ -2917,7 +2917,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', @@ -2927,42 +2927,15 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-uppercase', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => true, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-lowercase', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', - ], $this->getHeaders()), [ - 'enabled' => true, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-number', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', - ], $this->getHeaders()), [ - 'enabled' => true, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-special-char', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', - ], $this->getHeaders()), [ - 'enabled' => true, + 'requireUppercase' => true, + 'requireLowercase' => true, + 'requireNumber' => true, + 'requireSpecialChar' => true, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -3080,52 +3053,16 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/min-length', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'minLength' => 8, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-uppercase', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', - ], $this->getHeaders()), [ - 'enabled' => false, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-lowercase', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', - ], $this->getHeaders()), [ - 'enabled' => false, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-number', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', - ], $this->getHeaders()), [ - 'enabled' => false, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength/require-special-char', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', - ], $this->getHeaders()), [ - 'enabled' => false, + 'requireUppercase' => false, + 'requireLowercase' => false, + 'requireNumber' => false, + 'requireSpecialChar' => false, ]); $this->assertEquals(200, $response['headers']['status-code']); From 141996576f9345422f96ffcf41ea80458e8ff549 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 1 Jun 2026 14:45:03 +0400 Subject: [PATCH 11/16] Address password policy review feedback --- app/controllers/api/account.php | 8 +- app/controllers/api/users.php | 7 +- src/Appwrite/Auth/Validator/Password.php | 8 +- .../Auth/Validator/PasswordDictionary.php | 15 +- .../Auth/Validator/PasswordStrength.php | 3 +- .../Policies/PasswordStrength/Update.php | 8 +- .../Utopia/Response/Model/Project.php | 333 ------------------ tests/e2e/Services/Project/PoliciesBase.php | 46 ++- .../Project/ProjectConsoleClientTest.php | 20 +- .../Projects/ProjectsConsoleClientTest.php | 22 +- .../Auth/Validator/PasswordDictionaryTest.php | 4 +- .../Auth/Validator/PasswordStrengthTest.php | 10 + 12 files changed, 99 insertions(+), 385 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 3ab53f4994..69ad1fc2f2 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -7,6 +7,7 @@ use Appwrite\Auth\Phrase; use Appwrite\Auth\Validator\Password; use Appwrite\Auth\Validator\PasswordDictionary; use Appwrite\Auth\Validator\PasswordHistory; +use Appwrite\Auth\Validator\PasswordStrength; use Appwrite\Auth\Validator\PersonalData; use Appwrite\Auth\Validator\Phone; use Appwrite\Bus\Events\SessionCreated; @@ -71,6 +72,7 @@ use Utopia\Platform\Enum; use Utopia\Storage\Validator\FileName; use Utopia\System\System; use Utopia\Validator; +use Utopia\Validator\AllOf; use Utopia\Validator\ArrayList; use Utopia\Validator\Assoc; use Utopia\Validator\Boolean; @@ -255,7 +257,7 @@ Http::post('/v1/account') ->label('abuse-limit', 10) ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', '', new EmailValidator(), 'User email.') - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be between 6 and 256 chars.', false, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('request') ->inject('response') @@ -3271,7 +3273,7 @@ Http::patch('/v1/account/password') contentType: ContentType::JSON )) ->label('abuse-limit', 10) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be at least 6 chars.', false, ['project', 'passwordsDictionary']) ->param('oldPassword', '', new Password(), 'Current user password. Must be at least 8 chars.', true) ->inject('response') ->inject('user') @@ -3888,7 +3890,7 @@ Http::put('/v1/account/recovery') ->label('abuse-key', 'url:{url},userId:{param-userId}') ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) ->param('secret', '', new Text(256), 'Valid reset token.') - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be between 6 and 256 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('user') ->inject('dbForProject') diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index a168c98320..baed5fa63a 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -6,6 +6,7 @@ use Appwrite\Auth\MFA\Type\TOTP; use Appwrite\Auth\Validator\Password; use Appwrite\Auth\Validator\PasswordDictionary; use Appwrite\Auth\Validator\PasswordHistory; +use Appwrite\Auth\Validator\PasswordStrength; use Appwrite\Auth\Validator\PersonalData; use Appwrite\Auth\Validator\Phone; use Appwrite\Deletes\Identities as DeleteIdentities; @@ -65,6 +66,8 @@ use Utopia\Http\Http; use Utopia\Locale\Locale; use Utopia\Platform\Enum; use Utopia\System\System; +use Utopia\Validator; +use Utopia\Validator\AllOf; use Utopia\Validator\ArrayList; use Utopia\Validator\Assoc; use Utopia\Validator\Boolean; @@ -280,7 +283,7 @@ Http::post('/v1/users') ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', null, new Nullable(new EmailValidator()), 'User email.', true) ->param('phone', null, new Nullable(new Phone()), 'Phone number. Format this number with a leading \'+\' and a country code, e.g., +16175551212.', true) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'Plain text user password. Must be at least 8 chars.', true, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'Plain text user password. Must be at least 6 chars.', true, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('response') ->inject('project') @@ -1431,7 +1434,7 @@ Http::patch('/v1/users/:userId/password') ] )) ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) - ->param('password', '', fn ($project, $passwordsDictionary) => new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, allowEmpty: true, policy: $project->getAttribute('auths', [])['passwordStrength'] ?? []), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? [], allowEmpty: true), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be at least 6 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('project') ->inject('dbForProject') diff --git a/src/Appwrite/Auth/Validator/Password.php b/src/Appwrite/Auth/Validator/Password.php index bfe5577889..d1c72d686e 100644 --- a/src/Appwrite/Auth/Validator/Password.php +++ b/src/Appwrite/Auth/Validator/Password.php @@ -12,10 +12,12 @@ use Utopia\Validator; class Password extends Validator { protected bool $allowEmpty; + protected int $minLength; - public function __construct(bool $allowEmpty = false) + public function __construct(bool $allowEmpty = false, int $minLength = 8) { $this->allowEmpty = $allowEmpty; + $this->minLength = $minLength; } /** @@ -27,7 +29,7 @@ class Password extends Validator */ public function getDescription(): string { - return 'Password must be between 8 and 256 characters long.'; + return 'Password must be between ' . $this->minLength . ' and 256 characters long.'; } /** @@ -47,7 +49,7 @@ class Password extends Validator return true; } - if (\strlen($value) < 8) { + if (\strlen($value) < $this->minLength) { return false; } diff --git a/src/Appwrite/Auth/Validator/PasswordDictionary.php b/src/Appwrite/Auth/Validator/PasswordDictionary.php index 59a8d2f3a6..dd832e63d5 100644 --- a/src/Appwrite/Auth/Validator/PasswordDictionary.php +++ b/src/Appwrite/Auth/Validator/PasswordDictionary.php @@ -2,19 +2,20 @@ namespace Appwrite\Auth\Validator; +use Utopia\Validator; + /** * Password. * * Validates user password string */ -class PasswordDictionary extends PasswordStrength +class PasswordDictionary extends Validator { protected array $dictionary; protected bool $enabled; - public function __construct(array $dictionary, bool $enabled = false, bool $allowEmpty = false, array $policy = []) + public function __construct(array $dictionary, bool $enabled = false) { - parent::__construct($policy, $allowEmpty); $this->dictionary = $dictionary; $this->enabled = $enabled; } @@ -28,7 +29,7 @@ class PasswordDictionary extends PasswordStrength */ public function getDescription(): string { - return parent::getDescription() . ' It should not be one of the commonly used passwords.'; + return 'Password should not be one of the commonly used passwords.'; } /** @@ -40,11 +41,7 @@ class PasswordDictionary extends PasswordStrength */ public function isValid($value): bool { - if (!parent::isValid($value)) { - return false; - } - - if ($this->enabled && array_key_exists($value, $this->dictionary)) { + if ($this->enabled && \is_string($value) && array_key_exists($value, $this->dictionary)) { return false; } return true; diff --git a/src/Appwrite/Auth/Validator/PasswordStrength.php b/src/Appwrite/Auth/Validator/PasswordStrength.php index fc4d3cfd82..73ad4b8d58 100644 --- a/src/Appwrite/Auth/Validator/PasswordStrength.php +++ b/src/Appwrite/Auth/Validator/PasswordStrength.php @@ -17,9 +17,8 @@ class PasswordStrength extends Password public function __construct(array $policy = [], bool $allowEmpty = false) { - parent::__construct($allowEmpty); + parent::__construct($allowEmpty, $policy['minLength'] ?? 8); - $this->minLength = $policy['minLength'] ?? 8; $this->requireUppercase = $policy['requireUppercase'] ?? false; $this->requireLowercase = $policy['requireLowercase'] ?? false; $this->requireNumber = $policy['requireNumber'] ?? false; diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index cce5e6adb5..453cd9ca78 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -46,11 +46,11 @@ class Update extends Action responses: [ new SDKResponse( code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, + model: Response::MODEL_POLICY_PASSWORD_STRENGTH, ), ], )) - ->param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) + ->param('minLength', null, new Range(6, 256), 'Minimum password length. Value must be between 6 and 256. Default is 8.', optional: true) ->param('requireUppercase', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.', optional: true) ->param('requireLowercase', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.', optional: true) ->param('requireNumber', null, new Boolean(), 'Whether passwords must include at least one number.', optional: true) @@ -108,6 +108,8 @@ class Update extends Action ->setParam('projectId', $project->getId()) ->setParam('policy', 'password-strength'); - $response->dynamic($project, Response::MODEL_PROJECT); + $response->dynamic(new Document(\array_merge($auths['passwordStrength'], [ + '$id' => 'password-strength', + ])), Response::MODEL_POLICY_PASSWORD_STRENGTH); } } diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index f965934b16..c788833e88 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -43,197 +43,6 @@ class Project extends Model 'default' => '', 'example' => '1592981250', ]) - ->addRule('legalName', [ - 'type' => self::TYPE_STRING, - 'description' => 'Company legal name.', - 'default' => '', - 'example' => 'Company LTD.', - ]) - ->addRule('legalCountry', [ - 'type' => self::TYPE_STRING, - 'description' => 'Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format.', - 'default' => '', - 'example' => 'US', - ]) - ->addRule('legalState', [ - 'type' => self::TYPE_STRING, - 'description' => 'State name.', - 'default' => '', - 'example' => 'New York', - ]) - ->addRule('legalCity', [ - 'type' => self::TYPE_STRING, - 'description' => 'City name.', - 'default' => '', - 'example' => 'New York City.', - ]) - ->addRule('legalAddress', [ - 'type' => self::TYPE_STRING, - 'description' => 'Company Address.', - 'default' => '', - 'example' => '620 Eighth Avenue, New York, NY 10018', - ]) - ->addRule('legalTaxId', [ - 'type' => self::TYPE_STRING, - 'description' => 'Company Tax ID.', - 'default' => '', - 'example' => '131102020', - ]) - ->addRule('authDuration', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Session duration in seconds.', - 'default' => TOKEN_EXPIRATION_LOGIN_LONG, - 'example' => 60, - ]) - ->addRule('authLimit', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Max users allowed. 0 is unlimited.', - 'default' => 0, - 'example' => 100, - ]) - ->addRule('authSessionsLimit', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Max sessions allowed per user. 100 maximum.', - 'default' => 10, - 'example' => 10, - ]) - ->addRule('authPasswordHistory', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Max allowed passwords in the history list per user. Max passwords limit allowed in history is 20. Use 0 for disabling password history.', - 'default' => 0, - 'example' => 5, - ]) - ->addRule('authPasswordStrengthMinLength', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Minimum password length required for user passwords.', - 'default' => 8, - 'example' => 12, - ]) - ->addRule('authPasswordStrengthRequireUppercase', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not passwords must include at least one uppercase letter.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authPasswordStrengthRequireLowercase', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not passwords must include at least one lowercase letter.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authPasswordStrengthRequireNumber', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not passwords must include at least one number.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authPasswordStrengthRequireSpecialChar', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not passwords must include at least one special character.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authPasswordDictionary', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not to check user\'s password against most commonly used passwords.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authPersonalDataCheck', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not to check the user password for similarity with their personal data.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authDisposableEmails', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not to disallow disposable email addresses during signup and email updates.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authCanonicalEmails', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not to require canonical email addresses during signup and email updates.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authFreeEmails', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not to disallow free email addresses during signup and email updates.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authMockNumbers', [ - 'type' => Response::MODEL_MOCK_NUMBER, - 'description' => 'An array of mock numbers and their corresponding verification codes (OTPs).', - 'default' => [], - 'array' => true, - 'example' => [new \stdClass()], - ]) - ->addRule('authSessionAlerts', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not to send session alert emails to users.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authMembershipsUserName', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not to show user names in the teams membership response.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authMembershipsUserEmail', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not to show user emails in the teams membership response.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authMembershipsMfa', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not to show user MFA status in the teams membership response.', - 'default' => false, - 'example' => true, - ]) - ->addRule('authInvalidateSessions', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether or not all existing sessions should be invalidated on password change', - 'default' => false, - 'example' => true, - ]) - ->addRule('oAuthProviders', [ - 'type' => Response::MODEL_AUTH_PROVIDER, - 'description' => 'List of Auth Providers.', - 'default' => [], - 'example' => [new \stdClass()], - 'array' => true, - ]) - ->addRule('platforms', [ - 'type' => [ - Response::MODEL_PLATFORM_WEB, - Response::MODEL_PLATFORM_APPLE, - Response::MODEL_PLATFORM_ANDROID, - Response::MODEL_PLATFORM_WINDOWS, - Response::MODEL_PLATFORM_LINUX, - ], - 'description' => 'List of Platforms.', - 'default' => [], - 'example' => new \stdClass(), - 'array' => true, - ]) - ->addRule('webhooks', [ - 'type' => Response::MODEL_WEBHOOK, - 'description' => 'List of Webhooks.', - 'default' => [], - 'example' => new \stdClass(), - 'array' => true, - ]) - ->addRule('keys', [ - 'type' => Response::MODEL_KEY, - 'description' => 'List of API Keys.', - 'default' => [], - 'example' => new \stdClass(), - 'array' => true, - ]) // Resource: Dev Keys ->addRule('devKeys', [ @@ -365,46 +174,6 @@ class Project extends Model 'array' => true, ]) ; - - foreach (Config::getParam('auth', []) as $method) { - $name = $method['name'] ?? ''; - $key = $method['key'] ?? ''; - - $this->addRule('auth' . ucfirst($key), [ - 'type' => self::TYPE_BOOLEAN, - 'description' => $name . ' auth method status', - 'example' => true, - 'default' => true, - ]); - } - - foreach (Config::getParam('services', []) as $service) { - if (!$service['optional']) { - continue; - } - - $name = $service['name'] ?? ''; - $key = $service['key'] ?? ''; - - $this->addRule('serviceStatusFor' . ucfirst($key), [ - 'type' => self::TYPE_BOOLEAN, - 'description' => $name . ' service status', - 'example' => true, - 'default' => true, - ]); - } - - foreach (Config::getParam('protocols', []) as $api) { - $name = $api['name'] ?? ''; - $key = $api['key'] ?? ''; - - $this->addRule('protocolStatusFor' . ucfirst($key), [ - 'type' => self::TYPE_BOOLEAN, - 'description' => $name . ' protocol status', - 'example' => true, - 'default' => true, - ]); - } } /** @@ -435,10 +204,6 @@ class Project extends Model public function filter(Document $document): Document { $this->expandSmtpFields($document); - $this->expandServiceFields($document); - $this->expandApiFields($document); - $this->expandAuthFields($document); - $this->expandOAuthProviders($document); $this->expandServices($document); $this->expandProtocols($document); $this->expandAuthMethods($document); @@ -466,104 +231,6 @@ class Project extends Model $document->setAttribute('smtpSecure', $smtp['secure'] ?? ''); } - private function expandServiceFields(Document $document): void - { - if (!$document->isSet('services')) { - return; - } - - $values = $document->getAttribute('services', []); - - foreach (Config::getParam('services', []) as $service) { - if (!$service['optional']) { - continue; - } - - $key = $service['key'] ?? ''; - $value = $values[$key] ?? true; - $document->setAttribute('serviceStatusFor' . ucfirst($key), $value); - } - } - - private function expandApiFields(Document $document): void - { - if (!$document->isSet('apis')) { - return; - } - - $values = $document->getAttribute('apis', []); - - foreach (Config::getParam('protocols', []) as $api) { - $key = $api['key'] ?? ''; - $value = $values[$key] ?? true; - $document->setAttribute('protocolStatusFor' . ucfirst($key), $value); - } - } - - private function expandAuthFields(Document $document): void - { - if (!$document->isSet('auths')) { - return; - } - - $authValues = $document->getAttribute('auths', []); - $passwordStrength = $authValues['passwordStrength'] ?? []; - - $document->setAttribute('authLimit', $authValues['limit'] ?? 0); - $document->setAttribute('authDuration', $authValues['duration'] ?? TOKEN_EXPIRATION_LOGIN_LONG); - $document->setAttribute('authSessionsLimit', $authValues['maxSessions'] ?? 0); - $document->setAttribute('authPasswordHistory', $authValues['passwordHistory'] ?? 0); - $document->setAttribute('authPasswordStrengthMinLength', $passwordStrength['minLength'] ?? 8); - $document->setAttribute('authPasswordStrengthRequireUppercase', $passwordStrength['requireUppercase'] ?? false); - $document->setAttribute('authPasswordStrengthRequireLowercase', $passwordStrength['requireLowercase'] ?? false); - $document->setAttribute('authPasswordStrengthRequireNumber', $passwordStrength['requireNumber'] ?? false); - $document->setAttribute('authPasswordStrengthRequireSpecialChar', $passwordStrength['requireSpecialChar'] ?? false); - $document->setAttribute('authPasswordDictionary', $authValues['passwordDictionary'] ?? false); - $document->setAttribute('authPersonalDataCheck', $authValues['personalDataCheck'] ?? false); - $document->setAttribute('authDisposableEmails', $authValues['disposableEmails'] ?? false); - $document->setAttribute('authCanonicalEmails', $authValues['canonicalEmails'] ?? false); - $document->setAttribute('authFreeEmails', $authValues['freeEmails'] ?? false); - $document->setAttribute('authMockNumbers', $authValues['mockNumbers'] ?? []); - $document->setAttribute('authSessionAlerts', $authValues['sessionAlerts'] ?? false); - $document->setAttribute('authMembershipsUserName', $authValues['membershipsUserName'] ?? true); - $document->setAttribute('authMembershipsUserEmail', $authValues['membershipsUserEmail'] ?? true); - $document->setAttribute('authMembershipsMfa', $authValues['membershipsMfa'] ?? true); - $document->setAttribute('authInvalidateSessions', $authValues['invalidateSessions'] ?? false); - - foreach (Config::getParam('auth', []) as $method) { - $key = $method['key']; - $value = $authValues[$key] ?? true; - $document->setAttribute('auth' . ucfirst($key), $value); - } - } - - private function expandOAuthProviders(Document $document): void - { - if (!$document->isSet('oAuthProviders')) { - return; - } - - $providers = Config::getParam('oAuthProviders', []); - $providerValues = $document->getAttribute('oAuthProviders', []); - $projectProviders = []; - - foreach ($providers as $key => $provider) { - if (!$provider['enabled']) { - continue; - } - - $projectProviders[] = new Document([ - 'key' => $key, - 'name' => $provider['name'] ?? '', - 'appId' => $providerValues[$key . 'Appid'] ?? '', - 'secret' => $providerValues[$key . 'Secret'] ?? '', - 'enabled' => $providerValues[$key . 'Enabled'] ?? false, - ]); - } - - $document->setAttribute('oAuthProviders', $projectProviders); - } - private function expandServices(Document $document): void { $values = $document->getAttribute('services', []); diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 37c2339de8..66517fb5af 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -480,11 +480,12 @@ trait PoliciesBase ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(12, $response['body']['authPasswordStrengthMinLength']); - $this->assertSame(true, $response['body']['authPasswordStrengthRequireUppercase']); - $this->assertSame(true, $response['body']['authPasswordStrengthRequireLowercase']); - $this->assertSame(true, $response['body']['authPasswordStrengthRequireNumber']); - $this->assertSame(true, $response['body']['authPasswordStrengthRequireSpecialChar']); + $this->assertSame('password-strength', $response['body']['$id']); + $this->assertSame(12, $response['body']['minLength']); + $this->assertSame(true, $response['body']['requireUppercase']); + $this->assertSame(true, $response['body']['requireLowercase']); + $this->assertSame(true, $response['body']['requireNumber']); + $this->assertSame(true, $response['body']['requireSpecialChar']); $policy = $this->getPolicy('password-strength'); $this->assertSame(200, $policy['headers']['status-code']); @@ -515,11 +516,24 @@ trait PoliciesBase ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(12, $response['body']['authPasswordStrengthMinLength']); - $this->assertSame(true, $response['body']['authPasswordStrengthRequireUppercase']); - $this->assertSame(false, $response['body']['authPasswordStrengthRequireLowercase']); - $this->assertSame(true, $response['body']['authPasswordStrengthRequireNumber']); - $this->assertSame(true, $response['body']['authPasswordStrengthRequireSpecialChar']); + $this->assertSame(12, $response['body']['minLength']); + $this->assertSame(true, $response['body']['requireUppercase']); + $this->assertSame(false, $response['body']['requireLowercase']); + $this->assertSame(true, $response['body']['requireNumber']); + $this->assertSame(true, $response['body']['requireSpecialChar']); + + // Cleanup + $this->resetPasswordStrengthPolicy(); + } + + public function testUpdatePasswordStrengthPolicyMinLength(): void + { + $response = $this->updatePasswordStrengthPolicy([ + 'minLength' => 6, + ]); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame(6, $response['body']['minLength']); // Cleanup $this->resetPasswordStrengthPolicy(); @@ -528,7 +542,7 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicyBelowMinLength(): void { $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders(), [ - 'minLength' => 7, + 'minLength' => 5, ]); $this->assertSame(400, $response['headers']['status-code']); @@ -541,11 +555,11 @@ trait PoliciesBase $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders(), []); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(8, $response['body']['authPasswordStrengthMinLength']); - $this->assertSame(false, $response['body']['authPasswordStrengthRequireUppercase']); - $this->assertSame(false, $response['body']['authPasswordStrengthRequireLowercase']); - $this->assertSame(false, $response['body']['authPasswordStrengthRequireNumber']); - $this->assertSame(false, $response['body']['authPasswordStrengthRequireSpecialChar']); + $this->assertSame(8, $response['body']['minLength']); + $this->assertSame(false, $response['body']['requireUppercase']); + $this->assertSame(false, $response['body']['requireLowercase']); + $this->assertSame(false, $response['body']['requireNumber']); + $this->assertSame(false, $response['body']['requireSpecialChar']); } public function testUpdatePasswordStrengthPolicyWithoutAuth(): void diff --git a/tests/e2e/Services/Project/ProjectConsoleClientTest.php b/tests/e2e/Services/Project/ProjectConsoleClientTest.php index 382ff63861..f2ae8ef904 100644 --- a/tests/e2e/Services/Project/ProjectConsoleClientTest.php +++ b/tests/e2e/Services/Project/ProjectConsoleClientTest.php @@ -114,10 +114,28 @@ class ProjectConsoleClientTest extends Scope $this->assertSame(0, $response['body']['pingCount']); $this->assertSame('', $response['body']['pingedAt']); - // Ensure old unsupported fields are not present + // Ensure old flattened fields are not present $this->assertArrayNotHasKey('description', $response['body']); $this->assertArrayNotHasKey('logo', $response['body']); $this->assertArrayNotHasKey('url', $response['body']); + $this->assertArrayNotHasKey('authDuration', $response['body']); + $this->assertArrayNotHasKey('authLimit', $response['body']); + $this->assertArrayNotHasKey('authSessionsLimit', $response['body']); + $this->assertArrayNotHasKey('authPasswordHistory', $response['body']); + $this->assertArrayNotHasKey('authPasswordStrengthMinLength', $response['body']); + $this->assertArrayNotHasKey('authPasswordStrengthRequireUppercase', $response['body']); + $this->assertArrayNotHasKey('authPasswordStrengthRequireLowercase', $response['body']); + $this->assertArrayNotHasKey('authPasswordStrengthRequireNumber', $response['body']); + $this->assertArrayNotHasKey('authPasswordStrengthRequireSpecialChar', $response['body']); + $this->assertArrayNotHasKey('authPasswordDictionary', $response['body']); + $this->assertArrayNotHasKey('authPersonalDataCheck', $response['body']); + $this->assertArrayNotHasKey('authDisposableEmails', $response['body']); + $this->assertArrayNotHasKey('authCanonicalEmails', $response['body']); + $this->assertArrayNotHasKey('authFreeEmails', $response['body']); + $this->assertArrayNotHasKey('oAuthProviders', $response['body']); + $this->assertArrayNotHasKey('platforms', $response['body']); + $this->assertArrayNotHasKey('webhooks', $response['body']); + $this->assertArrayNotHasKey('keys', $response['body']); } protected function createTeam(string $name): array diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index dd45f5e6fd..07f5785e5e 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2912,7 +2912,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'minLength' => 7, + 'minLength' => 5, ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -2939,11 +2939,11 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(12, $response['body']['authPasswordStrengthMinLength']); - $this->assertEquals(true, $response['body']['authPasswordStrengthRequireUppercase']); - $this->assertEquals(true, $response['body']['authPasswordStrengthRequireLowercase']); - $this->assertEquals(true, $response['body']['authPasswordStrengthRequireNumber']); - $this->assertEquals(true, $response['body']['authPasswordStrengthRequireSpecialChar']); + $this->assertEquals(12, $response['body']['minLength']); + $this->assertEquals(true, $response['body']['requireUppercase']); + $this->assertEquals(true, $response['body']['requireLowercase']); + $this->assertEquals(true, $response['body']['requireNumber']); + $this->assertEquals(true, $response['body']['requireSpecialChar']); $weakPassword = 'password123!'; $validPassword = 'Password123!'; @@ -3066,11 +3066,11 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(8, $response['body']['authPasswordStrengthMinLength']); - $this->assertEquals(false, $response['body']['authPasswordStrengthRequireUppercase']); - $this->assertEquals(false, $response['body']['authPasswordStrengthRequireLowercase']); - $this->assertEquals(false, $response['body']['authPasswordStrengthRequireNumber']); - $this->assertEquals(false, $response['body']['authPasswordStrengthRequireSpecialChar']); + $this->assertEquals(8, $response['body']['minLength']); + $this->assertEquals(false, $response['body']['requireUppercase']); + $this->assertEquals(false, $response['body']['requireLowercase']); + $this->assertEquals(false, $response['body']['requireNumber']); + $this->assertEquals(false, $response['body']['requireSpecialChar']); } #[Group('smtpAndTemplates')] diff --git a/tests/unit/Auth/Validator/PasswordDictionaryTest.php b/tests/unit/Auth/Validator/PasswordDictionaryTest.php index 60b5ca7ae3..1cb8e68e32 100644 --- a/tests/unit/Auth/Validator/PasswordDictionaryTest.php +++ b/tests/unit/Auth/Validator/PasswordDictionaryTest.php @@ -19,7 +19,7 @@ class PasswordDictionaryTest extends TestCase public function testValues(): void { - $this->assertEquals($this->object->isValid('1'), false); // to check parent is being called + $this->assertEquals($this->object->isValid('1'), true); $this->assertEquals($this->object->isValid('123456'), false); $this->assertEquals($this->object->isValid('password'), false); $this->assertEquals($this->object->isValid('myPasswordIsRight'), true); @@ -33,6 +33,6 @@ class PasswordDictionaryTest extends TestCase $pass .= 'p'; // 257 chars - $this->assertEquals($this->object->isValid($pass), false); + $this->assertEquals($this->object->isValid($pass), true); } } diff --git a/tests/unit/Auth/Validator/PasswordStrengthTest.php b/tests/unit/Auth/Validator/PasswordStrengthTest.php index 042d853653..49896f4e1f 100644 --- a/tests/unit/Auth/Validator/PasswordStrengthTest.php +++ b/tests/unit/Auth/Validator/PasswordStrengthTest.php @@ -34,6 +34,16 @@ class PasswordStrengthTest extends TestCase $this->assertTrue($validator->isValid('Password123€')); } + public function testMinLengthCanBeSix(): void + { + $validator = new PasswordStrength([ + 'minLength' => 6, + ]); + + $this->assertFalse($validator->isValid('12345')); + $this->assertTrue($validator->isValid('123456')); + } + public function testAllowEmpty(): void { $validator = new PasswordStrength([ From 4015eccc3f0a3e98ce141862ea95f0e016ae0747 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 1 Jun 2026 14:52:49 +0400 Subject: [PATCH 12/16] Minimize projects console password policy test diff --- .../Projects/ProjectsConsoleClientTest.php | 1435 +++++++++-------- 1 file changed, 728 insertions(+), 707 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 07f5785e5e..ca7ccb18e3 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -19,14 +19,14 @@ use Utopia\System\System; class ProjectsConsoleClientTest extends Scope { - use Async; - use ProjectConsole; use ProjectsBase; + use ProjectConsole; use SideClient; + use Async; #[Group('smtpAndTemplates')] #[Group('projectsCRUD')] - public function test_create_project(): void + public function testCreateProject(): void { /** * Test for SUCCESS @@ -46,12 +46,12 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-response-format' => '1.9.4', + 'x-appwrite-response-format' => '1.9.4' ], $this->getHeaders()), [ 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -96,7 +96,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => '', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -108,13 +108,13 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'projectId' => ID::unique(), 'name' => 'Project Test', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(401, $response['headers']['status-code']); } - public function test_delete_project_with_multi_db(): void + public function testDeleteProjectWithMultiDB(): void { // Create a team and project $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -136,7 +136,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'MultiDB Project', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -156,7 +156,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $database['headers']['status-code']); $databaseId = $database['body']['$id']; - $collection = $this->client->call(Client::METHOD_POST, '/databases/'.$databaseId.'/collections', $projectAdminHeaders, [ + $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', $projectAdminHeaders, [ 'collectionId' => ID::unique(), 'name' => 'Legacy Collection', 'documentSecurity' => true, @@ -174,7 +174,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $documentsDb['headers']['status-code']); $documentsDbId = $documentsDb['body']['$id']; - $documentsCollection = $this->client->call(Client::METHOD_POST, '/documentsdb/'.$documentsDbId.'/collections', $projectAdminHeaders, [ + $documentsCollection = $this->client->call(Client::METHOD_POST, '/documentsdb/' . $documentsDbId . '/collections', $projectAdminHeaders, [ 'collectionId' => ID::unique(), 'name' => 'Documents Collection', 'documentSecurity' => true, @@ -192,7 +192,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $vectorDb['headers']['status-code']); $vectorDbId = $vectorDb['body']['$id']; - $vectorCollection = $this->client->call(Client::METHOD_POST, '/vectorsdb/'.$vectorDbId.'/collections', $projectAdminHeaders, [ + $vectorCollection = $this->client->call(Client::METHOD_POST, '/vectorsdb/' . $vectorDbId . '/collections', $projectAdminHeaders, [ 'collectionId' => ID::unique(), 'name' => 'Vector Collection', 'dimension' => 3, @@ -204,7 +204,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $vectorCollection['headers']['status-code']); // Delete project - $delete = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ + $delete = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -212,7 +212,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $delete['headers']['status-code']); // Ensure project is gone - $getProject = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ + $getProject = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -221,7 +221,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $getProject['headers']['status-code']); } - public function test_create_duplicate_project(): void + public function testCreateDuplicateProject(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -245,7 +245,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => $projectId, 'name' => 'Original Project', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -261,7 +261,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => $projectId, 'name' => 'Project Duplicate', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(409, $response['headers']['status-code']); @@ -270,7 +270,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('projectsCRUD')] - public function test_transfer_project_team() + public function testTransferProjectTeam() { /** * Test for SUCCESS @@ -324,7 +324,7 @@ class ProjectsConsoleClientTest extends Scope $projectId = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/team', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/team', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -339,7 +339,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('projectsCRUD')] - public function test_list_project(): void + public function testListProject(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -347,6 +347,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ + $response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -365,7 +366,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders(), [ - 'search' => $id, + 'search' => $id ])); $this->assertEquals(200, $response['headers']['status-code']); @@ -377,7 +378,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders(), [ - 'search' => 'Project Test', + 'search' => 'Project Test' ])); $this->assertEquals($response['headers']['status-code'], 200); @@ -407,7 +408,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test 2', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -529,7 +530,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('projectsCRUD')] - public function test_list_projects_query_select(): void + public function testListProjectsQuerySelect(): void { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', @@ -550,7 +551,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Query Select Test Project', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -592,7 +593,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-response-format' => '1.9.4', + 'x-appwrite-response-format' => '1.9.4' ], $this->getHeaders()), [ 'queries' => [ Query::select(['$id', 'name', 'teamId', 'description', '$createdAt', '$updatedAt'])->toString(), @@ -788,7 +789,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `queries` param: Invalid query: Attribute not found in schema: invalidAttribute', $response['body']['message']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -796,7 +797,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } - public function test_get_project(): void + public function testGetProject(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -827,7 +828,7 @@ class ProjectsConsoleClientTest extends Scope 'legalState' => 'Custom state', 'legalCity' => 'Košice', 'legalAddress' => 'Main street 32', - 'legalTaxId' => 'TAXID_123456', + 'legalTaxId' => 'TAXID_123456' ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -874,7 +875,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'number' => '+421123456789', - 'otp' => '123456', + 'otp' => '123456' ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -884,12 +885,12 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'labels' => ['custom1', 'custom2'], + 'labels' => ['custom1', 'custom2'] ]); $this->assertEquals(200, $response['headers']['status-code']); // Create dev keys - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ 'content-type' => 'application/json', ], $this->getHeaders()), [ 'name' => 'Custom key 1', @@ -897,11 +898,11 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(201, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ 'content-type' => 'application/json', ], $this->getHeaders()), [ 'name' => 'Custom key 2', - 'expire' => '2099-05-07 11:23:30.713', + 'expire' => '2099-05-07 11:23:30.713' ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -911,7 +912,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'number' => '+420987654321', - 'otp' => '654321', + 'otp' => '654321' ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -921,7 +922,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'duration' => 135, + 'duration' => 135 ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -930,7 +931,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'total' => 54, + 'total' => 54 ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -939,7 +940,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'total' => 7, + 'total' => 7 ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -948,7 +949,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'total' => 9, + 'total' => 9 ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -957,7 +958,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => true, + 'enabled' => true ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -966,7 +967,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => true, + 'enabled' => true ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -975,7 +976,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => true, + 'enabled' => true ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -997,7 +998,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => true, + 'enabled' => true ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1018,7 +1019,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $webhook['headers']['status-code']); // Create API key - $key = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1029,7 +1030,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $key['headers']['status-code']); // Create platform - $platform = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $platform = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1055,7 +1056,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1262,7 +1263,7 @@ class ProjectsConsoleClientTest extends Scope 'authPhone', ]; foreach ($authsKeys as $authsKey) { - $this->assertTrue($response['body'][$authsKey], 'Auth method should be enabled: '.$authsKey); + $this->assertTrue($response['body'][$authsKey], 'Auth method should be enabled: ' . $authsKey); } $serviceKeys = [ @@ -1285,7 +1286,7 @@ class ProjectsConsoleClientTest extends Scope 'serviceStatusForMessaging', ]; foreach ($serviceKeys as $serviceKey) { - $this->assertTrue($response['body'][$serviceKey], 'Service should be enabled: '.$serviceKey); + $this->assertTrue($response['body'][$serviceKey], 'Service should be enabled: ' . $serviceKey); } $protocolKeys = [ @@ -1294,7 +1295,7 @@ class ProjectsConsoleClientTest extends Scope 'protocolStatusForWebsocket', ]; foreach ($protocolKeys as $protocolKey) { - $this->assertTrue($response['body'][$protocolKey], 'Protocol should be enabled: '.$protocolKey); + $this->assertTrue($response['body'][$protocolKey], 'Protocol should be enabled: ' . $protocolKey); } // Ensure booleans can be falsy @@ -1304,7 +1305,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => false, + 'enabled' => false ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1313,7 +1314,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => false, + 'enabled' => false ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1322,7 +1323,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => false, + 'enabled' => false ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1344,7 +1345,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'enabled' => false, + 'enabled' => false ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1354,7 +1355,7 @@ class ProjectsConsoleClientTest extends Scope foreach ($authMethods as $authMethod) { $response = $this->client->call( Client::METHOD_PATCH, - '/project/auth-methods/'.$authMethod, + '/project/auth-methods/' . $authMethod, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, @@ -1371,7 +1372,7 @@ class ProjectsConsoleClientTest extends Scope foreach ($protocols as $protocol) { $response = $this->client->call( Client::METHOD_PATCH, - '/project/protocols/'.$protocol, + '/project/protocols/' . $protocol, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, @@ -1407,7 +1408,7 @@ class ProjectsConsoleClientTest extends Scope foreach ($services as $service) { $response = $this->client->call( Client::METHOD_PATCH, - '/project/services/'.$service, + '/project/services/' . $service, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, @@ -1440,7 +1441,7 @@ class ProjectsConsoleClientTest extends Scope ); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1474,7 +1475,7 @@ class ProjectsConsoleClientTest extends Scope 'authPhone', ]; foreach ($authsKeys as $authsKey) { - $this->assertFalse($response['body'][$authsKey], 'Auth method should be disabled: '.$authsKey); + $this->assertFalse($response['body'][$authsKey], 'Auth method should be disabled: ' . $authsKey); } $serviceKeys = [ @@ -1497,7 +1498,7 @@ class ProjectsConsoleClientTest extends Scope 'serviceStatusForMessaging', ]; foreach ($serviceKeys as $serviceKey) { - $this->assertFalse($response['body'][$serviceKey], 'Service should be disabled: '.$serviceKey); + $this->assertFalse($response['body'][$serviceKey], 'Service should be disabled: ' . $serviceKey); } $protocolKeys = [ @@ -1506,7 +1507,7 @@ class ProjectsConsoleClientTest extends Scope 'protocolStatusForWebsocket', ]; foreach ($protocolKeys as $protocolKey) { - $this->assertFalse($response['body'][$protocolKey], 'Protocol should be disabled: '.$protocolKey); + $this->assertFalse($response['body'][$protocolKey], 'Protocol should be disabled: ' . $protocolKey); } /** @@ -1530,14 +1531,14 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function test_get_project_usage(): void + public function testGetProjectUsage(): void { $this->markTestIncomplete( 'This test is failing right now due to functions collection.' ); } - public function test_update_project(): void + public function testUpdateProject(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -1560,7 +1561,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -1569,7 +1570,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1603,19 +1604,19 @@ class ProjectsConsoleClientTest extends Scope } #[Group('smtpAndTemplates')] - public function test_update_project_smtp(): void + public function testUpdateProjectSMTP(): void { $data = $this->setupProjectData(); $id = $data['projectId']; - $smtpHost = System::getEnv('_APP_SMTP_HOST', 'maildev'); - $smtpPort = intval(System::getEnv('_APP_SMTP_PORT', '1025')); + $smtpHost = System::getEnv('_APP_SMTP_HOST', "maildev"); + $smtpPort = intval(System::getEnv('_APP_SMTP_PORT', "1025")); $smtpUsername = System::getEnv('_APP_SMTP_USERNAME', 'user'); $smtpPassword = System::getEnv('_APP_SMTP_PASSWORD', 'password'); /** * Test for SUCCESS: Valid Credentials */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/smtp', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1641,7 +1642,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('', $response['body']['smtpSecure']); // Check the project - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1661,7 +1662,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE: Invalid Credentials */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/smtp', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1681,10 +1682,10 @@ class ProjectsConsoleClientTest extends Scope } #[Group('smtpAndTemplates')] - public function test_create_project_smtp_tests(): void + public function testCreateProjectSMTPTests(): void { - $smtpHost = System::getEnv('_APP_SMTP_HOST', 'maildev'); - $smtpPort = intval(System::getEnv('_APP_SMTP_PORT', '1025')); + $smtpHost = System::getEnv('_APP_SMTP_HOST', "maildev"); + $smtpPort = intval(System::getEnv('_APP_SMTP_PORT', "1025")); $smtpUsername = System::getEnv('_APP_SMTP_USERNAME', 'user'); $smtpPassword = System::getEnv('_APP_SMTP_PASSWORD', 'password'); @@ -1709,13 +1710,13 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/smtp/tests', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1748,7 +1749,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsStringIgnoringCase('251 Little Falls Drive', $email1['html']); $this->assertEquals('custommailer@appwrite.io', $email2['from'][0]['address']); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/smtp/tests', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1764,7 +1765,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/smtp/tests', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -1782,13 +1783,13 @@ class ProjectsConsoleClientTest extends Scope } #[Group('smtpAndTemplates')] - public function test_update_templates(): void + public function testUpdateTemplates(): void { $data = $this->setupProjectData(); $id = $data['projectId']; /** Get Default Email Template */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/templates/email/verification/en-us', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/email/verification/en-us', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1804,10 +1805,10 @@ class ProjectsConsoleClientTest extends Scope $projectWithoutSmtp = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'Project Without SMTP', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectWithoutSmtp.'/templates/email/verification/en-us', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectWithoutSmtp . '/templates/email/verification/en-us', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1825,7 +1826,7 @@ class ProjectsConsoleClientTest extends Scope $smtpPort = 1025; $smtpUsername = 'user'; $smtpPassword = 'password'; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/smtp', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1841,7 +1842,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); /** Update Email template */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/templates/email/verification/en-us', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/templates/email/verification/en-us', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1861,7 +1862,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('Please verify your email {{url}}', $response['body']['message']); /** Get Updated Email Template */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/templates/email/verification/en-us', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/email/verification/en-us', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1877,7 +1878,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('smtpAndTemplates')] - public function test_session_alert_locale_fallback(): void + public function testSessionAlertLocaleFallback(): void { $smtpHost = 'maildev'; $smtpPort = 1025; @@ -1910,7 +1911,7 @@ class ProjectsConsoleClientTest extends Scope $projectId = $project['body']['$id']; /** Configure custom SMTP pointing to maildev */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/smtp', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/smtp', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1931,7 +1932,7 @@ class ProjectsConsoleClientTest extends Scope * default locale (en), which is the same slot used as the system-wide * fallback when a session's locale has no dedicated template. */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/templates/email', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/templates/email', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1950,7 +1951,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('fallback@appwrite.io', $response['body']['senderEmail']); /** Set custom sessionAlert template for Slovak locale */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/templates/email', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/templates/email', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1969,7 +1970,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('sk@appwrite.io', $response['body']['senderEmail']); /** Enable session alerts */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/auth/session-alerts', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/auth/session-alerts', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -1979,7 +1980,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); /** Verify alerts are enabled */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -1988,7 +1989,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertTrue($response['body']['authSessionAlerts']); /** Create user (email + password) in the project */ - $userEmail = 'session-alert-'.uniqid().'@appwrite.io'; + $userEmail = 'session-alert-' . uniqid() . '@appwrite.io'; $password = 'password'; $response = $this->client->call(Client::METHOD_POST, '/account', [ 'origin' => 'http://localhost', @@ -2082,27 +2083,27 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString('Slovak sign-in alert body', $lastEmail['html']); /** Cleanup — delete the project */ - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); /** Cleanup — delete the team */ - $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); } - public function test_update_project_auth_duration(): void + public function testUpdateProjectAuthDuration(): void { $data = $this->setupProjectData(); $id = $data['projectId']; // Check defaults - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2114,7 +2115,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/duration', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2138,7 +2139,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $projectId, ], $this->getHeaders()), [ 'userId' => 'unique()', - 'email' => 'test'.rand(0, 9999).'@example.com', + 'email' => 'test' . rand(0, 9999) . '@example.com', 'password' => 'password', 'name' => 'Test User', ]); @@ -2182,7 +2183,7 @@ class ProjectsConsoleClientTest extends Scope }, timeoutMs: 15 * 1000); // Set session duration to 10min - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/duration', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2203,7 +2204,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(401, $response['headers']['status-code']); // Return project back to normal - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/duration', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2215,7 +2216,7 @@ class ProjectsConsoleClientTest extends Scope $projectId = $response['body']['$id']; // Check project is back to normal - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2225,7 +2226,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(TOKEN_EXPIRATION_LOGIN_LONG, $response['body']['authDuration']); // 1 Year } - public function test_update_project_invalidate_sessions(): void + public function testUpdateProjectInvalidateSessions(): void { // Create a team for the test project $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -2247,14 +2248,14 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Session Invalidation Test Project', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; // Check defaults - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2263,7 +2264,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertTrue($response['body']['authInvalidateSessions']); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/session-invalidation', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/session-invalidation', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2272,7 +2273,7 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertFalse($response['body']['authInvalidateSessions']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2281,7 +2282,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertFalse($response['body']['authInvalidateSessions']); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/session-invalidation', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/session-invalidation', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2290,7 +2291,7 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertTrue($response['body']['authInvalidateSessions']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '1.9.4', @@ -2300,7 +2301,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertTrue($response['body']['authInvalidateSessions']); } - public function test_update_project_o_auth(): void + public function testUpdateProjectOAuth(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -2323,33 +2324,33 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; - $providers = require __DIR__.'/../../../../app/config/oAuthProviders.php'; + $providers = require(__DIR__ . '/../../../../app/config/oAuthProviders.php'); /** * Test for SUCCESS */ foreach ($providers as $key => $provider) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ 'provider' => $key, - 'appId' => 'AppId-'.ucfirst($key), - 'secret' => 'Secret-'.ucfirst($key), + 'appId' => 'AppId-' . ucfirst($key), + 'secret' => 'Secret-' . ucfirst($key), ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); } - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -2363,7 +2364,7 @@ class ProjectsConsoleClientTest extends Scope $asserted = false; foreach ($response['body']['oAuthProviders'] as $responseProvider) { if ($responseProvider['key'] === $key) { - $this->assertEquals('AppId-'.ucfirst($key), $responseProvider['appId']); + $this->assertEquals('AppId-' . ucfirst($key), $responseProvider['appId']); $this->assertEmpty($responseProvider['secret']); $this->assertFalse($responseProvider['enabled']); $asserted = true; @@ -2377,13 +2378,13 @@ class ProjectsConsoleClientTest extends Scope // Enable providers $i = 0; foreach ($providers as $key => $provider) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ 'provider' => $key, - 'enabled' => $i === 0 ? false : true, // On first provider, test enabled=false + 'enabled' => $i === 0 ? false : true // On first provider, test enabled=false ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -2392,7 +2393,7 @@ class ProjectsConsoleClientTest extends Scope $i++; } - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -2422,7 +2423,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -2435,7 +2436,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function test_update_project_auth_status(): void + public function testUpdateProjectAuthStatus(): void { // Create a team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -2458,14 +2459,14 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $response['headers']['status-code']); $id = $response['body']['$id']; - $auth = require __DIR__.'/../../../../app/config/auth.php'; - $originalEmail = uniqid().'user@localhost.test'; + $auth = require(__DIR__ . '/../../../../app/config/auth.php'); + $originalEmail = uniqid() . 'user@localhost.test'; $originalPassword = 'password'; $originalName = 'User Name'; @@ -2489,13 +2490,13 @@ class ProjectsConsoleClientTest extends Scope 'password' => $originalPassword, ]); - $session = $response['cookies']['a_session_'.$id]; + $session = $response['cookies']['a_session_' . $id]; /** * Test for SUCCESS */ foreach ($auth as $index => $method) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/'.$index, array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/' . $index, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2506,7 +2507,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -2514,10 +2515,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['auth'.ucfirst($method['key'])]); + $this->assertEquals(false, $response['body']['auth' . ucfirst($method['key'])]); } - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; $password = 'password'; $name = 'User Name'; @@ -2540,25 +2541,25 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_'.$id.'='.$session, + 'cookie' => 'a_session_' . $id . '=' . $session, ]), [ 'teamId' => ID::unique(), - 'name' => 'Arsenal', + 'name' => 'Arsenal' ]); $this->assertEquals(201, $response['headers']['status-code']); $teamUid = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamUid.'/memberships', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_'.$id.'='.$session, + 'cookie' => 'a_session_' . $id . '=' . $session, ]), [ 'email' => $email, 'name' => 'Friend User', 'roles' => ['admin', 'editor'], - 'url' => 'http://localhost:5000/join-us#title', + 'url' => 'http://localhost:5000/join-us#title' ]); $this->assertEquals($response['headers']['status-code'], 501); @@ -2566,7 +2567,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/jwt', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_'.$id.'='.$session, + 'cookie' => 'a_session_' . $id . '=' . $session, ])); $this->assertEquals($response['headers']['status-code'], 501); @@ -2593,7 +2594,7 @@ class ProjectsConsoleClientTest extends Scope // Cleanup foreach ($auth as $index => $method) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/'.$index, array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/' . $index, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2603,7 +2604,7 @@ class ProjectsConsoleClientTest extends Scope } } - public function test_update_project_auth_limit(): void + public function testUpdateProjectAuthLimit(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -2611,7 +2612,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/limit', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/limit', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2622,7 +2623,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; $password = 'password'; $name = 'User Name'; @@ -2654,10 +2655,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $team['headers']['status-code']); $teamId = $team['body']['$id']; - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; // Creating A User Using Team membership - $response = $this->client->call(Client::METHOD_POST, '/teams/'.$teamId.'/memberships', array_merge($this->getHeaders(), [ + $response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamId . '/memberships', array_merge($this->getHeaders(), [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $id, @@ -2670,7 +2671,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ 'origin' => 'http://localhost', @@ -2686,10 +2687,11 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(Exception::USER_COUNT_EXCEEDED, $response['body']['type']); $this->assertEquals(400, $response['headers']['status-code']); + /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/limit', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/limit', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2700,7 +2702,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ 'origin' => 'http://localhost', @@ -2716,18 +2718,18 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($response['headers']['status-code'], 201); } - public function test_update_project_auth_sessions_limit(): void + public function testUpdateProjectAuthSessionsLimit(): void { $id = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testUpdateProjectAuthSessionsLimit', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/max-sessions', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2739,7 +2741,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertNotEmpty($response['body']['$id']); $this->assertEquals(1, $response['body']['authSessionsLimit']); - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; $password = 'password'; $name = 'User Name'; @@ -2777,7 +2779,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $latestSessionId = $response['body']['$id']; - $sessionCookie = 'a_session_'.$id.'='.($response['cookies']['a_session_'.$id] ?? ''); + $sessionCookie = 'a_session_' . $id . '=' . ($response['cookies']['a_session_' . $id] ?? ''); // Small delay for shutdown hook to complete \usleep(500_000); @@ -2799,7 +2801,7 @@ class ProjectsConsoleClientTest extends Scope /** * Reset Limit */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/max-sessions', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2810,7 +2812,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); } - public function test_update_project_auth_password_history(): void + public function testUpdateProjectAuthPasswordHistory(): void { $data = $this->setupProjectWithAuthLimit(); $id = $data['projectId']; @@ -2818,7 +2820,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for Success */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-history', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2829,7 +2831,8 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['authPasswordHistory']); - $email = uniqid().'user@localhost.test'; + + $email = uniqid() . 'user@localhost.test'; $password = 'password'; $name = 'User Name'; @@ -2861,13 +2864,13 @@ class ProjectsConsoleClientTest extends Scope 'password' => $password, ]); $this->assertEquals(201, $session['headers']['status-code']); - $session = $session['cookies']['a_session_'.$id]; + $session = $session['cookies']['a_session_' . $id]; $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_'.$id.'='.$session, + 'cookie' => 'a_session_' . $id . '=' . $session, ]), [ 'oldPassword' => $password, 'password' => $password, @@ -2881,16 +2884,17 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]); - $response = $this->client->call(Client::METHOD_PATCH, '/users/'.$userId.'/password', $headers, [ + $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/password', $headers, [ 'password' => $password, ]); $this->assertEquals(400, $response['headers']['status-code']); + /** * Reset */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-history', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -2902,7 +2906,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(0, $response['body']['authPasswordHistory']); } - public function test_update_project_auth_password_strength(): void + public function testUpdateProjectAuthPasswordStrength(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -2947,7 +2951,7 @@ class ProjectsConsoleClientTest extends Scope $weakPassword = 'password123!'; $validPassword = 'Password123!'; - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ 'origin' => 'http://localhost', @@ -2955,7 +2959,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]), [ 'userId' => ID::unique(), - 'email' => uniqid().'weak-account@localhost.test', + 'email' => uniqid() . 'weak-account@localhost.test', 'password' => $weakPassword, 'name' => 'Weak Account', ]); @@ -2968,7 +2972,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ]), [ 'userId' => ID::unique(), - 'email' => uniqid().'weak-user@localhost.test', + 'email' => uniqid() . 'weak-user@localhost.test', 'password' => $weakPassword, 'name' => 'Weak User', ]); @@ -2999,13 +3003,13 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(201, $session['headers']['status-code']); - $session = $session['cookies']['a_session_'.$id]; + $session = $session['cookies']['a_session_' . $id]; $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'cookie' => 'a_session_'.$id.'='.$session, + 'cookie' => 'a_session_' . $id . '=' . $session, ]), [ 'oldPassword' => $validPassword, 'password' => $weakPassword, @@ -3047,7 +3051,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]); - $response = $this->client->call(Client::METHOD_PATCH, '/users/'.$userId.'/password', $headers, [ + $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/password', $headers, [ 'password' => $weakPassword, ]); @@ -3075,7 +3079,7 @@ class ProjectsConsoleClientTest extends Scope #[Group('smtpAndTemplates')] #[Group('projectsCRUD')] - public function test_update_mock_numbers(): void + public function testUpdateMockNumbers(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -3085,7 +3089,7 @@ class ProjectsConsoleClientTest extends Scope */ /** Trying to pass an empty body to the endpoint */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3095,21 +3099,21 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('Param "numbers" is not optional.', $response['body']['message']); /** Trying to pass body with incorrect structure */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ 'numbers' => [ 'phone' => '+1655513432', - 'otp' => '123456', - ], + 'otp' => '123456' + ] ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid payload structure. Please check the "phone" and "otp" fields', $response['body']['message']); /** Trying to pass an OTP longer than 6 characters*/ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3117,15 +3121,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '12345678', - ], - ], + 'otp' => '12345678' + ] + ] ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid OTP. Please make sure the OTP is a 6 digit number', $response['body']['message']); /** Trying to pass an OTP shorter than 6 characters*/ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3133,15 +3137,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '123', - ], - ], + 'otp' => '123' + ] + ] ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid OTP. Please make sure the OTP is a 6 digit number', $response['body']['message']); /** Trying to pass an OTP with non numeric characters */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3149,15 +3153,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '123re2', - ], - ], + 'otp' => '123re2' + ] + ] ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Invalid OTP. Please make sure the OTP is a 6 digit number', $response['body']['message']); /** Trying to pass an invalid phone number */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3165,15 +3169,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '1655234', - 'otp' => '123456', - ], - ], + 'otp' => '123456' + ] + ] ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Phone number must start with a \'+\' can have a maximum of fifteen digits.', $response['body']['message']); /** Trying to pass a number longer than 15 digits */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3181,15 +3185,15 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1234567890987654', - 'otp' => '123456', - ], - ], + 'otp' => '123456' + ] + ] ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `numbers` param: Value must a valid array no longer than 10 items and Phone number must start with a \'+\' can have a maximum of fifteen digits.', $response['body']['message']); /** Trying to pass duplicate numbers */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3197,13 +3201,13 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '123456', + 'otp' => '123456' ], [ 'phone' => '+1655513432', - 'otp' => '123456', - ], - ], + 'otp' => '123456' + ] + ] ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Duplicate phone numbers are not allowed.', $response['body']['message']); @@ -3212,17 +3216,17 @@ class ProjectsConsoleClientTest extends Scope for ($i = 0; $i < 11; $i++) { $numbers[] = [ 'phone' => '+1655513432', - 'otp' => '123456', + 'otp' => '123456' ]; } /** Trying to pass more than 10 values */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ - 'numbers' => $numbers, + 'numbers' => $numbers ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -3231,16 +3235,16 @@ class ProjectsConsoleClientTest extends Scope /** * Test for success */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', ], $this->getHeaders()), [ - 'numbers' => [], + 'numbers' => [] ]); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/mock-numbers', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/mock-numbers', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -3248,9 +3252,9 @@ class ProjectsConsoleClientTest extends Scope 'numbers' => [ [ 'phone' => '+1655513432', - 'otp' => '123456', - ], - ], + 'otp' => '123456' + ] + ] ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -3287,7 +3291,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); } - public function test_update_project_auth_password_dictionary(): void + public function testUpdateProjectAuthPasswordDictionary(): void { $data = $this->setupProjectWithAuthLimit(); $id = $data['projectId']; @@ -3308,7 +3312,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]), [ 'userId' => ID::unique(), - 'email' => uniqid().'user@localhost.test', + 'email' => uniqid() . 'user@localhost.test', 'password' => $password, 'name' => $name, ]); @@ -3324,7 +3328,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ]), [ 'userId' => ID::unique(), - 'email' => uniqid().'user@localhost.test', + 'email' => uniqid() . 'user@localhost.test', 'password' => 'password', 'name' => 'Cristiano Ronaldo', ]); @@ -3333,7 +3337,7 @@ class ProjectsConsoleClientTest extends Scope /** * Enable Disctionary */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-dictionary', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-dictionary', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3353,7 +3357,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]), [ 'userId' => ID::unique(), - 'email' => uniqid().'user@localhost.test', + 'email' => uniqid() . 'user@localhost.test', 'password' => $password, 'name' => $name, ]); @@ -3369,7 +3373,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ]), [ 'userId' => ID::unique(), - 'email' => uniqid().'user@localhost.test', + 'email' => uniqid() . 'user@localhost.test', 'password' => 'password', 'name' => 'Cristiano Ronaldo', ]); @@ -3381,16 +3385,17 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]); - $response = $this->client->call(Client::METHOD_PATCH, '/users/'.$userId.'/password', $headers, [ + $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/password', $headers, [ 'password' => $password, ]); $this->assertEquals(400, $response['headers']['status-code']); + /** * Reset */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-history', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3404,7 +3409,7 @@ class ProjectsConsoleClientTest extends Scope /** * Reset */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/password-dictionary', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-dictionary', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3416,7 +3421,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(false, $response['body']['authPasswordDictionary']); } - public function test_update_disallow_personal_data(): void + public function testUpdateDisallowPersonalData(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -3424,7 +3429,7 @@ class ProjectsConsoleClientTest extends Scope /** * Enable Disallowing of Personal Data */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/personal-data', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/personal-data', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3438,7 +3443,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for failure */ - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; $password = 'password'; $name = 'username'; $userId = ID::unique(); @@ -3451,7 +3456,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $email, 'password' => $email, 'name' => $name, - 'userId' => $userId, + 'userId' => $userId ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -3466,7 +3471,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $email, 'password' => $name, 'name' => $name, - 'userId' => $userId, + 'userId' => $userId ]); $phone = '+123456789'; @@ -3479,7 +3484,7 @@ class ProjectsConsoleClientTest extends Scope 'password' => $phone, 'name' => $name, 'userId' => $userId, - 'phone' => $phone, + 'phone' => $phone ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -3487,7 +3492,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(Exception::USER_PASSWORD_PERSONAL_DATA, $response['body']['type']); /** Test for success */ - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; $password = 'password'; $name = 'username'; $userId = ID::unique(); @@ -3499,7 +3504,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $email, 'password' => $password, 'name' => $name, - 'userId' => $userId, + 'userId' => $userId ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -3510,14 +3515,14 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ]), [ // Empty password - 'email' => uniqid().'user@localhost.test', + 'email' => uniqid() . 'user@localhost.test', 'name' => 'User', 'userId' => ID::unique(), ]); $this->assertEquals(201, $response['headers']['status-code']); - $email = uniqid().'user@localhost.test'; + $email = uniqid() . 'user@localhost.test'; $userId = ID::unique(); $response = $this->client->call(Client::METHOD_POST, '/users', array_merge($this->getHeaders(), [ 'content-type' => 'application/json', @@ -3528,15 +3533,16 @@ class ProjectsConsoleClientTest extends Scope 'password' => $password, 'name' => $name, 'userId' => $userId, - 'phone' => $phone, + 'phone' => $phone ]); $this->assertEquals(201, $response['headers']['status-code']); + /** * Reset */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/auth/personal-data', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/personal-data', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.1', @@ -3548,12 +3554,12 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(false, $response['body']['authPersonalDataCheck']); } - public function test_update_project_api_status(): void + public function testUpdateProjectApiStatus(): void { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'teamId' => ID::unique(), 'name' => 'Project Test', @@ -3566,12 +3572,12 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -3585,11 +3591,11 @@ class ProjectsConsoleClientTest extends Scope */ foreach ($protocols as $key) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/api', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'api' => $key, 'status' => false, @@ -3598,16 +3604,16 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['protocolStatusFor'.ucfirst($key)]); + $this->assertEquals(false, $response['body']['protocolStatusFor' . ucfirst($key)]); } /** @@ -3615,11 +3621,11 @@ class ProjectsConsoleClientTest extends Scope */ foreach ($protocols as $key) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/api', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'api' => $key, 'status' => true, @@ -3628,25 +3634,25 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(true, $response['body']['protocolStatusFor'.ucfirst($key)]); + $this->assertEquals(true, $response['body']['protocolStatusFor' . ucfirst($key)]); } } - public function test_update_project_api_status_realtime_backwards_compat(): void + public function testUpdateProjectApiStatusRealtimeBackwardsCompat(): void { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'teamId' => ID::unique(), 'name' => 'Project Test', @@ -3658,12 +3664,12 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -3673,11 +3679,11 @@ class ProjectsConsoleClientTest extends Scope /** * Test that "realtime" gets renamed to "websocket" via request filter */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/api', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'api' => 'realtime', 'status' => false, @@ -3685,22 +3691,22 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(false, $response['body']['protocolStatusForWebsocket']); // Re-enable via old "realtime" name - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/api', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'api' => 'realtime', 'status' => true, @@ -3708,23 +3714,23 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(true, $response['body']['protocolStatusForWebsocket']); } - public function test_update_project_service_status_admin(): array + public function testUpdateProjectServiceStatusAdmin(): array { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'teamId' => ID::unique(), 'name' => 'Project Test', @@ -3736,35 +3742,35 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'projectId' => ID::unique(), 'name' => 'Project Test', 'teamId' => $team['body']['$id'], - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $project['headers']['status-code']); $this->assertNotEmpty($project['body']['$id']); $id = $project['body']['$id']; - $services = require __DIR__.'/../../../../app/config/services.php'; + $services = require(__DIR__ . '/../../../../app/config/services.php'); /** * Test for Disabled */ foreach ($services as $service) { - if (! $service['optional']) { + if (!$service['optional']) { continue; } $key = $service['key'] ?? ''; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'service' => $key, 'status' => false, @@ -3773,40 +3779,41 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['serviceStatusFor'.ucfirst($key)]); + $this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]); } /** * Admin request must succeed */ + $response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', // 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $id, - 'cookie' => 'a_session_console='.$this->getRoot()['session'], - 'x-appwrite-mode' => 'admin', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-mode' => 'admin' ])); $this->assertEquals(200, $response['headers']['status-code']); foreach ($services as $service) { - if (! $service['optional']) { + if (!$service['optional']) { continue; } $key = $service['key'] ?? ''; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service/', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', @@ -3819,28 +3826,28 @@ class ProjectsConsoleClientTest extends Scope return ['projectId' => $id]; } - public function test_update_project_service_status(): void + public function testUpdateProjectServiceStatus(): void { $data = $this->setupProjectWithServicesDisabled(); $id = $data['projectId']; - $services = require __DIR__.'/../../../../app/config/services.php'; + $services = require(__DIR__ . '/../../../../app/config/services.php'); /** * Test for Disabled */ foreach ($services as $service) { - if (! $service['optional']) { + if (!$service['optional']) { continue; } $key = $service['key'] ?? ''; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'service' => $key, 'status' => false, @@ -3849,16 +3856,16 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['serviceStatusFor'.ucfirst($key)]); + $this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]); } /** @@ -3877,7 +3884,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, ]), [ 'teamId' => ID::unique(), - 'name' => 'Arsenal', + 'name' => 'Arsenal' ]); $this->assertEquals(403, $response['headers']['status-code']); @@ -3885,7 +3892,7 @@ class ProjectsConsoleClientTest extends Scope // Cleanup foreach ($services as $service) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service/', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', @@ -3896,28 +3903,28 @@ class ProjectsConsoleClientTest extends Scope } } - public function test_update_project_service_status_server(): void + public function testUpdateProjectServiceStatusServer(): void { $data = $this->setupProjectWithServicesDisabled(); $id = $data['projectId']; - $services = require __DIR__.'/../../../../app/config/services.php'; + $services = require(__DIR__ . '/../../../../app/config/services.php'); /** * Test for Disabled */ foreach ($services as $service) { - if (! $service['optional']) { + if (!$service['optional']) { continue; } $key = $service['key'] ?? ''; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'service' => $key, 'status' => false, @@ -3926,23 +3933,23 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ])); $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body']['serviceStatusFor'.ucfirst($key)]); + $this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]); } // Create API Key - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), [ 'keyId' => ID::unique(), 'name' => 'Key Test', @@ -3961,7 +3968,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-key' => $keySecret, - 'x-sdk-name' => 'python', + 'x-sdk-name' => 'python' ])); $this->assertEquals(200, $response['headers']['status-code']); @@ -3970,19 +3977,19 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-key' => $keySecret, - 'x-sdk-name' => 'php', + 'x-sdk-name' => 'php' ]), [ 'teamId' => ID::unique(), - 'name' => 'Arsenal', + 'name' => 'Arsenal' ]); $this->assertEquals(201, $response['headers']['status-code']); /** Check that the API key has been updated */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), []); $this->assertEquals(200, $response['headers']['status-code']); @@ -3995,16 +4002,16 @@ class ProjectsConsoleClientTest extends Scope // Cleanup - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_console='.$this->getRoot()['session'], + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], ]), []); $this->assertEquals(204, $response['headers']['status-code']); foreach ($services as $service) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/service/', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.0', @@ -4015,7 +4022,7 @@ class ProjectsConsoleClientTest extends Scope } } - public function test_create_project_webhook(): void + public function testCreateProjectWebhook(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -4023,7 +4030,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), [ 'webhookId' => 'unique()', 'name' => 'Webhook Test', @@ -4050,7 +4057,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), [ 'webhookId' => 'unique()', 'name' => 'Webhook Test', @@ -4066,7 +4073,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), [ 'webhookId' => 'unique()', 'name' => 'Webhook Test', @@ -4077,7 +4084,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function test_list_project_webhook(): void + public function testListProjectWebhook(): void { $data = $this->setupProjectWithWebhook(); $id = $data['projectId']; @@ -4085,7 +4092,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); @@ -4097,16 +4104,16 @@ class ProjectsConsoleClientTest extends Scope */ } - public function test_get_project_webhook(): void + public function testGetProjectWebhook(): void { $data = $this->setupProjectWithWebhook(); $id = $data['projectId']; $webhookId = $data['webhookId']; - $response = $this->client->call(Client::METHOD_GET, '/webhooks/'.$webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/webhooks/' . $webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); @@ -4125,22 +4132,22 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/webhooks/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), []); $this->assertEquals(404, $response['headers']['status-code']); } - public function test_update_project_webhook(): void + public function testUpdateProjectWebhook(): void { $data = $this->setupProjectWithWebhook(); $id = $data['projectId']; $webhookId = $data['webhookId']; - $response = $this->client->call(Client::METHOD_PUT, '/webhooks/'.$webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/webhooks/' . $webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), [ 'name' => 'Webhook Test Update', 'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'], @@ -4162,10 +4169,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('', $response['body']['authUsername']); $this->assertEquals('', $response['body']['authPassword']); - $response = $this->client->call(Client::METHOD_GET, '/webhooks/'.$webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/webhooks/' . $webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), []); $this->assertEquals(200, $response['headers']['status-code']); @@ -4185,10 +4192,10 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PUT, '/webhooks/'.$webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/webhooks/' . $webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), [ 'name' => 'Webhook Test Update', 'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.unknown'], @@ -4198,10 +4205,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PUT, '/webhooks/'.$webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/webhooks/' . $webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), [ 'name' => 'Webhook Test Update', 'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'], @@ -4211,10 +4218,10 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_PUT, '/webhooks/'.$webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/webhooks/' . $webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), [ 'name' => 'Webhook Test Update', 'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'], @@ -4224,17 +4231,17 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function test_update_project_webhook_signature(): void + public function testUpdateProjectWebhookSignature(): void { $data = $this->setupProjectWithWebhook(); $id = $data['projectId']; $webhookId = $data['webhookId']; $signatureKey = $data['signatureKey']; - $response = $this->client->call(Client::METHOD_PATCH, '/webhooks/'.$webhookId.'/secret', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/webhooks/' . $webhookId . '/secret', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); @@ -4242,7 +4249,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertNotEquals($signatureKey, $response['body']['secret']); } - public function test_delete_project_webhook(): void + public function testDeleteProjectWebhook(): void { // Create a fresh project with webhook for deletion test $projectData = $this->setupProjectData(); @@ -4252,7 +4259,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), [ 'webhookId' => 'unique()', 'name' => 'Webhook To Delete', @@ -4266,19 +4273,19 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $webhookId = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_DELETE, '/webhooks/'.$webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/webhooks/' . $webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), []); $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/webhooks/'.$webhookId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/webhooks/' . $webhookId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), []); $this->assertEquals(404, $response['headers']['status-code']); @@ -4289,7 +4296,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_DELETE, '/webhooks/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), []); $this->assertEquals(404, $response['headers']['status-code']); @@ -4297,12 +4304,12 @@ class ProjectsConsoleClientTest extends Scope // Keys - public function test_create_project_key(): void + public function testCreateProjectKey(): void { $data = $this->setupProjectData(); $id = $data['projectId']; - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4325,7 +4332,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS without key ID */ - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4340,8 +4347,8 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS with custom ID */ - $customKeyId = \uniqid().'custom-id'; - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $customKeyId = \uniqid() . 'custom-id'; + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4356,7 +4363,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE with custom ID */ - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4370,7 +4377,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS with magic string ID */ - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4385,13 +4392,13 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, [ 'keyId' => $response['body']['$id'], - 'secret' => $response['body']['secret'], + 'secret' => $response['body']['secret'] ]); /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4403,14 +4410,15 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function test_list_project_key(): void + + public function testListProjectKey(): void { $data = $this->setupProjectWithKey(); $id = $data['projectId']; /** Create a second key with an expiry for query testing */ $expireDate = DateTime::addSeconds(new \DateTime(), 3600); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4424,7 +4432,7 @@ class ProjectsConsoleClientTest extends Scope $key2Id = $response['body']['$id']; /** List all keys (no queries) — count depends on how many test methods ran before this in the same worker */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4435,13 +4443,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertCount($totalKeys, $response['body']['keys']); /** List keys with limit */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::limit(1)->toString(), - ], + ] ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -4449,13 +4457,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($totalKeys, $response['body']['total']); /** List keys with offset */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::offset(1)->toString(), - ], + ] ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -4463,13 +4471,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($totalKeys, $response['body']['total']); /** List keys with cursor after */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::cursorAfter(new Document(['$id' => $data['keyId']]))->toString(), - ], + ] ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -4477,26 +4485,26 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($totalKeys, $response['body']['total']); /** List keys filtering by expire (lessThan now — should match none) */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::lessThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString(), - ], + ] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(0, $response['body']['total']); /** List keys filtering by expire (greaterThan now — should match the key with expiry) */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::greaterThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString(), - ], + ] ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -4508,37 +4516,38 @@ class ProjectsConsoleClientTest extends Scope */ /** Test invalid query attribute */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::equal('secret', ['test'])->toString(), - ], + ] ]); $this->assertEquals(400, $response['headers']['status-code']); /** Test invalid cursor */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ Query::cursorAfter(new Document(['$id' => 'invalid']))->toString(), - ], + ] ]); $this->assertEquals(400, $response['headers']['status-code']); } - public function test_get_project_key(): void + + public function testGetProjectKey(): void { $data = $this->setupProjectWithKey(); $id = $data['projectId']; $keyId = $data['keyId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4559,7 +4568,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/error', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4567,7 +4576,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function test_validate_project_key(): void + public function testValidateProjectKey(): void { $data = $this->setupProjectData(); $projectId = $data['projectId']; @@ -4578,7 +4587,7 @@ class ProjectsConsoleClientTest extends Scope */ // Expiring key - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4591,7 +4600,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/users', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'], + 'x-appwrite-key' => $response['body']['secret'] ], [ 'userId' => ID::unique(), ]); @@ -4599,7 +4608,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); // No expiry - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4612,7 +4621,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/health', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'], + 'x-appwrite-key' => $response['body']['secret'] ], []); $this->assertEquals(200, $response['headers']['status-code']); @@ -4622,7 +4631,7 @@ class ProjectsConsoleClientTest extends Scope */ // Expired key - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4635,7 +4644,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/health', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'], + 'x-appwrite-key' => $response['body']['secret'] ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -4658,13 +4667,13 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, "/storage/buckets/{$bucketId}/files", [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => 'invalid-key', + 'x-appwrite-key' => 'invalid-key' ]); $this->assertEquals(401, $response['headers']['status-code']); // Invalid scopes - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4677,7 +4686,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/users', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'], + 'x-appwrite-key' => $response['body']['secret'] ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -4691,14 +4700,14 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Project Test 2', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $response['headers']['status-code']); $project2Id = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$project2Id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4711,19 +4720,20 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/health', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $response['body']['secret'], + 'x-appwrite-key' => $response['body']['secret'] ]); $this->assertEquals(401, $response['headers']['status-code']); } - public function test_update_project_key(): void + + public function testUpdateProjectKey(): void { $data = $this->setupProjectWithKey(); $id = $data['projectId']; $keyId = $data['keyId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/keys/' . $keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4746,7 +4756,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertArrayHasKey('accessedAt', $response['body']); $this->assertEmpty($response['body']['accessedAt']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4768,7 +4778,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/keys/' . $keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -4779,13 +4789,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function test_delete_project_key(): void + public function testDeleteProjectKey(): void { // Create a fresh key for deletion testing (cannot use cached key) $projectData = $this->setupProjectData(); $id = $projectData['projectId']; - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4797,7 +4807,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $keyId = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4805,7 +4815,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4815,7 +4825,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/error', array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4823,7 +4833,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function test_create_project_key_outdated(): void + public function testCreateProjectKeyOutdated(): void { $data = $this->setupProjectData(); $id = $data['projectId']; @@ -4832,13 +4842,13 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'projectId' => $id, + 'projectId' => $id ]); $this->assertEquals(201, $response['headers']['status-code']); $this->assertContains('users.read', $response['body']['scopes']); $this->assertNotEmpty($response['body']['secret']); - $this->assertStringStartsNotWith(API_KEY_STANDARD.'_', $response['body']['secret']); + $this->assertStringStartsNotWith(API_KEY_STANDARD . '_', $response['body']['secret']); $keyId = $response['body']['$id']; $secret = $response['body']['secret']; @@ -4846,12 +4856,12 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_GET, '/users', [ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-key' => $secret, + 'x-appwrite-key' => $secret ], []); $this->assertEquals(200, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/keys/'.$keyId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -4862,13 +4872,13 @@ class ProjectsConsoleClientTest extends Scope // JWT Keys - public function test_jwt_key(): void + public function testJWTKey(): void { $data = $this->setupProjectData(); $id = $data['projectId']; // Create JWT key - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/jwts', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/jwts', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.2', @@ -4917,12 +4927,12 @@ class ProjectsConsoleClientTest extends Scope // Platforms - public function test_create_project_platform(): void + public function testCreateProjectPlatform(): void { $data = $this->setupProjectData(); $id = $data['projectId']; - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4942,7 +4952,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformWebId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4962,7 +4972,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformFultteriOSId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -4982,7 +4992,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformFultterAndroidId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5002,7 +5012,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformFultterWebId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5022,7 +5032,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformAppleIosId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5042,7 +5052,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformAppleMacOsId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5062,7 +5072,7 @@ class ProjectsConsoleClientTest extends Scope $data = array_merge($data, ['platformAppleWatchOsId' => $response['body']['$id']]); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5085,7 +5095,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5098,13 +5108,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); } - public function test_list_project_platform(): void + public function testListProjectPlatform(): void { $data = $this->setupProjectWithPlatform(); $id = $data['projectId']; $this->assertEventually(function () use ($id) { - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5121,14 +5131,14 @@ class ProjectsConsoleClientTest extends Scope */ } - public function test_get_project_platform(): void + public function testGetProjectPlatform(): void { $data = $this->setupProjectWithPlatform(); $id = $data['projectId']; $platformWebId = $data['platformWebId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformWebId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5145,7 +5155,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultteriOSId = $data['platformFultteriOSId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultteriOSId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5162,7 +5172,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterAndroidId = $data['platformFultterAndroidId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultterAndroidId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5179,7 +5189,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterWebId = $data['platformFultterWebId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultterWebId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5196,7 +5206,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleIosId = $data['platformAppleIosId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleIosId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5213,7 +5223,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleMacOsId = $data['platformAppleMacOsId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleMacOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5230,7 +5240,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleWatchOsId = $data['platformAppleWatchOsId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleWatchOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5247,7 +5257,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleTvOsId = $data['platformAppleTvOsId']; - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleTvOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5265,7 +5275,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/error', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5274,14 +5284,14 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function test_update_project_platform(): void + public function testUpdateProjectPlatform(): void { $data = $this->setupProjectWithPlatform(); $id = $data['projectId']; $platformWebId = $data['platformWebId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformWebId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5301,7 +5311,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultteriOSId = $data['platformFultteriOSId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformFultteriOSId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5321,7 +5331,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterAndroidId = $data['platformFultterAndroidId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformFultterAndroidId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5341,7 +5351,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterWebId = $data['platformFultterWebId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformFultterWebId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5361,7 +5371,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleIosId = $data['platformAppleIosId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformAppleIosId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5381,7 +5391,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleMacOsId = $data['platformAppleMacOsId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformAppleMacOsId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5401,7 +5411,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleWatchOsId = $data['platformAppleWatchOsId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformAppleWatchOsId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5421,7 +5431,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleTvOsId = $data['platformAppleTvOsId']; - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/'.$platformAppleTvOsId, array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5442,7 +5452,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$id.'/platforms/error', array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5454,14 +5464,14 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function test_delete_project_platform(): void + public function testDeleteProjectPlatform(): void { // Create a fresh project with platforms for deletion testing (cannot use cached platforms) $projectData = $this->setupProjectData(); $id = $projectData['projectId']; // Create web platform - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5474,7 +5484,7 @@ class ProjectsConsoleClientTest extends Scope $platformWebId = $response['body']['$id']; // Create flutter-ios platform - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5487,7 +5497,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultteriOSId = $response['body']['$id']; // Create flutter-android platform - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5500,7 +5510,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterAndroidId = $response['body']['$id']; // Create flutter-web platform - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5513,7 +5523,7 @@ class ProjectsConsoleClientTest extends Scope $platformFultterWebId = $response['body']['$id']; // Create apple-ios platform - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5526,7 +5536,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleIosId = $response['body']['$id']; // Create apple-macos platform - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5539,7 +5549,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleMacOsId = $response['body']['$id']; // Create apple-watchos platform - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5552,7 +5562,7 @@ class ProjectsConsoleClientTest extends Scope $platformAppleWatchOsId = $response['body']['$id']; // Create apple-tvos platform - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/platforms', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5564,7 +5574,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); $platformAppleTvOsId = $response['body']['$id']; - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformWebId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5573,7 +5583,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformWebId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5581,7 +5591,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformFultteriOSId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5590,7 +5600,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultteriOSId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5598,7 +5608,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformFultterAndroidId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5607,7 +5617,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultterAndroidId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5615,7 +5625,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformFultterWebId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5624,7 +5634,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformFultterWebId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5632,7 +5642,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformAppleIosId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5641,7 +5651,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleIosId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5649,7 +5659,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformAppleMacOsId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5658,7 +5668,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleMacOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5666,7 +5676,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformAppleWatchOsId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5675,7 +5685,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleWatchOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5683,7 +5693,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$id.'/platforms/'.$platformAppleTvOsId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5692,7 +5702,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); $this->assertEmpty($response['body']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$id.'/platforms/'.$platformAppleTvOsId, array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.8.0', @@ -5706,13 +5716,13 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_DELETE, '/webhooks/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $id, - 'x-appwrite-mode' => 'admin', + 'x-appwrite-mode' => 'admin' ], $this->getHeaders()), []); $this->assertEquals(404, $response['headers']['status-code']); } - public function test_delete_project(): array + public function testDeleteProject(): array { $data = []; @@ -5739,7 +5749,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Amazing Project', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -5750,14 +5760,14 @@ class ProjectsConsoleClientTest extends Scope $projectId = $project['body']['$id']; // Ensure I can get both team and project - $team = $this->client->call(Client::METHOD_GET, '/teams/'.$teamId, array_merge([ + $team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(200, $team['headers']['status-code']); - $project = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ + $project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -5766,7 +5776,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $project['headers']['status-code']); // Delete Project - $project = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ + $project = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -5774,14 +5784,14 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $project['headers']['status-code']); // Ensure I can get team but not a project - $team = $this->client->call(Client::METHOD_GET, '/teams/'.$teamId, array_merge([ + $team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(200, $team['headers']['status-code']); - $project = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId, array_merge([ + $project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', @@ -5792,7 +5802,7 @@ class ProjectsConsoleClientTest extends Scope return $data; } - public function test_delete_shared_project(): void + public function testDeleteSharedProject(): void { $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', @@ -5813,7 +5823,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Amazing Project 1', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $project2 = $this->client->call(Client::METHOD_POST, '/projects', array_merge([ @@ -5824,14 +5834,14 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Amazing Project 2', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $project1Id = $project1['body']['$id']; $project2Id = $project2['body']['$id']; // Create user in each project - $key1 = $this->client->call(Client::METHOD_POST, '/projects/'.$project1Id.'/keys', array_merge([ + $key1 = $this->client->call(Client::METHOD_POST, '/projects/' . $project1Id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -5852,7 +5862,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $user1['headers']['status-code']); - $key2 = $this->client->call(Client::METHOD_POST, '/projects/'.$project2Id.'/keys', array_merge([ + $key2 = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -5874,7 +5884,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $user2['headers']['status-code']); // Delete project 1 - $project1 = $this->client->call(Client::METHOD_DELETE, '/projects/'.$project1Id, array_merge([ + $project1 = $this->client->call(Client::METHOD_DELETE, '/projects/' . $project1Id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -5883,7 +5893,7 @@ class ProjectsConsoleClientTest extends Scope // Ensure project 2 user is still there $this->assertEventually(function () use ($user2, $project2Id, $key2) { - $response = $this->client->call(Client::METHOD_GET, '/users/'.$user2['body']['$id'], [ + $response = $this->client->call(Client::METHOD_GET, '/users/' . $user2['body']['$id'], [ 'content-type' => 'application/json', 'x-appwrite-project' => $project2Id, 'x-appwrite-key' => $key2['body']['secret'], @@ -5899,13 +5909,13 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-key' => $key2['body']['secret'], ], [ 'userId' => ID::unique(), - 'email' => 'test3@appwrite.io', + 'email' => 'test3@appwrite.io' ]); $this->assertEquals(201, $user3['headers']['status-code']); } - public function test_create_project_variable(): void + public function testCreateProjectVariable(): void { $data = $this->setupProjectData(); @@ -5920,7 +5930,7 @@ class ProjectsConsoleClientTest extends Scope 'variableId' => 'unique()', 'key' => 'APP_TEST_CREATE', 'value' => 'TESTINGVALUE', - 'secret' => false, + 'secret' => false ]); $this->assertEquals(201, $variable['headers']['status-code']); @@ -5937,7 +5947,7 @@ class ProjectsConsoleClientTest extends Scope 'variableId' => 'unique()', 'key' => 'APP_TEST_CREATE_1', 'value' => 'TESTINGVALUE_1', - 'secret' => true, + 'secret' => true ]); $this->assertEquals(201, $variable['headers']['status-code']); @@ -5955,7 +5965,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'variableId' => 'unique()', 'key' => 'APP_TEST_CREATE', - 'value' => 'ANOTHERTESTINGVALUE', + 'value' => 'ANOTHERTESTINGVALUE' ]); $this->assertEquals(409, $variable['headers']['status-code']); @@ -5967,8 +5977,8 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'variableId' => 'unique()', - 'key' => str_repeat('A', 256), - 'value' => 'TESTINGVALUE', + 'key' => str_repeat("A", 256), + 'value' => 'TESTINGVALUE' ]); $this->assertEquals(400, $variable['headers']['status-code']); @@ -5981,19 +5991,20 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'variableId' => 'unique()', 'key' => 'LONGKEY', - 'value' => str_repeat('#', 8193), + 'value' => str_repeat("#", 8193), ]); $this->assertEquals(400, $variable['headers']['status-code']); } - public function test_list_variables(): void + public function testListVariables(): void { $data = $this->setupProjectWithVariable(); /** * Test for SUCCESS */ + $response = $this->client->call(Client::METHOD_GET, '/project/variables', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], @@ -6005,37 +6016,38 @@ class ProjectsConsoleClientTest extends Scope $this->assertGreaterThanOrEqual(2, $response['body']['total']); } - public function test_get_variable(): void + public function testGetVariable(): void { $data = $this->setupProjectWithVariable(); /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/project/variables/'.$data['variableId'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('APP_TEST', $response['body']['key']); - $this->assertEquals('TESTINGVALUE', $response['body']['value']); + $this->assertEquals("APP_TEST", $response['body']['key']); + $this->assertEquals("TESTINGVALUE", $response['body']['value']); - $response = $this->client->call(Client::METHOD_GET, '/project/variables/'.$data['secretVariableId'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['secretVariableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('APP_TEST_1', $response['body']['key']); + $this->assertEquals("APP_TEST_1", $response['body']['key']); $this->assertEmpty($response['body']['value']); $this->assertTrue($response['body']['secret']); /** * Test for FAILURE */ + $response = $this->client->call(Client::METHOD_GET, '/project/variables/NON_EXISTING_VARIABLE', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], @@ -6045,59 +6057,60 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - public function test_update_variable(): void + public function testUpdateVariable(): void { $data = $this->setupProjectWithVariable(); /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ + + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => 'APP_TEST_UPDATE', - 'value' => 'TESTINGVALUEUPDATED', + 'value' => 'TESTINGVALUEUPDATED' ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('APP_TEST_UPDATE', $response['body']['key']); - $this->assertEquals('TESTINGVALUEUPDATED', $response['body']['value']); + $this->assertEquals("APP_TEST_UPDATE", $response['body']['key']); + $this->assertEquals("TESTINGVALUEUPDATED", $response['body']['value']); - $variable = $this->client->call(Client::METHOD_GET, '/project/variables/'.$data['variableId'], array_merge([ + $variable = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); $this->assertEquals(200, $variable['headers']['status-code']); - $this->assertEquals('APP_TEST_UPDATE', $variable['body']['key']); - $this->assertEquals('TESTINGVALUEUPDATED', $variable['body']['value']); + $this->assertEquals("APP_TEST_UPDATE", $variable['body']['key']); + $this->assertEquals("TESTINGVALUEUPDATED", $variable['body']['value']); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['secretVariableId'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['secretVariableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => 'APP_TEST_UPDATE_1', - 'value' => 'TESTINGVALUEUPDATED_1', + 'value' => 'TESTINGVALUEUPDATED_1' ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals('APP_TEST_UPDATE_1', $response['body']['key']); + $this->assertEquals("APP_TEST_UPDATE_1", $response['body']['key']); $this->assertEmpty($response['body']['value']); - $variable = $this->client->call(Client::METHOD_GET, '/project/variables/'.$data['secretVariableId'], array_merge([ + $variable = $this->client->call(Client::METHOD_GET, '/project/variables/' . $data['secretVariableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders())); $this->assertEquals(200, $variable['headers']['status-code']); - $this->assertEquals('APP_TEST_UPDATE_1', $variable['body']['key']); + $this->assertEquals("APP_TEST_UPDATE_1", $variable['body']['key']); $this->assertEmpty($variable['body']['value']); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['secretVariableId'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['secretVariableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', @@ -6119,15 +6132,15 @@ class ProjectsConsoleClientTest extends Scope $this->assertGreaterThanOrEqual(2, count($response['body']['variables'])); // Verify our updated variables exist (may not be at specific positions) $variableKeys = array_column($response['body']['variables'], 'key'); - $this->assertContains('APP_TEST_UPDATE', $variableKeys); - $this->assertContains('APP_TEST_UPDATE_1', $variableKeys); + $this->assertContains("APP_TEST_UPDATE", $variableKeys); + $this->assertContains("APP_TEST_UPDATE_1", $variableKeys); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'value' => 'TESTINGVALUEUPDATED_2', + 'value' => 'TESTINGVALUEUPDATED_2' ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -6137,7 +6150,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', @@ -6145,26 +6158,26 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - $longKey = str_repeat('A', 256); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ + $longKey = str_repeat("A", 256); + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => $longKey, - 'value' => 'TESTINGVALUEUPDATED', + 'value' => 'TESTINGVALUEUPDATED' ]); $this->assertEquals(400, $response['headers']['status-code']); - $longValue = str_repeat('#', 8193); - $response = $this->client->call(Client::METHOD_PUT, '/project/variables/'.$data['variableId'], array_merge([ + $longValue = str_repeat("#", 8193); + $response = $this->client->call(Client::METHOD_PUT, '/project/variables/' . $data['variableId'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $data['projectId'], 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => 'APP_TEST_UPDATE', - 'value' => $longValue, + 'value' => $longValue ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -6175,13 +6188,13 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'key' => 'APP_TEST_UPDATE', - 'value' => 'TESTINGVALUEUPDATED', + 'value' => 'TESTINGVALUEUPDATED' ]); $this->assertEquals(404, $response['headers']['status-code']); } - public function test_delete_variable(): void + public function testDeleteVariable(): void { // Create a fresh project with variables for deletion testing $projectData = $this->setupProjectData(); @@ -6195,7 +6208,7 @@ class ProjectsConsoleClientTest extends Scope 'variableId' => 'unique()', 'key' => 'APP_TEST_DELETE', 'value' => 'TESTINGVALUE', - 'secret' => false, + 'secret' => false ]); $this->assertEquals(201, $variable['headers']['status-code']); @@ -6210,7 +6223,7 @@ class ProjectsConsoleClientTest extends Scope 'variableId' => 'unique()', 'key' => 'APP_TEST_DELETE_1', 'value' => 'TESTINGVALUE_1', - 'secret' => true, + 'secret' => true ]); $this->assertEquals(201, $variable['headers']['status-code']); @@ -6219,7 +6232,8 @@ class ProjectsConsoleClientTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/'.$variableId, array_merge([ + + $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/' . $variableId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectData['projectId'], 'x-appwrite-mode' => 'admin', @@ -6227,7 +6241,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/'.$secretVariableId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/' . $secretVariableId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectData['projectId'], 'x-appwrite-mode' => 'admin', @@ -6251,6 +6265,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ + $response = $this->client->call(Client::METHOD_DELETE, '/project/variables/NON_EXISTING_VARIABLE', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectData['projectId'], @@ -6263,8 +6278,9 @@ class ProjectsConsoleClientTest extends Scope /** * Devkeys Tests starts here ------------------------------------------------ */ + #[Group('abuseEnabled')] - public function test_create_project_dev_key(): void + public function testCreateProjectDevKey(): void { /** * Test for SUCCESS @@ -6272,15 +6288,15 @@ class ProjectsConsoleClientTest extends Scope $id = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testCreateProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -6291,12 +6307,12 @@ class ProjectsConsoleClientTest extends Scope $this->assertEmpty($response['body']['accessedAt']); /** Create a second dev key */ - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); $this->assertEquals(201, $response['headers']['status-code']); @@ -6311,18 +6327,19 @@ class ProjectsConsoleClientTest extends Scope */ /** TEST expiry date is required */ - $res = $this->client->call(Client::METHOD_POST, '/projects/'.$id.'/dev-keys', array_merge([ + $res = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'name' => 'Key Test', + 'name' => 'Key Test' ]); $this->assertEquals(400, $res['headers']['status-code']); } + #[Group('abuseEnabled')] - public function test_list_project_dev_key(): void + public function testListProjectDevKey(): void { /** * Test for SUCCESS @@ -6330,25 +6347,25 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testListProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); /** Create devKey 1 */ $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); /** Create devKey 2 */ $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); /** List all dev keys */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6357,20 +6374,20 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(2, $response['body']['total']); /** List dev keys with limit */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::limit(1)->toString(), - ], + Query::limit(1)->toString() + ] ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); /** List dev keys with search */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -6381,11 +6398,11 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('Dev Key Test', $response['body']['devKeys'][1]['name']); /** List dev keys with querying `expire` */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'queries' => [Query::lessThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString()], + 'queries' => [Query::lessThan('expire', (new \DateTime())->format('Y-m-d H:i:s'))->toString()] ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -6396,21 +6413,22 @@ class ProjectsConsoleClientTest extends Scope */ /** Test for search with invalid query */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'queries' => [ - Query::search('name', 'Invalid')->toString(), - ], + Query::search('name', 'Invalid')->toString() + ] ]); $this->assertEquals(400, $response['headers']['status-code']); $this->assertEquals('Invalid `queries` param: Invalid query: Attribute not found in schema: name', $response['body']['message']); } + #[Group('abuseEnabled')] - public function test_get_project_dev_key(): void + public function testGetProjectDevKey(): void { /** * Test for SUCCESS @@ -6418,16 +6436,16 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testGetProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6443,7 +6461,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/error', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6452,7 +6470,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('abuseEnabled')] - public function test_get_dev_key_with_sdks(): void + public function testGetDevKeyWithSdks(): void { /** * Test for SUCCESS @@ -6460,13 +6478,13 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testGetDevKeyWithSdks', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); /** Use dev key with python sdk */ @@ -6474,10 +6492,10 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-dev-key' => $devKey['secret'], - 'x-sdk-name' => 'python', + 'x-sdk-name' => 'python' ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(401, $res['headers']['status-code']); @@ -6486,15 +6504,15 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-dev-key' => $devKey['secret'], - 'x-sdk-name' => 'php', + 'x-sdk-name' => 'php' ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(401, $res['headers']['status-code']); /** Get the dev key */ - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6507,7 +6525,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('abuseEnabled')] - public function test_no_host_validation_with_dev_key(): void + public function testNoHostValidationWithDevKey(): void { /** * Test for SUCCESS @@ -6515,20 +6533,20 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testNoHostValidationWithDevKey', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); $provider = 'mock'; $appId = '1'; $secret = '123456'; - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/oauth2', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -6541,23 +6559,23 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); /** Test oauth2 and get invalid `success` URL */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, ], [ 'success' => 'https://example.com', - 'failure' => 'https://example.com', + 'failure' => 'https://example.com' ]); $this->assertEquals(400, $response['headers']['status-code']); /** Test oauth2 with devKey and now flow works with untrusted URL too */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'], + 'x-appwrite-dev-key' => $devKey['secret'] ], [ 'success' => 'https://example.com', - 'failure' => 'https://example.com', + 'failure' => 'https://example.com' ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); @@ -6565,6 +6583,7 @@ class ProjectsConsoleClientTest extends Scope $location = $response['headers']['location']; + $locationClient = new Client(); $locationClient->setEndpoint(''); $locationClient->addHeader('x-appwrite-dev-key', $devKey['secret']); @@ -6590,27 +6609,27 @@ class ProjectsConsoleClientTest extends Scope $this->assertSame('https://example.com/#', $response['headers']['location']); /** Ensure any hostname is allowed */ - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-dev-key' => $devKey['secret'], 'origin' => '', - 'referer' => 'https://domain-without-rule.com', + 'referer' => 'https://domain-without-rule.com' ], [ 'success' => 'https://domain-without-rule.com', - 'failure' => 'https://domain-without-rule.com', + 'failure' => 'https://domain-without-rule.com' ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-dev-key' => $devKey['secret'], 'referer' => '', - 'origin' => 'https://domain-without-rule.com', + 'origin' => 'https://domain-without-rule.com' ], [ 'success' => 'https://domain-without-rule.com', - 'failure' => 'https://domain-without-rule.com', + 'failure' => 'https://domain-without-rule.com' ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); @@ -6629,7 +6648,7 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'], + 'x-appwrite-dev-key' => $devKey['secret'] ], [ 'userId' => ID::unique(), 'email' => 'user@appwrite.io', @@ -6638,13 +6657,13 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); } - public function test_rule_o_auth_redirect(): void + public function testRuleOAuthRedirect(): void { // Prepare project $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testRuleOAuthRedirect', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $provider = 'mock'; @@ -6652,7 +6671,7 @@ class ProjectsConsoleClientTest extends Scope $secret = '123456'; // Prepare OAuth provider - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/oauth2', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -6665,31 +6684,31 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); // Prepare rule. In reality this is site rule, but for testing, API rule is enough, and faster to prepare - $domain = \uniqid().'-with-rule.custom.localhost'; + $domain = \uniqid() . '-with-rule.custom.localhost'; $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'domain' => $domain, + 'domain' => $domain ]); $this->assertEquals(201, $rule['headers']['status-code']); // Ensure unknown domain cannot be redirect URL - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'referer' => 'https://'.$domain, + 'referer' => 'https://' . $domain, 'origin' => '', ], [ 'success' => 'https://domain-without-rule.com', - 'failure' => 'https://domain-without-rule.com', + 'failure' => 'https://domain-without-rule.com' ], followRedirects: false); $this->assertEquals(400, $response['headers']['status-code']); // Also ensure final step blocks unknown redirect URL - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider.'/redirect', [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider . '/redirect', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'origin' => '', @@ -6698,7 +6717,7 @@ class ProjectsConsoleClientTest extends Scope 'code' => 'any-code', 'state' => \json_encode([ 'success' => 'https://domain-without-rule.com', - 'failure' => 'https://domain-without-rule.com', + 'failure' => 'https://domain-without-rule.com' ]), 'error' => '', 'error_description' => '', @@ -6707,19 +6726,19 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString('project_invalid_success_url', $response['body']); // Ensure rule's domain can be redirect URL - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider, [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'referer' => 'https://'.$domain, + 'referer' => 'https://' . $domain, 'origin' => '', ], [ - 'success' => 'https://'.$domain, - 'failure' => 'https://'.$domain, + 'success' => 'https://' . $domain, + 'failure' => 'https://' . $domain ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); // Also ensure final step allows redirect URL - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider.'/redirect', [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider . '/redirect', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'origin' => '', @@ -6727,20 +6746,20 @@ class ProjectsConsoleClientTest extends Scope ], [ 'code' => 'any-code', 'state' => \json_encode([ - 'success' => 'https://'.$domain, - 'failure' => 'https://'.$domain, + 'success' => 'https://' . $domain, + 'failure' => 'https://' . $domain ]), 'error' => '', 'error_deescription' => '', ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); - $this->assertStringContainsString('https://'.$domain, $response['headers']['location']); + $this->assertStringContainsString('https://' . $domain, $response['headers']['location']); // Ensure unknown domain cannot be redirect URL $response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'referer' => 'https://'.$domain, + 'referer' => 'https://' . $domain, 'origin' => '', ], [ 'userId' => ID::unique(), @@ -6753,23 +6772,23 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'referer' => 'https://'.$domain, + 'referer' => 'https://' . $domain, 'origin' => '', ], [ 'userId' => ID::unique(), 'email' => 'user@appwrite.io', - 'url' => 'https://'.$domain, + 'url' => 'https://' . $domain, ]); $this->assertEquals(201, $response['headers']['status-code']); } - public function test_o_auth_redirect_with_custom_scheme_state(): void + public function testOAuthRedirectWithCustomSchemeState(): void { // Prepare project $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testOAuthRedirectWithCustomSchemeState', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $provider = 'mock'; @@ -6777,7 +6796,7 @@ class ProjectsConsoleClientTest extends Scope $secret = '123456'; // Prepare OAuth provider - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId.'/oauth2', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/oauth2', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -6789,13 +6808,13 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $scheme = 'appwrite-callback-'.$projectId; + $scheme = 'appwrite-callback-' . $projectId; $state = \json_encode([ - 'success' => $scheme.':///', - 'failure' => $scheme.':///', + 'success' => $scheme . ':///', + 'failure' => $scheme . ':///' ]); - $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/'.$provider.'/redirect', [ + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider . '/redirect', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'origin' => '', @@ -6808,12 +6827,12 @@ class ProjectsConsoleClientTest extends Scope ], followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); - $this->assertStringStartsWith($scheme.'://', $response['headers']['location']); + $this->assertStringStartsWith($scheme . '://', $response['headers']['location']); $this->assertStringContainsString('error=', $response['headers']['location']); } #[Group('abuseEnabled')] - public function test_cors_with_dev_key(): void + public function testCorsWithDevKey(): void { /** * Test for SUCCESS @@ -6821,13 +6840,13 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testCorsWithDevKey', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); $origin = 'http://example.com'; @@ -6841,7 +6860,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $projectId, ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(403, $response['headers']['status-code']); @@ -6849,6 +6868,7 @@ class ProjectsConsoleClientTest extends Scope // you should not return a fallback origin for a disallowed host $this->assertNull($response['headers']['access-control-allow-origin'] ?? null); + /** * Test CORS with Dev Key (should bypass origin check) */ @@ -6856,17 +6876,17 @@ class ProjectsConsoleClientTest extends Scope 'origin' => $origin, 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'], + 'x-appwrite-dev-key' => $devKey['secret'] ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(401, $response['headers']['status-code']); $this->assertEquals($origin, $response['headers']['access-control-allow-origin'] ?? null); } - public function test_console_cors_with_trusted_project(): void + public function testConsoleCorsWithTrustedProject(): void { $trustedProjectIds = ['trusted-project', 'another-trusted-project']; // Set in env variable @@ -6878,17 +6898,17 @@ class ProjectsConsoleClientTest extends Scope $this->setupProject([ 'projectId' => $projectId, 'name' => 'Trusted project', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); // Add domain to trusted project; API for simplicity, in real work this will be site - $domain = \uniqid().'.custom.localhost'; + $domain = \uniqid() . '.custom.localhost'; $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'domain' => $domain, + 'domain' => $domain ]); $this->assertEquals(201, $rule['headers']['status-code']); @@ -6902,7 +6922,7 @@ class ProjectsConsoleClientTest extends Scope [ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', - 'origin' => 'http://'.$domain, + 'origin' => 'http://' . $domain ] ) ); @@ -6910,7 +6930,7 @@ class ProjectsConsoleClientTest extends Scope if (\in_array($projectId, $trustedProjectIds)) { // Trusted projects can $this->assertEquals(200, $currencies['headers']['status-code']); - $this->assertSame('http://'.$domain, $currencies['headers']['access-control-allow-origin']); + $this->assertSame('http://' . $domain, $currencies['headers']['access-control-allow-origin']); } else { // Untrusted projects cannot $this->assertEquals(403, $currencies['headers']['status-code']); @@ -6918,7 +6938,7 @@ class ProjectsConsoleClientTest extends Scope } } finally { // Cleanup - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -6929,7 +6949,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('abuseEnabled')] - public function test_no_rate_limit_with_dev_key(): void + public function testNoRateLimitWithDevKey(): void { /** * Test for SUCCESS @@ -6937,13 +6957,13 @@ class ProjectsConsoleClientTest extends Scope $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testNoRateLimitWithDevKey', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); /** @@ -6955,7 +6975,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $projectId, ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -6965,7 +6985,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $projectId, ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(429, $response['headers']['status-code']); @@ -6973,17 +6993,17 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'], + 'x-appwrite-dev-key' => $devKey['secret'] ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(401, $response['headers']['status-code']); /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_POST, '/projects/'.$projectId.'/dev-keys', array_merge([ + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/dev-keys', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -6994,10 +7014,10 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $response['body']['secret'], + 'x-appwrite-dev-key' => $response['body']['secret'] ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(429, $response['headers']['status-code']); @@ -7007,16 +7027,16 @@ class ProjectsConsoleClientTest extends Scope $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test Expire 5 seconds', - 'expire' => DateTime::addSeconds(new \DateTime(), 5), + 'expire' => DateTime::addSeconds(new \DateTime(), 5) ]); $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'], + 'x-appwrite-dev-key' => $devKey['secret'] ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -7024,31 +7044,31 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'], + 'x-appwrite-dev-key' => $devKey['secret'] ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(429, $response['headers']['status-code']); }, 15_000, 500); } #[Group('abuseEnabled')] - public function test_update_project_dev_key(): void + public function testUpdateProjectDevKey(): void { $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testUpdateProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); - $response = $this->client->call(Client::METHOD_PUT, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_PUT, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -7063,7 +7083,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertArrayHasKey('accessedAt', $response['body']); $this->assertEmpty($response['body']['accessedAt']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -7077,21 +7097,21 @@ class ProjectsConsoleClientTest extends Scope } #[Group('abuseEnabled')] - public function test_delete_project_dev_key(): void + public function testDeleteProjectDevKey(): void { $projectId = $this->setupProject([ 'projectId' => ID::unique(), 'name' => 'testDeleteProjectDevKey', - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $devKey = $this->setupDevKey([ 'projectId' => $projectId, 'name' => 'Dev Key Test', - 'expire' => DateTime::addSeconds(new \DateTime(), 36000), + 'expire' => DateTime::addSeconds(new \DateTime(), 36000) ]); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -7105,14 +7125,14 @@ class ProjectsConsoleClientTest extends Scope $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, - 'x-appwrite-dev-key' => $devKey['secret'], + 'x-appwrite-dev-key' => $devKey['secret'] ], [ 'email' => 'user@appwrite.io', - 'password' => 'password', + 'password' => 'password' ]); $this->assertEquals(429, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_GET, '/projects/'.$projectId.'/dev-keys/'.$devKey['$id'], array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId . '/dev-keys/' . $devKey['$id'], array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -7122,7 +7142,7 @@ class ProjectsConsoleClientTest extends Scope /** * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId.'/dev-keys/error', array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId . '/dev-keys/error', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -7133,7 +7153,8 @@ class ProjectsConsoleClientTest extends Scope /** * Devkeys Tests ends here ------------------------------------------------ */ - public function test_project_labels(): void + + public function testProjectLabels(): void { // Setup: Prepare team $team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ @@ -7156,7 +7177,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Test project - Labels 1', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -7165,11 +7186,11 @@ class ProjectsConsoleClientTest extends Scope $projectId = $project['body']['$id']; // Apply labels - $project = $this->client->call(Client::METHOD_PUT, '/projects/'.$projectId.'/labels', array_merge([ + $project = $this->client->call(Client::METHOD_PUT, '/projects/' . $projectId . '/labels', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'labels' => ['vip', 'imagine', 'blocked'], + 'labels' => ['vip', 'imagine', 'blocked'] ]); $this->assertEquals(200, $project['headers']['status-code']); @@ -7180,11 +7201,11 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('blocked', $project['body']['labels'][2]); // Update labels - $project = $this->client->call(Client::METHOD_PUT, '/projects/'.$projectId.'/labels', array_merge([ + $project = $this->client->call(Client::METHOD_PUT, '/projects/' . $projectId . '/labels', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'labels' => ['nonvip', 'imagine'], + 'labels' => ['nonvip', 'imagine'] ]); $this->assertEquals(200, $project['headers']['status-code']); $this->assertIsArray($project['body']['labels']); @@ -7200,7 +7221,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['nonvip'])->toString(), - ], + ] ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7213,7 +7234,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['vip'])->toString(), - ], + ] ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(0, $projects['body']['total']); @@ -7225,7 +7246,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['imagine'])->toString(), - ], + ] ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7238,7 +7259,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['nonvip', 'imagine'])->toString(), - ], + ] ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7253,7 +7274,7 @@ class ProjectsConsoleClientTest extends Scope 'projectId' => ID::unique(), 'name' => 'Test project - Labels 2', 'teamId' => $teamId, - 'region' => System::getEnv('_APP_REGION', 'default'), + 'region' => System::getEnv('_APP_REGION', 'default') ]); $this->assertEquals(201, $project['headers']['status-code']); @@ -7261,11 +7282,11 @@ class ProjectsConsoleClientTest extends Scope $this->assertCount(0, $project['body']['labels']); $projectId2 = $project['body']['$id']; - $project = $this->client->call(Client::METHOD_PUT, '/projects/'.$projectId2.'/labels', array_merge([ + $project = $this->client->call(Client::METHOD_PUT, '/projects/' . $projectId2 . '/labels', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'labels' => ['vip', 'imagine'], + 'labels' => ['vip', 'imagine'] ]); $this->assertEquals(200, $project['headers']['status-code']); $this->assertIsArray($project['body']['labels']); @@ -7281,7 +7302,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['imagine'])->toString(), - ], + ] ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(2, $projects['body']['total']); @@ -7296,7 +7317,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['vip'])->toString(), - ], + ] ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7311,7 +7332,7 @@ class ProjectsConsoleClientTest extends Scope 'queries' => [ Query::contains('labels', ['vip'])->toString(), Query::contains('labels', ['imagine'])->toString(), - ], + ] ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(1, $projects['body']['total']); @@ -7325,7 +7346,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'queries' => [ Query::contains('labels', ['vip', 'imagine'])->toString(), - ], + ] ]); $this->assertEquals(200, $projects['headers']['status-code']); $this->assertEquals(2, $projects['body']['total']); @@ -7333,21 +7354,21 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($projectId2, $projects['body']['projects'][1]['$id']); // Cleanup - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId2, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId2, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); $this->assertEquals(204, $response['headers']['status-code']); - $response = $this->client->call(Client::METHOD_DELETE, '/teams/'.$teamId, array_merge([ + $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders())); @@ -7356,7 +7377,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('ciIgnore')] - public function test_project_specific_permissions_for_list_projects(): void + public function testProjectSpecificPermissionsForListProjects(): void { $teamId = ID::unique(); $projectIdA = $this->setupProject([ @@ -7368,23 +7389,23 @@ class ProjectsConsoleClientTest extends Scope 'name' => 'Project Test B', ], $teamId, false); - $testUserEmail = 'test-'.ID::unique().'@localhost.test'; + $testUserEmail = 'test-' . ID::unique() . '@localhost.test'; $testUserName = 'Test User'; - ['membershipId' => $testUserMembershipId] = $this->setupUserMembership([ + [ 'membershipId' => $testUserMembershipId ] = $this->setupUserMembership([ 'teamId' => $teamId, 'email' => $testUserEmail, 'name' => $testUserName, - 'roles' => ['owner'], + 'roles' => ["owner"], ]); $testCases = [ [ - 'roles' => ['owner'], + 'roles' => ["owner"], 'successProjectIds' => [$projectIdA, $projectIdB], ], [ - 'roles' => ['developer'], + 'roles' => ["developer"], 'successProjectIds' => [$projectIdA, $projectIdB], ], [ @@ -7404,9 +7425,9 @@ class ProjectsConsoleClientTest extends Scope 'successProjectIds' => [$projectIdB], ], [ - 'roles' => ['developer', "project-$projectIdA-owner"], + 'roles' => ["developer", "project-$projectIdA-owner"], 'successProjectIds' => [$projectIdA, $projectIdB], - ], + ] ]; // Setup session @@ -7418,7 +7439,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $testUserEmail, 'password' => 'password', ]); - $token = $session['cookies']['a_session_'.$this->getProject()['$id']]; + $token = $session['cookies']['a_session_' . $this->getProject()['$id']]; foreach ($testCases as $testCase) { $this->updateMembershipRole($teamId, $testUserMembershipId, $testCase['roles']); @@ -7428,7 +7449,7 @@ class ProjectsConsoleClientTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -7443,7 +7464,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('ciIgnore')] - public function test_project_specific_permissions_for_update_project(): void + public function testProjectSpecificPermissionsForUpdateProject(): void { $teamId = ID::unique(); $projectIdA = $this->setupProject([ @@ -7455,24 +7476,24 @@ class ProjectsConsoleClientTest extends Scope 'name' => 'Project Test B', ], $teamId, false); - $testUserEmail = 'test-'.ID::unique().'@localhost.test'; + $testUserEmail = 'test-' . ID::unique() . '@localhost.test'; $testUserName = 'Test User'; - ['membershipId' => $testUserMembershipId] = $this->setupUserMembership([ + [ 'membershipId' => $testUserMembershipId ] = $this->setupUserMembership([ 'teamId' => $teamId, 'email' => $testUserEmail, 'name' => $testUserName, - 'roles' => ['owner'], + 'roles' => ["owner"], ]); $testCases = [ [ - 'roles' => ['owner'], + 'roles' => ["owner"], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], ], [ - 'roles' => ['developer'], + 'roles' => ["developer"], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], ], @@ -7497,10 +7518,10 @@ class ProjectsConsoleClientTest extends Scope 'failureProjectIds' => [$projectIdA], ], [ - 'roles' => ['developer', "project-$projectIdA-owner"], + 'roles' => ["developer", "project-$projectIdA-owner"], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], - ], + ] ]; // Setup session @@ -7512,20 +7533,20 @@ class ProjectsConsoleClientTest extends Scope 'email' => $testUserEmail, 'password' => 'password', ]); - $token = $session['cookies']['a_session_'.$this->getProject()['$id']]; + $token = $session['cookies']['a_session_' . $this->getProject()['$id']]; foreach ($testCases as $testCase) { $this->updateMembershipRole($teamId, $testUserMembershipId, $testCase['roles']); foreach ($testCase['successProjectIds'] as $projectId) { - $newProjectName = 'Updated Project Name '.ID::unique(); + $newProjectName = 'Updated Project Name ' . ID::unique(); // Success: User should be able to update the project they have access to. - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId, [ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId, [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, ], [ 'name' => $newProjectName, ]); @@ -7535,14 +7556,14 @@ class ProjectsConsoleClientTest extends Scope } foreach ($testCase['failureProjectIds'] as $projectId) { - $newProjectName = 'Updated Project Name '.ID::unique(); + $newProjectName = 'Updated Project Name ' . ID::unique(); // Failure: User should not be able to update the project they do not have access to. - $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$projectId, [ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId, [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-response-format' => '1.9.4', - 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, ], [ 'name' => $newProjectName, ]); @@ -7552,7 +7573,7 @@ class ProjectsConsoleClientTest extends Scope } #[Group('ciIgnore')] - public function test_project_specific_permissions_for_delete_project(): void + public function testProjectSpecificPermissionsForDeleteProject(): void { $teamId = ID::unique(); $projectIdA = $this->setupProject([ @@ -7576,24 +7597,24 @@ class ProjectsConsoleClientTest extends Scope 'name' => 'Project Test E', ], $teamId, false); - $testUserEmail = 'test-'.ID::unique().'@localhost.test'; + $testUserEmail = 'test-' . ID::unique() . '@localhost.test'; $testUserName = 'Test User'; - ['membershipId' => $testUserMembershipId] = $this->setupUserMembership([ + [ 'membershipId' => $testUserMembershipId ] = $this->setupUserMembership([ 'teamId' => $teamId, 'email' => $testUserEmail, 'name' => $testUserName, - 'roles' => ['owner'], + 'roles' => ["owner"], ]); $testCases = [ [ - 'roles' => ['owner'], + 'roles' => ["owner"], 'successProjectIds' => [$projectIdA], 'failureProjectIds' => [], ], [ - 'roles' => ['developer'], + 'roles' => ["developer"], 'successProjectIds' => [$projectIdB, $projectIdC], 'failureProjectIds' => [], ], @@ -7618,29 +7639,29 @@ class ProjectsConsoleClientTest extends Scope 'email' => $testUserEmail, 'password' => 'password', ]); - $token = $session['cookies']['a_session_'.$this->getProject()['$id']]; + $token = $session['cookies']['a_session_' . $this->getProject()['$id']]; foreach ($testCases as $testCase) { $this->updateMembershipRole($teamId, $testUserMembershipId, $testCase['roles']); foreach ($testCase['successProjectIds'] as $projectId) { // Success: User should be able to delete the project they have access to. - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, [ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, ]); $this->assertEquals(204, $response['headers']['status-code']); } foreach ($testCase['failureProjectIds'] as $projectId) { // Failure: User should not be able to delete the project they do not have access to. - $response = $this->client->call(Client::METHOD_DELETE, '/projects/'.$projectId, [ + $response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, ]); $this->assertTrue($response['headers']['status-code'] === 401 || $response['headers']['status-code'] === 404); } @@ -7651,7 +7672,7 @@ class ProjectsConsoleClientTest extends Scope * Test project specific permissions for project resources, in this case 'function variables'. */ #[Group('ciIgnore')] - public function test_project_specific_permissions_for_project_resources(): void + public function testProjectSpecificPermissionsForProjectResources(): void { $teamId = ID::unique(); $projectIdA = $this->setupProject([ @@ -7663,24 +7684,24 @@ class ProjectsConsoleClientTest extends Scope 'name' => 'Project Test B', ], $teamId, false); - $testUserEmail = 'test-'.ID::unique().'@localhost.test'; + $testUserEmail = 'test-' . ID::unique() . '@localhost.test'; $testUserName = 'Test User'; - ['membershipId' => $testUserMembershipId] = $this->setupUserMembership([ + [ 'membershipId' => $testUserMembershipId ] = $this->setupUserMembership([ 'teamId' => $teamId, 'email' => $testUserEmail, 'name' => $testUserName, - 'roles' => ['owner'], + 'roles' => ["owner"], ]); $testCases = [ [ - 'roles' => ['owner'], + 'roles' => ["owner"], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], ], [ - 'roles' => ['developer'], + 'roles' => ["developer"], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], ], @@ -7705,10 +7726,10 @@ class ProjectsConsoleClientTest extends Scope 'failureProjectIds' => [$projectIdA], ], [ - 'roles' => ['developer', "project-$projectIdA-owner"], + 'roles' => ["developer", "project-$projectIdA-owner"], 'successProjectIds' => [$projectIdA, $projectIdB], 'failureProjectIds' => [], - ], + ] ]; // Setup session @@ -7720,7 +7741,7 @@ class ProjectsConsoleClientTest extends Scope 'email' => $testUserEmail, 'password' => 'password', ]); - $token = $session['cookies']['a_session_'.$this->getProject()['$id']]; + $token = $session['cookies']['a_session_' . $this->getProject()['$id']]; // Setup functions $functionId = ID::unique(); @@ -7732,37 +7753,37 @@ class ProjectsConsoleClientTest extends Scope foreach ($testCase['successProjectIds'] as $projectId) { $variableId = ID::unique(); - $response = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/variables', [ + $response = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-mode' => 'admin', - 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, ], [ 'variableId' => $variableId, - 'key' => 'APP_TEST_'.$variableId, + 'key' => 'APP_TEST_' . $variableId, 'value' => 'TESTINGVALUE', - 'secret' => false, + 'secret' => false ]); $this->assertEquals(201, $response['headers']['status-code']); - $this->assertEquals('APP_TEST_'.$variableId, $response['body']['key']); + $this->assertEquals('APP_TEST_' . $variableId, $response['body']['key']); $this->assertEquals('TESTINGVALUE', $response['body']['value']); } foreach ($testCase['failureProjectIds'] as $projectId) { $variableId = ID::unique(); - $response = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/variables', [ + $response = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/variables', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, 'x-appwrite-mode' => 'admin', - 'cookie' => 'a_session_'.$this->getProject()['$id'].'='.$token, + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $token, ], [ 'variableId' => $variableId, - 'key' => 'APP_TEST_'.$variableId, + 'key' => 'APP_TEST_' . $variableId, 'value' => 'TESTINGVALUE', - 'secret' => false, + 'secret' => false ]); $this->assertTrue($response['headers']['status-code'] === 401 || $response['headers']['status-code'] === 404); @@ -7770,7 +7791,7 @@ class ProjectsConsoleClientTest extends Scope } } - public function test_password_recovery_url_params(): void + public function testPasswordRecoveryUrlParams(): void { // With search params $url = 'http://localhost/auth/signin?id=abcd1234&tenant=efgh5678&domain=example.com&referred=0'; @@ -7800,9 +7821,9 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString($url, $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); - $expectedUrl = $url.'&userId='.$userId.'&secret='; + $expectedUrl = $url . "&userId=" . $userId . "&secret="; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); @@ -7832,9 +7853,9 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString($url, $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); - $expectedUrl = $url.'&userId='.$userId.'&secret='; + $expectedUrl = $url . "&userId=" . $userId . "&secret="; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); @@ -7861,12 +7882,12 @@ class ProjectsConsoleClientTest extends Scope $userId = $response['body']['userId']; $lastEmail = $this->getLastEmailByAddress($userEmail, function ($email) use ($url, $userId) { - $this->assertStringContainsString($url.'?userId='.$userId, $email['html'] ?? ''); + $this->assertStringContainsString($url . '?userId=' . $userId, $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); - $expectedUrl = $url.'?userId='.$userId.'&secret='; + $expectedUrl = $url . "?userId=" . $userId . "&secret="; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); @@ -7893,12 +7914,12 @@ class ProjectsConsoleClientTest extends Scope $userId = $response['body']['userId']; $lastEmail = $this->getLastEmailByAddress($userEmail, function ($email) use ($url, $userId) { - $this->assertStringContainsString($url.'?userId='.$userId, $email['html'] ?? ''); + $this->assertStringContainsString($url . '?userId=' . $userId, $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); - $expectedUrl = $url.'?userId='.$userId.'&secret='; + $expectedUrl = $url . "?userId=" . $userId . "&secret="; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); @@ -7928,7 +7949,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString('INJECTED', $email['html'] ?? ''); }); - $this->assertEquals('Password Reset for '.$this->getProject()['name'], $lastEmail['subject']); + $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); $this->assertStringContainsString('INJECTED', $lastEmail['html']); $this->assertStringContainsString('

', $lastEmail['html']); @@ -7936,7 +7957,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertStringContainsString('">', $lastEmail['html']); $this->assertStringContainsString('', $lastEmail['html']); - $expectedUrl = $url.'?userId='.$userId.'&secret='; + $expectedUrl = $url . "?userId=" . $userId . "&secret="; $this->assertStringContainsString($expectedUrl, $lastEmail['html']); } From 9264fcec13d95cdabb846988f887d661ded59ccd Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 1 Jun 2026 15:01:39 +0400 Subject: [PATCH 13/16] Keep password policy minimum length at 8 --- app/controllers/api/account.php | 6 +++--- app/controllers/api/users.php | 4 ++-- src/Appwrite/Auth/Validator/Password.php | 8 +++----- src/Appwrite/Auth/Validator/PasswordStrength.php | 3 ++- .../Http/Project/Policies/PasswordStrength/Update.php | 2 +- tests/e2e/Services/Project/PoliciesBase.php | 6 +++--- tests/e2e/Services/Projects/ProjectsConsoleClientTest.php | 2 +- tests/unit/Auth/Validator/PasswordStrengthTest.php | 8 ++++---- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 69ad1fc2f2..114d9f4a17 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -257,7 +257,7 @@ Http::post('/v1/account') ->label('abuse-limit', 10) ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', '', new EmailValidator(), 'User email.') - ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be between 6 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('request') ->inject('response') @@ -3273,7 +3273,7 @@ Http::patch('/v1/account/password') contentType: ContentType::JSON )) ->label('abuse-limit', 10) - ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be at least 6 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) ->param('oldPassword', '', new Password(), 'Current user password. Must be at least 8 chars.', true) ->inject('response') ->inject('user') @@ -3890,7 +3890,7 @@ Http::put('/v1/account/recovery') ->label('abuse-key', 'url:{url},userId:{param-userId}') ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) ->param('secret', '', new Text(256), 'Valid reset token.') - ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be between 6 and 256 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be between 8 and 256 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('user') ->inject('dbForProject') diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index baed5fa63a..fb5514a6fe 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -283,7 +283,7 @@ Http::post('/v1/users') ->param('userId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) ->param('email', null, new Nullable(new EmailValidator()), 'User email.', true) ->param('phone', null, new Nullable(new Phone()), 'Phone number. Format this number with a leading \'+\' and a country code, e.g., +16175551212.', true) - ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'Plain text user password. Must be at least 6 chars.', true, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'Plain text user password. Must be at least 8 chars.', true, ['project', 'passwordsDictionary']) ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->inject('response') ->inject('project') @@ -1434,7 +1434,7 @@ Http::patch('/v1/users/:userId/password') ] )) ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) - ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? [], allowEmpty: true), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be at least 6 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? [], allowEmpty: true), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('project') ->inject('dbForProject') diff --git a/src/Appwrite/Auth/Validator/Password.php b/src/Appwrite/Auth/Validator/Password.php index d1c72d686e..bfe5577889 100644 --- a/src/Appwrite/Auth/Validator/Password.php +++ b/src/Appwrite/Auth/Validator/Password.php @@ -12,12 +12,10 @@ use Utopia\Validator; class Password extends Validator { protected bool $allowEmpty; - protected int $minLength; - public function __construct(bool $allowEmpty = false, int $minLength = 8) + public function __construct(bool $allowEmpty = false) { $this->allowEmpty = $allowEmpty; - $this->minLength = $minLength; } /** @@ -29,7 +27,7 @@ class Password extends Validator */ public function getDescription(): string { - return 'Password must be between ' . $this->minLength . ' and 256 characters long.'; + return 'Password must be between 8 and 256 characters long.'; } /** @@ -49,7 +47,7 @@ class Password extends Validator return true; } - if (\strlen($value) < $this->minLength) { + if (\strlen($value) < 8) { return false; } diff --git a/src/Appwrite/Auth/Validator/PasswordStrength.php b/src/Appwrite/Auth/Validator/PasswordStrength.php index 73ad4b8d58..fc4d3cfd82 100644 --- a/src/Appwrite/Auth/Validator/PasswordStrength.php +++ b/src/Appwrite/Auth/Validator/PasswordStrength.php @@ -17,8 +17,9 @@ class PasswordStrength extends Password public function __construct(array $policy = [], bool $allowEmpty = false) { - parent::__construct($allowEmpty, $policy['minLength'] ?? 8); + parent::__construct($allowEmpty); + $this->minLength = $policy['minLength'] ?? 8; $this->requireUppercase = $policy['requireUppercase'] ?? false; $this->requireLowercase = $policy['requireLowercase'] ?? false; $this->requireNumber = $policy['requireNumber'] ?? false; diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index 453cd9ca78..a131cacbfd 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -50,7 +50,7 @@ class Update extends Action ), ], )) - ->param('minLength', null, new Range(6, 256), 'Minimum password length. Value must be between 6 and 256. Default is 8.', optional: true) + ->param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) ->param('requireUppercase', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.', optional: true) ->param('requireLowercase', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.', optional: true) ->param('requireNumber', null, new Boolean(), 'Whether passwords must include at least one number.', optional: true) diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 66517fb5af..217ba7eba5 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -529,11 +529,11 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicyMinLength(): void { $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 6, + 'minLength' => 8, ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(6, $response['body']['minLength']); + $this->assertSame(8, $response['body']['minLength']); // Cleanup $this->resetPasswordStrengthPolicy(); @@ -542,7 +542,7 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicyBelowMinLength(): void { $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders(), [ - 'minLength' => 5, + 'minLength' => 7, ]); $this->assertSame(400, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index ca7ccb18e3..490f25153f 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2916,7 +2916,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'minLength' => 5, + 'minLength' => 7, ]); $this->assertEquals(400, $response['headers']['status-code']); diff --git a/tests/unit/Auth/Validator/PasswordStrengthTest.php b/tests/unit/Auth/Validator/PasswordStrengthTest.php index 49896f4e1f..44062bbf91 100644 --- a/tests/unit/Auth/Validator/PasswordStrengthTest.php +++ b/tests/unit/Auth/Validator/PasswordStrengthTest.php @@ -34,14 +34,14 @@ class PasswordStrengthTest extends TestCase $this->assertTrue($validator->isValid('Password123€')); } - public function testMinLengthCanBeSix(): void + public function testMinLengthCanBeEight(): void { $validator = new PasswordStrength([ - 'minLength' => 6, + 'minLength' => 8, ]); - $this->assertFalse($validator->isValid('12345')); - $this->assertTrue($validator->isValid('123456')); + $this->assertFalse($validator->isValid('1234567')); + $this->assertTrue($validator->isValid('12345678')); } public function testAllowEmpty(): void From 7cd02309879e41f9cfde51141d7250412fda0266 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 1 Jun 2026 18:45:34 +0400 Subject: [PATCH 14/16] Address password policy review feedback --- app/controllers/api/users.php | 2 +- .../projects/update-auth-password-strength.md | 1 - .../Auth/Validator/PasswordDictionary.php | 15 +-- .../Auth/Validator/PasswordStrength.php | 34 +++---- .../Project/Http/Project/Policies/Get.php | 8 +- .../Policies/PasswordStrength/Update.php | 40 ++++---- .../Project/Http/Project/Policies/XList.php | 8 +- .../Modules/Projects/Http/Projects/Create.php | 8 +- .../Response/Model/PolicyPasswordStrength.php | 10 +- tests/e2e/Services/Project/PoliciesBase.php | 92 +++++++++---------- ...oliciesPasswordStrengthIntegrationTest.php | 77 ++++++++++++++++ .../Projects/ProjectsConsoleClientTest.php | 32 +++---- .../Auth/Validator/PasswordDictionaryTest.php | 4 +- .../Auth/Validator/PasswordStrengthTest.php | 16 ++-- 14 files changed, 213 insertions(+), 134 deletions(-) delete mode 100644 docs/references/projects/update-auth-password-strength.md create mode 100644 tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index fb5514a6fe..d2db2fc69e 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1434,7 +1434,7 @@ Http::patch('/v1/users/:userId/password') ] )) ->param('userId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'User ID.', false, ['dbForProject']) - ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? [], allowEmpty: true), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) + ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? [], allowEmpty: true), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false, allowEmpty: true)], Validator::TYPE_STRING), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) ->inject('response') ->inject('project') ->inject('dbForProject') diff --git a/docs/references/projects/update-auth-password-strength.md b/docs/references/projects/update-auth-password-strength.md deleted file mode 100644 index ad7ff46b57..0000000000 --- a/docs/references/projects/update-auth-password-strength.md +++ /dev/null @@ -1 +0,0 @@ -Update the authentication password strength requirements. diff --git a/src/Appwrite/Auth/Validator/PasswordDictionary.php b/src/Appwrite/Auth/Validator/PasswordDictionary.php index dd832e63d5..99a6c81525 100644 --- a/src/Appwrite/Auth/Validator/PasswordDictionary.php +++ b/src/Appwrite/Auth/Validator/PasswordDictionary.php @@ -2,20 +2,19 @@ namespace Appwrite\Auth\Validator; -use Utopia\Validator; - /** * Password. * * Validates user password string */ -class PasswordDictionary extends Validator +class PasswordDictionary extends Password { protected array $dictionary; protected bool $enabled; - public function __construct(array $dictionary, bool $enabled = false) + public function __construct(array $dictionary, bool $enabled = false, bool $allowEmpty = false) { + parent::__construct($allowEmpty); $this->dictionary = $dictionary; $this->enabled = $enabled; } @@ -29,7 +28,7 @@ class PasswordDictionary extends Validator */ public function getDescription(): string { - return 'Password should not be one of the commonly used passwords.'; + return 'Password must be between 8 and 265 characters long, and should not be one of the commonly used password.'; } /** @@ -41,7 +40,11 @@ class PasswordDictionary extends Validator */ public function isValid($value): bool { - if ($this->enabled && \is_string($value) && array_key_exists($value, $this->dictionary)) { + if (!parent::isValid($value)) { + return false; + } + + if ($this->enabled && array_key_exists($value, $this->dictionary)) { return false; } return true; diff --git a/src/Appwrite/Auth/Validator/PasswordStrength.php b/src/Appwrite/Auth/Validator/PasswordStrength.php index fc4d3cfd82..46be71ad9e 100644 --- a/src/Appwrite/Auth/Validator/PasswordStrength.php +++ b/src/Appwrite/Auth/Validator/PasswordStrength.php @@ -10,20 +10,20 @@ namespace Appwrite\Auth\Validator; class PasswordStrength extends Password { protected int $minLength; - protected bool $requireUppercase; - protected bool $requireLowercase; - protected bool $requireNumber; - protected bool $requireSpecialChar; + protected bool $uppercase; + protected bool $lowercase; + protected bool $number; + protected bool $symbols; public function __construct(array $policy = [], bool $allowEmpty = false) { parent::__construct($allowEmpty); $this->minLength = $policy['minLength'] ?? 8; - $this->requireUppercase = $policy['requireUppercase'] ?? false; - $this->requireLowercase = $policy['requireLowercase'] ?? false; - $this->requireNumber = $policy['requireNumber'] ?? false; - $this->requireSpecialChar = $policy['requireSpecialChar'] ?? false; + $this->uppercase = $policy['uppercase'] ?? false; + $this->lowercase = $policy['lowercase'] ?? false; + $this->number = $policy['number'] ?? false; + $this->symbols = $policy['symbols'] ?? false; } public function getDescription(): string @@ -32,20 +32,20 @@ class PasswordStrength extends Password 'between ' . $this->minLength . ' and 256 characters long', ]; - if ($this->requireUppercase) { + if ($this->uppercase) { $requirements[] = 'include an uppercase letter'; } - if ($this->requireLowercase) { + if ($this->lowercase) { $requirements[] = 'include a lowercase letter'; } - if ($this->requireNumber) { + if ($this->number) { $requirements[] = 'include a number'; } - if ($this->requireSpecialChar) { - $requirements[] = 'include a special character'; + if ($this->symbols) { + $requirements[] = 'include a symbol'; } return 'Password must be ' . \implode(', ', $requirements) . '.'; @@ -68,19 +68,19 @@ class PasswordStrength extends Password return false; } - if ($this->requireUppercase && !\preg_match('/[A-Z]/', $value)) { + if ($this->uppercase && !\preg_match('/[A-Z]/', $value)) { return false; } - if ($this->requireLowercase && !\preg_match('/[a-z]/', $value)) { + if ($this->lowercase && !\preg_match('/[a-z]/', $value)) { return false; } - if ($this->requireNumber && !\preg_match('/\d/', $value)) { + if ($this->number && !\preg_match('/\d/', $value)) { return false; } - if ($this->requireSpecialChar && !\preg_match('/[^\p{L}\p{N}\s]/u', $value)) { + if ($this->symbols && !\preg_match('/[^\p{L}\p{N}\s]/u', $value)) { return false; } 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 1133019c1f..b2c64a5a2b 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php @@ -113,10 +113,10 @@ class Get extends Action 'password-strength' => [ new Document(\array_merge([ 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, + 'uppercase' => false, + 'lowercase' => false, + 'number' => false, + 'symbols' => false, ], $auths['passwordStrength'] ?? [], [ '$id' => 'password-strength', ])), diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index a131cacbfd..9580b83ce1 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -51,10 +51,10 @@ class Update extends Action ], )) ->param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) - ->param('requireUppercase', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.', optional: true) - ->param('requireLowercase', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.', optional: true) - ->param('requireNumber', null, new Boolean(), 'Whether passwords must include at least one number.', optional: true) - ->param('requireSpecialChar', null, new Boolean(), 'Whether passwords must include at least one special character.', optional: true) + ->param('uppercase', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.', optional: true) + ->param('lowercase', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.', optional: true) + ->param('number', null, new Boolean(), 'Whether passwords must include at least one number.', optional: true) + ->param('symbols', null, new Boolean(), 'Whether passwords must include at least one symbol.', optional: true) ->inject('response') ->inject('dbForPlatform') ->inject('project') @@ -65,10 +65,10 @@ class Update extends Action public function action( ?int $minLength, - ?bool $requireUppercase, - ?bool $requireLowercase, - ?bool $requireNumber, - ?bool $requireSpecialChar, + ?bool $uppercase, + ?bool $lowercase, + ?bool $number, + ?bool $symbols, Response $response, Database $dbForPlatform, Document $project, @@ -78,26 +78,26 @@ class Update extends Action $auths = $project->getAttribute('auths', []); $auths['passwordStrength'] = \array_merge([ 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, + 'uppercase' => false, + 'lowercase' => false, + 'number' => false, + 'symbols' => false, ], $auths['passwordStrength'] ?? []); if ($minLength !== null) { $auths['passwordStrength']['minLength'] = $minLength; } - if ($requireUppercase !== null) { - $auths['passwordStrength']['requireUppercase'] = $requireUppercase; + if ($uppercase !== null) { + $auths['passwordStrength']['uppercase'] = $uppercase; } - if ($requireLowercase !== null) { - $auths['passwordStrength']['requireLowercase'] = $requireLowercase; + if ($lowercase !== null) { + $auths['passwordStrength']['lowercase'] = $lowercase; } - if ($requireNumber !== null) { - $auths['passwordStrength']['requireNumber'] = $requireNumber; + if ($number !== null) { + $auths['passwordStrength']['number'] = $number; } - if ($requireSpecialChar !== null) { - $auths['passwordStrength']['requireSpecialChar'] = $requireSpecialChar; + if ($symbols !== null) { + $auths['passwordStrength']['symbols'] = $symbols; } $project = $authorization->skip(fn () => $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php index 8d7a8ce2a7..5c69b3caac 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php @@ -105,10 +105,10 @@ class XList extends Action ]), new Document(\array_merge([ 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, + 'uppercase' => false, + 'lowercase' => false, + 'number' => false, + 'symbols' => false, ], $auths['passwordStrength'] ?? [], [ '$id' => 'password-strength', ])), diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index f9e6723fac..92a19e0ca1 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -85,10 +85,10 @@ class Create extends Action 'maxSessions' => 0, 'passwordStrength' => [ 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, + 'uppercase' => false, + 'lowercase' => false, + 'number' => false, + 'symbols' => false, ], 'passwordHistory' => 0, 'passwordDictionary' => false, diff --git a/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php b/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php index 356f6313ba..29a698f703 100644 --- a/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php +++ b/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php @@ -21,27 +21,27 @@ class PolicyPasswordStrength extends PolicyBase 'default' => 8, 'example' => 12, ]) - ->addRule('requireUppercase', [ + ->addRule('uppercase', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether passwords must include at least one uppercase letter.', 'default' => false, 'example' => true, ]) - ->addRule('requireLowercase', [ + ->addRule('lowercase', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether passwords must include at least one lowercase letter.', 'default' => false, 'example' => true, ]) - ->addRule('requireNumber', [ + ->addRule('number', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether passwords must include at least one number.', 'default' => false, 'example' => true, ]) - ->addRule('requireSpecialChar', [ + ->addRule('symbols', [ 'type' => self::TYPE_BOOLEAN, - 'description' => 'Whether passwords must include at least one special character.', + 'description' => 'Whether passwords must include at least one symbol.', 'default' => false, 'example' => true, ]); diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 217ba7eba5..3a708b374b 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -15,7 +15,7 @@ trait PoliciesBase return [ 'password-dictionary' => ['enabled'], 'password-history' => ['total'], - 'password-strength' => ['minLength', 'requireUppercase', 'requireLowercase', 'requireNumber', 'requireSpecialChar'], + 'password-strength' => ['minLength', 'uppercase', 'lowercase', 'number', 'symbols'], 'password-personal-data' => ['enabled'], 'session-alert' => ['enabled'], 'session-duration' => ['duration'], @@ -69,10 +69,10 @@ trait PoliciesBase $this->updatePasswordHistoryPolicy(5); $this->updatePasswordStrengthPolicy([ 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, + 'uppercase' => true, + 'lowercase' => true, + 'number' => true, + 'symbols' => true, ]); $this->updateSessionDurationPolicy(3600); $this->updateMembershipPrivacyPolicy([ @@ -97,10 +97,10 @@ trait PoliciesBase $this->assertSame(200, $passwordStrength['headers']['status-code']); $this->assertSame(12, $passwordStrength['body']['minLength']); - $this->assertSame(true, $passwordStrength['body']['requireUppercase']); - $this->assertSame(true, $passwordStrength['body']['requireLowercase']); - $this->assertSame(true, $passwordStrength['body']['requireNumber']); - $this->assertSame(true, $passwordStrength['body']['requireSpecialChar']); + $this->assertSame(true, $passwordStrength['body']['uppercase']); + $this->assertSame(true, $passwordStrength['body']['lowercase']); + $this->assertSame(true, $passwordStrength['body']['number']); + $this->assertSame(true, $passwordStrength['body']['symbols']); $this->assertSame(200, $sessionDuration['headers']['status-code']); $this->assertSame(3600, $sessionDuration['body']['duration']); @@ -199,10 +199,10 @@ trait PoliciesBase $this->updatePasswordHistoryPolicy(5); $this->updatePasswordStrengthPolicy([ 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, + 'uppercase' => true, + 'lowercase' => true, + 'number' => true, + 'symbols' => true, ]); $this->updateSessionDurationPolicy(3600); $this->updateMembershipPrivacyPolicy([ @@ -225,10 +225,10 @@ trait PoliciesBase $this->assertSame(true, $byId['password-dictionary']['enabled']); $this->assertSame(5, $byId['password-history']['total']); $this->assertSame(12, $byId['password-strength']['minLength']); - $this->assertSame(true, $byId['password-strength']['requireUppercase']); - $this->assertSame(true, $byId['password-strength']['requireLowercase']); - $this->assertSame(true, $byId['password-strength']['requireNumber']); - $this->assertSame(true, $byId['password-strength']['requireSpecialChar']); + $this->assertSame(true, $byId['password-strength']['uppercase']); + $this->assertSame(true, $byId['password-strength']['lowercase']); + $this->assertSame(true, $byId['password-strength']['number']); + $this->assertSame(true, $byId['password-strength']['symbols']); $this->assertSame(3600, $byId['session-duration']['duration']); $this->assertSame(true, $byId['membership-privacy']['userId']); $this->assertSame(true, $byId['membership-privacy']['userEmail']); @@ -473,27 +473,27 @@ trait PoliciesBase { $response = $this->updatePasswordStrengthPolicy([ 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, + 'uppercase' => true, + 'lowercase' => true, + 'number' => true, + 'symbols' => true, ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('password-strength', $response['body']['$id']); $this->assertSame(12, $response['body']['minLength']); - $this->assertSame(true, $response['body']['requireUppercase']); - $this->assertSame(true, $response['body']['requireLowercase']); - $this->assertSame(true, $response['body']['requireNumber']); - $this->assertSame(true, $response['body']['requireSpecialChar']); + $this->assertSame(true, $response['body']['uppercase']); + $this->assertSame(true, $response['body']['lowercase']); + $this->assertSame(true, $response['body']['number']); + $this->assertSame(true, $response['body']['symbols']); $policy = $this->getPolicy('password-strength'); $this->assertSame(200, $policy['headers']['status-code']); $this->assertSame(12, $policy['body']['minLength']); - $this->assertSame(true, $policy['body']['requireUppercase']); - $this->assertSame(true, $policy['body']['requireLowercase']); - $this->assertSame(true, $policy['body']['requireNumber']); - $this->assertSame(true, $policy['body']['requireSpecialChar']); + $this->assertSame(true, $policy['body']['uppercase']); + $this->assertSame(true, $policy['body']['lowercase']); + $this->assertSame(true, $policy['body']['number']); + $this->assertSame(true, $policy['body']['symbols']); // Cleanup $this->resetPasswordStrengthPolicy(); @@ -503,24 +503,24 @@ trait PoliciesBase { $response = $this->updatePasswordStrengthPolicy([ 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, + 'uppercase' => true, + 'lowercase' => true, + 'number' => true, + 'symbols' => true, ]); $this->assertSame(200, $response['headers']['status-code']); $response = $this->updatePasswordStrengthPolicy([ - 'requireLowercase' => false, + 'lowercase' => false, ]); $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(12, $response['body']['minLength']); - $this->assertSame(true, $response['body']['requireUppercase']); - $this->assertSame(false, $response['body']['requireLowercase']); - $this->assertSame(true, $response['body']['requireNumber']); - $this->assertSame(true, $response['body']['requireSpecialChar']); + $this->assertSame(true, $response['body']['uppercase']); + $this->assertSame(false, $response['body']['lowercase']); + $this->assertSame(true, $response['body']['number']); + $this->assertSame(true, $response['body']['symbols']); // Cleanup $this->resetPasswordStrengthPolicy(); @@ -556,10 +556,10 @@ trait PoliciesBase $this->assertSame(200, $response['headers']['status-code']); $this->assertSame(8, $response['body']['minLength']); - $this->assertSame(false, $response['body']['requireUppercase']); - $this->assertSame(false, $response['body']['requireLowercase']); - $this->assertSame(false, $response['body']['requireNumber']); - $this->assertSame(false, $response['body']['requireSpecialChar']); + $this->assertSame(false, $response['body']['uppercase']); + $this->assertSame(false, $response['body']['lowercase']); + $this->assertSame(false, $response['body']['number']); + $this->assertSame(false, $response['body']['symbols']); } public function testUpdatePasswordStrengthPolicyWithoutAuth(): void @@ -1292,10 +1292,10 @@ trait PoliciesBase { $this->updatePasswordStrengthPolicy([ 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, + 'uppercase' => false, + 'lowercase' => false, + 'number' => false, + 'symbols' => false, ]); } diff --git a/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php b/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php new file mode 100644 index 0000000000..6a005a5a9c --- /dev/null +++ b/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php @@ -0,0 +1,77 @@ +getProject()['$id']; + $apiKey = $this->getProject()['apiKey']; + + $serverHeaders = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + 'x-appwrite-response-format' => '1.9.4', + ]; + + $signupHeaders = [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ]; + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $serverHeaders, [ + 'minLength' => 12, + 'uppercase' => true, + 'lowercase' => true, + 'number' => true, + 'symbols' => true, + ]); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertSame(12, $response['body']['minLength']); + $this->assertTrue($response['body']['uppercase']); + $this->assertTrue($response['body']['lowercase']); + $this->assertTrue($response['body']['number']); + $this->assertTrue($response['body']['symbols']); + + $weak = $this->client->call(Client::METHOD_POST, '/account', $signupHeaders, [ + 'userId' => ID::unique(), + 'email' => 'strength_weak_' . uniqid() . '@localhost.test', + 'password' => 'password123!', + 'name' => 'Weak Password User', + ]); + + $this->assertSame(400, $weak['headers']['status-code']); + + $valid = $this->client->call(Client::METHOD_POST, '/account', $signupHeaders, [ + 'userId' => ID::unique(), + 'email' => 'strength_valid_' . uniqid() . '@localhost.test', + 'password' => 'Password123!', + 'name' => 'Valid Password User', + ]); + + $this->assertSame(201, $valid['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $serverHeaders, [ + 'minLength' => 8, + 'uppercase' => false, + 'lowercase' => false, + 'number' => false, + 'symbols' => false, + ]); + + $this->assertSame(200, $response['headers']['status-code']); + } +} diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 490f25153f..171f8f4465 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2936,18 +2936,18 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, + 'uppercase' => true, + 'lowercase' => true, + 'number' => true, + 'symbols' => true, ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(12, $response['body']['minLength']); - $this->assertEquals(true, $response['body']['requireUppercase']); - $this->assertEquals(true, $response['body']['requireLowercase']); - $this->assertEquals(true, $response['body']['requireNumber']); - $this->assertEquals(true, $response['body']['requireSpecialChar']); + $this->assertEquals(true, $response['body']['uppercase']); + $this->assertEquals(true, $response['body']['lowercase']); + $this->assertEquals(true, $response['body']['number']); + $this->assertEquals(true, $response['body']['symbols']); $weakPassword = 'password123!'; $validPassword = 'Password123!'; @@ -3063,18 +3063,18 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ 'minLength' => 8, - 'requireUppercase' => false, - 'requireLowercase' => false, - 'requireNumber' => false, - 'requireSpecialChar' => false, + 'uppercase' => false, + 'lowercase' => false, + 'number' => false, + 'symbols' => false, ]); $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(8, $response['body']['minLength']); - $this->assertEquals(false, $response['body']['requireUppercase']); - $this->assertEquals(false, $response['body']['requireLowercase']); - $this->assertEquals(false, $response['body']['requireNumber']); - $this->assertEquals(false, $response['body']['requireSpecialChar']); + $this->assertEquals(false, $response['body']['uppercase']); + $this->assertEquals(false, $response['body']['lowercase']); + $this->assertEquals(false, $response['body']['number']); + $this->assertEquals(false, $response['body']['symbols']); } #[Group('smtpAndTemplates')] diff --git a/tests/unit/Auth/Validator/PasswordDictionaryTest.php b/tests/unit/Auth/Validator/PasswordDictionaryTest.php index 1cb8e68e32..60b5ca7ae3 100644 --- a/tests/unit/Auth/Validator/PasswordDictionaryTest.php +++ b/tests/unit/Auth/Validator/PasswordDictionaryTest.php @@ -19,7 +19,7 @@ class PasswordDictionaryTest extends TestCase public function testValues(): void { - $this->assertEquals($this->object->isValid('1'), true); + $this->assertEquals($this->object->isValid('1'), false); // to check parent is being called $this->assertEquals($this->object->isValid('123456'), false); $this->assertEquals($this->object->isValid('password'), false); $this->assertEquals($this->object->isValid('myPasswordIsRight'), true); @@ -33,6 +33,6 @@ class PasswordDictionaryTest extends TestCase $pass .= 'p'; // 257 chars - $this->assertEquals($this->object->isValid($pass), true); + $this->assertEquals($this->object->isValid($pass), false); } } diff --git a/tests/unit/Auth/Validator/PasswordStrengthTest.php b/tests/unit/Auth/Validator/PasswordStrengthTest.php index 44062bbf91..d8170086bf 100644 --- a/tests/unit/Auth/Validator/PasswordStrengthTest.php +++ b/tests/unit/Auth/Validator/PasswordStrengthTest.php @@ -19,10 +19,10 @@ class PasswordStrengthTest extends TestCase { $validator = new PasswordStrength([ 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, + 'uppercase' => true, + 'lowercase' => true, + 'number' => true, + 'symbols' => true, ]); $this->assertFalse($validator->isValid('Password1!')); @@ -48,10 +48,10 @@ class PasswordStrengthTest extends TestCase { $validator = new PasswordStrength([ 'minLength' => 12, - 'requireUppercase' => true, - 'requireLowercase' => true, - 'requireNumber' => true, - 'requireSpecialChar' => true, + 'uppercase' => true, + 'lowercase' => true, + 'number' => true, + 'symbols' => true, ], true); $this->assertTrue($validator->isValid('')); From 50df089517c2bacd65414c67148136b1b93e6026 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 2 Jun 2026 19:34:10 +0400 Subject: [PATCH 15/16] Fix old password validation --- app/controllers/api/account.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 114d9f4a17..74501671ad 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -3274,7 +3274,7 @@ Http::patch('/v1/account/password') )) ->label('abuse-limit', 10) ->param('password', '', fn ($project, $passwordsDictionary) => new AllOf([new PasswordStrength($project->getAttribute('auths', [])['passwordStrength'] ?? []), new PasswordDictionary($passwordsDictionary, enabled: $project->getAttribute('auths', [])['passwordDictionary'] ?? false)], Validator::TYPE_STRING), 'New user password. Must be at least 8 chars.', false, ['project', 'passwordsDictionary']) - ->param('oldPassword', '', new Password(), 'Current user password. Must be at least 8 chars.', true) + ->param('oldPassword', '', new Text(256, 0), 'Current user password. Max length: 256 chars.', true) ->inject('response') ->inject('user') ->inject('project') From 06eb6edeab56c59ec830ec8a19a728193c82acd6 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 3 Jun 2026 14:25:05 +0400 Subject: [PATCH 16/16] Rename password strength minimum field --- .../Auth/Validator/PasswordStrength.php | 8 ++--- .../Project/Http/Project/Policies/Get.php | 2 +- .../Policies/PasswordStrength/Update.php | 10 +++--- .../Project/Http/Project/Policies/XList.php | 2 +- .../Modules/Projects/Http/Projects/Create.php | 2 +- .../Response/Model/PolicyPasswordStrength.php | 2 +- tests/e2e/Services/Project/PoliciesBase.php | 36 +++++++++---------- ...oliciesPasswordStrengthIntegrationTest.php | 6 ++-- .../Project/ProjectConsoleClientTest.php | 2 +- .../Projects/ProjectsConsoleClientTest.php | 10 +++--- .../Auth/Validator/PasswordStrengthTest.php | 8 ++--- 11 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/Appwrite/Auth/Validator/PasswordStrength.php b/src/Appwrite/Auth/Validator/PasswordStrength.php index 46be71ad9e..a9772cbd22 100644 --- a/src/Appwrite/Auth/Validator/PasswordStrength.php +++ b/src/Appwrite/Auth/Validator/PasswordStrength.php @@ -9,7 +9,7 @@ namespace Appwrite\Auth\Validator; */ class PasswordStrength extends Password { - protected int $minLength; + protected int $min; protected bool $uppercase; protected bool $lowercase; protected bool $number; @@ -19,7 +19,7 @@ class PasswordStrength extends Password { parent::__construct($allowEmpty); - $this->minLength = $policy['minLength'] ?? 8; + $this->min = $policy['min'] ?? 8; $this->uppercase = $policy['uppercase'] ?? false; $this->lowercase = $policy['lowercase'] ?? false; $this->number = $policy['number'] ?? false; @@ -29,7 +29,7 @@ class PasswordStrength extends Password public function getDescription(): string { $requirements = [ - 'between ' . $this->minLength . ' and 256 characters long', + 'between ' . $this->min . ' and 256 characters long', ]; if ($this->uppercase) { @@ -64,7 +64,7 @@ class PasswordStrength extends Password return true; } - if (\strlen($value) < $this->minLength) { + if (\strlen($value) < $this->min) { return false; } 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 b2c64a5a2b..feb1c1f263 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php @@ -112,7 +112,7 @@ class Get extends Action ], 'password-strength' => [ new Document(\array_merge([ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index 9580b83ce1..3fbcbe8b30 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -50,7 +50,7 @@ class Update extends Action ), ], )) - ->param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) + ->param('min', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) ->param('uppercase', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.', optional: true) ->param('lowercase', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.', optional: true) ->param('number', null, new Boolean(), 'Whether passwords must include at least one number.', optional: true) @@ -64,7 +64,7 @@ class Update extends Action } public function action( - ?int $minLength, + ?int $min, ?bool $uppercase, ?bool $lowercase, ?bool $number, @@ -77,15 +77,15 @@ class Update extends Action ): void { $auths = $project->getAttribute('auths', []); $auths['passwordStrength'] = \array_merge([ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, 'symbols' => false, ], $auths['passwordStrength'] ?? []); - if ($minLength !== null) { - $auths['passwordStrength']['minLength'] = $minLength; + if ($min !== null) { + $auths['passwordStrength']['min'] = $min; } if ($uppercase !== null) { $auths['passwordStrength']['uppercase'] = $uppercase; diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php index 5c69b3caac..0c74b86547 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php @@ -104,7 +104,7 @@ class XList extends Action 'total' => $auths['passwordHistory'] ?? 0, ]), new Document(\array_merge([ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index 92a19e0ca1..1560788d09 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -84,7 +84,7 @@ class Create extends Action 'limit' => 0, 'maxSessions' => 0, 'passwordStrength' => [ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php b/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php index 29a698f703..2a56cfa7e9 100644 --- a/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php +++ b/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php @@ -15,7 +15,7 @@ class PolicyPasswordStrength extends PolicyBase parent::__construct(); $this - ->addRule('minLength', [ + ->addRule('min', [ 'type' => self::TYPE_INTEGER, 'description' => 'Minimum password length required for user passwords.', 'default' => 8, diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 3a708b374b..e92335a61c 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -15,7 +15,7 @@ trait PoliciesBase return [ 'password-dictionary' => ['enabled'], 'password-history' => ['total'], - 'password-strength' => ['minLength', 'uppercase', 'lowercase', 'number', 'symbols'], + 'password-strength' => ['min', 'uppercase', 'lowercase', 'number', 'symbols'], 'password-personal-data' => ['enabled'], 'session-alert' => ['enabled'], 'session-duration' => ['duration'], @@ -68,7 +68,7 @@ trait PoliciesBase $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -96,7 +96,7 @@ trait PoliciesBase $this->assertSame(5, $passwordHistory['body']['total']); $this->assertSame(200, $passwordStrength['headers']['status-code']); - $this->assertSame(12, $passwordStrength['body']['minLength']); + $this->assertSame(12, $passwordStrength['body']['min']); $this->assertSame(true, $passwordStrength['body']['uppercase']); $this->assertSame(true, $passwordStrength['body']['lowercase']); $this->assertSame(true, $passwordStrength['body']['number']); @@ -198,7 +198,7 @@ trait PoliciesBase $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -224,7 +224,7 @@ trait PoliciesBase $this->assertSame(true, $byId['password-dictionary']['enabled']); $this->assertSame(5, $byId['password-history']['total']); - $this->assertSame(12, $byId['password-strength']['minLength']); + $this->assertSame(12, $byId['password-strength']['min']); $this->assertSame(true, $byId['password-strength']['uppercase']); $this->assertSame(true, $byId['password-strength']['lowercase']); $this->assertSame(true, $byId['password-strength']['number']); @@ -472,7 +472,7 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicy(): void { $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -481,7 +481,7 @@ trait PoliciesBase $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('password-strength', $response['body']['$id']); - $this->assertSame(12, $response['body']['minLength']); + $this->assertSame(12, $response['body']['min']); $this->assertSame(true, $response['body']['uppercase']); $this->assertSame(true, $response['body']['lowercase']); $this->assertSame(true, $response['body']['number']); @@ -489,7 +489,7 @@ trait PoliciesBase $policy = $this->getPolicy('password-strength'); $this->assertSame(200, $policy['headers']['status-code']); - $this->assertSame(12, $policy['body']['minLength']); + $this->assertSame(12, $policy['body']['min']); $this->assertSame(true, $policy['body']['uppercase']); $this->assertSame(true, $policy['body']['lowercase']); $this->assertSame(true, $policy['body']['number']); @@ -502,7 +502,7 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicyOptionPreservesOtherOptions(): void { $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -516,7 +516,7 @@ trait PoliciesBase ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(12, $response['body']['minLength']); + $this->assertSame(12, $response['body']['min']); $this->assertSame(true, $response['body']['uppercase']); $this->assertSame(false, $response['body']['lowercase']); $this->assertSame(true, $response['body']['number']); @@ -526,23 +526,23 @@ trait PoliciesBase $this->resetPasswordStrengthPolicy(); } - public function testUpdatePasswordStrengthPolicyMinLength(): void + public function testUpdatePasswordStrengthPolicyMin(): void { $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 8, + 'min' => 8, ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(8, $response['body']['minLength']); + $this->assertSame(8, $response['body']['min']); // Cleanup $this->resetPasswordStrengthPolicy(); } - public function testUpdatePasswordStrengthPolicyBelowMinLength(): void + public function testUpdatePasswordStrengthPolicyBelowMin(): void { $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders(), [ - 'minLength' => 7, + 'min' => 7, ]); $this->assertSame(400, $response['headers']['status-code']); @@ -555,7 +555,7 @@ trait PoliciesBase $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders(), []); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(8, $response['body']['minLength']); + $this->assertSame(8, $response['body']['min']); $this->assertSame(false, $response['body']['uppercase']); $this->assertSame(false, $response['body']['lowercase']); $this->assertSame(false, $response['body']['number']); @@ -565,7 +565,7 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicyWithoutAuth(): void { $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, ], false); $this->assertSame(401, $response['headers']['status-code']); @@ -1291,7 +1291,7 @@ trait PoliciesBase protected function resetPasswordStrengthPolicy(): void { $this->updatePasswordStrengthPolicy([ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php b/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php index 6a005a5a9c..4a8d132e2f 100644 --- a/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php +++ b/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php @@ -32,7 +32,7 @@ class PoliciesPasswordStrengthIntegrationTest extends Scope ]; $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $serverHeaders, [ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -40,7 +40,7 @@ class PoliciesPasswordStrengthIntegrationTest extends Scope ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(12, $response['body']['minLength']); + $this->assertSame(12, $response['body']['min']); $this->assertTrue($response['body']['uppercase']); $this->assertTrue($response['body']['lowercase']); $this->assertTrue($response['body']['number']); @@ -65,7 +65,7 @@ class PoliciesPasswordStrengthIntegrationTest extends Scope $this->assertSame(201, $valid['headers']['status-code']); $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $serverHeaders, [ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/tests/e2e/Services/Project/ProjectConsoleClientTest.php b/tests/e2e/Services/Project/ProjectConsoleClientTest.php index f2ae8ef904..8fecd23823 100644 --- a/tests/e2e/Services/Project/ProjectConsoleClientTest.php +++ b/tests/e2e/Services/Project/ProjectConsoleClientTest.php @@ -122,7 +122,7 @@ class ProjectConsoleClientTest extends Scope $this->assertArrayNotHasKey('authLimit', $response['body']); $this->assertArrayNotHasKey('authSessionsLimit', $response['body']); $this->assertArrayNotHasKey('authPasswordHistory', $response['body']); - $this->assertArrayNotHasKey('authPasswordStrengthMinLength', $response['body']); + $this->assertArrayNotHasKey('authPasswordStrengthMin', $response['body']); $this->assertArrayNotHasKey('authPasswordStrengthRequireUppercase', $response['body']); $this->assertArrayNotHasKey('authPasswordStrengthRequireLowercase', $response['body']); $this->assertArrayNotHasKey('authPasswordStrengthRequireNumber', $response['body']); diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 171f8f4465..94eb483f29 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2916,7 +2916,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'minLength' => 7, + 'min' => 7, ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -2926,7 +2926,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'minLength' => 12, + 'min' => 12, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -2943,7 +2943,7 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(12, $response['body']['minLength']); + $this->assertEquals(12, $response['body']['min']); $this->assertEquals(true, $response['body']['uppercase']); $this->assertEquals(true, $response['body']['lowercase']); $this->assertEquals(true, $response['body']['number']); @@ -3062,7 +3062,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, @@ -3070,7 +3070,7 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(8, $response['body']['minLength']); + $this->assertEquals(8, $response['body']['min']); $this->assertEquals(false, $response['body']['uppercase']); $this->assertEquals(false, $response['body']['lowercase']); $this->assertEquals(false, $response['body']['number']); diff --git a/tests/unit/Auth/Validator/PasswordStrengthTest.php b/tests/unit/Auth/Validator/PasswordStrengthTest.php index d8170086bf..af49acb148 100644 --- a/tests/unit/Auth/Validator/PasswordStrengthTest.php +++ b/tests/unit/Auth/Validator/PasswordStrengthTest.php @@ -18,7 +18,7 @@ class PasswordStrengthTest extends TestCase public function testConfiguredPolicy(): void { $validator = new PasswordStrength([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -34,10 +34,10 @@ class PasswordStrengthTest extends TestCase $this->assertTrue($validator->isValid('Password123€')); } - public function testMinLengthCanBeEight(): void + public function testMinimumCanBeEight(): void { $validator = new PasswordStrength([ - 'minLength' => 8, + 'min' => 8, ]); $this->assertFalse($validator->isValid('1234567')); @@ -47,7 +47,7 @@ class PasswordStrengthTest extends TestCase public function testAllowEmpty(): void { $validator = new PasswordStrength([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true,