diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index a81eb33ef4..7e730513f7 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -969,19 +969,10 @@ App::post('/v1/projects/:projectId/platforms') ->param('name', null, new Text(128), 'Platform name. Max length: 128 chars.') ->param('key', '', new Text(256), 'Package name for Android or bundle ID for iOS or macOS. Max length: 256 chars.', true) ->param('store', '', new Text(256), 'App store or Google Play store ID. Max length: 256 chars.', true) - ->param('hostname', '', new Text(256), 'Platform client hostname. Max length: 256 chars.', true) + ->param('hostname', '', new Hostname(), 'Platform client hostname. Max length: 256 chars.', true) ->inject('response') ->inject('dbForConsole') ->action(function (string $projectId, string $type, string $name, string $key, string $store, string $hostname, Response $response, Database $dbForConsole) { - - // Ensure hostname has proper structure (no port, protocol..) - if(!empty($hostname)) { - $validator = new Hostname(); - if (!is_null($hostname) && !$validator->isValid($hostname)) { - throw new Exception($validator->getDescription(), 400, Exception::ATTRIBUTE_VALUE_INVALID); - } - } - $project = $dbForConsole->getDocument('projects', $projectId); if ($project->isEmpty()) { @@ -1090,19 +1081,10 @@ App::put('/v1/projects/:projectId/platforms/:platformId') ->param('name', null, new Text(128), 'Platform name. Max length: 128 chars.') ->param('key', '', new Text(256), 'Package name for android or bundle ID for iOS. Max length: 256 chars.', true) ->param('store', '', new Text(256), 'App store or Google Play store ID. Max length: 256 chars.', true) - ->param('hostname', '', new Text(256), 'Platform client URL. Max length: 256 chars.', true) + ->param('hostname', '', new Hostname(), 'Platform client URL. Max length: 256 chars.', true) ->inject('response') ->inject('dbForConsole') ->action(function (string $projectId, string $platformId, string $name, string $key, string $store, string $hostname, Response $response, Database $dbForConsole) { - - // Ensure hostname has proper structure (no port, protocol..) - if(!empty($hostname)) { - $validator = new Hostname(); - if (!is_null($hostname) && !$validator->isValid($hostname)) { - throw new Exception($validator->getDescription(), 400, Exception::ATTRIBUTE_VALUE_INVALID); - } - } - $project = $dbForConsole->getDocument('projects', $projectId); if ($project->isEmpty()) { diff --git a/composer.lock b/composer.lock index 7ca6be00d3..20d500ee5c 100644 --- a/composer.lock +++ b/composer.lock @@ -6576,5 +6576,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.3.0" } diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index e0a7cb158a..1154515648 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -1910,6 +1910,17 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); + $response = $this->client->call(Client::METHOD_POST, '/projects/' . $id . '/platforms', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'type' => 'web', + 'name' => 'Too Long Hostname', + 'key' => '', + 'store' => '', + 'hostname' => \str_repeat("bestdomain", 25) . '.com' // 250 + 4 chars total (exactly above limit) + ]); + return $data; }