2019-09-16 08:17:10 +12:00
|
|
|
<?php
|
|
|
|
|
2020-01-12 02:58:02 +13:00
|
|
|
namespace Tests\E2E\Scopes;
|
2019-09-16 08:17:10 +12:00
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
|
2020-01-12 02:58:02 +13:00
|
|
|
trait ProjectCustom
|
2019-09-16 08:17:10 +12:00
|
|
|
{
|
2020-01-12 02:58:02 +13:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2020-01-12 10:53:57 +13:00
|
|
|
protected static $project = [];
|
2019-09-16 08:17:10 +12:00
|
|
|
|
2020-01-12 02:58:02 +13:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getProject(): array
|
2019-09-16 08:17:10 +12:00
|
|
|
{
|
2020-10-28 08:48:38 +13:00
|
|
|
if (!empty(self::$project)) {
|
2020-01-12 10:53:57 +13:00
|
|
|
return self::$project;
|
2020-01-12 02:58:02 +13:00
|
|
|
}
|
2019-09-16 08:17:10 +12:00
|
|
|
|
2019-10-21 19:01:07 +13:00
|
|
|
$team = $this->client->call(Client::METHOD_POST, '/teams', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-01-13 10:28:26 +13:00
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
2019-11-30 07:26:06 +13:00
|
|
|
'x-appwrite-project' => 'console',
|
2019-10-21 19:01:07 +13:00
|
|
|
], [
|
2021-07-19 19:50:51 +12:00
|
|
|
'teamId' => 'unique()',
|
2019-10-21 19:01:07 +13:00
|
|
|
'name' => 'Demo Project Team',
|
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $team['headers']['status-code']);
|
|
|
|
$this->assertEquals('Demo Project Team', $team['body']['name']);
|
2020-02-17 20:16:11 +13:00
|
|
|
$this->assertNotEmpty($team['body']['$id']);
|
2019-10-21 19:01:07 +13:00
|
|
|
|
|
|
|
$project = $this->client->call(Client::METHOD_POST, '/projects', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-01-13 10:28:26 +13:00
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
2019-11-30 07:26:06 +13:00
|
|
|
'x-appwrite-project' => 'console',
|
2019-10-21 19:01:07 +13:00
|
|
|
], [
|
2021-07-19 20:55:20 +12:00
|
|
|
'projectId' => 'unique()',
|
2019-10-21 19:01:07 +13:00
|
|
|
'name' => 'Demo Project',
|
2020-02-17 20:16:11 +13:00
|
|
|
'teamId' => $team['body']['$id'],
|
2019-10-21 19:01:07 +13:00
|
|
|
'description' => 'Demo Project Description',
|
|
|
|
'logo' => '',
|
|
|
|
'url' => 'https://appwrite.io',
|
|
|
|
'legalName' => '',
|
|
|
|
'legalCountry' => '',
|
|
|
|
'legalState' => '',
|
|
|
|
'legalCity' => '',
|
|
|
|
'legalAddress' => '',
|
|
|
|
'legalTaxId' => '',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $project['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($project['body']);
|
|
|
|
|
2020-02-17 20:16:11 +13:00
|
|
|
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$id'] . '/keys', [
|
2019-10-21 19:01:07 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2020-01-13 10:28:26 +13:00
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
2019-11-30 07:26:06 +13:00
|
|
|
'x-appwrite-project' => 'console',
|
2019-10-21 19:01:07 +13:00
|
|
|
], [
|
|
|
|
'name' => 'Demo Project Key',
|
2020-01-12 02:58:02 +13:00
|
|
|
'scopes' => [
|
2020-01-13 00:46:39 +13:00
|
|
|
'users.read',
|
|
|
|
'users.write',
|
|
|
|
'teams.read',
|
|
|
|
'teams.write',
|
2022-06-22 22:51:49 +12:00
|
|
|
'databases.read',
|
|
|
|
'databases.write',
|
2020-01-13 00:46:39 +13:00
|
|
|
'collections.read',
|
|
|
|
'collections.write',
|
|
|
|
'documents.read',
|
|
|
|
'documents.write',
|
2020-01-12 10:53:57 +13:00
|
|
|
'files.read',
|
2020-01-13 00:46:39 +13:00
|
|
|
'files.write',
|
2021-06-16 18:07:35 +12:00
|
|
|
'buckets.read',
|
2021-06-15 18:38:05 +12:00
|
|
|
'buckets.write',
|
2020-05-06 08:37:59 +12:00
|
|
|
'functions.read',
|
|
|
|
'functions.write',
|
2020-12-30 20:26:01 +13:00
|
|
|
'execution.read',
|
|
|
|
'execution.write',
|
2020-01-13 00:46:39 +13:00
|
|
|
'locale.read',
|
|
|
|
'avatars.read',
|
2020-06-07 18:01:35 +12:00
|
|
|
'health.read',
|
2020-01-12 02:58:02 +13:00
|
|
|
],
|
2019-10-21 19:01:07 +13:00
|
|
|
]);
|
|
|
|
|
2020-11-21 01:35:16 +13:00
|
|
|
$this->assertEquals(201, $key['headers']['status-code']);
|
2019-10-21 19:01:07 +13:00
|
|
|
$this->assertNotEmpty($key['body']);
|
|
|
|
$this->assertNotEmpty($key['body']['secret']);
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$webhook = $this->client->call(Client::METHOD_POST, '/projects/' . $project['body']['$id'] . '/webhooks', [
|
2020-11-21 10:03:14 +13:00
|
|
|
'origin' => 'http://localhost',
|
2020-11-21 01:35:16 +13:00
|
|
|
'content-type' => 'application/json',
|
2020-11-21 10:03:14 +13:00
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
], [
|
2020-11-21 01:35:16 +13:00
|
|
|
'name' => 'Webhook Test',
|
|
|
|
'events' => [
|
2022-06-22 22:51:49 +12:00
|
|
|
'databases.*',
|
2022-04-04 18:30:07 +12:00
|
|
|
'functions.*',
|
|
|
|
'buckets.*',
|
|
|
|
'teams.*',
|
|
|
|
'users.*'
|
2020-11-21 01:35:16 +13:00
|
|
|
],
|
|
|
|
'url' => 'http://request-catcher:5000/webhook',
|
|
|
|
'security' => false,
|
|
|
|
'httpUser' => '',
|
|
|
|
'httpPass' => '',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $webhook['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($webhook['body']);
|
2020-01-12 02:58:02 +13:00
|
|
|
|
2020-01-12 10:53:57 +13:00
|
|
|
self::$project = [
|
2020-02-17 20:16:11 +13:00
|
|
|
'$id' => $project['body']['$id'],
|
2020-01-12 02:58:02 +13:00
|
|
|
'name' => $project['body']['name'],
|
|
|
|
'apiKey' => $key['body']['secret'],
|
2020-12-04 06:56:07 +13:00
|
|
|
'webhookId' => $webhook['body']['$id'],
|
2022-06-08 03:11:07 +12:00
|
|
|
'signatureKey' => $webhook['body']['signatureKey'],
|
2020-01-12 02:58:02 +13:00
|
|
|
];
|
2019-11-04 08:05:26 +13:00
|
|
|
|
2020-01-12 10:53:57 +13:00
|
|
|
return self::$project;
|
2019-10-21 19:01:07 +13:00
|
|
|
}
|
2021-05-14 02:47:35 +12:00
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
public function getNewKey(array $scopes)
|
|
|
|
{
|
2021-05-14 02:47:35 +12:00
|
|
|
|
|
|
|
$projectId = self::$project['$id'];
|
|
|
|
|
|
|
|
$key = $this->client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
], [
|
|
|
|
'name' => 'Demo Project Key',
|
|
|
|
'scopes' => $scopes,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $key['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($key['body']);
|
|
|
|
$this->assertNotEmpty($key['body']['secret']);
|
|
|
|
|
|
|
|
return $key['body']['secret'];
|
|
|
|
}
|
2019-09-30 19:13:40 +13:00
|
|
|
}
|