2020-01-13 10:28:26 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Storage;
|
|
|
|
|
2022-01-16 20:55:55 +13:00
|
|
|
use Tests\E2E\Client;
|
2020-01-13 10:28:26 +13:00
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\SideServer;
|
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;
|
2023-03-02 01:00:36 +13:00
|
|
|
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
2020-01-13 10:28:26 +13:00
|
|
|
|
|
|
|
class StorageCustomServerTest extends Scope
|
|
|
|
{
|
|
|
|
use StorageBase;
|
|
|
|
use ProjectCustom;
|
|
|
|
use SideServer;
|
2021-06-16 17:50:40 +12:00
|
|
|
|
2022-01-16 20:55:55 +13:00
|
|
|
public function testCreateBucket(): array
|
2021-06-16 17:50:40 +12:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'bucketId' => ID::unique(),
|
2021-06-16 17:50:40 +12:00
|
|
|
'name' => 'Test Bucket',
|
2022-08-03 16:17:49 +12:00
|
|
|
'fileSecurity' => true,
|
2021-06-16 17:50:40 +12:00
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucket['body']['$id']);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($bucket['body']['$createdAt']));
|
2022-08-02 21:19:15 +12:00
|
|
|
$this->assertIsArray($bucket['body']['$permissions']);
|
2021-06-16 17:54:19 +12:00
|
|
|
$this->assertIsArray($bucket['body']['allowedFileExtensions']);
|
2021-06-16 17:50:40 +12:00
|
|
|
$this->assertEquals('Test Bucket', $bucket['body']['name']);
|
|
|
|
$this->assertEquals(true, $bucket['body']['enabled']);
|
2021-06-16 17:54:19 +12:00
|
|
|
$this->assertEquals(true, $bucket['body']['encryption']);
|
2022-01-16 20:55:55 +13:00
|
|
|
$this->assertEquals(true, $bucket['body']['antivirus']);
|
2021-06-16 17:50:40 +12:00
|
|
|
$bucketId = $bucket['body']['$id'];
|
2021-09-02 22:11:10 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test create with Custom ID
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'bucketId' => ID::custom('bucket1'),
|
2021-09-02 22:11:10 +12:00
|
|
|
'name' => 'Test Bucket',
|
2022-08-03 16:17:49 +12:00
|
|
|
'fileSecurity' => true,
|
2021-09-02 22:11:10 +12:00
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertEquals('bucket1', $bucket['body']['$id']);
|
2022-01-16 20:55:55 +13:00
|
|
|
|
2021-06-16 17:50:40 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'bucketId' => ID::unique(),
|
2021-06-16 17:50:40 +12:00
|
|
|
'name' => '',
|
2022-08-03 16:17:49 +12:00
|
|
|
'fileSecurity' => true,
|
2021-06-16 17:50:40 +12:00
|
|
|
]);
|
|
|
|
$this->assertEquals(400, $bucket['headers']['status-code']);
|
|
|
|
|
|
|
|
return ['bucketId' => $bucketId];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateBucket
|
|
|
|
*/
|
|
|
|
public function testListBucket($data): array
|
|
|
|
{
|
|
|
|
$id = $data['bucketId'] ?? '';
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(
|
|
|
|
Client::METHOD_GET,
|
|
|
|
'/storage/buckets',
|
|
|
|
array_merge(
|
|
|
|
[
|
2021-06-16 17:50:40 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-24 02:54:50 +12:00
|
|
|
],
|
|
|
|
$this->getHeaders()
|
|
|
|
)
|
|
|
|
);
|
2021-06-16 17:50:40 +12:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertEquals($id, $response['body']['buckets'][0]['$id']);
|
|
|
|
$this->assertEquals('Test Bucket', $response['body']['buckets'][0]['name']);
|
|
|
|
|
2022-08-24 23:55:43 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/storage/buckets', 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-08-24 23:55:43 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertCount(1, $response['body']['buckets']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/storage/buckets', 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(1)->toString(),
|
|
|
|
],
|
2022-08-24 23:55:43 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertCount(1, $response['body']['buckets']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/storage/buckets', 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('$id', ['bucket1'])->toString(),
|
|
|
|
],
|
2022-08-24 23:55:43 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertCount(1, $response['body']['buckets']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/storage/buckets', 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('fileSecurity', [true])->toString(),
|
|
|
|
],
|
2022-08-24 23:55:43 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertCount(2, $response['body']['buckets']);
|
|
|
|
|
2021-09-02 22:11:10 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/storage/buckets', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2023-12-20 23:55:09 +13:00
|
|
|
'queries' => [
|
|
|
|
Query::cursorAfter(new Document(['$id' => $response['body']['buckets'][0]['$id']]))->toString(),
|
|
|
|
],
|
2021-09-02 22:11:10 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertNotEmpty($response['body']['buckets']);
|
|
|
|
$this->assertCount(1, $response['body']['buckets']);
|
|
|
|
|
|
|
|
$this->assertEquals('bucket1', $response['body']['buckets'][0]['$id']);
|
2021-06-16 17:50:40 +12:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateBucket
|
|
|
|
*/
|
2021-06-16 22:17:14 +12:00
|
|
|
public function testGetBucket(array $data): array
|
2021-06-16 17:50:40 +12:00
|
|
|
{
|
|
|
|
$id = $data['bucketId'] ?? '';
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(
|
|
|
|
Client::METHOD_GET,
|
|
|
|
'/storage/buckets/' . $id,
|
|
|
|
array_merge(
|
|
|
|
[
|
2021-06-16 17:50:40 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-24 02:54:50 +12:00
|
|
|
],
|
|
|
|
$this->getHeaders()
|
|
|
|
)
|
|
|
|
);
|
2021-06-16 17:50:40 +12:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
$this->assertEquals($id, $response['body']['$id']);
|
|
|
|
$this->assertEquals('Test Bucket', $response['body']['name']);
|
2022-01-16 20:55:55 +13:00
|
|
|
|
2021-06-16 17:50:40 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-01-16 20:55:55 +13:00
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(
|
|
|
|
Client::METHOD_GET,
|
|
|
|
'/storage/buckets/empty',
|
|
|
|
array_merge(
|
|
|
|
[
|
2021-06-16 17:50:40 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-24 02:54:50 +12:00
|
|
|
],
|
|
|
|
$this->getHeaders()
|
|
|
|
)
|
|
|
|
);
|
2021-06-16 17:50:40 +12:00
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
2022-01-16 20:55:55 +13:00
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(
|
|
|
|
Client::METHOD_GET,
|
|
|
|
'/storage/buckets/id-is-really-long-id-is-really-long-id-is-really-long-id-is-really-long',
|
|
|
|
array_merge(
|
|
|
|
[
|
2021-06-16 17:50:40 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-24 02:54:50 +12:00
|
|
|
],
|
|
|
|
$this->getHeaders()
|
|
|
|
)
|
|
|
|
);
|
2021-06-16 17:50:40 +12:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2021-06-16 21:59:47 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateBucket
|
|
|
|
*/
|
2022-01-16 20:55:55 +13:00
|
|
|
public function testUpdateBucket(array $data): array
|
2021-06-16 21:59:47 +12:00
|
|
|
{
|
|
|
|
$id = $data['bucketId'] ?? '';
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2021-09-02 20:30:10 +12:00
|
|
|
$bucket = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $id, array_merge([
|
2021-06-16 21:59:47 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'bucketId' => ID::unique(),
|
2021-06-16 21:59:47 +12:00
|
|
|
'name' => 'Test Bucket Updated',
|
|
|
|
'enabled' => false,
|
2022-08-03 16:17:49 +12:00
|
|
|
'fileSecurity' => true,
|
2021-06-16 21:59:47 +12:00
|
|
|
]);
|
2021-09-02 20:30:10 +12:00
|
|
|
$this->assertEquals(200, $bucket['headers']['status-code']);
|
2021-06-16 21:59:47 +12:00
|
|
|
$this->assertNotEmpty($bucket['body']['$id']);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($bucket['body']['$createdAt']));
|
2022-08-02 21:19:15 +12:00
|
|
|
$this->assertIsArray($bucket['body']['$permissions']);
|
2021-06-16 21:59:47 +12:00
|
|
|
$this->assertIsArray($bucket['body']['allowedFileExtensions']);
|
|
|
|
$this->assertEquals('Test Bucket Updated', $bucket['body']['name']);
|
|
|
|
$this->assertEquals(false, $bucket['body']['enabled']);
|
|
|
|
$this->assertEquals(true, $bucket['body']['encryption']);
|
2022-01-16 20:55:55 +13:00
|
|
|
$this->assertEquals(true, $bucket['body']['antivirus']);
|
2021-06-16 21:59:47 +12:00
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2021-09-02 20:30:10 +12:00
|
|
|
$bucket = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $id, array_merge([
|
2021-06-16 21:59:47 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => '',
|
|
|
|
'enabled' => 'false',
|
|
|
|
]);
|
|
|
|
$this->assertEquals(400, $bucket['headers']['status-code']);
|
|
|
|
|
|
|
|
return ['bucketId' => $bucketId];
|
|
|
|
}
|
2021-06-16 22:17:14 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateBucket
|
|
|
|
*/
|
|
|
|
public function testDeleteBucket(array $data): array
|
|
|
|
{
|
|
|
|
$id = $data['bucketId'] ?? '';
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(
|
|
|
|
Client::METHOD_DELETE,
|
|
|
|
'/storage/buckets/' . $id,
|
|
|
|
array_merge(
|
|
|
|
[
|
2021-06-16 22:17:14 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-24 02:54:50 +12:00
|
|
|
],
|
|
|
|
$this->getHeaders()
|
|
|
|
)
|
|
|
|
);
|
2021-06-16 22:17:14 +12:00
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
|
|
|
$this->assertEmpty($response['body']);
|
2022-01-16 20:55:55 +13:00
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$response = $this->client->call(
|
|
|
|
Client::METHOD_GET,
|
|
|
|
'/storage/buckets/' . $id,
|
|
|
|
array_merge(
|
|
|
|
[
|
2021-06-16 22:17:14 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-05-24 02:54:50 +12:00
|
|
|
],
|
|
|
|
$this->getHeaders()
|
|
|
|
)
|
|
|
|
);
|
2021-06-16 22:17:14 +12:00
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2022-01-16 20:55:55 +13:00
|
|
|
}
|