2020-07-08 21:11:12 +12:00
|
|
|
<?php
|
|
|
|
|
2020-12-27 01:10:14 +13:00
|
|
|
namespace Tests\E2E\Services\Projects;
|
2020-07-08 21:11:12 +12:00
|
|
|
|
2022-07-06 06:55:20 +12:00
|
|
|
use Appwrite\Auth\Auth;
|
2023-04-29 19:43:33 +12:00
|
|
|
use Appwrite\Extend\Exception;
|
2020-07-08 21:11:12 +12:00
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\ProjectConsole;
|
|
|
|
use Tests\E2E\Scopes\SideClient;
|
|
|
|
use Tests\E2E\Client;
|
2023-12-10 23:03:01 +13:00
|
|
|
use Tests\E2E\General\UsageTest;
|
2022-07-13 01:32:39 +12:00
|
|
|
use Utopia\Database\DateTime;
|
2023-12-20 23:55:09 +13:00
|
|
|
use Utopia\Database\Document;
|
2022-12-15 04:42:25 +13:00
|
|
|
use Utopia\Database\Helpers\ID;
|
2023-12-20 23:55:09 +13:00
|
|
|
use Utopia\Database\Query;
|
2020-07-08 21:11:12 +12:00
|
|
|
|
|
|
|
class ProjectsConsoleClientTest extends Scope
|
|
|
|
{
|
|
|
|
use ProjectsBase;
|
|
|
|
use ProjectConsole;
|
|
|
|
use SideClient;
|
|
|
|
|
2023-03-14 20:21:56 +13:00
|
|
|
/**
|
|
|
|
* @group smtpAndTemplates
|
2023-07-19 19:24:58 +12:00
|
|
|
* @group projectsCRUD */
|
2020-07-08 21:11:12 +12:00
|
|
|
public function testCreateProject(): array
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'teamId' => ID::unique(),
|
2020-07-08 21:11:12 +12:00
|
|
|
'name' => 'Project Test',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $team['headers']['status-code']);
|
|
|
|
$this->assertEquals('Project Test', $team['body']['name']);
|
|
|
|
$this->assertNotEmpty($team['body']['$id']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'projectId' => ID::unique(),
|
2020-07-08 21:11:12 +12:00
|
|
|
'name' => 'Project Test',
|
|
|
|
'teamId' => $team['body']['$id'],
|
2022-10-01 01:22:11 +13:00
|
|
|
'region' => 'default',
|
2020-07-08 21:11:12 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('Project Test', $response['body']['name']);
|
|
|
|
$this->assertEquals($team['body']['$id'], $response['body']['teamId']);
|
|
|
|
$this->assertArrayHasKey('platforms', $response['body']);
|
|
|
|
$this->assertArrayHasKey('webhooks', $response['body']);
|
|
|
|
$this->assertArrayHasKey('keys', $response['body']);
|
|
|
|
|
|
|
|
$projectId = $response['body']['$id'];
|
|
|
|
|
2022-11-25 10:37:11 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'projectId' => ID::unique(),
|
|
|
|
'name' => 'Project Test',
|
|
|
|
'teamId' => $team['body']['$id'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('Project Test', $response['body']['name']);
|
|
|
|
$this->assertEquals($team['body']['$id'], $response['body']['teamId']);
|
|
|
|
$this->assertArrayHasKey('platforms', $response['body']);
|
|
|
|
$this->assertArrayHasKey('webhooks', $response['body']);
|
|
|
|
$this->assertArrayHasKey('keys', $response['body']);
|
|
|
|
|
2020-07-08 21:11:12 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'projectId' => ID::unique(),
|
2020-07-08 21:11:12 +12:00
|
|
|
'name' => '',
|
|
|
|
'teamId' => $team['body']['$id'],
|
2022-10-01 01:22:11 +13:00
|
|
|
'region' => 'default'
|
2020-07-08 21:11:12 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2021-08-10 00:47:16 +12:00
|
|
|
|
2020-07-08 21:11:12 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'projectId' => ID::unique(),
|
2020-07-08 21:11:12 +12:00
|
|
|
'name' => 'Project Test',
|
2022-10-01 01:22:11 +13:00
|
|
|
'region' => 'default'
|
2020-07-08 21:11:12 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2023-04-29 19:43:33 +12:00
|
|
|
return [
|
|
|
|
'projectId' => $projectId,
|
|
|
|
'teamId' => $team['body']['$id']
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateProject
|
|
|
|
*/
|
|
|
|
public function testCreateDuplicateProject($data)
|
|
|
|
{
|
|
|
|
$teamId = $data['teamId'] ?? '';
|
|
|
|
$projectId = $data['projectId'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'projectId' => $projectId,
|
|
|
|
'name' => 'Project Duplicate',
|
|
|
|
'teamId' => $teamId,
|
|
|
|
'region' => 'default'
|
|
|
|
]);
|
|
|
|
|
2023-04-30 08:24:45 +12:00
|
|
|
$this->assertEquals(409, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals(409, $response['body']['code']);
|
2023-04-29 19:43:33 +12:00
|
|
|
$this->assertEquals(Exception::PROJECT_ALREADY_EXISTS, $response['body']['type']);
|
2020-07-08 21:11:12 +12:00
|
|
|
}
|
|
|
|
|
2023-05-10 18:46:30 +12:00
|
|
|
/** @group projectsCRUD */
|
2023-05-02 19:28:46 +12:00
|
|
|
public function testTransferProjectTeam()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'teamId' => ID::unique(),
|
2023-05-10 18:46:30 +12:00
|
|
|
'name' => 'Team 1',
|
2023-05-02 19:28:46 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $team['headers']['status-code']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertEquals('Team 1', $team['body']['name']);
|
2023-05-02 19:28:46 +12:00
|
|
|
$this->assertNotEmpty($team['body']['$id']);
|
|
|
|
|
|
|
|
$team1 = $team['body']['$id'];
|
|
|
|
|
|
|
|
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'teamId' => ID::unique(),
|
2023-05-10 18:46:30 +12:00
|
|
|
'name' => 'Team 2',
|
2023-05-02 19:28:46 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $team['headers']['status-code']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertEquals('Team 2', $team['body']['name']);
|
2023-05-02 19:28:46 +12:00
|
|
|
$this->assertNotEmpty($team['body']['$id']);
|
|
|
|
|
|
|
|
$team2 = $team['body']['$id'];
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'projectId' => ID::unique(),
|
2023-05-10 18:46:30 +12:00
|
|
|
'name' => 'Team 1 Project',
|
2023-05-02 19:28:46 +12:00
|
|
|
'teamId' => $team1,
|
|
|
|
'region' => 'default',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertEquals('Team 1 Project', $response['body']['name']);
|
2023-05-02 19:28:46 +12:00
|
|
|
$this->assertEquals($team1, $response['body']['teamId']);
|
|
|
|
$this->assertArrayHasKey('platforms', $response['body']);
|
|
|
|
$this->assertArrayHasKey('webhooks', $response['body']);
|
|
|
|
$this->assertArrayHasKey('keys', $response['body']);
|
|
|
|
|
|
|
|
$projectId = $response['body']['$id'];
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $projectId . '/team', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'teamId' => $team2,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertEquals('Team 1 Project', $response['body']['name']);
|
2023-05-02 19:28:46 +12:00
|
|
|
$this->assertEquals($team2, $response['body']['teamId']);
|
|
|
|
}
|
|
|
|
|
2020-07-09 03:20:18 +12:00
|
|
|
/**
|
2023-05-10 18:46:30 +12:00
|
|
|
* @group projectsCRUD
|
2020-07-09 03:20:18 +12:00
|
|
|
* @depends testCreateProject
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
public function testListProject($data): array
|
2020-07-09 03:20:18 +12:00
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2020-07-09 03:20:18 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2021-09-23 19:01:10 +12:00
|
|
|
|
2020-07-09 03:20:18 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', 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']);
|
|
|
|
$this->assertEquals($id, $response['body']['projects'][0]['$id']);
|
|
|
|
$this->assertEquals('Project Test', $response['body']['projects'][0]['name']);
|
|
|
|
|
2021-09-23 19:01:10 +12:00
|
|
|
/**
|
|
|
|
* Test search queries
|
|
|
|
*/
|
2021-09-21 20:22:13 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders(), [
|
|
|
|
'search' => $id
|
|
|
|
]));
|
|
|
|
|
2021-09-23 19:01:10 +12:00
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
2023-05-04 13:26:03 +12:00
|
|
|
$this->assertEquals($response['body']['total'], 3);
|
2021-09-23 19:01:10 +12:00
|
|
|
$this->assertIsArray($response['body']['projects']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertCount(3, $response['body']['projects']);
|
2021-09-23 19:01:10 +12:00
|
|
|
$this->assertEquals($response['body']['projects'][0]['name'], 'Project Test');
|
2021-09-21 20:22:13 +12:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders(), [
|
|
|
|
'search' => 'Project Test'
|
|
|
|
]));
|
|
|
|
|
2021-09-23 19:01:10 +12:00
|
|
|
$this->assertEquals($response['headers']['status-code'], 200);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertEquals(3, $response['body']['total']);
|
2021-09-23 19:01:10 +12:00
|
|
|
$this->assertIsArray($response['body']['projects']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertCount(3, $response['body']['projects']);
|
2021-09-23 19:01:10 +12:00
|
|
|
$this->assertEquals($response['body']['projects'][0]['$id'], $data['projectId']);
|
2021-09-21 20:22:13 +12:00
|
|
|
|
2021-08-10 00:47:16 +12:00
|
|
|
/**
|
2022-09-01 04:00:14 +12:00
|
|
|
* Test pagination
|
2021-08-10 00:47:16 +12:00
|
|
|
*/
|
|
|
|
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'teamId' => ID::unique(),
|
2021-08-10 00:47:16 +12:00
|
|
|
'name' => 'Project Test 2',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $team['headers']['status-code']);
|
|
|
|
$this->assertEquals('Project Test 2', $team['body']['name']);
|
|
|
|
$this->assertNotEmpty($team['body']['$id']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'projectId' => ID::unique(),
|
2021-08-10 00:47:16 +12:00
|
|
|
'name' => 'Project Test 2',
|
|
|
|
'teamId' => $team['body']['$id'],
|
2022-10-01 01:22:11 +13:00
|
|
|
'region' => 'default'
|
2021-08-10 00:47:16 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('Project Test 2', $response['body']['name']);
|
|
|
|
$this->assertEquals($team['body']['$id'], $response['body']['teamId']);
|
|
|
|
$this->assertArrayHasKey('platforms', $response['body']);
|
|
|
|
$this->assertArrayHasKey('webhooks', $response['body']);
|
|
|
|
$this->assertArrayHasKey('keys', $response['body']);
|
|
|
|
|
2022-09-01 04:00:14 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
2022-10-03 20:16:49 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 23:55:09 +13:00
|
|
|
'queries' => [
|
|
|
|
Query::equal('teamId', [$team['body']['$id']])->toString(),
|
|
|
|
],
|
2022-10-03 20:16:49 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertCount(1, $response['body']['projects']);
|
2022-10-03 20:54:55 +13:00
|
|
|
$this->assertEquals($team['body']['$id'], $response['body']['projects'][0]['teamId']);
|
2022-10-03 20:16:49 +13:00
|
|
|
|
2022-09-01 04:00:14 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 23:55:09 +13:00
|
|
|
'queries' => [
|
|
|
|
Query::limit(1)->toString(),
|
|
|
|
],
|
2022-09-01 04:00:14 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertCount(1, $response['body']['projects']);
|
|
|
|
$this->assertEquals('Project Test', $response['body']['projects'][0]['name']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 23:55:09 +13:00
|
|
|
'queries' => [
|
|
|
|
Query::offset(3)->toString(),
|
|
|
|
],
|
2022-09-01 04:00:14 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertCount(1, $response['body']['projects']);
|
|
|
|
$this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 23:55:09 +13:00
|
|
|
'queries' => [
|
|
|
|
Query::equal('name', ['Project Test 2'])->toString(),
|
|
|
|
],
|
2022-09-01 04:00:14 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertCount(1, $response['body']['projects']);
|
|
|
|
$this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 23:55:09 +13:00
|
|
|
'queries' => [
|
|
|
|
Query::orderDesc()->toString(),
|
|
|
|
],
|
2022-09-01 04:00:14 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertCount(4, $response['body']['projects']);
|
2022-09-01 04:00:14 +12:00
|
|
|
$this->assertEquals('Project Test 2', $response['body']['projects'][0]['name']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertEquals('Team 1 Project', $response['body']['projects'][1]['name']);
|
2022-09-01 04:00:14 +12:00
|
|
|
|
2021-08-10 00:47:16 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', 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']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertCount(4, $response['body']['projects']);
|
2021-08-10 00:47:16 +12:00
|
|
|
$this->assertEquals('Project Test', $response['body']['projects'][0]['name']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertEquals('Team 1 Project', $response['body']['projects'][2]['name']);
|
2021-08-10 00:47:16 +12:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-04-19 04:21:45 +12:00
|
|
|
], $this->getHeaders()), [
|
2023-12-20 23:55:09 +13:00
|
|
|
'queries' => [
|
|
|
|
Query::cursorAfter(new Document(['$id' => $response['body']['projects'][0]['$id']]))->toString(),
|
|
|
|
],
|
2021-08-10 00:47:16 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2023-05-10 18:46:30 +12:00
|
|
|
$this->assertCount(3, $response['body']['projects']);
|
|
|
|
$this->assertEquals('Team 1 Project', $response['body']['projects'][1]['name']);
|
2021-10-05 23:30:33 +13:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-04-19 04:21:45 +12:00
|
|
|
], $this->getHeaders()), [
|
2023-12-20 23:55:09 +13:00
|
|
|
'queries' => [
|
|
|
|
Query::cursorBefore(new Document(['$id' => $response['body']['projects'][0]['$id']]))->toString(),
|
|
|
|
],
|
2021-10-05 23:30:33 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertCount(1, $response['body']['projects']);
|
|
|
|
$this->assertEquals('Project Test', $response['body']['projects'][0]['name']);
|
|
|
|
|
2020-07-09 03:20:18 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2021-10-05 23:30:33 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-04-19 04:21:45 +12:00
|
|
|
], $this->getHeaders()), [
|
2023-12-20 23:55:09 +13:00
|
|
|
'queries' => [
|
|
|
|
Query::cursorAfter(new Document(['$id' => 'unknown']))->toString(),
|
|
|
|
],
|
2021-10-05 23:30:33 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2020-07-09 03:20:18 +12:00
|
|
|
|
2020-07-09 21:13:14 +12:00
|
|
|
return $data;
|
2020-07-09 03:20:18 +12:00
|
|
|
}
|
|
|
|
|
2020-07-08 21:11:12 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProject
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
public function testGetProject($data): array
|
2020-07-08 21:11:12 +12:00
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2020-07-08 21:11:12 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
2020-07-08 21:11:12 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertEquals($id, $response['body']['$id']);
|
|
|
|
$this->assertEquals('Project Test', $response['body']['name']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/empty', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/id-is-really-long-id-is-really-long-id-is-really-long-id-is-really-long', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2020-10-28 08:48:38 +13:00
|
|
|
return $data;
|
2020-07-08 21:11:12 +12:00
|
|
|
}
|
2020-07-09 03:20:18 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateProject
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
public function testGetProjectUsage($data): array
|
2020-07-09 03:20:18 +12:00
|
|
|
{
|
2024-01-10 00:58:36 +13:00
|
|
|
$this->markTestIncomplete(
|
|
|
|
'This test is failing right now due to functions collection.'
|
|
|
|
);
|
2020-07-09 03:20:18 +12:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2023-10-25 20:39:59 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/project/usage', array_merge([
|
2020-07-09 03:20:18 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2023-12-10 23:03:01 +13:00
|
|
|
], $this->getHeaders()), [
|
|
|
|
'startDate' => UsageTest::getToday(),
|
|
|
|
'endDate' => UsageTest::getTomorrow(),
|
|
|
|
]);
|
2020-07-09 03:20:18 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2023-12-10 23:03:01 +13:00
|
|
|
$this->assertEquals(8, count($response['body']));
|
2020-07-09 03:20:18 +12:00
|
|
|
$this->assertNotEmpty($response['body']);
|
2023-08-21 00:29:43 +12:00
|
|
|
$this->assertIsArray($response['body']['requests']);
|
2021-08-29 20:11:29 +12:00
|
|
|
$this->assertIsArray($response['body']['network']);
|
2023-11-27 09:57:57 +13:00
|
|
|
$this->assertIsNumeric($response['body']['executionsTotal']);
|
|
|
|
$this->assertIsNumeric($response['body']['documentsTotal']);
|
|
|
|
$this->assertIsNumeric($response['body']['databasesTotal']);
|
|
|
|
$this->assertIsNumeric($response['body']['bucketsTotal']);
|
|
|
|
$this->assertIsNumeric($response['body']['usersTotal']);
|
|
|
|
$this->assertIsNumeric($response['body']['filesStorageTotal']);
|
|
|
|
|
2020-07-09 03:20:18 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/empty', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/id-is-really-long-id-is-really-long-id-is-really-long-id-is-really-long', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2020-10-28 08:48:38 +13:00
|
|
|
return $data;
|
2020-07-09 21:13:14 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-01-10 00:58:36 +13:00
|
|
|
* @depends testCreateProject
|
2020-07-09 21:13:14 +12:00
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
public function testUpdateProject($data): array
|
2020-07-09 21:13:14 +12:00
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2020-07-09 21:13:14 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id, array_merge([
|
2020-07-09 21:13:14 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'projectId' => ID::unique(),
|
2020-07-09 21:13:14 +12:00
|
|
|
'name' => 'Project Test 2',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('Project Test 2', $response['body']['name']);
|
2020-11-21 12:31:17 +13:00
|
|
|
$this->assertArrayHasKey('platforms', $response['body']);
|
|
|
|
$this->assertArrayHasKey('webhooks', $response['body']);
|
|
|
|
$this->assertArrayHasKey('keys', $response['body']);
|
2020-07-09 21:13:14 +12:00
|
|
|
|
|
|
|
$projectId = $response['body']['$id'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-09 21:13:14 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'projectId' => ID::unique(),
|
2020-07-09 21:13:14 +12:00
|
|
|
'name' => '',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return ['projectId' => $projectId];
|
|
|
|
}
|
|
|
|
|
2023-03-10 15:44:43 +13:00
|
|
|
/**
|
2023-03-14 20:21:56 +13:00
|
|
|
* @group smtpAndTemplates
|
2023-03-10 15:44:43 +13:00
|
|
|
* @depends testCreateProject
|
|
|
|
*/
|
2023-03-10 15:46:34 +13:00
|
|
|
public function testUpdateProjectSMTP($data): array
|
|
|
|
{
|
2023-03-10 15:44:43 +13:00
|
|
|
$id = $data['projectId'];
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'enabled' => true,
|
2023-08-30 16:30:44 +12:00
|
|
|
'senderEmail' => 'mailer@appwrite.io',
|
|
|
|
'senderName' => 'Mailer',
|
2023-07-20 13:32:19 +12:00
|
|
|
'host' => 'maildev',
|
|
|
|
'port' => 1025,
|
|
|
|
'username' => 'user',
|
|
|
|
'password' => 'password',
|
2023-03-10 15:44:43 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertTrue($response['body']['smtpEnabled']);
|
2023-08-30 16:30:44 +12:00
|
|
|
$this->assertEquals('mailer@appwrite.io', $response['body']['smtpSenderEmail']);
|
|
|
|
$this->assertEquals('Mailer', $response['body']['smtpSenderName']);
|
2023-07-20 13:32:19 +12:00
|
|
|
$this->assertEquals('maildev', $response['body']['smtpHost']);
|
|
|
|
$this->assertEquals(1025, $response['body']['smtpPort']);
|
|
|
|
$this->assertEquals('user', $response['body']['smtpUsername']);
|
|
|
|
$this->assertEquals('password', $response['body']['smtpPassword']);
|
2023-03-10 15:44:43 +13:00
|
|
|
$this->assertEquals('', $response['body']['smtpSecure']);
|
2023-03-14 20:21:56 +13:00
|
|
|
|
|
|
|
/** Test Reading Project */
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertTrue($response['body']['smtpEnabled']);
|
2023-08-30 16:30:44 +12:00
|
|
|
$this->assertEquals('mailer@appwrite.io', $response['body']['smtpSenderEmail']);
|
|
|
|
$this->assertEquals('Mailer', $response['body']['smtpSenderName']);
|
2023-07-20 13:33:27 +12:00
|
|
|
$this->assertEquals('maildev', $response['body']['smtpHost']);
|
|
|
|
$this->assertEquals(1025, $response['body']['smtpPort']);
|
|
|
|
$this->assertEquals('user', $response['body']['smtpUsername']);
|
|
|
|
$this->assertEquals('password', $response['body']['smtpPassword']);
|
2023-03-14 20:21:56 +13:00
|
|
|
$this->assertEquals('', $response['body']['smtpSecure']);
|
2023-03-17 19:37:16 +13:00
|
|
|
|
2023-03-14 20:21:56 +13:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2023-12-20 04:19:57 +13:00
|
|
|
/**
|
|
|
|
* @group smtpAndTemplates
|
2024-01-16 00:00:33 +13:00
|
|
|
* @depends testCreateProject
|
2023-12-20 04:19:57 +13:00
|
|
|
*/
|
|
|
|
public function testCreateProjectSMTPTests($data): array
|
|
|
|
{
|
|
|
|
$id = $data['projectId'];
|
2023-12-20 11:31:45 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([
|
2023-12-20 04:19:57 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2024-01-16 00:00:33 +13:00
|
|
|
'emails' => [ 'testuser@appwrite.io', 'testusertwo@appwrite.io' ],
|
|
|
|
'senderEmail' => 'custommailer@appwrite.io',
|
|
|
|
'senderName' => 'Custom Mailer',
|
|
|
|
'replyTo' => 'reply@appwrite.io',
|
|
|
|
'host' => 'maildev',
|
|
|
|
'port' => 1025,
|
|
|
|
'username' => '',
|
|
|
|
'password' => '',
|
2023-12-20 04:19:57 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
|
2024-01-16 00:00:33 +13:00
|
|
|
$emails = $this->getLastEmail(2);
|
|
|
|
$this->assertCount(2, $emails);
|
|
|
|
$this->assertEquals('custommailer@appwrite.io', $emails[0]['from'][0]['address']);
|
|
|
|
$this->assertEquals('Custom Mailer', $emails[0]['from'][0]['name']);
|
|
|
|
$this->assertEquals('reply@appwrite.io', $emails[0]['replyTo'][0]['address']);
|
|
|
|
$this->assertEquals('Custom Mailer', $emails[0]['replyTo'][0]['name']);
|
2024-01-18 00:22:08 +13:00
|
|
|
$this->assertEquals('Custom SMTP email sample', $emails[0]['subject']);
|
|
|
|
$this->assertStringContainsStringIgnoringCase('working correctly', $emails[0]['text']);
|
|
|
|
$this->assertStringContainsStringIgnoringCase('working correctly', $emails[0]['html']);
|
|
|
|
$this->assertStringContainsStringIgnoringCase('251 Little Falls Drive', $emails[0]['text']);
|
|
|
|
$this->assertStringContainsStringIgnoringCase('251 Little Falls Drive', $emails[0]['html']);
|
2024-01-16 00:00:33 +13:00
|
|
|
|
|
|
|
$to = [
|
|
|
|
$emails[0]['to'][0]['address'],
|
|
|
|
$emails[1]['to'][0]['address']
|
|
|
|
];
|
|
|
|
\sort($to);
|
|
|
|
|
|
|
|
$this->assertEquals('testuser@appwrite.io', $to[0]);
|
|
|
|
$this->assertEquals('testusertwo@appwrite.io', $to[1]);
|
2023-12-20 10:39:40 +13:00
|
|
|
|
2024-01-18 05:47:26 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'emails' => [ 'u1@appwrite.io', 'u2@appwrite.io', 'u3@appwrite.io', 'u4@appwrite.io', 'u5@appwrite.io', 'u6@appwrite.io', 'u7@appwrite.io', 'u8@appwrite.io', 'u9@appwrite.io', 'u10@appwrite.io' ],
|
|
|
|
'senderEmail' => 'custommailer@appwrite.io',
|
|
|
|
'senderName' => 'Custom Mailer',
|
|
|
|
'replyTo' => 'reply@appwrite.io',
|
|
|
|
'host' => 'maildev',
|
|
|
|
'port' => 1025,
|
|
|
|
'username' => '',
|
|
|
|
'password' => '',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/smtp/tests', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'emails' => [ 'u1@appwrite.io', 'u2@appwrite.io', 'u3@appwrite.io', 'u4@appwrite.io', 'u5@appwrite.io', 'u6@appwrite.io', 'u7@appwrite.io', 'u8@appwrite.io', 'u9@appwrite.io', 'u10@appwrite.io', 'u11@appwrite.io' ],
|
|
|
|
'senderEmail' => 'custommailer@appwrite.io',
|
|
|
|
'senderName' => 'Custom Mailer',
|
|
|
|
'replyTo' => 'reply@appwrite.io',
|
|
|
|
'host' => 'maildev',
|
|
|
|
'port' => 1025,
|
|
|
|
'username' => '',
|
|
|
|
'password' => '',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2023-12-20 04:19:57 +13:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2023-03-14 20:21:56 +13:00
|
|
|
/**
|
2023-03-14 20:24:03 +13:00
|
|
|
* @group smtpAndTemplates
|
2023-08-29 14:41:48 +12:00
|
|
|
* @depends testUpdateProjectSMTP
|
|
|
|
*/
|
2023-03-14 20:21:56 +13:00
|
|
|
public function testUpdateTemplates($data): array
|
|
|
|
{
|
|
|
|
$id = $data['projectId'];
|
|
|
|
|
2023-03-14 22:13:43 +13:00
|
|
|
/** Get Default Email Template */
|
2023-04-18 19:13:52 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/email/verification/en-us', array_merge([
|
2023-03-14 20:21:56 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('Account Verification', $response['body']['subject']);
|
2023-08-30 17:31:21 +12:00
|
|
|
$this->assertEquals('', $response['body']['senderEmail']);
|
2023-03-14 20:21:56 +13:00
|
|
|
$this->assertEquals('verification', $response['body']['type']);
|
2023-04-18 19:13:52 +12:00
|
|
|
$this->assertEquals('en-us', $response['body']['locale']);
|
2023-03-14 20:24:03 +13:00
|
|
|
|
2023-03-14 22:13:43 +13:00
|
|
|
/** Update Email template */
|
2023-04-18 19:13:52 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/templates/email/verification/en-us', array_merge([
|
2023-03-14 20:21:56 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'subject' => 'Please verify your email',
|
|
|
|
'message' => 'Please verify your email {{url}}',
|
|
|
|
'senderName' => 'Appwrite Custom',
|
|
|
|
'senderEmail' => 'custom@appwrite.io',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('Please verify your email', $response['body']['subject']);
|
|
|
|
$this->assertEquals('Appwrite Custom', $response['body']['senderName']);
|
|
|
|
$this->assertEquals('custom@appwrite.io', $response['body']['senderEmail']);
|
|
|
|
$this->assertEquals('verification', $response['body']['type']);
|
2023-04-18 19:13:52 +12:00
|
|
|
$this->assertEquals('en-us', $response['body']['locale']);
|
2023-03-14 20:21:56 +13:00
|
|
|
$this->assertEquals('Please verify your email {{url}}', $response['body']['message']);
|
|
|
|
|
2023-03-14 22:13:43 +13:00
|
|
|
/** Get Updated Email Template */
|
2023-04-18 19:13:52 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/email/verification/en-us', array_merge([
|
2023-03-14 20:21:56 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('Please verify your email', $response['body']['subject']);
|
|
|
|
$this->assertEquals('Appwrite Custom', $response['body']['senderName']);
|
|
|
|
$this->assertEquals('custom@appwrite.io', $response['body']['senderEmail']);
|
|
|
|
$this->assertEquals('verification', $response['body']['type']);
|
2023-04-18 19:13:52 +12:00
|
|
|
$this->assertEquals('en-us', $response['body']['locale']);
|
2023-03-14 20:21:56 +13:00
|
|
|
$this->assertEquals('Please verify your email {{url}}', $response['body']['message']);
|
|
|
|
|
2023-08-26 03:13:25 +12:00
|
|
|
// Temporary disabled until implemented
|
|
|
|
// /** Get Default SMS Template */
|
|
|
|
// $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/sms/verification/en-us', array_merge([
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
// ], $this->getHeaders()));
|
|
|
|
|
|
|
|
// $this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
// $this->assertEquals('verification', $response['body']['type']);
|
|
|
|
// $this->assertEquals('en-us', $response['body']['locale']);
|
|
|
|
// $this->assertEquals('{{token}}', $response['body']['message']);
|
|
|
|
|
|
|
|
// /** Update SMS template */
|
|
|
|
// $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/templates/sms/verification/en-us', array_merge([
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
// ], $this->getHeaders()), [
|
|
|
|
// 'message' => 'Please verify your email {{token}}',
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
// $this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
// $this->assertEquals('verification', $response['body']['type']);
|
|
|
|
// $this->assertEquals('en-us', $response['body']['locale']);
|
|
|
|
// $this->assertEquals('Please verify your email {{token}}', $response['body']['message']);
|
|
|
|
|
|
|
|
// /** Get Updated SMS Template */
|
|
|
|
// $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/templates/sms/verification/en-us', array_merge([
|
|
|
|
// 'content-type' => 'application/json',
|
|
|
|
// 'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
// ], $this->getHeaders()));
|
|
|
|
|
|
|
|
// $this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
// $this->assertEquals('verification', $response['body']['type']);
|
|
|
|
// $this->assertEquals('en-us', $response['body']['locale']);
|
|
|
|
// $this->assertEquals('Please verify your email {{token}}', $response['body']['message']);
|
2023-03-14 22:13:43 +13:00
|
|
|
|
2023-03-10 15:44:43 +13:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2024-01-10 00:58:36 +13:00
|
|
|
/** @depends testCreateProject */
|
2022-11-02 03:43:18 +13:00
|
|
|
public function testUpdateProjectAuthDuration($data): array
|
2022-11-02 00:15:45 +13:00
|
|
|
{
|
|
|
|
$id = $data['projectId'];
|
|
|
|
|
2022-11-15 23:19:35 +13:00
|
|
|
// Check defaults
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals(Auth::TOKEN_EXPIRATION_LOGIN_LONG, $response['body']['authDuration']); // 1 Year
|
|
|
|
|
2022-11-02 00:15:45 +13:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-11-14 22:42:18 +13:00
|
|
|
|
2022-11-15 02:00:50 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([
|
2022-11-02 00:15:45 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2024-01-16 03:37:47 +13:00
|
|
|
'duration' => 60, // Set session duration to 1 minute
|
2022-11-02 00:15:45 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('Project Test 2', $response['body']['name']);
|
|
|
|
$this->assertArrayHasKey('platforms', $response['body']);
|
|
|
|
$this->assertArrayHasKey('webhooks', $response['body']);
|
|
|
|
$this->assertArrayHasKey('keys', $response['body']);
|
2022-11-15 02:00:50 +13:00
|
|
|
$this->assertEquals(60, $response['body']['authDuration']);
|
2022-11-02 00:15:45 +13:00
|
|
|
|
|
|
|
$projectId = $response['body']['$id'];
|
|
|
|
|
|
|
|
// Create New User
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'userId' => 'unique()',
|
|
|
|
'email' => 'test' . rand(0, 9999) . '@example.com',
|
|
|
|
'password' => 'password',
|
|
|
|
'name' => 'Test User',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$userEmail = $response['body']['email'];
|
|
|
|
|
|
|
|
// Create New User Session
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
]), [
|
|
|
|
'email' => $userEmail,
|
|
|
|
'password' => 'password',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$sessionCookie = $response['headers']['set-cookie'];
|
|
|
|
|
|
|
|
// Test for SUCCESS
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
'Cookie' => $sessionCookie,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
2022-11-15 23:31:32 +13:00
|
|
|
// Check session doesn't expire too soon.
|
|
|
|
sleep(30);
|
|
|
|
|
|
|
|
// Get User
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
'Cookie' => $sessionCookie,
|
|
|
|
]));
|
2022-11-15 23:38:02 +13:00
|
|
|
|
2022-11-15 23:31:32 +13:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
2022-11-02 00:15:45 +13:00
|
|
|
// Wait just over a minute
|
2022-11-15 23:31:32 +13:00
|
|
|
sleep(35);
|
2022-11-02 00:15:45 +13:00
|
|
|
|
|
|
|
// Get User
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
'Cookie' => $sessionCookie,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
2024-01-16 09:04:36 +13:00
|
|
|
// Set session duration to 15s
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'duration' => 15, // seconds
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals(15, $response['body']['authDuration']);
|
|
|
|
|
|
|
|
// Create session
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
]), [
|
|
|
|
'email' => $userEmail,
|
|
|
|
'password' => 'password',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$sessionCookie = $response['headers']['set-cookie'];
|
|
|
|
|
|
|
|
// Wait 10 seconds, ensure valid session, extend session
|
|
|
|
\sleep(10);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
'Cookie' => $sessionCookie,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/sessions/current', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
'cookie' => $sessionCookie,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
// Wait 20 seconds, ensure non-valid session
|
|
|
|
\sleep(20);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $projectId,
|
|
|
|
'Cookie' => $sessionCookie,
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
|
|
|
|
2022-11-02 00:15:45 +13:00
|
|
|
// Return project back to normal
|
2022-11-15 02:00:50 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/duration', array_merge([
|
2022-11-02 00:15:45 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-11-15 23:31:32 +13:00
|
|
|
'duration' => Auth::TOKEN_EXPIRATION_LOGIN_LONG,
|
2022-11-02 00:15:45 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$projectId = $response['body']['$id'];
|
|
|
|
|
2022-11-02 00:34:56 +13:00
|
|
|
// Check project is back to normal
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => 'console',
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-11-15 23:31:32 +13:00
|
|
|
$this->assertEquals(Auth::TOKEN_EXPIRATION_LOGIN_LONG, $response['body']['authDuration']); // 1 Year
|
2022-11-02 00:34:56 +13:00
|
|
|
|
2022-11-02 00:15:45 +13:00
|
|
|
return ['projectId' => $projectId];
|
|
|
|
}
|
|
|
|
|
2020-07-09 21:13:14 +12:00
|
|
|
/**
|
2024-01-10 00:58:36 +13:00
|
|
|
* @depends testCreateProject
|
2020-07-09 21:13:14 +12:00
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
public function testUpdateProjectOAuth($data): array
|
2020-07-09 21:13:14 +12:00
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2023-10-26 06:33:23 +13:00
|
|
|
$providers = require('app/config/oAuthProviders.php');
|
2020-07-09 21:13:14 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
2020-10-28 08:48:38 +13:00
|
|
|
foreach ($providers as $key => $provider) {
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
|
2020-07-09 21:13:14 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'provider' => $key,
|
2022-04-19 04:21:45 +12:00
|
|
|
'appId' => 'AppId-' . ucfirst($key),
|
|
|
|
'secret' => 'Secret-' . ucfirst($key),
|
2020-07-09 21:13:14 +12:00
|
|
|
]);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-09 21:13:14 +12:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
}
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
2020-07-09 21:13:14 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertEquals($id, $response['body']['$id']);
|
|
|
|
|
2020-10-28 08:48:38 +13:00
|
|
|
foreach ($providers as $key => $provider) {
|
2022-08-19 21:43:03 +12:00
|
|
|
$asserted = false;
|
2023-10-26 06:33:23 +13:00
|
|
|
foreach ($response['body']['oAuthProviders'] as $responseProvider) {
|
2023-07-21 10:54:38 +12:00
|
|
|
if ($responseProvider['key'] === $key) {
|
2022-08-19 21:43:03 +12:00
|
|
|
$this->assertEquals('AppId-' . ucfirst($key), $responseProvider['appId']);
|
|
|
|
$this->assertEquals('Secret-' . ucfirst($key), $responseProvider['secret']);
|
|
|
|
$this->assertFalse($responseProvider['enabled']);
|
|
|
|
$asserted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue($asserted);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable providers
|
|
|
|
$i = 0;
|
|
|
|
foreach ($providers as $key => $provider) {
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'provider' => $key,
|
|
|
|
'enabled' => $i === 0 ? false : true // On first provider, test enabled=false
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $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']);
|
|
|
|
$this->assertEquals($id, $response['body']['$id']);
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
foreach ($providers as $key => $provider) {
|
|
|
|
$asserted = false;
|
2023-10-26 06:33:23 +13:00
|
|
|
foreach ($response['body']['oAuthProviders'] as $responseProvider) {
|
2023-07-21 10:54:38 +12:00
|
|
|
if ($responseProvider['key'] === $key) {
|
2022-08-19 21:43:03 +12:00
|
|
|
// On first provider, test enabled=false
|
|
|
|
$this->assertEquals($i !== 0, $responseProvider['enabled']);
|
|
|
|
$asserted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertTrue($asserted);
|
|
|
|
|
|
|
|
$i++;
|
2020-07-09 21:13:14 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/oauth2', array_merge([
|
2020-07-09 21:13:14 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'provider' => 'unknown',
|
2022-08-27 15:16:37 +12:00
|
|
|
'appId' => 'AppId',
|
2020-07-09 21:13:14 +12:00
|
|
|
'secret' => 'Secret',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2021-03-01 10:22:03 +13:00
|
|
|
/**
|
2024-01-10 00:58:36 +13:00
|
|
|
* @depends testCreateProject
|
2021-03-01 10:22:03 +13:00
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
public function testUpdateProjectAuthStatus($data): array
|
2021-03-01 10:22:03 +13:00
|
|
|
{
|
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
$auth = require('app/config/auth.php');
|
2022-04-19 04:21:45 +12:00
|
|
|
|
|
|
|
$originalEmail = uniqid() . 'user@localhost.test';
|
2021-03-01 10:22:03 +13:00
|
|
|
$originalPassword = 'password';
|
|
|
|
$originalName = 'User Name';
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2021-03-01 10:22:03 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'userId' => ID::unique(),
|
2021-03-01 10:22:03 +13:00
|
|
|
'email' => $originalEmail,
|
|
|
|
'password' => $originalPassword,
|
|
|
|
'name' => $originalName,
|
|
|
|
]);
|
|
|
|
|
2022-06-14 20:17:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
2021-03-01 10:22:03 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'email' => $originalEmail,
|
|
|
|
'password' => $originalPassword,
|
|
|
|
]);
|
|
|
|
|
2023-12-09 12:17:13 +13:00
|
|
|
$session = $response['cookies']['a_session_' . $id];
|
2021-03-01 10:22:03 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
foreach ($auth as $index => $method) {
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/' . $index, array_merge([
|
2021-03-01 10:22:03 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'status' => false,
|
|
|
|
]);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2021-03-01 10:22:03 +13:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
2021-03-01 10:22:03 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2022-04-19 04:21:45 +12:00
|
|
|
$this->assertEquals(false, $response['body']['auth' . ucfirst($method['key'])]);
|
2021-03-01 10:22:03 +13:00
|
|
|
}
|
2022-04-19 04:21:45 +12:00
|
|
|
|
|
|
|
$email = uniqid() . 'user@localhost.test';
|
2021-03-01 10:22:03 +13:00
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'userId' => ID::unique(),
|
2021-03-01 10:22:03 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 501);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
2022-04-19 04:21:45 +12:00
|
|
|
'cookie' => 'a_session_' . $id . '=' . $session,
|
2021-03-01 10:22:03 +13:00
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'teamId' => ID::unique(),
|
2021-03-01 10:22:03 +13:00
|
|
|
'name' => 'Arsenal'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$teamUid = $response['body']['$id'];
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([
|
2021-03-01 10:22:03 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
2022-04-19 04:21:45 +12:00
|
|
|
'cookie' => 'a_session_' . $id . '=' . $session,
|
2021-03-01 10:22:03 +13:00
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'name' => 'Friend User',
|
|
|
|
'roles' => ['admin', 'editor'],
|
|
|
|
'url' => 'http://localhost:5000/join-us#title'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 501);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/jwt', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
2022-04-19 04:21:45 +12:00
|
|
|
'cookie' => 'a_session_' . $id . '=' . $session,
|
2021-03-01 10:22:03 +13:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 501);
|
|
|
|
|
2022-06-14 20:17:50 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
2021-03-01 10:22:03 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'email' => $originalEmail,
|
|
|
|
'password' => $originalPassword,
|
|
|
|
]);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2021-03-01 10:22:03 +13:00
|
|
|
$this->assertEquals($response['headers']['status-code'], 501);
|
|
|
|
|
2023-05-30 18:26:17 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/anonymous', array_merge([
|
2021-04-03 21:56:32 +13:00
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
2023-05-30 18:26:17 +12:00
|
|
|
]));
|
2021-04-03 21:56:32 +13:00
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 501);
|
|
|
|
|
2021-03-01 10:22:03 +13:00
|
|
|
// Cleanup
|
|
|
|
|
|
|
|
foreach ($auth as $index => $method) {
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/' . $index, array_merge([
|
2021-03-01 10:22:03 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'status' => true,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-01-10 00:58:36 +13:00
|
|
|
* @depends testCreateProject
|
2021-03-01 10:22:03 +13:00
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
public function testUpdateProjectAuthLimit($data): array
|
2021-03-01 10:22:03 +13:00
|
|
|
{
|
|
|
|
$id = $data['projectId'] ?? '';
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2021-03-01 10:22:03 +13:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/limit', array_merge([
|
2021-03-01 10:22:03 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 1,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
|
|
|
$email = uniqid() . 'user@localhost.test';
|
2021-03-01 10:22:03 +13:00
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'userId' => ID::unique(),
|
2021-03-01 10:22:03 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
2023-05-30 18:26:17 +12:00
|
|
|
$email = uniqid() . 'user@localhost.test';
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
2021-03-01 10:22:03 +13:00
|
|
|
$this->assertEquals($response['headers']['status-code'], 501);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/limit', array_merge([
|
2021-03-01 10:22:03 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 0,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2023-05-30 18:26:17 +12:00
|
|
|
$email = uniqid() . 'user@localhost.test';
|
|
|
|
|
2021-03-01 10:22:03 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'userId' => ID::unique(),
|
2021-03-01 10:22:03 +13:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($response['headers']['status-code'], 201);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2022-12-10 00:54:23 +13:00
|
|
|
/**
|
|
|
|
* @depends testUpdateProjectAuthLimit
|
|
|
|
*/
|
2022-12-27 23:33:38 +13:00
|
|
|
public function testUpdateProjectAuthSessionsLimit($data): array
|
2022-12-10 00:54:23 +13:00
|
|
|
{
|
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for failure
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 0,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 1,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2022-12-27 23:40:24 +13:00
|
|
|
$this->assertEquals(1, $response['body']['authSessionsLimit']);
|
2022-12-10 00:54:23 +13:00
|
|
|
|
|
|
|
$email = uniqid() . 'user@localhost.test';
|
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create new user
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
2022-12-11 20:15:47 +13:00
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2022-12-10 00:54:23 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* create new session
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
2022-12-11 20:15:47 +13:00
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2022-12-10 00:54:23 +13:00
|
|
|
$sessionId1 = $response['body']['$id'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create new session
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
2022-12-11 20:15:47 +13:00
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
2022-12-10 00:54:23 +13:00
|
|
|
$sessionCookie = $response['headers']['set-cookie'];
|
|
|
|
$sessionId2 = $response['body']['$id'];
|
|
|
|
|
2022-12-11 21:26:31 +13:00
|
|
|
// request was called in parallel and test failed
|
|
|
|
sleep(5);
|
|
|
|
|
2022-12-10 00:54:23 +13:00
|
|
|
/**
|
|
|
|
* List sessions
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/account/sessions', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'Cookie' => $sessionCookie,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$sessions = $response['body']['sessions'];
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($sessions));
|
|
|
|
$this->assertEquals($sessionId2, $sessions[0]['$id']);
|
|
|
|
|
2022-12-12 18:02:48 +13:00
|
|
|
/**
|
|
|
|
* Reset Limit
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 10,
|
|
|
|
]);
|
|
|
|
|
2022-12-10 00:54:23 +13:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2022-12-18 19:27:41 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testUpdateProjectAuthLimit
|
|
|
|
*/
|
|
|
|
public function testUpdateProjectAuthPasswordHistory($data): array
|
|
|
|
{
|
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
|
2022-12-21 19:42:27 +13:00
|
|
|
/**
|
|
|
|
* Test for Failure
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 25,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
2022-12-18 19:27:41 +13:00
|
|
|
/**
|
|
|
|
* Test for Success
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 1,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals(1, $response['body']['authPasswordHistory']);
|
|
|
|
|
|
|
|
|
|
|
|
$email = uniqid() . 'user@localhost.test';
|
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create new user
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
2022-12-19 18:07:41 +13:00
|
|
|
$userId = $response['body']['$id'];
|
|
|
|
|
2022-12-18 19:27:41 +13:00
|
|
|
// create session
|
|
|
|
$session = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
], [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $session['headers']['status-code']);
|
2023-12-09 12:36:01 +13:00
|
|
|
$session = $session['cookies']['a_session_' . $id];
|
2022-12-18 19:27:41 +13:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'cookie' => 'a_session_' . $id . '=' . $session,
|
|
|
|
]), [
|
|
|
|
'oldPassword' => $password,
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
2023-04-14 08:20:03 +12:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-12-19 18:07:41 +13:00
|
|
|
|
2022-12-19 21:28:02 +13:00
|
|
|
$headers = array_merge($this->getHeaders(), [
|
|
|
|
'x-appwrite-mode' => 'admin',
|
2022-12-19 18:07:41 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
2022-12-19 21:28:02 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/password', $headers, [
|
2022-12-19 18:07:41 +13:00
|
|
|
'password' => $password,
|
|
|
|
]);
|
2022-12-18 19:27:41 +13:00
|
|
|
|
2023-04-14 08:20:03 +12:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-12-18 19:27:41 +13:00
|
|
|
|
2022-12-18 19:31:14 +13:00
|
|
|
|
2022-12-18 19:27:41 +13:00
|
|
|
/**
|
|
|
|
* Reset
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 0,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals(0, $response['body']['authPasswordHistory']);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2022-12-26 18:46:35 +13:00
|
|
|
/**
|
|
|
|
* @depends testUpdateProjectAuthLimit
|
|
|
|
*/
|
|
|
|
public function testUpdateProjectAuthPasswordDictionary($data): array
|
|
|
|
{
|
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
|
|
|
|
$password = 'password';
|
|
|
|
$name = 'User Name';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Success
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create account
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => uniqid() . 'user@localhost.test',
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$userId = $response['body']['$id'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create user
|
|
|
|
*/
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/users', array_merge($this->getHeaders(), [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'x-appwrite-mode' => 'admin',
|
|
|
|
]), [
|
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => uniqid() . 'user@localhost.test',
|
|
|
|
'password' => 'password',
|
|
|
|
'name' => 'Cristiano Ronaldo',
|
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable Disctionary
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-dictionary', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'enabled' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals(true, $response['body']['authPasswordDictionary']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for failure
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => uniqid() . 'user@localhost.test',
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
]);
|
|
|
|
|
2022-12-26 23:22:25 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-12-26 18:47:20 +13:00
|
|
|
|
2022-12-26 18:46:35 +13:00
|
|
|
/**
|
|
|
|
* Create user
|
|
|
|
*/
|
|
|
|
$user = $this->client->call(Client::METHOD_POST, '/users', array_merge($this->getHeaders(), [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'x-appwrite-mode' => 'admin',
|
|
|
|
]), [
|
|
|
|
'userId' => ID::unique(),
|
|
|
|
'email' => uniqid() . 'user@localhost.test',
|
|
|
|
'password' => 'password',
|
|
|
|
'name' => 'Cristiano Ronaldo',
|
|
|
|
]);
|
2022-12-26 23:22:25 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-12-26 18:46:35 +13:00
|
|
|
|
|
|
|
$headers = array_merge($this->getHeaders(), [
|
|
|
|
'x-appwrite-mode' => 'admin',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/password', $headers, [
|
|
|
|
'password' => $password,
|
|
|
|
]);
|
|
|
|
|
2022-12-26 23:22:25 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-12-26 18:46:35 +13:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-history', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'limit' => 0,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals(0, $response['body']['authPasswordHistory']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-dictionary', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-12-26 23:22:25 +13:00
|
|
|
'enabled' => false,
|
2022-12-26 18:46:35 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-12-26 23:22:25 +13:00
|
|
|
$this->assertEquals(false, $response['body']['authPasswordDictionary']);
|
2022-12-26 18:46:35 +13:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2023-04-14 08:20:03 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProject
|
|
|
|
*/
|
|
|
|
public function testUpdateDisallowPersonalData($data): void
|
|
|
|
{
|
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable Disallowing of Personal Data
|
|
|
|
*/
|
2023-07-21 01:12:41 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/personal-data', array_merge([
|
2023-04-14 08:20:03 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'enabled' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2023-07-20 10:24:32 +12:00
|
|
|
$this->assertEquals(true, $response['body']['authPersonalDataCheck']);
|
2023-04-14 08:20:03 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for failure
|
|
|
|
*/
|
|
|
|
$email = uniqid() . 'user@localhost.test';
|
|
|
|
$password = 'password';
|
|
|
|
$name = 'username';
|
|
|
|
$userId = ID::unique();
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $email,
|
|
|
|
'name' => $name,
|
|
|
|
'userId' => $userId
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals(400, $response['body']['code']);
|
|
|
|
$this->assertEquals(Exception::USER_PASSWORD_PERSONAL_DATA, $response['body']['type']);
|
|
|
|
|
2023-04-14 08:59:35 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $name,
|
|
|
|
'name' => $name,
|
|
|
|
'userId' => $userId
|
|
|
|
]);
|
|
|
|
|
2023-04-14 08:20:03 +12:00
|
|
|
$phone = '+123456789';
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/users', array_merge($this->getHeaders(), [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'x-appwrite-mode' => 'admin',
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $phone,
|
|
|
|
'name' => $name,
|
|
|
|
'userId' => $userId,
|
|
|
|
'phone' => $phone
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals(400, $response['body']['code']);
|
|
|
|
$this->assertEquals(Exception::USER_PASSWORD_PERSONAL_DATA, $response['body']['type']);
|
|
|
|
|
|
|
|
/** Test for success */
|
|
|
|
$email = uniqid() . 'user@localhost.test';
|
|
|
|
$password = 'password';
|
|
|
|
$name = 'username';
|
|
|
|
$userId = ID::unique();
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/account', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
'userId' => $userId
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$email = uniqid() . 'user@localhost.test';
|
|
|
|
$userId = ID::unique();
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/users', array_merge($this->getHeaders(), [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'x-appwrite-mode' => 'admin',
|
|
|
|
]), [
|
|
|
|
'email' => $email,
|
|
|
|
'password' => $password,
|
|
|
|
'name' => $name,
|
|
|
|
'userId' => $userId,
|
|
|
|
'phone' => $phone
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset
|
|
|
|
*/
|
2023-07-21 01:12:41 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/personal-data', array_merge([
|
2023-04-14 08:20:03 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'enabled' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2023-07-20 10:24:32 +12:00
|
|
|
$this->assertEquals(false, $response['body']['authPersonalDataCheck']);
|
2023-04-14 08:20:03 +12:00
|
|
|
}
|
|
|
|
|
2023-11-06 12:34:44 +13:00
|
|
|
public function testUpdateProjectServicesAll(): void
|
|
|
|
{
|
|
|
|
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
|
|
|
'teamId' => ID::unique(),
|
|
|
|
'name' => 'Project Test',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $team['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($team['body']['$id']);
|
|
|
|
|
|
|
|
$project = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
|
|
|
'projectId' => ID::unique(),
|
|
|
|
'name' => 'Project Test',
|
|
|
|
'teamId' => $team['body']['$id'],
|
|
|
|
'region' => 'default'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $project['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($project['body']['$id']);
|
|
|
|
|
|
|
|
$id = $project['body']['$id'];
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/all', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
|
|
|
'status' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
|
|
|
$matches = [];
|
|
|
|
$pattern = '/serviceStatusFor.*/';
|
|
|
|
|
|
|
|
foreach ($response['body'] as $key => $value) {
|
|
|
|
if (\preg_match($pattern, $key)) {
|
|
|
|
$matches[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($matches as $value) {
|
|
|
|
$this->assertFalse($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/all', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
|
|
|
'status' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$matches = [];
|
|
|
|
foreach ($response['body'] as $key => $value) {
|
|
|
|
if (\preg_match($pattern, $key)) {
|
|
|
|
$matches[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($matches as $value) {
|
|
|
|
$this->assertTrue($value);
|
|
|
|
}
|
|
|
|
}
|
2022-12-18 19:27:41 +13:00
|
|
|
|
2021-07-29 22:56:25 +12:00
|
|
|
public function testUpdateProjectServiceStatusAdmin(): array
|
2021-07-29 22:28:17 +12:00
|
|
|
{
|
2021-07-29 22:56:25 +12:00
|
|
|
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'teamId' => ID::unique(),
|
2021-07-29 22:56:25 +12:00
|
|
|
'name' => 'Project Test',
|
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $team['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($team['body']['$id']);
|
|
|
|
|
|
|
|
$project = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'projectId' => ID::unique(),
|
2021-07-29 22:56:25 +12:00
|
|
|
'name' => 'Project Test',
|
|
|
|
'teamId' => $team['body']['$id'],
|
2022-10-01 01:22:11 +13:00
|
|
|
'region' => 'default'
|
2021-07-29 22:56:25 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $project['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($project['body']['$id']);
|
|
|
|
|
|
|
|
$id = $project['body']['$id'];
|
2021-08-01 20:00:13 +12:00
|
|
|
$services = require('app/config/services.php');
|
2021-07-29 22:28:17 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Disabled
|
|
|
|
*/
|
|
|
|
foreach ($services as $service) {
|
2022-04-19 04:21:45 +12:00
|
|
|
if (!$service['optional']) {
|
2021-08-01 20:00:13 +12:00
|
|
|
continue;
|
|
|
|
}
|
2021-08-01 22:15:06 +12:00
|
|
|
|
|
|
|
$key = $service['key'] ?? '';
|
2022-04-19 04:21:45 +12:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([
|
2021-07-29 22:28:17 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2021-07-29 22:56:25 +12:00
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
2021-08-01 22:15:06 +12:00
|
|
|
'service' => $key,
|
2021-07-29 22:28:17 +12:00
|
|
|
'status' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
2021-07-29 22:28:17 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2021-07-29 22:56:25 +12:00
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]));
|
2021-07-29 22:28:17 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2022-04-19 04:21:45 +12:00
|
|
|
$this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]);
|
2021-07-29 22:28:17 +12:00
|
|
|
}
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2021-07-29 22:28:17 +12:00
|
|
|
/**
|
2021-07-29 22:56:25 +12:00
|
|
|
* Admin request must succeed
|
2021-07-29 22:28:17 +12:00
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2021-07-29 22:28:17 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
2021-07-29 22:56:25 +12:00
|
|
|
// 'x-appwrite-project' => $this->getProject()['$id'],
|
2021-07-29 22:28:17 +12:00
|
|
|
'x-appwrite-project' => $id,
|
2021-07-29 22:56:25 +12:00
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
'x-appwrite-mode' => 'admin'
|
|
|
|
]));
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2021-07-29 22:56:25 +12:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2021-07-29 22:28:17 +12:00
|
|
|
|
|
|
|
foreach ($services as $service) {
|
2022-04-19 04:21:45 +12:00
|
|
|
if (!$service['optional']) {
|
2021-08-01 22:15:06 +12:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = $service['key'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([
|
2021-07-29 22:28:17 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2021-08-01 22:15:06 +12:00
|
|
|
'service' => $key,
|
2021-07-29 22:28:17 +12:00
|
|
|
'status' => true,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-07-29 22:56:25 +12:00
|
|
|
return ['projectId' => $id];
|
2021-07-29 22:28:17 +12:00
|
|
|
}
|
|
|
|
|
2021-07-29 22:56:25 +12:00
|
|
|
/** @depends testUpdateProjectServiceStatusAdmin */
|
2022-04-19 04:21:45 +12:00
|
|
|
public function testUpdateProjectServiceStatus($data): void
|
2021-07-29 22:28:17 +12:00
|
|
|
{
|
2021-07-29 22:56:25 +12:00
|
|
|
$id = $data['projectId'];
|
2021-07-29 22:28:17 +12:00
|
|
|
|
2021-08-01 22:15:06 +12:00
|
|
|
$services = require('app/config/services.php');
|
2021-07-29 22:28:17 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Disabled
|
|
|
|
*/
|
|
|
|
foreach ($services as $service) {
|
2022-04-19 04:21:45 +12:00
|
|
|
if (!$service['optional']) {
|
2021-08-01 22:15:06 +12:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = $service['key'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([
|
2021-07-29 22:28:17 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
2021-08-01 22:15:06 +12:00
|
|
|
'service' => $key,
|
2021-07-29 22:28:17 +12:00
|
|
|
'status' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
2021-07-29 22:28:17 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2022-04-19 04:21:45 +12:00
|
|
|
$this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]);
|
2021-07-29 22:28:17 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-29 22:56:25 +12:00
|
|
|
* Test for FAILURE
|
2021-07-29 22:28:17 +12:00
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([
|
|
|
|
'origin' => 'http://localhost',
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
2021-07-29 22:56:25 +12:00
|
|
|
], $this->getHeaders()));
|
2021-07-29 22:28:17 +12:00
|
|
|
|
2021-07-29 22:56:25 +12:00
|
|
|
$this->assertEquals(503, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'teamId' => ID::unique(),
|
2021-07-29 22:56:25 +12:00
|
|
|
'name' => 'Arsenal'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(503, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
|
|
|
|
foreach ($services as $service) {
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([
|
2021-07-29 22:56:25 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'service' => $service,
|
|
|
|
'status' => true,
|
|
|
|
]);
|
|
|
|
}
|
2021-07-29 22:28:17 +12:00
|
|
|
}
|
|
|
|
|
2022-05-22 18:57:59 +12:00
|
|
|
/** @depends testUpdateProjectServiceStatusAdmin */
|
|
|
|
public function testUpdateProjectServiceStatusServer($data): void
|
|
|
|
{
|
|
|
|
$id = $data['projectId'];
|
|
|
|
|
|
|
|
$services = require('app/config/services.php');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for Disabled
|
|
|
|
*/
|
|
|
|
foreach ($services as $service) {
|
|
|
|
if (!$service['optional']) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = $service['key'] ?? '';
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
|
|
|
'service' => $key,
|
|
|
|
'status' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals(false, $response['body']['serviceStatusFor' . ucfirst($key)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create API Key
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), [
|
|
|
|
'name' => 'Key Test',
|
|
|
|
'scopes' => ['functions.read', 'teams.write'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$keyId = $response['body']['$id'];
|
|
|
|
$keySecret = $response['body']['secret'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request with API Key must succeed
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/functions', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'x-appwrite-key' => $keySecret,
|
2022-08-31 02:04:42 +12:00
|
|
|
'x-sdk-name' => 'python'
|
2022-05-22 18:57:59 +12:00
|
|
|
]));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'x-appwrite-key' => $keySecret,
|
2022-08-31 02:04:42 +12:00
|
|
|
'x-sdk-name' => 'php'
|
2022-05-22 18:57:59 +12:00
|
|
|
]), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'teamId' => ID::unique(),
|
2022-05-22 18:57:59 +12:00
|
|
|
'name' => 'Arsenal'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
2022-08-31 02:04:42 +12:00
|
|
|
/** Check that the API key has been updated */
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), []);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertArrayHasKey('sdks', $response['body']);
|
|
|
|
$this->assertCount(2, $response['body']['sdks']);
|
2022-08-31 05:33:54 +12:00
|
|
|
$this->assertContains('python', $response['body']['sdks']);
|
|
|
|
$this->assertContains('php', $response['body']['sdks']);
|
2022-08-31 02:04:42 +12:00
|
|
|
$this->assertArrayHasKey('accessedAt', $response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['accessedAt']);
|
2022-08-31 06:26:02 +12:00
|
|
|
|
2022-05-22 18:57:59 +12:00
|
|
|
// Cleanup
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
]), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
foreach ($services as $service) {
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/service/', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'service' => $service,
|
|
|
|
'status' => true,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 21:13:14 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProject
|
|
|
|
*/
|
|
|
|
public function testCreateProjectWebhook($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2020-07-09 21:13:14 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/webhooks', array_merge([
|
2020-07-09 21:13:14 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Webhook Test',
|
2022-04-19 04:21:45 +12:00
|
|
|
'events' => ['users.*.create', 'users.*.update.email'],
|
2020-07-09 21:13:14 +12:00
|
|
|
'url' => 'https://appwrite.io',
|
|
|
|
'security' => true,
|
|
|
|
'httpUser' => 'username',
|
|
|
|
'httpPass' => 'password',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
2022-04-19 04:21:45 +12:00
|
|
|
$this->assertContains('users.*.create', $response['body']['events']);
|
|
|
|
$this->assertContains('users.*.update.email', $response['body']['events']);
|
2020-07-09 21:13:14 +12:00
|
|
|
$this->assertCount(2, $response['body']['events']);
|
|
|
|
$this->assertEquals('https://appwrite.io', $response['body']['url']);
|
2020-07-12 01:01:04 +12:00
|
|
|
$this->assertIsBool($response['body']['security']);
|
|
|
|
$this->assertEquals(true, $response['body']['security']);
|
2020-07-09 21:13:14 +12:00
|
|
|
$this->assertEquals('username', $response['body']['httpUser']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2022-06-21 06:35:33 +12:00
|
|
|
$data = array_merge($data, ['webhookId' => $response['body']['$id'], 'signatureKey' => $response['body']['signatureKey']]);
|
2020-07-09 21:13:14 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/webhooks', array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Webhook Test',
|
2022-04-19 04:21:45 +12:00
|
|
|
'events' => ['account.unknown', 'users.*.update.email'],
|
2020-07-12 01:01:04 +12:00
|
|
|
'url' => 'https://appwrite.io',
|
|
|
|
'security' => true,
|
|
|
|
'httpUser' => 'username',
|
|
|
|
'httpPass' => 'password',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/webhooks', array_merge([
|
2022-02-17 04:16:37 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Webhook Test',
|
2022-04-19 04:21:45 +12:00
|
|
|
'events' => ['users.*.create', 'users.*.update.email'],
|
2022-02-17 04:16:37 +13:00
|
|
|
'url' => 'invalid://appwrite.io',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-07-13 01:43:47 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProjectWebhook
|
|
|
|
*/
|
|
|
|
public function testListProjectWebhook($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2020-07-13 01:43:47 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks', array_merge([
|
2020-07-13 01:43:47 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(1, $response['body']['total']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-13 01:43:47 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProjectWebhook
|
|
|
|
*/
|
|
|
|
public function testGetProjectWebhook($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
$webhookId = $data['webhookId'] ?? '';
|
2020-07-12 01:01:04 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'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($webhookId, $response['body']['$id']);
|
2022-04-19 04:21:45 +12:00
|
|
|
$this->assertContains('users.*.create', $response['body']['events']);
|
|
|
|
$this->assertContains('users.*.update.email', $response['body']['events']);
|
2020-07-12 01:01:04 +12:00
|
|
|
$this->assertCount(2, $response['body']['events']);
|
|
|
|
$this->assertEquals('https://appwrite.io', $response['body']['url']);
|
|
|
|
$this->assertEquals('username', $response['body']['httpUser']);
|
|
|
|
$this->assertEquals('password', $response['body']['httpPass']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks/error', array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateProjectWebhook
|
|
|
|
*/
|
|
|
|
public function testUpdateProjectWebhook($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
$webhookId = $data['webhookId'] ?? '';
|
2020-07-12 01:01:04 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Webhook Test Update',
|
2022-04-19 04:21:45 +12:00
|
|
|
'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'],
|
2020-07-12 01:01:04 +12:00
|
|
|
'url' => 'https://appwrite.io/new',
|
|
|
|
'security' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($webhookId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('Webhook Test Update', $response['body']['name']);
|
2022-04-19 04:21:45 +12:00
|
|
|
$this->assertContains('users.*.delete', $response['body']['events']);
|
|
|
|
$this->assertContains('users.*.sessions.*.delete', $response['body']['events']);
|
|
|
|
$this->assertContains('buckets.*.files.*.create', $response['body']['events']);
|
2020-07-12 01:01:04 +12:00
|
|
|
$this->assertCount(3, $response['body']['events']);
|
|
|
|
$this->assertEquals('https://appwrite.io/new', $response['body']['url']);
|
|
|
|
$this->assertIsBool($response['body']['security']);
|
|
|
|
$this->assertEquals(false, $response['body']['security']);
|
|
|
|
$this->assertEquals('', $response['body']['httpUser']);
|
2020-11-21 12:31:17 +13:00
|
|
|
$this->assertEquals('', $response['body']['httpPass']);
|
2020-07-12 01:01:04 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'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($webhookId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('Webhook Test Update', $response['body']['name']);
|
2022-04-19 04:21:45 +12:00
|
|
|
$this->assertContains('users.*.delete', $response['body']['events']);
|
|
|
|
$this->assertContains('users.*.sessions.*.delete', $response['body']['events']);
|
|
|
|
$this->assertContains('buckets.*.files.*.create', $response['body']['events']);
|
2020-07-12 01:01:04 +12:00
|
|
|
$this->assertCount(3, $response['body']['events']);
|
|
|
|
$this->assertEquals('https://appwrite.io/new', $response['body']['url']);
|
|
|
|
$this->assertIsBool($response['body']['security']);
|
|
|
|
$this->assertEquals(false, $response['body']['security']);
|
|
|
|
$this->assertEquals('', $response['body']['httpUser']);
|
2020-11-21 12:31:17 +13:00
|
|
|
$this->assertEquals('', $response['body']['httpPass']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Webhook Test Update',
|
2022-04-19 04:21:45 +12:00
|
|
|
'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.unknown'],
|
2020-07-12 01:01:04 +12:00
|
|
|
'url' => 'https://appwrite.io/new',
|
|
|
|
'security' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Webhook Test Update',
|
2022-04-19 04:21:45 +12:00
|
|
|
'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'],
|
2020-07-12 01:01:04 +12:00
|
|
|
'url' => 'appwrite.io/new',
|
|
|
|
'security' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
|
2022-02-17 04:16:37 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Webhook Test Update',
|
2022-04-19 04:21:45 +12:00
|
|
|
'events' => ['users.*.delete', 'users.*.sessions.*.delete', 'buckets.*.files.*.create'],
|
2022-02-17 04:16:37 +13:00
|
|
|
'url' => 'invalid://appwrite.io/new',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2022-06-21 06:35:33 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProjectWebhook
|
|
|
|
*/
|
|
|
|
public function testUpdateProjectWebhookSignature($data): void
|
|
|
|
{
|
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
$webhookId = $data['webhookId'] ?? '';
|
|
|
|
$signatureKey = $data['signatureKey'] ?? '';
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/webhooks/' . $webhookId . '/signature', 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']['signatureKey']);
|
|
|
|
$this->assertNotEquals($signatureKey, $response['body']['signatureKey']);
|
|
|
|
}
|
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProjectWebhook
|
|
|
|
*/
|
|
|
|
public function testDeleteProjectWebhook($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
$webhookId = $data['webhookId'] ?? '';
|
2020-07-12 01:01:04 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/webhooks/' . $webhookId, array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/webhooks/error', array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
2020-07-09 21:13:14 +12:00
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2020-07-09 21:13:14 +12:00
|
|
|
|
|
|
|
return $data;
|
2020-07-09 03:20:18 +12:00
|
|
|
}
|
2020-07-12 01:01:04 +12:00
|
|
|
|
|
|
|
// Keys
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateProject
|
|
|
|
*/
|
|
|
|
public function testCreateProjectKey($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2020-07-12 01:01:04 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Key Test',
|
|
|
|
'scopes' => ['teams.read', 'teams.write'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('Key Test', $response['body']['name']);
|
|
|
|
$this->assertContains('teams.read', $response['body']['scopes']);
|
|
|
|
$this->assertContains('teams.write', $response['body']['scopes']);
|
|
|
|
$this->assertNotEmpty($response['body']['secret']);
|
2022-08-31 02:04:42 +12:00
|
|
|
$this->assertArrayHasKey('sdks', $response['body']);
|
|
|
|
$this->assertEmpty($response['body']['sdks']);
|
|
|
|
$this->assertArrayHasKey('accessedAt', $response['body']);
|
|
|
|
$this->assertEmpty($response['body']['accessedAt']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2022-06-01 03:41:12 +12:00
|
|
|
$data = array_merge($data, [
|
|
|
|
'keyId' => $response['body']['$id'],
|
|
|
|
'secret' => $response['body']['secret']
|
|
|
|
]);
|
2020-07-12 01:01:04 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Key Test',
|
|
|
|
'scopes' => ['unknown'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2022-06-01 03:41:12 +12:00
|
|
|
|
2020-07-13 01:43:47 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProjectKey
|
|
|
|
*/
|
|
|
|
public function testListProjectKey($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2020-07-13 01:43:47 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys', array_merge([
|
2020-07-13 01:43:47 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
2022-06-01 18:26:55 +12:00
|
|
|
|
2020-07-13 01:43:47 +12:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2022-02-27 22:57:09 +13:00
|
|
|
$this->assertEquals(1, $response['body']['total']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-13 01:43:47 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2022-06-01 03:41:12 +12:00
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProjectKey
|
|
|
|
*/
|
|
|
|
public function testGetProjectKey($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
$keyId = $data['keyId'] ?? '';
|
2020-07-12 01:01:04 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-06-01 18:26:55 +12:00
|
|
|
'x-appwrite-key' => $keyId
|
2020-07-12 01:01:04 +12:00
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($keyId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('Key Test', $response['body']['name']);
|
|
|
|
$this->assertContains('teams.read', $response['body']['scopes']);
|
|
|
|
$this->assertContains('teams.write', $response['body']['scopes']);
|
|
|
|
$this->assertCount(2, $response['body']['scopes']);
|
|
|
|
$this->assertNotEmpty($response['body']['secret']);
|
2022-08-31 02:04:42 +12:00
|
|
|
$this->assertArrayHasKey('sdks', $response['body']);
|
|
|
|
$this->assertEmpty($response['body']['sdks']);
|
|
|
|
$this->assertArrayHasKey('accessedAt', $response['body']);
|
|
|
|
$this->assertEmpty($response['body']['accessedAt']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-12 01:01:04 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/error', array_merge([
|
2020-07-12 01:01:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2022-06-01 03:41:12 +12:00
|
|
|
/**
|
2022-06-01 18:26:55 +12:00
|
|
|
* @depends testCreateProject
|
2022-06-01 03:41:12 +12:00
|
|
|
*/
|
|
|
|
public function testValidateProjectKey($data): void
|
|
|
|
{
|
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
|
2022-06-01 18:26:55 +12:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
|
2022-06-01 03:41:12 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-06-01 18:26:55 +12:00
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Key Test',
|
|
|
|
'scopes' => ['health.read'],
|
2022-07-14 02:02:49 +12:00
|
|
|
'expire' => DateTime::addSeconds(new \DateTime(), 3600),
|
2022-06-01 18:26:55 +12:00
|
|
|
]);
|
|
|
|
|
2022-06-03 21:12:19 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/health', [
|
2022-06-01 18:26:55 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'x-appwrite-key' => $response['body']['secret']
|
|
|
|
], []);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Key Test',
|
|
|
|
'scopes' => ['health.read'],
|
2022-07-06 06:55:20 +12:00
|
|
|
'expire' => null,
|
2022-06-01 18:26:55 +12:00
|
|
|
]);
|
|
|
|
|
2022-06-03 21:12:19 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/health', [
|
2022-06-01 18:26:55 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'x-appwrite-key' => $response['body']['secret']
|
|
|
|
], []);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/keys', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Key Test',
|
|
|
|
'scopes' => ['health.read'],
|
2022-07-14 02:02:49 +12:00
|
|
|
'expire' => DateTime::addSeconds(new \DateTime(), -3600),
|
2022-06-01 18:26:55 +12:00
|
|
|
]);
|
|
|
|
|
2022-06-03 21:12:19 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/health', [
|
2022-06-01 18:26:55 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $id,
|
|
|
|
'x-appwrite-key' => $response['body']['secret']
|
|
|
|
], []);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $response['headers']['status-code']);
|
2022-06-01 03:41:12 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-12 01:26:04 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProjectKey
|
|
|
|
*/
|
|
|
|
public function testUpdateProjectKey($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
$keyId = $data['keyId'] ?? '';
|
2020-07-12 01:26:04 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/keys/' . $keyId, array_merge([
|
2020-07-12 01:26:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Key Test Update',
|
|
|
|
'scopes' => ['users.read', 'users.write', 'collections.read'],
|
2022-07-14 02:02:49 +12:00
|
|
|
'expire' => DateTime::addSeconds(new \DateTime(), 360),
|
2020-07-12 01:26:04 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($keyId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('Key Test Update', $response['body']['name']);
|
|
|
|
$this->assertContains('users.read', $response['body']['scopes']);
|
|
|
|
$this->assertContains('users.write', $response['body']['scopes']);
|
|
|
|
$this->assertContains('collections.read', $response['body']['scopes']);
|
|
|
|
$this->assertCount(3, $response['body']['scopes']);
|
2022-08-31 02:04:42 +12:00
|
|
|
$this->assertArrayHasKey('sdks', $response['body']);
|
|
|
|
$this->assertEmpty($response['body']['sdks']);
|
|
|
|
$this->assertArrayHasKey('accessedAt', $response['body']);
|
|
|
|
$this->assertEmpty($response['body']['accessedAt']);
|
2020-07-12 01:26:04 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([
|
2020-07-12 01:26:04 +12:00
|
|
|
'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($keyId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('Key Test Update', $response['body']['name']);
|
|
|
|
$this->assertContains('users.read', $response['body']['scopes']);
|
|
|
|
$this->assertContains('users.write', $response['body']['scopes']);
|
|
|
|
$this->assertContains('collections.read', $response['body']['scopes']);
|
|
|
|
$this->assertCount(3, $response['body']['scopes']);
|
2022-08-31 02:04:42 +12:00
|
|
|
$this->assertArrayHasKey('sdks', $response['body']);
|
|
|
|
$this->assertEmpty($response['body']['sdks']);
|
|
|
|
$this->assertArrayHasKey('accessedAt', $response['body']);
|
|
|
|
$this->assertEmpty($response['body']['accessedAt']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-12 01:26:04 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/keys/' . $keyId, array_merge([
|
2020-07-12 01:26:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Key Test Update',
|
|
|
|
'scopes' => ['users.read', 'users.write', 'collections.read', 'unknown'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateProjectKey
|
|
|
|
*/
|
|
|
|
public function testDeleteProjectKey($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
|
|
|
$keyId = $data['keyId'] ?? '';
|
2020-07-12 01:26:04 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/' . $keyId, array_merge([
|
2020-07-12 01:26:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/keys/' . $keyId, array_merge([
|
2020-07-12 01:26:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-12 01:26:04 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/keys/error', array_merge([
|
2020-07-12 01:26:04 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2020-07-12 07:40:58 +12:00
|
|
|
|
2020-07-12 23:57:31 +12:00
|
|
|
// Platforms
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateProject
|
|
|
|
*/
|
|
|
|
public function testCreateProjectPlatform($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'type' => 'web',
|
|
|
|
'name' => 'Web App',
|
|
|
|
'hostname' => 'localhost',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('web', $response['body']['type']);
|
|
|
|
$this->assertEquals('Web App', $response['body']['name']);
|
|
|
|
$this->assertEquals('', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('localhost', $response['body']['hostname']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-12 23:57:31 +12:00
|
|
|
$data = array_merge($data, ['platformWebId' => $response['body']['$id']]);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'type' => 'flutter-ios',
|
|
|
|
'name' => 'Flutter App (iOS)',
|
|
|
|
'key' => 'com.example.ios',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('flutter-ios', $response['body']['type']);
|
|
|
|
$this->assertEquals('Flutter App (iOS)', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.ios', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-12 23:57:31 +12:00
|
|
|
$data = array_merge($data, ['platformFultteriOSId' => $response['body']['$id']]);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'type' => 'flutter-android',
|
|
|
|
'name' => 'Flutter App (Android)',
|
|
|
|
'key' => 'com.example.android',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('flutter-android', $response['body']['type']);
|
|
|
|
$this->assertEquals('Flutter App (Android)', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.android', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-12 23:57:31 +12:00
|
|
|
$data = array_merge($data, ['platformFultterAndroidId' => $response['body']['$id']]);
|
|
|
|
|
2023-01-12 12:38:09 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'type' => 'flutter-web',
|
|
|
|
'name' => 'Flutter App (Web)',
|
|
|
|
'hostname' => 'flutter.appwrite.io',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('flutter-web', $response['body']['type']);
|
|
|
|
$this->assertEquals('Flutter App (Web)', $response['body']['name']);
|
|
|
|
$this->assertEquals('', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('flutter.appwrite.io', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$data = array_merge($data, ['platformFultterWebId' => $response['body']['$id']]);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'type' => 'apple-ios',
|
|
|
|
'name' => 'iOS App',
|
|
|
|
'key' => 'com.example.ios',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-ios', $response['body']['type']);
|
|
|
|
$this->assertEquals('iOS App', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.ios', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$data = array_merge($data, ['platformAppleIosId' => $response['body']['$id']]);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'type' => 'apple-macos',
|
|
|
|
'name' => 'macOS App',
|
|
|
|
'key' => 'com.example.macos',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-macos', $response['body']['type']);
|
|
|
|
$this->assertEquals('macOS App', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.macos', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$data = array_merge($data, ['platformAppleMacOsId' => $response['body']['$id']]);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'type' => 'apple-watchos',
|
|
|
|
'name' => 'watchOS App',
|
|
|
|
'key' => 'com.example.watchos',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-watchos', $response['body']['type']);
|
|
|
|
$this->assertEquals('watchOS App', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.watchos', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$data = array_merge($data, ['platformAppleWatchOsId' => $response['body']['$id']]);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'type' => 'apple-tvos',
|
|
|
|
'name' => 'tvOS App',
|
|
|
|
'key' => 'com.example.tvos',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-tvos', $response['body']['type']);
|
|
|
|
$this->assertEquals('tvOS App', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.tvos', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$data = array_merge($data, ['platformAppleTvOsId' => $response['body']['$id']]);
|
|
|
|
|
2020-07-12 23:57:31 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'type' => 'unknown',
|
|
|
|
'name' => 'Web App',
|
|
|
|
'hostname' => 'localhost',
|
|
|
|
]);
|
|
|
|
|
2021-12-02 00:48:23 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2020-07-12 23:57:31 +12:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-07-13 01:43:47 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProjectPlatform
|
|
|
|
*/
|
|
|
|
public function testListProjectPlatform($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2021-12-02 00:48:23 +13:00
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms', array_merge([
|
2020-07-13 01:43:47 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2023-01-12 12:38:09 +13:00
|
|
|
$this->assertEquals(8, $response['body']['total']);
|
2020-07-13 01:43:47 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-07-13 01:43:47 +12:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2020-07-12 23:57:31 +12:00
|
|
|
/**
|
|
|
|
* @depends testCreateProjectPlatform
|
|
|
|
*/
|
|
|
|
public function testGetProjectPlatform($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2021-12-02 00:48:23 +13:00
|
|
|
|
2020-10-15 10:11:12 +13:00
|
|
|
$platformWebId = $data['platformWebId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'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($platformWebId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('web', $response['body']['type']);
|
|
|
|
$this->assertEquals('Web App', $response['body']['name']);
|
|
|
|
$this->assertEquals('', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('localhost', $response['body']['hostname']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-10-15 10:11:12 +13:00
|
|
|
$platformFultteriOSId = $data['platformFultteriOSId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'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($platformFultteriOSId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('flutter-ios', $response['body']['type']);
|
|
|
|
$this->assertEquals('Flutter App (iOS)', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.ios', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-10-15 10:11:12 +13:00
|
|
|
$platformFultterAndroidId = $data['platformFultterAndroidId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'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($platformFultterAndroidId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('flutter-android', $response['body']['type']);
|
|
|
|
$this->assertEquals('Flutter App (Android)', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.android', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
2021-10-14 02:44:52 +13:00
|
|
|
|
2023-01-12 12:38:09 +13:00
|
|
|
$platformFultterWebId = $data['platformFultterWebId'] ?? '';
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterWebId, 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($platformFultterWebId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('flutter-web', $response['body']['type']);
|
|
|
|
$this->assertEquals('Flutter App (Web)', $response['body']['name']);
|
|
|
|
$this->assertEquals('', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('flutter.appwrite.io', $response['body']['hostname']);
|
|
|
|
|
2021-10-14 02:44:52 +13:00
|
|
|
$platformAppleIosId = $data['platformAppleIosId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'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($platformAppleIosId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-ios', $response['body']['type']);
|
|
|
|
$this->assertEquals('iOS App', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.ios', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$platformAppleMacOsId = $data['platformAppleMacOsId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'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($platformAppleMacOsId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-macos', $response['body']['type']);
|
|
|
|
$this->assertEquals('macOS App', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.macos', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$platformAppleWatchOsId = $data['platformAppleWatchOsId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'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($platformAppleWatchOsId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-watchos', $response['body']['type']);
|
|
|
|
$this->assertEquals('watchOS App', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.watchos', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$platformAppleTvOsId = $data['platformAppleTvOsId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'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($platformAppleTvOsId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-tvos', $response['body']['type']);
|
|
|
|
$this->assertEquals('tvOS App', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.tvos', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
2020-07-12 23:57:31 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/error', array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateProjectPlatform
|
|
|
|
*/
|
|
|
|
public function testUpdateProjectPlatform($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2020-10-15 10:11:12 +13:00
|
|
|
$platformWebId = $data['platformWebId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Web App 2',
|
|
|
|
'hostname' => 'localhost-new',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($platformWebId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('web', $response['body']['type']);
|
|
|
|
$this->assertEquals('Web App 2', $response['body']['name']);
|
|
|
|
$this->assertEquals('', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('localhost-new', $response['body']['hostname']);
|
|
|
|
|
2020-10-15 10:11:12 +13:00
|
|
|
$platformFultteriOSId = $data['platformFultteriOSId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Flutter App (iOS) 2',
|
|
|
|
'key' => 'com.example.ios2',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($platformFultteriOSId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('flutter-ios', $response['body']['type']);
|
|
|
|
$this->assertEquals('Flutter App (iOS) 2', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.ios2', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-10-15 10:11:12 +13:00
|
|
|
$platformFultterAndroidId = $data['platformFultterAndroidId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Flutter App (Android) 2',
|
|
|
|
'key' => 'com.example.android2',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($platformFultterAndroidId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('flutter-android', $response['body']['type']);
|
|
|
|
$this->assertEquals('Flutter App (Android) 2', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.android2', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
2023-01-12 12:38:09 +13:00
|
|
|
$platformFultterWebId = $data['platformFultterWebId'] ?? '';
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Flutter App (Web) 2',
|
|
|
|
'hostname' => 'flutter2.appwrite.io',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($platformFultterWebId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('flutter-web', $response['body']['type']);
|
|
|
|
$this->assertEquals('Flutter App (Web) 2', $response['body']['name']);
|
|
|
|
$this->assertEquals('', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('flutter2.appwrite.io', $response['body']['hostname']);
|
|
|
|
|
2021-10-14 02:44:52 +13:00
|
|
|
$platformAppleIosId = $data['platformAppleIosId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'iOS App 2',
|
|
|
|
'key' => 'com.example.ios2',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($platformAppleIosId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-ios', $response['body']['type']);
|
|
|
|
$this->assertEquals('iOS App 2', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.ios2', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$platformAppleMacOsId = $data['platformAppleMacOsId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'macOS App 2',
|
|
|
|
'key' => 'com.example.macos2',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($platformAppleMacOsId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-macos', $response['body']['type']);
|
|
|
|
$this->assertEquals('macOS App 2', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.macos2', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$platformAppleWatchOsId = $data['platformAppleWatchOsId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'watchOS App 2',
|
|
|
|
'key' => 'com.example.watchos2',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($platformAppleWatchOsId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-watchos', $response['body']['type']);
|
|
|
|
$this->assertEquals('watchOS App 2', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.watchos2', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
|
|
|
$platformAppleTvOsId = $data['platformAppleTvOsId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'tvOS App 2',
|
|
|
|
'key' => 'com.example.tvos2',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']['$id']);
|
|
|
|
$this->assertEquals($platformAppleTvOsId, $response['body']['$id']);
|
|
|
|
$this->assertEquals('apple-tvos', $response['body']['type']);
|
|
|
|
$this->assertEquals('tvOS App 2', $response['body']['name']);
|
|
|
|
$this->assertEquals('com.example.tvos2', $response['body']['key']);
|
|
|
|
$this->assertEquals('', $response['body']['store']);
|
|
|
|
$this->assertEquals('', $response['body']['hostname']);
|
|
|
|
|
2020-07-12 23:57:31 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_PUT, '/projects/' . $id . '/platforms/error', array_merge([
|
2021-09-01 19:03:22 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'Flutter App (Android) 2',
|
|
|
|
'key' => 'com.example.android2',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2020-07-12 23:57:31 +12:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateProjectPlatform
|
|
|
|
*/
|
|
|
|
public function testDeleteProjectPlatform($data): array
|
|
|
|
{
|
2020-10-15 10:11:12 +13:00
|
|
|
$id = $data['projectId'] ?? '';
|
2022-04-19 04:21:45 +12:00
|
|
|
|
2020-10-15 10:11:12 +13:00
|
|
|
$platformWebId = $data['platformWebId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformWebId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
2020-10-15 10:11:12 +13:00
|
|
|
$platformFultteriOSId = $data['platformFultteriOSId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultteriOSId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
2020-10-15 10:11:12 +13:00
|
|
|
$platformFultterAndroidId = $data['platformFultterAndroidId'] ?? '';
|
2020-07-12 23:57:31 +12:00
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterAndroidId, array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2021-10-14 02:44:52 +13:00
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
2023-01-12 12:38:09 +13:00
|
|
|
$platformFultterWebId = $data['platformFultterWebId'] ?? '';
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformFultterWebId, 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']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformFultterWebId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
2021-10-14 02:44:52 +13:00
|
|
|
$platformAppleIosId = $data['platformAppleIosId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleIosId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$platformAppleMacOsId = $data['platformAppleMacOsId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleMacOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$platformAppleWatchOsId = $data['platformAppleWatchOsId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleWatchOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$platformAppleTvOsId = $data['platformAppleTvOsId'] ?? '';
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
|
|
|
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/projects/' . $id . '/platforms/' . $platformAppleTvOsId, array_merge([
|
2021-10-14 02:44:52 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-07-12 23:57:31 +12:00
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-04-19 04:21:45 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/projects/' . $id . '/webhooks/error', array_merge([
|
2020-07-12 23:57:31 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), []);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2020-07-13 01:43:47 +12:00
|
|
|
|
2022-10-03 21:06:48 +13:00
|
|
|
public function testDeleteProject(): array
|
|
|
|
{
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
// Create a team and a project
|
|
|
|
$team = $this->client->call(Client::METHOD_POST, '/teams', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'teamId' => ID::unique(),
|
|
|
|
'name' => 'Amating Team',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $team['headers']['status-code']);
|
|
|
|
$this->assertEquals('Amating Team', $team['body']['name']);
|
|
|
|
$this->assertNotEmpty($team['body']['$id']);
|
|
|
|
|
|
|
|
$teamId = $team['body']['$id'];
|
|
|
|
|
|
|
|
$project = $this->client->call(Client::METHOD_POST, '/projects', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'projectId' => ID::unique(),
|
|
|
|
'name' => 'Amazing Project',
|
|
|
|
'teamId' => $teamId,
|
|
|
|
'region' => 'default'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(201, $project['headers']['status-code']);
|
|
|
|
$this->assertEquals('Amazing Project', $project['body']['name']);
|
|
|
|
$this->assertEquals($teamId, $project['body']['teamId']);
|
|
|
|
$this->assertNotEmpty($project['body']['$id']);
|
|
|
|
|
|
|
|
$projectId = $project['body']['$id'];
|
|
|
|
|
|
|
|
// Ensure I can get both team and project
|
|
|
|
$team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $team['headers']['status-code']);
|
|
|
|
|
|
|
|
$project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $project['headers']['status-code']);
|
|
|
|
|
2023-05-25 12:32:49 +12:00
|
|
|
// Delete Project
|
2023-05-25 13:26:13 +12:00
|
|
|
$project = $this->client->call(Client::METHOD_DELETE, '/projects/' . $projectId, array_merge([
|
2022-10-03 21:06:48 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2023-05-25 12:32:49 +12:00
|
|
|
], $this->getHeaders()));
|
2022-10-03 21:06:48 +13:00
|
|
|
|
2023-05-25 12:32:49 +12:00
|
|
|
$this->assertEquals(204, $project['headers']['status-code']);
|
2022-10-03 21:06:48 +13:00
|
|
|
|
|
|
|
// Ensure I can get team but not a project
|
|
|
|
$team = $this->client->call(Client::METHOD_GET, '/teams/' . $teamId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $team['headers']['status-code']);
|
|
|
|
|
|
|
|
$project = $this->client->call(Client::METHOD_GET, '/projects/' . $projectId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(404, $project['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2020-07-12 07:40:58 +12:00
|
|
|
}
|