diff --git a/app/init/constants.php b/app/init/constants.php index 0a754f1b48..53ae5c9c32 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -31,6 +31,8 @@ const APP_MODE_ADMIN = 'admin'; const APP_PAGING_LIMIT = 12; const APP_LIMIT_COUNT = 5000; const APP_LIMIT_USERS = 10_000; +const APP_LIMIT_USER_PASSWORD_HISTORY = 20; +const APP_LIMIT_USER_SESSIONS_MAX = 100; const APP_LIMIT_ANTIVIRUS = 20_000_000; //20MB const APP_LIMIT_ENCRYPTION = 20_000_000; //20MB const APP_LIMIT_COMPRESSION = 20_000_000; //20MB diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php index be611e299f..dcfde09aaa 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordHistory/Update.php @@ -53,7 +53,7 @@ class Update extends Action ) ], )) - ->param('total', null, new Nullable(new Range(1, APP_LIMIT_COUNT)), 'Set the password history length per user. Value can be between 1 and ' . APP_LIMIT_COUNT . ', or null to disable the limit.') + ->param('total', null, new Nullable(new Range(1, APP_LIMIT_USER_PASSWORD_HISTORY)), 'Set the password history length per user. Value can be between 1 and ' . APP_LIMIT_USER_PASSWORD_HISTORY . ', or null to disable the limit.') ->inject('response') ->inject('dbForPlatform') ->inject('project') diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php index 93ae339b79..92ca2bccb7 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/SessionLimit/Update.php @@ -12,7 +12,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Authorization; use Utopia\Platform\Scope\HTTP; -use Utopia\Validator\Nullable; use Utopia\Validator\Range; class Update extends Action @@ -51,7 +50,7 @@ class Update extends Action ) ], )) - ->param('total', null, new Nullable(new Range(1, APP_LIMIT_COUNT)), 'Set the maximum number of sessions allowed per user. Value can be between 1 and ' . APP_LIMIT_COUNT . ', or null to disable the limit.') + ->param('total', null, new Range(1, APP_LIMIT_USER_SESSIONS_MAX), 'Set the maximum number of sessions allowed per user. Value can be between 1 and ' . APP_LIMIT_USER_SESSIONS_MAX . '.') ->inject('response') ->inject('dbForPlatform') ->inject('project') @@ -61,7 +60,7 @@ class Update extends Action } public function action( - ?int $total, + int $total, Response $response, Database $dbForPlatform, Document $project, @@ -69,12 +68,7 @@ class Update extends Action Event $queueForEvents, ): void { $auths = $project->getAttribute('auths', []); - - if (\is_null($total)) { - $auths['maxSessions'] = 0; - } else { - $auths['maxSessions'] = $total; - } + $auths['maxSessions'] = $total; $updates = new Document([ 'auths' => $auths, diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index e92335a61c..e865671cd9 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -405,10 +405,10 @@ trait PoliciesBase public function testUpdatePasswordHistoryPolicyMax(): void { - $response = $this->updatePasswordHistoryPolicy(5000); + $response = $this->updatePasswordHistoryPolicy(20); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(5000, $response['body']['authPasswordHistory']); + $this->assertSame(20, $response['body']['authPasswordHistory']); // Cleanup $this->updatePasswordHistoryPolicy(null); @@ -437,7 +437,7 @@ trait PoliciesBase public function testUpdatePasswordHistoryPolicyAboveMax(): void { - $response = $this->updatePasswordHistoryPolicy(5001); + $response = $this->updatePasswordHistoryPolicy(21); $this->assertSame(400, $response['headers']['status-code']); } @@ -851,21 +851,10 @@ trait PoliciesBase public function testUpdateSessionLimitPolicyMax(): void { - $response = $this->updateSessionLimitPolicy(5000); + $response = $this->updateSessionLimitPolicy(100); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(5000, $response['body']['authSessionsLimit']); - - // Cleanup - $this->updateSessionLimitPolicy(10); - } - - public function testUpdateSessionLimitPolicyDisable(): void - { - $response = $this->updateSessionLimitPolicy(null); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(0, $response['body']['authSessionsLimit']); + $this->assertSame(100, $response['body']['authSessionsLimit']); // Cleanup $this->updateSessionLimitPolicy(10); @@ -880,7 +869,7 @@ trait PoliciesBase public function testUpdateSessionLimitPolicyAboveMax(): void { - $response = $this->updateSessionLimitPolicy(5001); + $response = $this->updateSessionLimitPolicy(101); $this->assertSame(400, $response['headers']['status-code']); }