Deprecate dev keys creation + remove tests

This commit is contained in:
Matej Bačo committed 2026-07-21 16:54:45 +02:00
1 parent 9274be8128
commit 3dd52fdf2f
20 files changed
+29 -1035

No files matched your search

+1
View File
@@ -1472,6 +1472,7 @@ Http::error()
case 405: // Error allowed publicly
case 408: // Error allowed publicly
case 409: // Error allowed publicly
case 410: // Error allowed publicly
case 412: // Error allowed publicly
case 416: // Error allowed publicly
case 422: // Error allowed publicly
-15
View File
@@ -3,7 +3,6 @@
namespace Tests\E2E\Scopes;
use Tests\E2E\Client;
use Utopia\Database\DateTime;
use Utopia\Database\Helpers\ID;
use Utopia\System\System;
@@ -198,19 +197,6 @@ trait ProjectCustom
$this->assertNotEmpty($key['body']);
$this->assertNotEmpty($key['body']['secret']);
$devKey = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$id'] . '/dev-keys', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
'x-appwrite-project' => 'console',
], [
'name' => 'Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 3600),
]);
$this->assertEquals(201, $devKey['headers']['status-code']);
$this->assertNotEmpty($devKey['body']);
$this->assertNotEmpty($devKey['body']['secret']);
$webhook = $this->client->call(Client::METHOD_POST, '/webhooks', [
'origin' => 'http://localhost',
'content-type' => 'application/json',
@@ -253,7 +239,6 @@ trait ProjectCustom
'$id' => $project['body']['$id'],
'name' => $project['body']['name'],
'apiKey' => $key['body']['secret'],
'devKey' => $devKey['body']['secret'],
'webhookId' => $webhook['body']['$id'],
'signatureKey' => $webhook['body']['secret'],
];
+1 -1
View File
@@ -430,7 +430,7 @@ abstract class Scope extends TestCase
/**
* @return array
*/
abstract public function getHeaders(bool $devKey = true): array;
abstract public function getHeaders(): array;
/**
* @return array
+2 -6
View File
@@ -4,17 +4,13 @@ namespace Tests\E2E\Scopes;
trait SideClient
{
public function getHeaders(bool $devKey = true): array
public function getHeaders(): array
{
$headers = [
return [
'origin' => 'http://localhost',
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $this->getUser()['session'],
];
if ($devKey && isset($this->getProject()['devKey'])) {
$headers['x-appwrite-dev-key'] = $this->getProject()['devKey'];
}
return $headers;
}
/**
+1 -1
View File
@@ -4,7 +4,7 @@ namespace Tests\E2E\Scopes;
trait SideConsole
{
public function getHeaders(bool $devKey = true): array
public function getHeaders(): array
{
return [
'origin' => 'http://localhost',
+1 -1
View File
@@ -4,7 +4,7 @@ namespace Tests\E2E\Scopes;
trait SideNone
{
public function getHeaders(bool $devKey = true): array
public function getHeaders(): array
{
return [];
}
+1 -1
View File
@@ -9,7 +9,7 @@ trait SideServer
*/
protected $key = [];
public function getHeaders(bool $devKey = false): array
public function getHeaders(): array
{
return [
'x-appwrite-key' => $this->getProject()['apiKey']
@@ -93,7 +93,6 @@ trait AccountBase
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? '',
]), [
'userId' => ID::unique(),
'email' => '',
@@ -107,7 +106,6 @@ trait AccountBase
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? ''
]), [
'userId' => ID::unique(),
'email' => 'shortpass@appwrite.io',
@@ -125,7 +123,6 @@ trait AccountBase
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? ''
]), [
'userId' => ID::unique(),
'email' => 'longpass@appwrite.io',
@@ -302,7 +299,6 @@ trait AccountBase
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? ''
]), [
'userId' => ID::unique(),
'email' => $email,
@@ -166,7 +166,6 @@ final class AccountConsoleClientTest extends Scope
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? ''
]), [
'userId' => ID::unique(),
'email' => $email,
@@ -1387,7 +1387,6 @@ final class AccountCustomClientTest extends Scope
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? ''
]), [
'userId' => ID::unique(),
'email' => $data['email'],
@@ -1939,7 +1938,6 @@ final class AccountCustomClientTest extends Scope
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? ''
]), [
'userId' => ID::unique(),
'email' => $email,
@@ -58,7 +58,6 @@ trait DatabasesPermissionsBase
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? '',
], [
'userId' => $id,
'email' => $email,
@@ -15,7 +15,6 @@ trait DatabasesPermissionsScope
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? '',
], [
'userId' => $id,
'email' => $email,
@@ -91,7 +91,7 @@ final class AbuseTest extends Scope
$response = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], $this->getHeaders(false)), $graphQLPayload);
], $this->getHeaders()), $graphQLPayload);
$max = System::getEnv('_APP_GRAPHQL_MAX_QUERY_COMPLEXITY', '250');
+20 -20
View File
@@ -34,7 +34,7 @@ trait PresenceBase
*/
protected function getPresenceServerHeaders(): array
{
$headers = $this->getHeaders(false);
$headers = $this->getHeaders();
// Override the project API key added by `SideServer` with a presence-scoped key.
$headers['x-appwrite-key'] = $this->getPresenceApiKey();
@@ -136,7 +136,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'status' => 'online',
'metadata' => ['device' => 'web'],
@@ -153,7 +153,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false))
], $this->getHeaders())
);
$this->assertEquals(200, $get['headers']['status-code']);
@@ -190,7 +190,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'status' => 'online',
'metadata' => ['device' => 'web'],
@@ -207,7 +207,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'queries' => [
Query::equal('userId', [$upsert['body']['userId']])->toString(),
@@ -261,7 +261,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'queries' => [
Query::equal('userId', [$otherUserId])->toString(),
@@ -458,7 +458,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'status' => 'away',
'metadata' => ['source' => 'setup'],
@@ -471,7 +471,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false))
], $this->getHeaders())
);
$presenceId = $presence['$id'];
@@ -481,7 +481,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'status' => 'busy',
'metadata' => ['source' => 'update'],
@@ -641,7 +641,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'status' => 'temp-delete',
'metadata' => ['cleanup' => true],
@@ -654,7 +654,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false))
], $this->getHeaders())
);
$presenceId = $presence['$id'];
@@ -664,7 +664,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false))
], $this->getHeaders())
);
$this->assertEquals(204, $delete['headers']['status-code']);
@@ -706,7 +706,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'status' => 'cache-update-setup',
'metadata' => ['cache' => 'update-setup'],
@@ -716,7 +716,7 @@ trait PresenceBase
$headers = \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false));
], $this->getHeaders());
$presence = $this->resolvePresenceForUser($upsert['body']['userId'], $headers);
} else {
$presence = $this->setupPresence([
@@ -783,7 +783,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'status' => 'cache-purge-only-setup',
'metadata' => ['cache' => 'purge-only-setup'],
@@ -793,7 +793,7 @@ trait PresenceBase
$headers = \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false));
], $this->getHeaders());
$presence = $this->resolvePresenceForUser($upsert['body']['userId'], $headers);
} else {
$presence = $this->setupPresence([
@@ -859,7 +859,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'status' => 'cache-delete-setup',
'metadata' => ['cache' => 'delete-setup'],
@@ -869,7 +869,7 @@ trait PresenceBase
$headers = \array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false));
], $this->getHeaders());
$presence = $this->resolvePresenceForUser($upsert['body']['userId'], $headers);
} else {
$presence = $this->setupPresence([
@@ -920,7 +920,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'status' => 'ghost',
]
@@ -964,7 +964,7 @@ trait PresenceBase
\array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(false)),
], $this->getHeaders()),
[
'userId' => ID::unique(),
'status' => 'online',
@@ -31,7 +31,7 @@ final class PresenceConsoleClientTest extends Scope
// `x-appwrite-mode: admin` is forbidden for the console project, so authenticate
// as a console session user instead — `getUser()` signs them up against project=console.
public function getHeaders(bool $devKey = true): array
public function getHeaders(): array
{
return [
'origin' => 'http://localhost',
@@ -112,7 +112,6 @@ final class ProjectConsoleClientTest extends Scope
// Other fields
$this->assertIsArray($response['body']['labels']);
$this->assertIsArray($response['body']['devKeys']);
$this->assertSame(0, $response['body']['pingCount']);
$this->assertSame('', $response['body']['pingedAt']);
@@ -1088,7 +1088,6 @@ trait TemplatesBase
'origin' => 'http://localhost',
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-dev-key' => $this->getProject()['devKey'] ?? '',
], [
'userId' => ID::unique(),
'email' => $email,
@@ -465,21 +465,6 @@ trait ProjectsBase
return $project['body']['$id'];
}
protected function setupDevKey(mixed $params): array
{
$devKey = $this->client->call(Client::METHOD_POST, '/projects/' . $params['projectId'] . '/dev-keys', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), $params);
$this->assertEquals(201, $devKey['headers']['status-code'], 'Setup devKey failed with status code: ' . $devKey['headers']['status-code'] . ' and response: ' . json_encode($devKey['body'], JSON_PRETTY_PRINT));
return [
'$id' => $devKey['body']['$id'],
'secret' => $devKey['body']['secret'],
];
}
protected function setupUserMembership(mixed $params): array
{
// Create membership
@@ -582,7 +582,6 @@ final class ProjectsConsoleClientTest extends Scope
$this->assertArrayNotHasKey('platforms', $project);
$this->assertArrayNotHasKey('webhooks', $project);
$this->assertArrayNotHasKey('keys', $project);
$this->assertArrayNotHasKey('devKeys', $project);
$this->assertArrayNotHasKey('oAuthProviders', $project);
$this->assertArrayNotHasKey('smtpEnabled', $project);
$this->assertArrayNotHasKey('smtpHost', $project);
@@ -616,7 +615,6 @@ final class ProjectsConsoleClientTest extends Scope
$this->assertArrayNotHasKey('platforms', $project);
$this->assertArrayNotHasKey('webhooks', $project);
$this->assertArrayNotHasKey('keys', $project);
$this->assertArrayNotHasKey('devKeys', $project);
$this->assertArrayNotHasKey('oAuthProviders', $project);
$this->assertArrayNotHasKey('smtpEnabled', $project);
$this->assertArrayNotHasKey('authLimit', $project);
@@ -648,7 +646,6 @@ final class ProjectsConsoleClientTest extends Scope
$this->assertArrayNotHasKey('platforms', $project);
$this->assertArrayNotHasKey('webhooks', $project);
$this->assertArrayNotHasKey('keys', $project);
$this->assertArrayNotHasKey('devKeys', $project);
$this->assertArrayNotHasKey('oAuthProviders', $project);
$this->assertArrayNotHasKey('smtpEnabled', $project);
$this->assertArrayNotHasKey('authLimit', $project);
@@ -677,7 +674,6 @@ final class ProjectsConsoleClientTest extends Scope
$this->assertArrayNotHasKey('platforms', $p);
$this->assertArrayNotHasKey('webhooks', $p);
$this->assertArrayNotHasKey('keys', $p);
$this->assertArrayNotHasKey('devKeys', $p);
$this->assertArrayNotHasKey('oAuthProviders', $p);
$this->assertArrayNotHasKey('smtpEnabled', $p);
$this->assertArrayNotHasKey('authLimit', $p);
@@ -708,7 +704,6 @@ final class ProjectsConsoleClientTest extends Scope
$this->assertIsArray($project['platforms']);
$this->assertArrayNotHasKey('webhooks', $project);
$this->assertArrayNotHasKey('keys', $project);
$this->assertArrayNotHasKey('devKeys', $project);
$this->assertArrayNotHasKey('oAuthProviders', $project);
$this->assertArrayNotHasKey('smtpEnabled', $project);
$this->assertArrayNotHasKey('authLimit', $project);
@@ -739,7 +734,6 @@ final class ProjectsConsoleClientTest extends Scope
$this->assertIsArray($project['webhooks']);
$this->assertIsArray($project['keys']);
$this->assertArrayNotHasKey('platforms', $project);
$this->assertArrayNotHasKey('devKeys', $project);
$this->assertArrayNotHasKey('smtpEnabled', $project);
$this->assertArrayNotHasKey('authLimit', $project);
@@ -768,7 +762,6 @@ final class ProjectsConsoleClientTest extends Scope
$this->assertArrayHasKey('platforms', $project);
$this->assertArrayHasKey('webhooks', $project);
$this->assertArrayHasKey('keys', $project);
$this->assertArrayHasKey('devKeys', $project);
$this->assertArrayHasKey('oAuthProviders', $project);
$this->assertArrayHasKey('smtpEnabled', $project);
$this->assertArrayHasKey('smtpHost', $project);
@@ -891,23 +884,6 @@ final class ProjectsConsoleClientTest extends Scope
]);
$this->assertEquals(200, $response['headers']['status-code']);
// Create dev keys
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/dev-keys', array_merge([
'content-type' => 'application/json',
], $this->getHeaders()), [
'name' => 'Custom key 1',
'expire' => '2099-05-07 09:23:30.713',
]);
$this->assertEquals(201, $response['headers']['status-code']);
$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'
]);
$this->assertEquals(201, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/project/mock-phones', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $id,
@@ -1123,34 +1099,6 @@ final class ProjectsConsoleClientTest extends Scope
$this->assertEquals('custom1', $response['body']['labels'][0]);
$this->assertEquals('custom2', $response['body']['labels'][1]);
$this->assertCount(2, $response['body']['devKeys']);
$this->assertEquals('Custom key 1', $response['body']['devKeys'][0]['name']);
$this->assertEquals('Custom key 2', $response['body']['devKeys'][1]['name']);
$this->assertEquals('2099-05-07T09:23:30.713+00:00', $response['body']['devKeys'][0]['expire']);
$this->assertEquals('2099-05-07T11:23:30.713+00:00', $response['body']['devKeys'][1]['expire']);
foreach ($response['body']['devKeys'] as $devKey) {
$this->assertIsString($devKey['$id']);
$this->assertNotEmpty($devKey['$id']);
$this->assertIsString($devKey['secret']);
$this->assertNotEmpty($devKey['secret']);
$this->assertIsString($devKey['accessedAt']);
$this->assertEmpty($devKey['accessedAt']);
$this->assertIsString($devKey['$createdAt']);
$this->assertNotEmpty($devKey['$createdAt']);
$this->assertNotFalse(\strtotime($devKey['$createdAt']));
$this->assertIsString($devKey['$updatedAt']);
$this->assertNotEmpty($devKey['$updatedAt']);
$this->assertNotFalse(\strtotime($devKey['$updatedAt']));
$this->assertIsArray($devKey['sdks']);
$this->assertCount(0, $devKey['sdks']);
}
$this->assertCount(2, $response['body']['authMockNumbers']);
$this->assertEquals('+421123456789', $response['body']['authMockNumbers'][0]['phone']);
$this->assertEquals('+420987654321', $response['body']['authMockNumbers'][1]['phone']);
@@ -6299,885 +6247,6 @@ final class ProjectsConsoleClientTest extends Scope
$this->assertEquals(404, $response['headers']['status-code']);
}
/**
* Devkeys Tests starts here ------------------------------------------------
*/
#[Group('abuseEnabled')]
public function testCreateProjectDevKey(): void
{
/**
* Test for SUCCESS
*/
$id = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testCreateProjectDevKey',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$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)
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('Key Test', $response['body']['name']);
$this->assertNotEmpty($response['body']['secret']);
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertEmpty($response['body']['accessedAt']);
/** Create a second dev key */
$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)
]);
$this->assertEquals(201, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals('Dev Key Test', $response['body']['name']);
$this->assertNotEmpty($response['body']['secret']);
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertEmpty($response['body']['accessedAt']);
/**
* Test for FAILURE
*/
/** TEST expiry date is required */
$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'
]);
$this->assertEquals(400, $res['headers']['status-code']);
}
#[Group('abuseEnabled')]
public function testListProjectDevKey(): void
{
/**
* Test for SUCCESS
*/
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testListProjectDevKey',
'region' => System::getEnv('_APP_REGION', 'default')
]);
/** Create devKey 1 */
$this->setupDevKey([
'projectId' => $projectId,
'name' => 'Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 36000)
]);
/** Create devKey 2 */
$this->setupDevKey([
'projectId' => $projectId,
'name' => 'Dev Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 36000)
]);
/** List all dev keys */
$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()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(2, $response['body']['total']);
/** List dev keys with limit */
$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()
]
]);
$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([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(2, $response['body']['total']);
$this->assertEquals('Key Test', $response['body']['devKeys'][0]['name']);
$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([
'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']); // No dev keys expired
/**
* Test for FAILURE
*/
/** Test for search with invalid query */
$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()
]
]);
$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
{
/**
* Test for SUCCESS
*/
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testGetProjectDevKey',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$devKey = $this->setupDevKey([
'projectId' => $projectId,
'name' => 'Dev Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 36000)
]);
$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()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($devKey['$id'], $response['body']['$id']);
$this->assertEquals('Dev Key Test', $response['body']['name']);
$this->assertNotEmpty($response['body']['secret']);
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertEmpty($response['body']['accessedAt']);
/**
* Test for FAILURE
*/
$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()), []);
$this->assertEquals(404, $response['headers']['status-code']);
}
#[Group('abuseEnabled')]
public function testGetDevKeyWithSdks(): void
{
/**
* Test for SUCCESS
*/
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testGetDevKeyWithSdks',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$devKey = $this->setupDevKey([
'projectId' => $projectId,
'name' => 'Dev Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 36000)
]);
/** Use dev key with python sdk */
$res = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-dev-key' => $devKey['secret'],
'x-sdk-name' => 'python'
], [
'email' => 'user@appwrite.io',
'password' => 'password'
]);
$this->assertEquals(401, $res['headers']['status-code']);
/** Use dev key with php sdk */
$res = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-dev-key' => $devKey['secret'],
'x-sdk-name' => 'php'
], [
'email' => 'user@appwrite.io',
'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([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertArrayHasKey('sdks', $response['body']);
$this->assertCount(2, $response['body']['sdks']);
$this->assertContains('python', $response['body']['sdks']);
$this->assertContains('php', $response['body']['sdks']);
}
#[Group('abuseEnabled')]
public function testNoHostValidationWithDevKey(): void
{
/**
* Test for SUCCESS
*/
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testNoHostValidationWithDevKey',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$devKey = $this->setupDevKey([
'projectId' => $projectId,
'name' => 'Dev Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 36000)
]);
$provider = 'mock';
$appId = '1';
$secret = '123456';
$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'],
], $this->getHeaders()), [
'provider' => $provider,
'appId' => $appId,
'secret' => $secret,
'enabled' => true,
]);
$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, [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], [
'success' => '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, [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-dev-key' => $devKey['secret']
], [
'success' => 'https://example.com',
'failure' => 'https://example.com'
], followRedirects: false);
$this->assertEquals(301, $response['headers']['status-code']);
$this->assertArrayHasKey('location', $response['headers']);
$location = $response['headers']['location'];
$locationClient = new Client();
$locationClient->setEndpoint('');
$locationClient->addHeader('x-appwrite-dev-key', $devKey['secret']);
$response = $locationClient->call(Client::METHOD_GET, $location, followRedirects: false);
$this->assertEquals(301, $response['headers']['status-code']);
$this->assertArrayHasKey('location', $response['headers']);
$location = $response['headers']['location'];
$this->assertStringStartsWith('http://appwrite:/v1/account/sessions/oauth2/callback/mock/', $response['headers']['location']);
$response = $locationClient->call(Client::METHOD_GET, $location, followRedirects: false);
$this->assertEquals(301, $response['headers']['status-code']);
$this->assertArrayHasKey('location', $response['headers']);
$location = $response['headers']['location'];
$this->assertStringStartsWith('http://appwrite:/v1/account/sessions/oauth2/mock/redirect', $response['headers']['location']);
$response = $locationClient->call(Client::METHOD_GET, $location, followRedirects: false);
$this->assertEquals(301, $response['headers']['status-code']);
$this->assertSame('https://example.com/#', $response['headers']['location']);
/** Ensure any hostname is allowed */
$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'
], [
'success' => '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, [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-dev-key' => $devKey['secret'],
'referer' => '',
'origin' => 'https://domain-without-rule.com'
], [
'success' => 'https://domain-without-rule.com',
'failure' => 'https://domain-without-rule.com'
], followRedirects: false);
$this->assertEquals(301, $response['headers']['status-code']);
/** Test hostname in Magic URL */
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/magic-url', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], [
'userId' => ID::unique(),
'email' => 'user@appwrite.io',
'url' => 'https://example.com',
]);
$this->assertEquals(400, $response['headers']['status-code']);
/** Test hostname in Magic URL with devKey */
$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']
], [
'userId' => ID::unique(),
'email' => 'user@appwrite.io',
'url' => 'https://example.com',
]);
$this->assertEquals(201, $response['headers']['status-code']);
}
public function testRuleOAuthRedirect(): void
{
// Prepare project
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testRuleOAuthRedirect',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$provider = 'mock';
$appId = '1';
$secret = '123456';
// Prepare OAuth provider
$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'],
], $this->getHeaders()), [
'provider' => $provider,
'appId' => $appId,
'secret' => $secret,
'enabled' => true,
]);
$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';
$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
]);
$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, [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'referer' => 'https://' . $domain,
'origin' => '',
], [
'success' => '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', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'origin' => '',
'referer' => 'https://mockserver.com',
], [
'code' => 'any-code',
'state' => \json_encode([
'success' => 'https://domain-without-rule.com',
'failure' => 'https://domain-without-rule.com'
]),
'error' => '',
'error_description' => '',
], followRedirects: false);
$this->assertEquals(400, $response['headers']['status-code']);
$this->assertStringContainsString('project_invalid_success_url', (string) $response['body']);
// Ensure rule's domain can be redirect URL
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider, [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'referer' => 'https://' . $domain,
'origin' => '',
], [
'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', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'origin' => '',
'referer' => 'https://mockserver.com',
], [
'code' => 'any-code',
'state' => \json_encode([
'success' => 'https://' . $domain,
'failure' => 'https://' . $domain
]),
'error' => '',
'error_deescription' => '',
], followRedirects: false);
$this->assertEquals(301, $response['headers']['status-code']);
$this->assertStringContainsString('https://' . $domain, (string) $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,
'origin' => '',
], [
'userId' => ID::unique(),
'email' => 'user@appwrite.io',
'url' => 'https://domain-without-rule.com',
]);
$this->assertEquals(400, $response['headers']['status-code']);
// Ensure rule's domain can 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,
'origin' => '',
], [
'userId' => ID::unique(),
'email' => 'user@appwrite.io',
'url' => 'https://' . $domain,
]);
$this->assertEquals(201, $response['headers']['status-code']);
}
public function testOAuthRedirectWithCustomSchemeState(): void
{
// Prepare project
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testOAuthRedirectWithCustomSchemeState',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$provider = 'mock';
$appId = '1';
$secret = '123456';
// Prepare OAuth provider
$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'],
], $this->getHeaders()), [
'provider' => $provider,
'appId' => $appId,
'secret' => $secret,
'enabled' => true,
]);
$this->assertEquals(200, $response['headers']['status-code']);
$scheme = 'appwrite-callback-' . $projectId;
$state = \json_encode([
'success' => $scheme . ':///',
'failure' => $scheme . ':///'
]);
$response = $this->client->call(Client::METHOD_GET, '/account/sessions/oauth2/' . $provider . '/redirect', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'origin' => '',
'referer' => '',
], [
'code' => 'any-code',
'state' => $state,
'error' => 'access_denied',
'error_description' => 'test',
], followRedirects: false);
$this->assertEquals(301, $response['headers']['status-code']);
$this->assertStringStartsWith($scheme . '://', $response['headers']['location']);
$this->assertStringContainsString('error=', (string) $response['headers']['location']);
}
#[Group('abuseEnabled')]
public function testCorsWithDevKey(): void
{
/**
* Test for SUCCESS
*/
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testCorsWithDevKey',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$devKey = $this->setupDevKey([
'projectId' => $projectId,
'name' => 'Dev Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 36000)
]);
$origin = 'http://example.com';
/**
* Test CORS without Dev Key (should fail due to origin)
*/
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'origin' => $origin,
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], [
'email' => 'user@appwrite.io',
'password' => 'password'
]);
$this->assertEquals(403, $response['headers']['status-code']);
$this->assertNotEquals($origin, $response['headers']['access-control-allow-origin'] ?? null);
// 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)
*/
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'origin' => $origin,
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-dev-key' => $devKey['secret']
], [
'email' => 'user@appwrite.io',
'password' => 'password'
]);
$this->assertEquals(401, $response['headers']['status-code']);
$this->assertEquals($origin, $response['headers']['access-control-allow-origin'] ?? null);
}
public function testConsoleCorsWithTrustedProject(): void
{
$trustedProjectIds = ['trusted-project', 'another-trusted-project']; // Set in env variable
$projectIds = \array_merge($trustedProjectIds, ['untrusted-project-id']);
foreach ($projectIds as $projectId) {
try {
// Create project
$this->setupProject([
'projectId' => $projectId,
'name' => 'Trusted project',
'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';
$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
]);
$this->assertEquals(201, $rule['headers']['status-code']);
// Talk to Console APIs from trusted project domain
$currencies = $this->client->call(
Client::METHOD_GET,
'/locale/currencies',
array_merge(
$this->getHeaders(),
[
'content-type' => 'application/json',
'x-appwrite-project' => 'console',
'origin' => 'http://' . $domain
]
)
);
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']);
} else {
// Untrusted projects cannot
$this->assertEquals(403, $currencies['headers']['status-code']);
$this->assertArrayNotHasKey('access-control-allow-origin', $currencies['headers']);
}
} finally {
// Cleanup
$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']);
}
}
}
#[Group('abuseEnabled')]
public function testNoRateLimitWithDevKey(): void
{
/**
* Test for SUCCESS
*/
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testNoRateLimitWithDevKey',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$devKey = $this->setupDevKey([
'projectId' => $projectId,
'name' => 'Dev Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 36000)
]);
/**
* Test for SUCCESS
*/
for ($i = 0; $i < 10; $i++) {
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], [
'email' => 'user@appwrite.io',
'password' => 'password'
]);
$this->assertEquals(401, $response['headers']['status-code']);
}
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
], [
'email' => 'user@appwrite.io',
'password' => 'password'
]);
$this->assertEquals(429, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-dev-key' => $devKey['secret']
], [
'email' => 'user@appwrite.io',
'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([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'Key Test',
'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']
], [
'email' => 'user@appwrite.io',
'password' => 'password'
]);
$this->assertEquals(429, $response['headers']['status-code']);
/**
* Test for FAILURE after expire
*/
$devKey = $this->setupDevKey([
'projectId' => $projectId,
'name' => 'Dev Key Test Expire 5 seconds',
'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']
], [
'email' => 'user@appwrite.io',
'password' => 'password'
]);
$this->assertEquals(401, $response['headers']['status-code']);
$this->assertEventually(function () use ($projectId, $devKey) {
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-dev-key' => $devKey['secret']
], [
'email' => 'user@appwrite.io',
'password' => 'password'
]);
$this->assertEquals(429, $response['headers']['status-code']);
}, 15_000, 500);
}
#[Group('abuseEnabled')]
public function testUpdateProjectDevKey(): void
{
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testUpdateProjectDevKey',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$devKey = $this->setupDevKey([
'projectId' => $projectId,
'name' => 'Dev Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 36000)
]);
$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),
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($devKey['$id'], $response['body']['$id']);
$this->assertEquals('Key Test Update', $response['body']['name']);
$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([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertNotEmpty($response['body']['$id']);
$this->assertEquals($devKey['$id'], $response['body']['$id']);
$this->assertEquals('Key Test Update', $response['body']['name']);
$this->assertArrayHasKey('accessedAt', $response['body']);
$this->assertEmpty($response['body']['accessedAt']);
}
#[Group('abuseEnabled')]
public function testDeleteProjectDevKey(): void
{
$projectId = $this->setupProject([
'projectId' => ID::unique(),
'name' => 'testDeleteProjectDevKey',
'region' => System::getEnv('_APP_REGION', 'default')
]);
$devKey = $this->setupDevKey([
'projectId' => $projectId,
'name' => 'Dev Key Test',
'expire' => DateTime::addSeconds(new \DateTime(), 36000)
]);
$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()), []);
$this->assertEquals(204, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
/**
* Get rate limit trying to use the deleted key
*/
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
'content-type' => 'application/json',
'x-appwrite-project' => $projectId,
'x-appwrite-dev-key' => $devKey['secret']
], [
'email' => 'user@appwrite.io',
'password' => 'password'
]);
$this->assertEquals(429, $response['headers']['status-code']);
$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()), []);
$this->assertEquals(404, $response['headers']['status-code']);
/**
* Test for FAILURE
*/
$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()), []);
$this->assertEquals(404, $response['headers']['status-code']);
}
/**
* Devkeys Tests ends here ------------------------------------------------
*/
public function testProjectLabels(): void
{
// Setup: Prepare team
@@ -209,37 +209,6 @@ final class V19Test extends TestCase
$this->assertEquals($expected, $result);
}
public static function projectProvider(): \Iterator
{
yield 'remove devKeys field' => [
[
'devKeys' => ['key1', 'key2'],
'name' => 'test-project',
],
[
'name' => 'test-project',
]
];
yield 'handle content without devKeys' => [
[
'name' => 'test-project',
],
[
'name' => 'test-project',
]
];
}
#[DataProvider('projectProvider')]
public function testProject(array $content, array $expected): void
{
$model = Response::MODEL_PROJECT;
$result = $this->filter->parse($content, $model);
$this->assertEquals($expected, $result);
}
public static function providerRepositoryProvider(): \Iterator
{
yield 'remove runtime field' => [