mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Fix existing tests
This commit is contained in:
@@ -13,6 +13,14 @@ class V23 extends Filter
|
||||
case 'project.updateMembershipPrivacyPolicy':
|
||||
$content = $this->parseUpdateMembershipPrivacyPolicy($content);
|
||||
break;
|
||||
case 'project.updateSessionAlertPolicy':
|
||||
$content = $this->parseUpdateSessionAlertPolicy($content);
|
||||
break;
|
||||
case 'project.updateUserLimitPolicy':
|
||||
case 'project.updatePasswordHistoryPolicy':
|
||||
case 'project.updateSessionLimitPolicy':
|
||||
$content = $this->parseLimitToTotal($content);
|
||||
break;
|
||||
}
|
||||
|
||||
return $content;
|
||||
@@ -23,6 +31,31 @@ class V23 extends Filter
|
||||
$content['userId'] = false;
|
||||
$content['userPhone'] = false;
|
||||
|
||||
if (isset($content['mfa'])) {
|
||||
$content['userMFA'] = $content['mfa'];
|
||||
unset($content['mfa']);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function parseUpdateSessionAlertPolicy(array $content): array
|
||||
{
|
||||
if (isset($content['alerts'])) {
|
||||
$content['enabled'] = $content['alerts'];
|
||||
unset($content['alerts']);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function parseLimitToTotal(array $content): array
|
||||
{
|
||||
if (isset($content['limit'])) {
|
||||
$content['total'] = $content['limit'];
|
||||
unset($content['limit']);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2050,6 +2050,7 @@ class AccountCustomClientTest extends Scope
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => 'console',
|
||||
'x-appwrite-response-format' => '1.9.1',
|
||||
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
||||
]), [
|
||||
'alerts' => true,
|
||||
|
||||
@@ -82,27 +82,30 @@ class PoliciesSessionLimitIntegrationTest extends Scope
|
||||
|
||||
// New session pushes old one out
|
||||
$session2 = $login();
|
||||
$this->assertEventually(function () use ($getAccount, $session1, $session2) {
|
||||
$this->assertSame(200, $getAccount($session2)['headers']['status-code']);
|
||||
$this->assertSame(401, $getAccount($session1)['headers']['status-code']);
|
||||
}, 15_000, 500);
|
||||
|
||||
\sleep(3); // Giving ::shutdown() hooks some time
|
||||
|
||||
$this->assertSame(200, $getAccount($session2)['headers']['status-code']);
|
||||
$this->assertSame(401, $getAccount($session1)['headers']['status-code']);
|
||||
|
||||
// Step 2: Session limit = 2
|
||||
$setSessionLimit(2);
|
||||
|
||||
$session3 = $login();
|
||||
$this->assertEventually(function () use ($getAccount, $session2, $session3) {
|
||||
$this->assertSame(200, $getAccount($session2)['headers']['status-code']);
|
||||
$this->assertSame(200, $getAccount($session3)['headers']['status-code']);
|
||||
}, 15_000, 500);
|
||||
|
||||
\sleep(3); // Giving ::shutdown() hooks some time
|
||||
|
||||
$this->assertSame(200, $getAccount($session2)['headers']['status-code']);
|
||||
$this->assertSame(200, $getAccount($session3)['headers']['status-code']);
|
||||
|
||||
// Step 3: 4th session evicts session2 (oldest), session3 and session4 remain
|
||||
$session4 = $login();
|
||||
$this->assertEventually(function () use ($getAccount, $session2, $session3, $session4) {
|
||||
$this->assertSame(200, $getAccount($session4)['headers']['status-code']);
|
||||
$this->assertSame(200, $getAccount($session3)['headers']['status-code']);
|
||||
$this->assertSame(401, $getAccount($session2)['headers']['status-code']);
|
||||
}, 15_000, 500);
|
||||
|
||||
\sleep(3); // Giving ::shutdown() hooks some time
|
||||
|
||||
$this->assertSame(200, $getAccount($session4)['headers']['status-code']);
|
||||
$this->assertSame(200, $getAccount($session3)['headers']['status-code']);
|
||||
$this->assertSame(401, $getAccount($session2)['headers']['status-code']);
|
||||
|
||||
// Step 4: Disable session limit, create 5 new sessions, all should remain usable
|
||||
$setSessionLimit(null);
|
||||
@@ -112,10 +115,8 @@ class PoliciesSessionLimitIntegrationTest extends Scope
|
||||
$newSessions[] = $login();
|
||||
}
|
||||
|
||||
$this->assertEventually(function () use ($getAccount, $newSessions) {
|
||||
foreach ($newSessions as $index => $sessionCookie) {
|
||||
$this->assertSame(200, $getAccount($sessionCookie)['headers']['status-code'], 'Session #' . ($index + 1) . ' should remain valid when limit is disabled');
|
||||
}
|
||||
}, 15_000, 500);
|
||||
foreach ($newSessions as $index => $sessionCookie) {
|
||||
$this->assertSame(200, $getAccount($sessionCookie)['headers']['status-code'], 'Session #' . ($index + 1) . ' should remain valid when limit is disabled');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,6 +331,7 @@ trait ProjectsBase
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 0,
|
||||
]);
|
||||
|
||||
@@ -1255,6 +1255,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'alerts' => true,
|
||||
]);
|
||||
@@ -1397,6 +1398,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'duration' => 10, // Set session duration to 10 seconds
|
||||
]);
|
||||
@@ -1464,6 +1466,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'duration' => 600, // seconds
|
||||
]);
|
||||
@@ -1484,6 +1487,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'duration' => TOKEN_EXPIRATION_LOGIN_LONG,
|
||||
]);
|
||||
@@ -1540,6 +1544,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'enabled' => false,
|
||||
]);
|
||||
@@ -1556,6 +1561,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'enabled' => true,
|
||||
]);
|
||||
@@ -1874,6 +1880,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 1,
|
||||
]);
|
||||
@@ -1952,6 +1959,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 0,
|
||||
]);
|
||||
@@ -1989,6 +1997,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 0,
|
||||
]);
|
||||
@@ -2001,6 +2010,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 1,
|
||||
]);
|
||||
@@ -2072,6 +2082,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 10,
|
||||
]);
|
||||
@@ -2090,6 +2101,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 25,
|
||||
]);
|
||||
@@ -2103,6 +2115,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 1,
|
||||
]);
|
||||
@@ -2176,6 +2189,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 0,
|
||||
]);
|
||||
@@ -2436,6 +2450,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'enabled' => true,
|
||||
]);
|
||||
@@ -2493,6 +2508,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'limit' => 0,
|
||||
]);
|
||||
@@ -2506,6 +2522,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'enabled' => false,
|
||||
]);
|
||||
@@ -2525,6 +2542,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'enabled' => true,
|
||||
]);
|
||||
@@ -2637,6 +2655,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||
$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',
|
||||
], $this->getHeaders()), [
|
||||
'enabled' => false,
|
||||
]);
|
||||
|
||||
@@ -254,7 +254,7 @@ trait TeamsBaseClient
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertNotEmpty($response['body']['$id']);
|
||||
$this->assertFalse($response['body']['mfa']);
|
||||
$this->assertNotEmpty($response['body']['userId']);
|
||||
$this->assertArrayHasKey($response['body']['userId']);
|
||||
$this->assertArrayHasKey('userName', $response['body']);
|
||||
$this->assertArrayHasKey('userEmail', $response['body']);
|
||||
$this->assertNotEmpty($response['body']['teamId']);
|
||||
|
||||
Reference in New Issue
Block a user