diff --git a/app/controllers/general.php b/app/controllers/general.php index fef58f541..1251974cd 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -369,6 +369,19 @@ App::init() }); */ +App::init() + ->groups(['database', 'functions', 'storage', 'messaging']) + ->inject('project') + ->inject('request') + ->action(function (Document $project, Request $request) { + if ($project->getId() === 'console') { + $message = empty($request->getHeader('x-appwrite-project')) ? + 'No Appwrite project was specified. Please specify your project ID when initializing your Appwrite SDK.' : + 'This endpoint is not available for the console project. The Appwrite Console is a reserved project ID and cannot be used with the Appwrite SDKs and APIs. Please check if your project ID is correct.'; + throw new AppwriteException(AppwriteException::GENERAL_ACCESS_FORBIDDEN, $message); + } + }); + App::init() ->groups(['api', 'web']) ->inject('utopia') diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index d3424e281..c362b9405 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -85,6 +85,36 @@ trait DatabasesBase ]; } + /** + * @depends testCreateCollection + */ + public function testConsoleProject(array $data) + { + $response = $this->client->call( + Client::METHOD_GET, + '/databases/console/collections/' . $data['moviesId'] . '/documents', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders()) + ); + + $this->assertEquals(401, $response['headers']['status-code']); + $this->assertEquals('general_access_forbidden', $response['body']['type']); + $this->assertEquals('This endpoint is not available for the console project. The Appwrite Console is a reserved project ID and cannot be used with the Appwrite SDKs and APIs. Please check if your project ID is correct.', $response['body']['message']); + + $response = $this->client->call( + Client::METHOD_GET, + '/databases/console/collections/' . $data['moviesId'] . '/documents', + array_merge([ + 'content-type' => 'application/json', + // 'x-appwrite-project' => '', empty header + ], $this->getHeaders()) + ); + $this->assertEquals(401, $response['headers']['status-code']); + $this->assertEquals('No Appwrite project was specified. Please specify your project ID when initializing your Appwrite SDK.', $response['body']['message']); + } + /** * @depends testCreateCollection */