1
0
Fork 0
mirror of synced 2024-10-05 20:53:27 +13:00

Merge pull request #7951 from appwrite/fix-admin-mode-on-console

fix: admin mode on console
This commit is contained in:
Eldad A. Fux 2024-04-10 20:18:51 +02:00 committed by GitHub
commit 143b73deef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 0 deletions

View file

@ -367,6 +367,16 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
return false;
}
App::init()
->groups(['api'])
->inject('project')
->inject('mode')
->action(function (Document $project, string $mode) {
if ($mode === APP_MODE_ADMIN && $project->getId() === 'console') {
throw new AppwriteException(AppwriteException::GENERAL_BAD_REQUEST, 'Admin mode is not allowed for console project');
}
});
App::init()
->groups(['api', 'web'])
->inject('utopia')

View file

@ -0,0 +1,30 @@
<?php
namespace Tests\E2E\Services\Console;
use Appwrite\Extend\Exception;
use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectConsole;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideClient;
class ModeTest extends Scope
{
use ProjectConsole;
use SideClient;
public function testConsoleWithAdminMode(): void
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-mode' => 'admin',
], $this->getHeaders()));
$this->assertEquals(400, $response['headers']['status-code']);
$this->assertEquals(Exception::GENERAL_BAD_REQUEST, $response['body']['type']);
}
}