mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix: restore remaining auth-policy limits dropped in the refactor
Three more accidental regressions from the same auth-settings refactor that swapped policy limits to the generic APP_LIMIT_COUNT: - User limit max was halved: 10,000 (APP_LIMIT_USERS) -> 5,000 (APP_LIMIT_COUNT copy-paste). Restore Range(0, APP_LIMIT_USERS), keeping 0 as the original "unlimited" sentinel. - Default session cap for new projects silently became unlimited (APP_LIMIT_USER_SESSIONS_DEFAULT dropped, default flipped to 0, and the enforcement fallback in shared/api.php followed suit). Restore the constant (10) and use it in both project-create paths and the fallback. - Session duration minimum was loosened from 60 to 5 seconds to speed up an integration test, not as a deliberate product decision. Restore the 60-second floor and adjust the test's polling windows.
This commit is contained in:
1 parent
189062745e
commit
5bf39b8fd2
8 files changed
+27
-18
No files matched your search
@@ -774,7 +774,7 @@ Http::shutdown()
|
||||
->inject('project')
|
||||
->inject('dbForProject')
|
||||
->action(function (Request $request, Response $response, Document $project, Database $dbForProject) {
|
||||
$sessionLimit = $project->getAttribute('auths', [])['maxSessions'] ?? 0;
|
||||
$sessionLimit = $project->getAttribute('auths', [])['maxSessions'] ?? APP_LIMIT_USER_SESSIONS_DEFAULT;
|
||||
|
||||
if ($sessionLimit === 0) {
|
||||
return;
|
||||
|
||||
@@ -33,6 +33,7 @@ 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_USER_SESSIONS_DEFAULT = 10;
|
||||
const APP_LIMIT_ANTIVIRUS = 20_000_000; //20MB
|
||||
const APP_LIMIT_ENCRYPTION = 20_000_000; //20MB
|
||||
const APP_LIMIT_COMPRESSION = 20_000_000; //20MB
|
||||
|
||||
@@ -86,7 +86,7 @@ class Create extends Action
|
||||
$auth = Config::getParam('auth', []);
|
||||
$auths = [
|
||||
'limit' => 0,
|
||||
'maxSessions' => 0,
|
||||
'maxSessions' => APP_LIMIT_USER_SESSIONS_DEFAULT,
|
||||
'passwordHistory' => 0,
|
||||
'passwordDictionary' => false,
|
||||
'duration' => TOKEN_EXPIRATION_LOGIN_LONG,
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ class Update extends Action
|
||||
)
|
||||
],
|
||||
))
|
||||
->param('duration', null, new Range(5, 31536000), 'Maximum session length in seconds. Minium allowed value is 5 second, and maximum is 1 year, which is 31536000 seconds.')
|
||||
->param('duration', null, new Range(60, 31536000), 'Maximum session length in seconds. Minium allowed value is 60 seconds, and maximum is 1 year, which is 31536000 seconds.')
|
||||
->inject('response')
|
||||
->inject('dbForPlatform')
|
||||
->inject('project')
|
||||
|
||||
@@ -51,7 +51,7 @@ class Update extends Action
|
||||
)
|
||||
],
|
||||
))
|
||||
->param('total', null, new Nullable(new Range(1, APP_LIMIT_COUNT)), 'Set the maximum number of users allowed in the project. Value can be between 1 and ' . APP_LIMIT_COUNT . ', or null to disable the limit.')
|
||||
->param('total', null, new Nullable(new Range(0, APP_LIMIT_USERS)), 'Set the maximum number of users allowed in the project. Value can be between 0 and ' . APP_LIMIT_USERS . '. Use 0 or null to disable the limit.')
|
||||
->inject('response')
|
||||
->inject('dbForPlatform')
|
||||
->inject('project')
|
||||
|
||||
@@ -82,7 +82,7 @@ class Create extends Action
|
||||
$auth = Config::getParam('auth', []);
|
||||
$auths = [
|
||||
'limit' => 0,
|
||||
'maxSessions' => 0,
|
||||
'maxSessions' => APP_LIMIT_USER_SESSIONS_DEFAULT,
|
||||
'passwordStrength' => [
|
||||
'min' => 8,
|
||||
'uppercase' => false,
|
||||
|
||||
@@ -707,10 +707,10 @@ trait PoliciesBase
|
||||
|
||||
public function testUpdateSessionDurationPolicyMin(): void
|
||||
{
|
||||
$response = $this->updateSessionDurationPolicy(5);
|
||||
$response = $this->updateSessionDurationPolicy(60);
|
||||
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
$this->assertSame(5, $response['body']['authDuration']);
|
||||
$this->assertSame(60, $response['body']['authDuration']);
|
||||
|
||||
// Cleanup
|
||||
$this->updateSessionDurationPolicy(31536000);
|
||||
@@ -726,7 +726,7 @@ trait PoliciesBase
|
||||
|
||||
public function testUpdateSessionDurationPolicyBelowMin(): void
|
||||
{
|
||||
$response = $this->updateSessionDurationPolicy(4);
|
||||
$response = $this->updateSessionDurationPolicy(59);
|
||||
|
||||
$this->assertSame(400, $response['headers']['status-code']);
|
||||
}
|
||||
@@ -930,10 +930,10 @@ trait PoliciesBase
|
||||
|
||||
public function testUpdateUserLimitPolicyMax(): void
|
||||
{
|
||||
$response = $this->updateUserLimitPolicy(5000);
|
||||
$response = $this->updateUserLimitPolicy(10000);
|
||||
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
$this->assertSame(5000, $response['body']['authLimit']);
|
||||
$this->assertSame(10000, $response['body']['authLimit']);
|
||||
|
||||
// Cleanup
|
||||
$this->updateUserLimitPolicy(null);
|
||||
@@ -953,16 +953,24 @@ trait PoliciesBase
|
||||
$this->assertSame(0, $project['body']['authLimit']);
|
||||
}
|
||||
|
||||
public function testUpdateUserLimitPolicyBelowMin(): void
|
||||
public function testUpdateUserLimitPolicyZeroMeansUnlimited(): void
|
||||
{
|
||||
$response = $this->updateUserLimitPolicy(0);
|
||||
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
$this->assertSame(0, $response['body']['authLimit']);
|
||||
}
|
||||
|
||||
public function testUpdateUserLimitPolicyBelowMin(): void
|
||||
{
|
||||
$response = $this->updateUserLimitPolicy(-1);
|
||||
|
||||
$this->assertSame(400, $response['headers']['status-code']);
|
||||
}
|
||||
|
||||
public function testUpdateUserLimitPolicyAboveMax(): void
|
||||
{
|
||||
$response = $this->updateUserLimitPolicy(5001);
|
||||
$response = $this->updateUserLimitPolicy(10001);
|
||||
|
||||
$this->assertSame(400, $response['headers']['status-code']);
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ final class PoliciesSessionDurationIntegrationTest extends Scope
|
||||
$this->assertSame($seconds, $response['body']['authDuration']);
|
||||
};
|
||||
|
||||
// Step 1: Set session duration to 5 seconds
|
||||
$setDuration(5);
|
||||
// Step 1: Set session duration to 60 seconds (the policy minimum)
|
||||
$setDuration(60);
|
||||
|
||||
// Step 2: Create user and a session
|
||||
$email = 'duration_' . uniqid() . '@localhost.test';
|
||||
@@ -73,14 +73,14 @@ final class PoliciesSessionDurationIntegrationTest extends Scope
|
||||
$response = $this->client->call(Client::METHOD_GET, '/account', $accountHeaders);
|
||||
$this->assertSame(200, $response['headers']['status-code']);
|
||||
|
||||
// Step 3: Poll until the 5s TTL elapses - session should expire
|
||||
// Step 3: Poll until the 60s TTL elapses - session should expire
|
||||
$this->assertEventually(function () use ($accountHeaders) {
|
||||
$response = $this->client->call(Client::METHOD_GET, '/account', $accountHeaders);
|
||||
$this->assertSame(401, $response['headers']['status-code']);
|
||||
}, 15_000, 500);
|
||||
}, 75_000, 500);
|
||||
|
||||
// Step 4: Raise duration to 10s - same session should still not be usable
|
||||
$setDuration(10);
|
||||
// Step 4: Raise duration to 120s - same session should still not be usable
|
||||
$setDuration(120);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/account', $accountHeaders);
|
||||
$this->assertSame(401, $response['headers']['status-code']);
|
||||
|
||||
Reference in new issue
Block a user