From 14fe7a32939a3f5140cb847d86da477efc02dae5 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 20:35:59 +0530 Subject: [PATCH 1/3] updated errro for the string encryption --- app/controllers/api/databases.php | 3 +++ .../Services/Databases/DatabasesCustomServerTest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 75f89d5733..c57c29d9a2 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1352,6 +1352,9 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string if ($encrypt && !empty($plan) && !($plan['databasesAllowEncrypt'] ?? false)) { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Encrypted string attributes are not available on your plan. Please upgrade to create encrypted string attributes.'); } + if ($encrypt && $size < 150) { + throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Size too small. Encrypted strings require a minimum size of 150 characters.'); + } // Ensure attribute default is within required size $validator = new Text($size, 0); if (!is_null($default) && !$validator->isValid($default)) { diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index c0d8763aa7..25c7e30a4f 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -686,6 +686,18 @@ class DatabasesCustomServerTest extends Scope 'size' => 256, 'required' => true, ]); + // checking size test + $lastName = $this->client->call(Client::METHOD_POST, $attributesPath . '/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'lastName', + 'size' => 149, + 'required' => true, + 'encrypt' => true + ]); + $this->assertEquals('Size too small. Encrypted strings require a minimum size of 150 characters.', $lastName['body']['message']); $lastName = $this->client->call(Client::METHOD_POST, $attributesPath . '/string', array_merge([ 'content-type' => 'application/json', From 6af9d1206d63b50d2970d59445b86c8b5d8b4328 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 20:41:08 +0530 Subject: [PATCH 2/3] added a constant --- app/controllers/api/databases.php | 2 +- app/init/constants.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index c57c29d9a2..b38596239c 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1352,7 +1352,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string if ($encrypt && !empty($plan) && !($plan['databasesAllowEncrypt'] ?? false)) { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Encrypted string attributes are not available on your plan. Please upgrade to create encrypted string attributes.'); } - if ($encrypt && $size < 150) { + if ($encrypt && $size < APP_DATABASE_ENCRYPT_SIZE_MIN) { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Size too small. Encrypted strings require a minimum size of 150 characters.'); } // Ensure attribute default is within required size diff --git a/app/init/constants.php b/app/init/constants.php index 7686759719..4699014925 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -51,6 +51,7 @@ const APP_DATABASE_TIMEOUT_MILLISECONDS_API = 15 * 1000; // 15 seconds const APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER = 300 * 1000; // 5 minutes const APP_DATABASE_TIMEOUT_MILLISECONDS_TASK = 300 * 1000; // 5 minutes const APP_DATABASE_QUERY_MAX_VALUES = 500; +const APP_DATABASE_ENCRYPT_SIZE_MIN = 150; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_SITES = '/storage/sites'; const APP_STORAGE_FUNCTIONS = '/storage/functions'; From 49f8369fdd3ecb02337a36f8127fed4865a4090f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Fri, 23 May 2025 20:45:36 +0530 Subject: [PATCH 3/3] updated the message --- app/controllers/api/databases.php | 5 ++++- tests/e2e/Services/Databases/DatabasesCustomServerTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index b38596239c..7eb3273c38 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1353,7 +1353,10 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/string throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Encrypted string attributes are not available on your plan. Please upgrade to create encrypted string attributes.'); } if ($encrypt && $size < APP_DATABASE_ENCRYPT_SIZE_MIN) { - throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Size too small. Encrypted strings require a minimum size of 150 characters.'); + throw new Exception( + Exception::GENERAL_BAD_REQUEST, + "Size too small. Encrypted strings require a minimum size of " . APP_DATABASE_ENCRYPT_SIZE_MIN . " characters." + ); } // Ensure attribute default is within required size $validator = new Text($size, 0); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 25c7e30a4f..e66207b215 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -697,7 +697,7 @@ class DatabasesCustomServerTest extends Scope 'required' => true, 'encrypt' => true ]); - $this->assertEquals('Size too small. Encrypted strings require a minimum size of 150 characters.', $lastName['body']['message']); + $this->assertEquals("Size too small. Encrypted strings require a minimum size of " . APP_DATABASE_ENCRYPT_SIZE_MIN . " characters.", $lastName['body']['message']); $lastName = $this->client->call(Client::METHOD_POST, $attributesPath . '/string', array_merge([ 'content-type' => 'application/json',