From 1c0b49d16d7856f0f445e2fdeeb52122a64b3c0e Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Thu, 2 Jun 2022 12:20:48 +0200 Subject: [PATCH] style: run formatter --- app/controllers/api/projects.php | 4 ++-- app/controllers/general.php | 4 ++-- .../Services/Projects/ProjectsConsoleClientTest.php | 13 ++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 4b385574be..7b3e382b0d 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -776,7 +776,7 @@ App::post('/v1/projects/:projectId/keys') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', null, new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.') - ->param('expire', 0, new Integer() , 'Key expiration time in Unix timestamp. Use 0 for unlimited expiration.', true) + ->param('expire', 0, new Integer(), 'Key expiration time in Unix timestamp. Use 0 for unlimited expiration.', true) ->inject('response') ->inject('dbForConsole') ->action(function (string $projectId, string $name, array $scopes, int $expire, Response $response, Database $dbForConsole) { @@ -885,7 +885,7 @@ App::put('/v1/projects/:projectId/keys/:keyId') ->param('keyId', null, new UID(), 'Key unique ID.') ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', null, new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.') - ->param('expire', 0, new Integer() , 'Key expiration time in Unix timestamp. Use 0 for unlimited expiration.', true) + ->param('expire', 0, new Integer(), 'Key expiration time in Unix timestamp. Use 0 for unlimited expiration.', true) ->inject('response') ->inject('dbForConsole') ->action(function (string $projectId, string $keyId, string $name, array $scopes, int $expire, Response $response, Database $dbForConsole) { diff --git a/app/controllers/general.php b/app/controllers/general.php index d25762f624..a67d9cfd7c 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -281,9 +281,9 @@ App::init(function (App $utopia, Request $request, Response $response, Document $expire = $key->getAttribute('expire', 0); - if(!empty($expire) && $expire < \time()){ + if (!empty($expire) && $expire < \time()) { throw new AppwriteException('Project key expired', 401, AppwriteException:: PROJECT_KEY_EXPIRED); - } + } Authorization::setRole('role:' . Auth::USER_ROLE_APP); Authorization::setDefaultStatus(false); // Cancel security segmentation for API keys. diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 1b9fefc64d..18f19c3969 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -1260,10 +1260,10 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'name' => 'Key Test', 'scopes' => ['health.read'], - 'expire' => time()+3600, + 'expire' => time() + 3600, ]); - $response = $this->client->call(Client::METHOD_GET, '/health' , [ + $response = $this->client->call(Client::METHOD_GET, '/health', [ 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-key' => $response['body']['secret'] @@ -1283,7 +1283,7 @@ class ProjectsConsoleClientTest extends Scope 'expire' => 0, ]); - $response = $this->client->call(Client::METHOD_GET, '/health' , [ + $response = $this->client->call(Client::METHOD_GET, '/health', [ 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-key' => $response['body']['secret'] @@ -1300,17 +1300,16 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'name' => 'Key Test', 'scopes' => ['health.read'], - 'expire' => time()-3600, + 'expire' => time() - 3600, ]); - $response = $this->client->call(Client::METHOD_GET, '/health' , [ + $response = $this->client->call(Client::METHOD_GET, '/health', [ 'content-type' => 'application/json', 'x-appwrite-project' => $id, 'x-appwrite-key' => $response['body']['secret'] ], []); $this->assertEquals(401, $response['headers']['status-code']); - } @@ -1328,7 +1327,7 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders()), [ 'name' => 'Key Test Update', 'scopes' => ['users.read', 'users.write', 'collections.read'], - 'expire' => time()+360, + 'expire' => time() + 360, ]); $this->assertEquals(200, $response['headers']['status-code']);