2020-01-13 10:28:26 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Storage;
|
|
|
|
|
2021-09-07 01:33:06 +12:00
|
|
|
use CURLFile;
|
|
|
|
use Tests\E2E\Client;
|
2020-01-13 10:28:26 +13:00
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
use Tests\E2E\Scopes\SideClient;
|
2022-07-13 04:44:58 +12:00
|
|
|
use Utopia\Database\DateTime;
|
2022-12-15 04:42:25 +13:00
|
|
|
use Utopia\Database\Helpers\ID;
|
2022-12-15 05:04:06 +13:00
|
|
|
use Utopia\Database\Helpers\Permission;
|
|
|
|
use Utopia\Database\Helpers\Role;
|
2023-03-02 01:00:36 +13:00
|
|
|
use Utopia\Database\Validator\Datetime as DatetimeValidator;
|
2020-01-13 10:28:26 +13:00
|
|
|
|
|
|
|
class StorageCustomClientTest extends Scope
|
|
|
|
{
|
|
|
|
use StorageBase;
|
|
|
|
use ProjectCustom;
|
|
|
|
use SideClient;
|
2022-08-25 23:29:23 +12:00
|
|
|
use StoragePermissionsScope;
|
2021-09-07 01:33:06 +12:00
|
|
|
|
2022-11-11 03:43:17 +13:00
|
|
|
public function testCachedFilePreview(): void
|
2022-03-15 22:51:51 +13:00
|
|
|
{
|
|
|
|
/**
|
2022-11-11 03:43:17 +13:00
|
|
|
Create a bucket with File Level Security with no permissions.
|
|
|
|
Add a file with no permissions.
|
|
|
|
Login as UserA from SDK
|
|
|
|
Call File Preview from SDK all good userA can't see preview.
|
|
|
|
Add read permission to UserA, all good userA can now see preview.
|
|
|
|
Remove read permission for UserA.
|
|
|
|
Call File Preview from SDK and now userA can't see the preview.
|
2022-03-15 22:51:51 +13:00
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
2022-08-14 22:33:36 +12:00
|
|
|
'bucketId' => ID::unique(),
|
2022-03-15 22:51:51 +13:00
|
|
|
'name' => 'Test Bucket',
|
2022-11-11 03:43:17 +13:00
|
|
|
'fileSecurity' => true,
|
|
|
|
'permissions' => [],
|
2022-08-25 23:29:23 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucketId);
|
|
|
|
|
2022-11-11 03:43:17 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-11-11 03:43:17 +13:00
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey']
|
|
|
|
]), [
|
2022-08-25 23:29:23 +12:00
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = $file['body']['$id'];
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($fileId);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file['body']['$createdAt']));
|
2022-08-25 23:29:23 +12:00
|
|
|
$this->assertEquals('permissions.png', $file['body']['name']);
|
|
|
|
$this->assertEquals('image/png', $file['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
|
|
|
|
2022-11-11 03:43:17 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', array_merge([
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-11-11 03:43:17 +13:00
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(404, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'name' => 'permissions.png',
|
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::user($this->getUser()['$id'])),
|
|
|
|
],
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-11-11 03:43:17 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', array_merge([
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-11-11 03:43:17 +13:00
|
|
|
], $this->getHeaders()));
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-11-11 03:43:17 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-11-11 03:43:17 +13:00
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'name' => 'permissions.png',
|
|
|
|
'permissions' => [],
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-11-11 03:43:17 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', array_merge([
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-11-11 03:43:17 +13:00
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(404, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $file['headers']['status-code']);
|
|
|
|
$this->assertEmpty($file['body']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBucketAnyPermissions(): void
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'bucketId' => ID::unique(),
|
|
|
|
'name' => 'Test Bucket',
|
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::any()),
|
|
|
|
Permission::create(Role::any()),
|
|
|
|
Permission::update(Role::any()),
|
|
|
|
Permission::delete(Role::any()),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucketId);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = $file['body']['$id'];
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($fileId);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file['body']['$createdAt']));
|
2022-11-11 03:43:17 +13:00
|
|
|
$this->assertEquals('permissions.png', $file['body']['name']);
|
|
|
|
$this->assertEquals('image/png', $file['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
2022-11-11 03:43:17 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-08-29 17:53:37 +12:00
|
|
|
], [
|
2022-11-11 03:43:17 +13:00
|
|
|
'name' => 'permissions.png',
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
2022-11-11 03:43:17 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(204, $file['headers']['status-code']);
|
|
|
|
$this->assertEmpty($file['body']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBucketUsersPermissions(): void
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'bucketId' => ID::unique(),
|
|
|
|
'name' => 'Test Bucket',
|
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::users()),
|
2022-08-14 17:21:11 +12:00
|
|
|
Permission::create(Role::users()),
|
|
|
|
Permission::update(Role::users()),
|
|
|
|
Permission::delete(Role::users()),
|
2022-08-03 16:17:49 +12:00
|
|
|
],
|
2022-03-15 22:51:51 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucketId);
|
2022-08-16 23:39:57 +12:00
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
|
2022-03-15 22:51:51 +13:00
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'fileId' => ID::unique(),
|
2022-03-15 22:51:51 +13:00
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = $file['body']['$id'];
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($fileId);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file['body']['$createdAt']));
|
2022-03-15 22:51:51 +13:00
|
|
|
$this->assertEquals('permissions.png', $file['body']['name']);
|
|
|
|
$this->assertEquals('image/png', $file['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'permissions.png',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-03-15 22:51:51 +13:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2022-08-25 23:29:23 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'permissions' => [],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(204, $file['headers']['status-code']);
|
|
|
|
$this->assertEmpty($file['body']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBucketUserPermissions(): void
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'bucketId' => ID::unique(),
|
|
|
|
'name' => 'Test Bucket',
|
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::user($this->getUser()['$id'])),
|
|
|
|
Permission::create(Role::user($this->getUser()['$id'])),
|
|
|
|
Permission::update(Role::user($this->getUser()['$id'])),
|
|
|
|
Permission::delete(Role::user($this->getUser()['$id'])),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucketId);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = $file['body']['$id'];
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($fileId);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file['body']['$createdAt']));
|
2022-08-25 23:29:23 +12:00
|
|
|
$this->assertEquals('permissions.png', $file['body']['name']);
|
|
|
|
$this->assertEquals('image/png', $file['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
|
|
|
'name' => 'permissions.png',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-08-25 23:29:23 +12:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$this->client->call(CLient::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'name' => 'permissions.png',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
|
|
|
|
2022-08-25 23:29:23 +12:00
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$email = ID::unique() . '@localhost.test';
|
|
|
|
$password = 'password';
|
|
|
|
$user2 = $this->createUser('user2', $email, $password);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
2022-03-15 22:51:51 +13:00
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-08-25 23:29:23 +12:00
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
2022-03-15 22:51:51 +13:00
|
|
|
], [
|
2022-08-14 22:33:36 +12:00
|
|
|
'fileId' => ID::unique(),
|
2022-03-15 22:51:51 +13:00
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
2022-08-25 23:29:23 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
], [
|
|
|
|
'permissions' => [],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
2022-03-15 22:51:51 +13:00
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(204, $file['headers']['status-code']);
|
|
|
|
$this->assertEmpty($file['body']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBucketTeamPermissions(): void
|
|
|
|
{
|
|
|
|
$team1 = $this->createTeam(ID::unique(), 'Team 1');
|
|
|
|
$team2 = $this->createTeam(ID::unique(), 'Team 1');
|
|
|
|
$user1 = $this->createUser(ID::unique(), ID::unique() . '@localhost.test', 'password');
|
|
|
|
$user2 = $this->createUser(ID::unique(), ID::unique() . '@localhost.test', 'password');
|
|
|
|
|
|
|
|
$this->addToTeam($user1['$id'], $team1['$id']);
|
|
|
|
$this->addToTeam($user2['$id'], $team2['$id']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'bucketId' => ID::unique(),
|
|
|
|
'name' => 'Test Bucket',
|
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::team(ID::custom($team1['$id']))),
|
|
|
|
Permission::read(Role::team(ID::custom($team2['$id']))),
|
|
|
|
Permission::create(Role::team(ID::custom($team1['$id']))),
|
|
|
|
Permission::update(Role::team(ID::custom($team1['$id']))),
|
|
|
|
Permission::delete(Role::team(ID::custom($team1['$id']))),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucketId);
|
|
|
|
|
|
|
|
// Team 1 create success
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = $file['body']['$id'];
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($fileId);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file['body']['$createdAt']));
|
2022-08-25 23:29:23 +12:00
|
|
|
$this->assertEquals('permissions.png', $file['body']['name']);
|
|
|
|
$this->assertEquals('image/png', $file['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
|
|
|
|
|
|
|
// Team 1 read success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 2 read success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 1 preview success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 2 preview success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 1 download success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 2 download success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 1 view success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 1 view success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Team 2 create failure
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
// Team 2 update failure
|
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
], [
|
|
|
|
'permissions' => [],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
// Team 2 delete failure
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
// Team 1 delete success
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(204, $file['headers']['status-code']);
|
|
|
|
$this->assertEmpty($file['body']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFileAnyPermissions(): void
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'bucketId' => ID::unique(),
|
|
|
|
'name' => 'Test Bucket',
|
|
|
|
'permissions' => [],
|
|
|
|
'fileSecurity' => true
|
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucketId);
|
|
|
|
|
|
|
|
$file1 = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::any()),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = $file1['body']['$id'];
|
|
|
|
$this->assertEquals($file1['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($fileId);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file1['body']['$createdAt']));
|
2022-08-25 23:29:23 +12:00
|
|
|
$this->assertEquals('permissions.png', $file1['body']['name']);
|
|
|
|
$this->assertEquals('image/png', $file1['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file1['body']['sizeOriginal']);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', [
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', [
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', [
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
|
|
|
|
2022-08-29 17:53:37 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
2022-08-25 23:29:23 +12:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-08-29 17:53:37 +12:00
|
|
|
]);
|
2022-08-25 23:29:23 +12:00
|
|
|
|
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFileUsersPermissions(): void
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'bucketId' => ID::unique(),
|
|
|
|
'name' => 'Test Bucket',
|
|
|
|
'permissions' => [],
|
|
|
|
'fileSecurity' => true
|
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucketId);
|
|
|
|
|
|
|
|
$file1 = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::users()),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = $file1['body']['$id'];
|
|
|
|
$this->assertEquals($file1['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($fileId);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file1['body']['$createdAt']));
|
2022-08-25 23:29:23 +12:00
|
|
|
$this->assertEquals('permissions.png', $file1['body']['name']);
|
|
|
|
$this->assertEquals('image/png', $file1['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file1['body']['sizeOriginal']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFileUserPermissions(): void
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'bucketId' => ID::unique(),
|
|
|
|
'name' => 'Test Bucket',
|
|
|
|
'permissions' => [],
|
|
|
|
'fileSecurity' => true
|
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucketId);
|
|
|
|
|
|
|
|
$file1 = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::user($this->getUser()['$id'])),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = $file1['body']['$id'];
|
|
|
|
$this->assertEquals($file1['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($fileId);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file1['body']['$createdAt']));
|
2022-08-25 23:29:23 +12:00
|
|
|
$this->assertEquals('permissions.png', $file1['body']['name']);
|
|
|
|
$this->assertEquals('image/png', $file1['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file1['body']['sizeOriginal']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()));
|
|
|
|
|
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
$user2 = $this->createUser(ID::unique(), uniqid() . '@localhost.test', 'password');
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 404);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
], [
|
|
|
|
'permissions' => [],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFileTeamPermissions(): void
|
|
|
|
{
|
|
|
|
$team1 = $this->createTeam(ID::unique(), 'Team 1');
|
|
|
|
$team2 = $this->createTeam(ID::unique(), 'Team 1');
|
|
|
|
$user1 = $this->createUser(ID::unique(), ID::unique() . '@localhost.test', 'password');
|
|
|
|
$user2 = $this->createUser(ID::unique(), ID::unique() . '@localhost.test', 'password');
|
|
|
|
|
|
|
|
$this->addToTeam($user1['$id'], $team1['$id']);
|
|
|
|
$this->addToTeam($user2['$id'], $team2['$id']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'bucketId' => ID::unique(),
|
|
|
|
'name' => 'Test Bucket',
|
|
|
|
'permissions' => [],
|
|
|
|
'fileSecurity' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucketId);
|
|
|
|
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::team(ID::custom($team1['$id']))),
|
|
|
|
Permission::read(Role::team(ID::custom($team2['$id']))),
|
|
|
|
Permission::update(Role::team(ID::custom($team1['$id']))),
|
|
|
|
Permission::delete(Role::team(ID::custom($team1['$id']))),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = $file['body']['$id'];
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($fileId);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file['body']['$createdAt']));
|
2022-08-25 23:29:23 +12:00
|
|
|
$this->assertEquals('permissions.png', $file['body']['name']);
|
|
|
|
$this->assertEquals('image/png', $file['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
|
|
|
|
|
|
|
// Team 1 read success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 2 read success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 1 preview success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 2 preview success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 1 download success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 2 download success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/download', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 1 view success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
// Team 1 view success
|
|
|
|
$file = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId . '/view', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $file['headers']['status-code']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Team 1 create failure
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Team 2 create failure
|
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
// Team 2 update failure
|
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
], [
|
|
|
|
'permissions' => [],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
// Team 2 delete failure
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user2['session'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 401);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
// Team 1 delete success
|
|
|
|
$file = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $fileId, [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $user1['session'],
|
|
|
|
]);
|
|
|
|
|
2022-03-15 22:51:51 +13:00
|
|
|
$this->assertEquals(204, $file['headers']['status-code']);
|
|
|
|
$this->assertEmpty($file['body']);
|
|
|
|
}
|
|
|
|
|
2022-09-05 14:16:40 +12:00
|
|
|
public function testAllowedPermissions(): void
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Bucket aliases write to create, update, delete
|
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
|
|
|
], [
|
|
|
|
'bucketId' => ID::unique(),
|
|
|
|
'name' => 'Test Bucket',
|
|
|
|
'permissions' => [
|
2022-09-06 21:13:42 +12:00
|
|
|
Permission::write(Role::user($this->getUser()['$id'])),
|
2022-09-05 14:16:40 +12:00
|
|
|
],
|
|
|
|
'fileSecurity' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$bucketId = $bucket['body']['$id'];
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
|
|
|
|
$this->assertContains(Permission::create(Role::user($this->getUser()['$id'])), $bucket['body']['$permissions']);
|
|
|
|
$this->assertContains(Permission::update(Role::user($this->getUser()['$id'])), $bucket['body']['$permissions']);
|
|
|
|
$this->assertContains(Permission::delete(Role::user($this->getUser()['$id'])), $bucket['body']['$permissions']);
|
|
|
|
|
|
|
|
// File aliases write to update, delete
|
2022-09-05 19:51:33 +12:00
|
|
|
$file1 = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
|
2022-09-05 14:16:40 +12:00
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2022-09-05 19:51:33 +12:00
|
|
|
], $this->getHeaders()), [
|
2022-09-05 14:16:40 +12:00
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
'permissions' => [
|
2022-09-06 21:13:42 +12:00
|
|
|
Permission::write(Role::user($this->getUser()['$id'])),
|
2022-09-05 14:16:40 +12:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertNotContains(Permission::create(Role::user($this->getUser()['$id'])), $file1['body']['$permissions']);
|
|
|
|
$this->assertContains(Permission::update(Role::user($this->getUser()['$id'])), $file1['body']['$permissions']);
|
|
|
|
$this->assertContains(Permission::delete(Role::user($this->getUser()['$id'])), $file1['body']['$permissions']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
// File does not allow create permission
|
|
|
|
$file2 = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', [
|
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'fileId' => ID::unique(),
|
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
|
|
|
'permissions' => [
|
|
|
|
Permission::create(Role::user($this->getUser()['$id'])),
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $file2['headers']['status-code']);
|
|
|
|
}
|
|
|
|
|
2021-12-11 05:48:54 +13:00
|
|
|
public function testCreateFileDefaultPermissions(): array
|
2021-09-07 01:33:06 +12:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
2022-02-16 21:30:09 +13:00
|
|
|
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', [
|
2021-10-17 20:12:59 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
'x-appwrite-key' => $this->getProject()['apiKey'],
|
2022-02-16 21:30:09 +13:00
|
|
|
], [
|
2022-08-14 22:33:36 +12:00
|
|
|
'bucketId' => ID::unique(),
|
2021-10-17 20:12:59 +13:00
|
|
|
'name' => 'Test Bucket',
|
2022-08-02 21:19:15 +12:00
|
|
|
'fileSecurity' => true,
|
|
|
|
'permissions' => [
|
2022-08-14 17:21:11 +12:00
|
|
|
Permission::read(Role::any()),
|
|
|
|
Permission::create(Role::any()),
|
|
|
|
Permission::update(Role::any()),
|
|
|
|
Permission::delete(Role::any()),
|
2022-08-02 21:19:15 +12:00
|
|
|
],
|
2021-10-17 20:12:59 +13:00
|
|
|
]);
|
|
|
|
$this->assertEquals(201, $bucket['headers']['status-code']);
|
|
|
|
$this->assertNotEmpty($bucket['body']['$id']);
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucket['body']['$id'] . '/files', array_merge([
|
2021-09-07 01:33:06 +12:00
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'fileId' => ID::unique(),
|
2021-10-08 21:39:37 +13:00
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
2021-09-07 01:33:06 +12:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals($file['headers']['status-code'], 201);
|
|
|
|
$this->assertNotEmpty($file['body']['$id']);
|
2022-08-15 02:22:38 +12:00
|
|
|
$this->assertContains(Permission::read(Role::user($this->getUser()['$id'])), $file['body']['$permissions']);
|
|
|
|
$this->assertContains(Permission::update(Role::user($this->getUser()['$id'])), $file['body']['$permissions']);
|
|
|
|
$this->assertContains(Permission::delete(Role::user($this->getUser()['$id'])), $file['body']['$permissions']);
|
2023-02-06 09:39:41 +13:00
|
|
|
$this->assertEquals(true, (new DatetimeValidator())->isValid($file['body']['$createdAt']));
|
2021-10-08 21:39:37 +13:00
|
|
|
$this->assertEquals('permissions.png', $file['body']['name']);
|
2021-09-07 01:33:06 +12:00
|
|
|
$this->assertEquals('image/png', $file['body']['mimeType']);
|
|
|
|
$this->assertEquals(47218, $file['body']['sizeOriginal']);
|
2021-12-11 05:48:54 +13:00
|
|
|
|
2021-12-14 22:42:39 +13:00
|
|
|
return ['fileId' => $file['body']['$id'], 'bucketId' => $bucket['body']['$id']];
|
2021-12-11 05:48:54 +13:00
|
|
|
}
|
|
|
|
|
2021-12-14 22:42:39 +13:00
|
|
|
/**
|
|
|
|
* @depends testCreateFileDefaultPermissions
|
|
|
|
*/
|
|
|
|
public function testCreateFileAbusePermissions(array $data): void
|
2021-12-11 05:48:54 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2021-12-14 22:42:39 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([
|
2021-12-11 05:48:54 +13:00
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'fileId' => ID::unique(),
|
2021-12-11 05:48:54 +13:00
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
2022-08-14 22:33:36 +12:00
|
|
|
'folderId' => ID::custom('xyz'),
|
2022-08-03 16:17:49 +12:00
|
|
|
'permissions' => [
|
2022-08-14 22:33:36 +12:00
|
|
|
Permission::read(Role::user(ID::custom('notme'))),
|
2022-08-03 16:17:49 +12:00
|
|
|
],
|
2021-12-11 05:48:54 +13:00
|
|
|
]);
|
|
|
|
|
2022-08-16 23:29:11 +12:00
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
2022-08-09 19:11:30 +12:00
|
|
|
$this->assertStringStartsWith('Permissions must be one of:', $file['body']['message']);
|
2022-08-03 16:17:49 +12:00
|
|
|
$this->assertStringContainsString('any', $file['body']['message']);
|
|
|
|
$this->assertStringContainsString('users', $file['body']['message']);
|
2022-05-24 02:54:50 +12:00
|
|
|
$this->assertStringContainsString('user:' . $this->getUser()['$id'], $file['body']['message']);
|
2021-12-11 05:48:54 +13:00
|
|
|
|
2021-12-14 22:42:39 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([
|
2021-12-11 05:48:54 +13:00
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'fileId' => ID::unique(),
|
2021-12-11 05:48:54 +13:00
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
2022-08-14 22:33:36 +12:00
|
|
|
'folderId' => ID::custom('xyz'),
|
2022-08-08 23:00:15 +12:00
|
|
|
'permissions' => [
|
2022-08-14 22:33:36 +12:00
|
|
|
Permission::update(Role::user(ID::custom('notme'))),
|
|
|
|
Permission::delete(Role::user(ID::custom('notme'))),
|
2022-08-08 23:00:15 +12:00
|
|
|
]
|
2021-12-11 05:48:54 +13:00
|
|
|
]);
|
|
|
|
|
2022-08-16 23:29:11 +12:00
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
2022-08-09 19:11:30 +12:00
|
|
|
$this->assertStringStartsWith('Permissions must be one of:', $file['body']['message']);
|
2022-08-03 16:17:49 +12:00
|
|
|
$this->assertStringContainsString('any', $file['body']['message']);
|
|
|
|
$this->assertStringContainsString('users', $file['body']['message']);
|
2022-05-24 02:54:50 +12:00
|
|
|
$this->assertStringContainsString('user:' . $this->getUser()['$id'], $file['body']['message']);
|
2021-12-11 05:48:54 +13:00
|
|
|
|
2021-12-14 22:42:39 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $data['bucketId'] . '/files', array_merge([
|
2021-12-11 05:48:54 +13:00
|
|
|
'content-type' => 'multipart/form-data',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-14 22:33:36 +12:00
|
|
|
'fileId' => ID::unique(),
|
2021-12-11 05:48:54 +13:00
|
|
|
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'permissions.png'),
|
2022-08-14 22:33:36 +12:00
|
|
|
'folderId' => ID::custom('xyz'),
|
2022-08-03 16:17:49 +12:00
|
|
|
'permissions' => [
|
2022-08-14 22:33:36 +12:00
|
|
|
Permission::read(Role::user(ID::custom('notme'))),
|
|
|
|
Permission::update(Role::user(ID::custom('notme'))),
|
|
|
|
Permission::delete(Role::user(ID::custom('notme'))),
|
2022-08-03 16:17:49 +12:00
|
|
|
],
|
2021-12-11 05:48:54 +13:00
|
|
|
]);
|
|
|
|
|
2022-08-16 23:29:11 +12:00
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
2022-08-09 19:11:30 +12:00
|
|
|
$this->assertStringStartsWith('Permissions must be one of:', $file['body']['message']);
|
2022-08-03 16:17:49 +12:00
|
|
|
$this->assertStringContainsString('any', $file['body']['message']);
|
|
|
|
$this->assertStringContainsString('users', $file['body']['message']);
|
2022-05-24 02:54:50 +12:00
|
|
|
$this->assertStringContainsString('user:' . $this->getUser()['$id'], $file['body']['message']);
|
2021-12-11 05:48:54 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testCreateFileDefaultPermissions
|
|
|
|
*/
|
|
|
|
public function testUpdateFileAbusePermissions(array $data): void
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
2021-12-14 22:42:39 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $data['bucketId'] . '/files/' . $data['fileId'], array_merge([
|
2021-12-11 05:48:54 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-16 23:29:11 +12:00
|
|
|
'permissions' => [
|
|
|
|
Permission::read(Role::user(ID::custom('notme'))),
|
|
|
|
],
|
2021-12-11 05:48:54 +13:00
|
|
|
]);
|
|
|
|
|
2022-08-16 23:29:11 +12:00
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
2022-08-09 19:11:30 +12:00
|
|
|
$this->assertStringStartsWith('Permissions must be one of:', $file['body']['message']);
|
2022-08-03 16:17:49 +12:00
|
|
|
$this->assertStringContainsString('any', $file['body']['message']);
|
|
|
|
$this->assertStringContainsString('users', $file['body']['message']);
|
2022-05-24 02:54:50 +12:00
|
|
|
$this->assertStringContainsString('user:' . $this->getUser()['$id'], $file['body']['message']);
|
2021-12-11 05:48:54 +13:00
|
|
|
|
2021-12-14 22:42:39 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $data['bucketId'] . '/files/' . $data['fileId'], array_merge([
|
2021-12-11 05:48:54 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-08 23:00:15 +12:00
|
|
|
'permissions' => [
|
2022-08-14 22:33:36 +12:00
|
|
|
Permission::update(Role::user(ID::custom('notme'))),
|
|
|
|
Permission::delete(Role::user(ID::custom('notme'))),
|
2022-08-08 23:00:15 +12:00
|
|
|
]
|
2021-12-11 05:48:54 +13:00
|
|
|
]);
|
|
|
|
|
2022-08-16 23:29:11 +12:00
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
2022-08-09 19:11:30 +12:00
|
|
|
$this->assertStringStartsWith('Permissions must be one of:', $file['body']['message']);
|
2022-08-03 16:17:49 +12:00
|
|
|
$this->assertStringContainsString('any', $file['body']['message']);
|
|
|
|
$this->assertStringContainsString('users', $file['body']['message']);
|
2022-05-24 02:54:50 +12:00
|
|
|
$this->assertStringContainsString('user:' . $this->getUser()['$id'], $file['body']['message']);
|
2021-12-11 05:48:54 +13:00
|
|
|
|
2021-12-14 22:42:39 +13:00
|
|
|
$file = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $data['bucketId'] . '/files/' . $data['fileId'], array_merge([
|
2021-12-11 05:48:54 +13:00
|
|
|
'content-type' => 'application/json',
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], $this->getHeaders()), [
|
2022-08-03 16:17:49 +12:00
|
|
|
'permissions' => [
|
2022-08-14 22:33:36 +12:00
|
|
|
Permission::read(Role::user(ID::custom('notme'))),
|
2022-09-06 13:02:32 +12:00
|
|
|
Permission::update(Role::user(ID::custom('notme'))),
|
|
|
|
Permission::delete(Role::user(ID::custom('notme'))),
|
2022-08-03 16:17:49 +12:00
|
|
|
],
|
2021-12-11 05:48:54 +13:00
|
|
|
]);
|
|
|
|
|
2022-08-16 23:29:11 +12:00
|
|
|
$this->assertEquals(401, $file['headers']['status-code']);
|
2022-08-09 19:11:30 +12:00
|
|
|
$this->assertStringStartsWith('Permissions must be one of:', $file['body']['message']);
|
2022-08-03 16:17:49 +12:00
|
|
|
$this->assertStringContainsString('any', $file['body']['message']);
|
|
|
|
$this->assertStringContainsString('users', $file['body']['message']);
|
2022-05-24 02:54:50 +12:00
|
|
|
$this->assertStringContainsString('user:' . $this->getUser()['$id'], $file['body']['message']);
|
2021-09-07 01:33:06 +12:00
|
|
|
}
|
2022-05-24 02:54:50 +12:00
|
|
|
}
|