From cfab9221f21889d22aa3ebe72f29ea84e1ce3e3f Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sun, 14 Aug 2022 12:32:41 +0530 Subject: [PATCH] feat: exceptions on more files --- app/controllers/api/databases.php | 4 +-- app/controllers/api/storage.php | 2 +- .../Databases/DatabasesCustomServerTest.php | 26 +++++++++---------- tests/e2e/Services/Storage/StorageBase.php | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c186dacddc..72afb1f82c 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -116,7 +116,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att } catch (DuplicateException $exception) { throw new Exception(Exception::ATTRIBUTE_ALREADY_EXISTS); } catch (LimitException $exception) { - throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED); + throw new Exception(Exception::ATTRIBUTE_LIMIT_EXCEEDED, 'Attribute limit exceeded'); } $dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $collectionId); @@ -1527,7 +1527,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') $limit = 64 - MariaDB::getNumberOfDefaultIndexes(); if ($count >= $limit) { - throw new Exception(Exception::INDEX_LIMIT_EXCEEDED); + throw new Exception(Exception::INDEX_LIMIT_EXCEEDED, 'Index limit exceeded.'); } // Convert Document[] to array of attribute metadata diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 8ddfb6d9a4..9d897b4bb1 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -446,7 +446,7 @@ App::post('/v1/storage/buckets/:bucketId/files') $allowedFileExtensions = $bucket->getAttribute('allowedFileExtensions', []); $fileExt = new FileExt($allowedFileExtensions); if (!empty($allowedFileExtensions) && !$fileExt->isValid($fileName)) { - throw new Exception(Exception::STORAGE_FILE_TYPE_UNSUPPORTED); + throw new Exception(Exception::STORAGE_FILE_TYPE_UNSUPPORTED, 'File extension not allowed'); } // Check if file size is exceeding allowed limit diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index d229f0ae73..9f4c649fdf 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -618,8 +618,8 @@ class DatabasesCustomServerTest extends Scope 'required' => true, ]); - $this->assertEquals(201, $attribute1['headers']['status-code']); - $this->assertEquals(201, $attribute2['headers']['status-code']); + $this->assertEquals(202, $attribute1['headers']['status-code']); + $this->assertEquals(202, $attribute2['headers']['status-code']); $this->assertEquals('attribute1', $attribute1['body']['key']); $this->assertEquals('attribute2', $attribute2['body']['key']); @@ -646,8 +646,8 @@ class DatabasesCustomServerTest extends Scope 'attributes' => ['attribute2'], ]); - $this->assertEquals(201, $index1['headers']['status-code']); - $this->assertEquals(201, $index2['headers']['status-code']); + $this->assertEquals(202, $index1['headers']['status-code']); + $this->assertEquals(202, $index2['headers']['status-code']); $this->assertEquals('index1', $index1['body']['key']); $this->assertEquals('index2', $index2['body']['key']); @@ -742,8 +742,8 @@ class DatabasesCustomServerTest extends Scope 'required' => true, ]); - $this->assertEquals(201, $attribute1['headers']['status-code']); - $this->assertEquals(201, $attribute2['headers']['status-code']); + $this->assertEquals(202, $attribute1['headers']['status-code']); + $this->assertEquals(202, $attribute2['headers']['status-code']); $this->assertEquals('attribute1', $attribute1['body']['key']); $this->assertEquals('attribute2', $attribute2['body']['key']); @@ -770,8 +770,8 @@ class DatabasesCustomServerTest extends Scope 'attributes' => ['attribute2'], ]); - $this->assertEquals(201, $index1['headers']['status-code']); - $this->assertEquals(201, $index2['headers']['status-code']); + $this->assertEquals(202, $index1['headers']['status-code']); + $this->assertEquals(202, $index2['headers']['status-code']); $this->assertEquals('index1', $index1['body']['key']); $this->assertEquals('index2', $index2['body']['key']); @@ -980,7 +980,7 @@ class DatabasesCustomServerTest extends Scope 'required' => true, ]); - $this->assertEquals($attribute['headers']['status-code'], 201); + $this->assertEquals($attribute['headers']['status-code'], 202); } sleep(5); @@ -996,7 +996,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $tooWide['headers']['status-code']); - $this->assertEquals('The maximum number of attributes has been reached.', $tooWide['body']['message']); + $this->assertEquals('Attribute limit exceeded', $tooWide['body']['message']); } public function testIndexLimitException() @@ -1043,7 +1043,7 @@ class DatabasesCustomServerTest extends Scope 'required' => true, ]); - $this->assertEquals($attribute['headers']['status-code'], 201); + $this->assertEquals($attribute['headers']['status-code'], 202); } sleep(20); @@ -1080,7 +1080,7 @@ class DatabasesCustomServerTest extends Scope 'attributes' => ["attribute{$i}"], ]); - $this->assertEquals(201, $index['headers']['status-code']); + $this->assertEquals(202, $index['headers']['status-code']); $this->assertEquals("key_attribute{$i}", $index['body']['key']); } @@ -1110,7 +1110,7 @@ class DatabasesCustomServerTest extends Scope ]); $this->assertEquals(400, $tooMany['headers']['status-code']); - $this->assertEquals('The maximum number of indexes has been reached.', $tooMany['body']['message']); + $this->assertEquals('Index limit exceeded', $tooMany['body']['message']); $collection = $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collectionId, array_merge([ 'content-type' => 'application/json', diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index c71d212079..edcaa0f8a6 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -185,7 +185,7 @@ trait StorageBase ]); $this->assertEquals(400, $res['headers']['status-code']); - $this->assertEquals('The file type is not supported.', $res['body']['message']); + $this->assertEquals('File extension not allowed', $res['body']['message']); return ['bucketId' => $bucketId, 'fileId' => $file['body']['$id'], 'largeFileId' => $largeFile['body']['$id'], 'largeBucketId' => $bucket2['body']['$id']];