From eb12a8c26f7669dcdd563a36cd4ff6c23983d883 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 18 Aug 2021 12:20:49 +0200 Subject: [PATCH 1/4] fix(general): role reference overwrite --- app/controllers/general.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 878c54e38..2b5736583 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -33,7 +33,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB /** @var Utopia\Locale\Locale $locale */ /** @var bool $mode */ /** @var array $clients */ - + $domain = $request->getHostname(); $domains = Config::getParam('domains', []); if (!array_key_exists($domain, $domains)) { @@ -98,7 +98,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB $refDomain = (!empty($protocol) ? $protocol : $request->getProtocol()).'://'.((\in_array($origin, $clients)) ? $origin : 'localhost').(!empty($port) ? ':'.$port : ''); - + $refDomain = (!$route->getLabel('origin', false)) // This route is publicly accessible ? $refDomain : (!empty($protocol) ? $protocol : $request->getProtocol()).'://'.$origin.(!empty($port) ? ':'.$port : ''); @@ -119,7 +119,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB Config::setParam('domainVerification', ($selfDomain->getRegisterable() === $endDomain->getRegisterable()) && $endDomain->getRegisterable() !== ''); - + Config::setParam('cookieDomain', ( $request->getHostname() === 'localhost' || $request->getHostname() === 'localhost:'.$request->getPort() || @@ -189,7 +189,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB && empty($request->getHeader('x-appwrite-key', ''))) { throw new Exception($originValidator->getDescription(), 403); } - + /* * ACL Check */ @@ -223,7 +223,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB if (!empty($authKey)) { // API Key authentication // Check if given key match project API keys $key = $project->search('secret', $authKey, $project->getAttribute('keys', [])); - + /* * Try app auth when we have project key and no user * Mock user to app and grant API key scopes in addition to default app scopes @@ -245,8 +245,8 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB } } - foreach (Auth::getRoles($user) as $role) { - Authorization::setRole($role); + foreach (Auth::getRoles($user) as $authRole) { + Authorization::setRole($authRole); } // TDOO Check if user is root @@ -255,7 +255,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS !== $project->getCollection()) { // Check if permission is denied because project is missing throw new Exception('Project not found', 404); } - + throw new Exception($user->getAttribute('email', 'User').' (role: '.\strtolower($roles[$role]['label']).') missing scope ('.$scope.')', 401); } @@ -302,12 +302,12 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project) { if (php_sapi_name() === 'cli') { Console::error('[Error] Timestamp: '.date('c', time())); - + if($route) { Console::error('[Error] Method: '.$route->getMethod()); Console::error('[Error] URL: '.$route->getURL()); } - + Console::error('[Error] Type: '.get_class($error)); Console::error('[Error] Message: '.$error->getMessage()); Console::error('[Error] File: '.$error->getFile()); From 39e91037df127a0030ad096a97cde73ba183117d Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 18 Aug 2021 12:25:25 +0200 Subject: [PATCH 2/4] debug failing tests --- tests/e2e/Services/Realtime/RealtimeBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Realtime/RealtimeBase.php b/tests/e2e/Services/Realtime/RealtimeBase.php index 5407d13a5..0a098f079 100644 --- a/tests/e2e/Services/Realtime/RealtimeBase.php +++ b/tests/e2e/Services/Realtime/RealtimeBase.php @@ -650,7 +650,7 @@ trait RealtimeBase 'command' => 'php index.php', 'code' => new CURLFile(realpath(__DIR__ . '/../../../resources/functions/timeout.tar.gz'), 'application/x-gzip', 'php-fx.tar.gz'), ]); - + var_dump($tag); $tagId = $tag['body']['$id'] ?? ''; $this->assertEquals($tag['headers']['status-code'], 201); From e2948ea02fa8c5110d8893e3641fb2eb4f677f4a Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 18 Aug 2021 12:28:17 +0200 Subject: [PATCH 3/4] debug failing tests --- tests/e2e/Services/Realtime/RealtimeBase.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/Services/Realtime/RealtimeBase.php b/tests/e2e/Services/Realtime/RealtimeBase.php index 0a098f079..a30c7113a 100644 --- a/tests/e2e/Services/Realtime/RealtimeBase.php +++ b/tests/e2e/Services/Realtime/RealtimeBase.php @@ -636,6 +636,7 @@ trait RealtimeBase 'execute' => ['*'], 'timeout' => 10, ]); + var_dump($function); $functionId = $function['body']['$id'] ?? ''; From 4695ea9914d48bd995b9da64f35be0b3e6b41eb1 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 18 Aug 2021 12:49:34 +0200 Subject: [PATCH 4/4] fix(tests): realtime with functions --- tests/e2e/Services/Realtime/RealtimeBase.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Realtime/RealtimeBase.php b/tests/e2e/Services/Realtime/RealtimeBase.php index a30c7113a..b9f4f5f84 100644 --- a/tests/e2e/Services/Realtime/RealtimeBase.php +++ b/tests/e2e/Services/Realtime/RealtimeBase.php @@ -632,11 +632,10 @@ trait RealtimeBase 'x-appwrite-key' => $this->getProject()['apiKey'] ]), [ 'name' => 'Test', - 'runtime' => 'php-7.4', + 'runtime' => 'php-8.0', 'execute' => ['*'], 'timeout' => 10, ]); - var_dump($function); $functionId = $function['body']['$id'] ?? ''; @@ -651,7 +650,7 @@ trait RealtimeBase 'command' => 'php index.php', 'code' => new CURLFile(realpath(__DIR__ . '/../../../resources/functions/timeout.tar.gz'), 'application/x-gzip', 'php-fx.tar.gz'), ]); - var_dump($tag); + $tagId = $tag['body']['$id'] ?? ''; $this->assertEquals($tag['headers']['status-code'], 201);