1
0
Fork 0
mirror of synced 2024-07-08 16:06:02 +12:00

test for bucket file size limit

This commit is contained in:
Damodar Lohani 2021-06-21 12:51:28 +05:45
parent 0f317ffa24
commit 80b9fbd3ef

View file

@ -4,11 +4,10 @@ namespace Tests\E2E\Services\Storage;
use CURLFile; use CURLFile;
use Tests\E2E\Client; use Tests\E2E\Client;
use Utopia\Image\Image;
trait StorageBase trait StorageBase
{ {
public function testCreateBucketFile():array public function testCreateBucketFile(): array
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS
@ -16,9 +15,10 @@ trait StorageBase
$bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', array_merge([ $bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', array_merge([
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'] 'x-appwrite-key' => $this->getProject()['apiKey'],
], $this->getHeaders()), [ ], $this->getHeaders()), [
'name' => 'Test Bucket', 'name' => 'Test Bucket',
'maximumFileSize' => 2000000, //2MB
'read' => ['role:all'], 'read' => ['role:all'],
'write' => ['role:all'], 'write' => ['role:all'],
]); ]);
@ -27,7 +27,7 @@ trait StorageBase
$bucketId = $bucket['body']['$id']; $bucketId = $bucket['body']['$id'];
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId .'/files', array_merge([ $file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
'content-type' => 'multipart/form-data', 'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [ ], $this->getHeaders()), [
@ -56,13 +56,34 @@ trait StorageBase
]); ]);
$this->assertEquals(404, $res['headers']['status-code']); $this->assertEquals(404, $res['headers']['status-code']);
return ['bucketId' => $bucketId,'fileId' => $file['body']['$id']]; /**
* Test for FAILURE large file size
*/
$res = $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()), [
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/disk-b/kitten-1.png'), 'image/png', 'kitten-1.png'),
'read' => ['role:all'],
'write' => ['role:all'],
]);
$this->assertEquals(400, $res['headers']['status-code']);
$this->assertEquals('File size not allowed', $res['body']['message']);
/**
* Test for FAILURE unsupported bucket extension
* TODO awaiting FileType validator update
*/
return ['bucketId' => $bucketId, 'fileId' => $file['body']['$id']];
} }
/** /**
* @depends testCreateBucketFile * @depends testCreateBucketFile
*/ */
public function testListBucketFiles(array $data):array public function testListBucketFiles(array $data): array
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS
@ -91,7 +112,7 @@ trait StorageBase
/** /**
* @depends testCreateBucketFile * @depends testCreateBucketFile
*/ */
public function testGetBucketFile(array $data):array public function testGetBucketFile(array $data): array
{ {
$bucketId = $data['bucketId']; $bucketId = $data['bucketId'];
/** /**
@ -141,7 +162,6 @@ trait StorageBase
'rotation' => '45', 'rotation' => '45',
]); ]);
$this->assertEquals(200, $file3['headers']['status-code']); $this->assertEquals(200, $file3['headers']['status-code']);
$this->assertEquals('image/png', $file3['headers']['content-type']); $this->assertEquals('image/png', $file3['headers']['content-type']);
$this->assertNotEmpty($file3['body']); $this->assertNotEmpty($file3['body']);
@ -213,7 +233,7 @@ trait StorageBase
/** /**
* @depends testCreateBucketFile * @depends testCreateBucketFile
*/ */
public function testUpdateBucketFile(array $data):array public function testUpdateBucketFile(array $data): array
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS
@ -222,7 +242,7 @@ trait StorageBase
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [ ], $this->getHeaders()), [
'read' => ['role:all','user:x'], 'read' => ['role:all', 'user:x'],
'write' => ['role:all', 'user:x'], 'write' => ['role:all', 'user:x'],
]); ]);
@ -251,7 +271,7 @@ trait StorageBase
'content-type' => 'application/json', 'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [ ], $this->getHeaders()), [
'read' => ['role:all','user:x'], 'read' => ['role:all', 'user:x'],
'write' => ['role:all', 'user:x'], 'write' => ['role:all', 'user:x'],
]); ]);
@ -263,7 +283,7 @@ trait StorageBase
/** /**
* @depends testUpdateBucketFile * @depends testUpdateBucketFile
*/ */
public function testDeleteBucketFile(array $data):array public function testDeleteBucketFile(array $data): array
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS
@ -290,7 +310,7 @@ trait StorageBase
return $data; return $data;
} }
public function testCreateFile():array public function testCreateFile(): array
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS
@ -320,7 +340,7 @@ trait StorageBase
/** /**
* @depends testCreateFile * @depends testCreateFile
*/ */
public function testGetFile(array $data):array public function testGetFile(array $data): array
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS
@ -369,7 +389,6 @@ trait StorageBase
'rotation' => '45', 'rotation' => '45',
]); ]);
$this->assertEquals(200, $file3['headers']['status-code']); $this->assertEquals(200, $file3['headers']['status-code']);
$this->assertEquals('image/png', $file3['headers']['content-type']); $this->assertEquals('image/png', $file3['headers']['content-type']);
$this->assertNotEmpty($file3['body']); $this->assertNotEmpty($file3['body']);
@ -434,7 +453,7 @@ trait StorageBase
/** /**
* @depends testGetFile * @depends testGetFile
*/ */
public function testListFiles(array $data):array public function testListFiles(array $data): array
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS
@ -458,7 +477,7 @@ trait StorageBase
/** /**
* @depends testListFiles * @depends testListFiles
*/ */
public function testUpdateFile(array $data):array public function testUpdateFile(array $data): array
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS
@ -498,7 +517,7 @@ trait StorageBase
/** /**
* @depends testUpdateFile * @depends testUpdateFile
*/ */
public function testDeleteFile(array $data):array public function testDeleteFile(array $data): array
{ {
/** /**
* Test for SUCCESS * Test for SUCCESS