Address password policy review feedback

This commit is contained in:
Torsten Dittmann committed 2026-06-01 14:45:03 +04:00
1 parent 16b86db541
commit 141996576f
12 files changed
+99 -385

No files matched your search

+5 -3
View File
@@ -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')
+5 -2
View File
@@ -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')
+5 -3
View File
@@ -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;
}
@@ -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;
@@ -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;
@@ -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);
}
}
@@ -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', []);
+30 -16
View File
@@ -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
@@ -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
@@ -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')]
@@ -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);
}
}
@@ -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([