From f77a6a48145a5da94019b29416e80060e9e53b06 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 1 May 2020 13:24:36 +0300 Subject: [PATCH] Updated tests --- Dockerfile | 6 +++- app/controllers/api/health.php | 36 ++++++++++++++++-------- tests/e2e/Services/Health/HealthBase.php | 10 +++---- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index f170a0957..25269eae0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -126,8 +126,12 @@ COPY --from=builder /usr/local/src/vendor /usr/share/nginx/html/vendor RUN mkdir -p /storage/uploads && \ mkdir -p /storage/cache && \ + mkdir -p /storage/config && \ + mkdir -p /storage/certificates && \ chown -Rf www-data.www-data /storage/uploads && chmod -Rf 0755 /storage/uploads && \ - chown -Rf www-data.www-data /storage/cache && chmod -Rf 0755 /storage/cache + chown -Rf www-data.www-data /storage/cache && chmod -Rf 0755 /storage/cache && \ + chown -Rf www-data.www-data /storage/config && chmod -Rf 0755 /storage/config && \ + chown -Rf www-data.www-data /storage/certificates && chmod -Rf 0755 /storage/certificates # Supervisord Conf COPY ./docker/supervisord.conf /etc/supervisord.conf diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index a0a595f04..2982d8919 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -23,7 +23,7 @@ $utopia->get('/v1/health') $utopia->get('/v1/health/db') ->desc('Check DB Health') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getDB') @@ -39,7 +39,7 @@ $utopia->get('/v1/health/db') $utopia->get('/v1/health/cache') ->desc('Check Cache Health') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getCache') @@ -55,7 +55,7 @@ $utopia->get('/v1/health/cache') $utopia->get('/v1/health/time') ->desc('Check Time Health') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getTime') @@ -103,7 +103,7 @@ $utopia->get('/v1/health/time') $utopia->get('/v1/health/queue/webhooks') ->desc('Check number of pending webhook messages') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueWebhooks') @@ -117,7 +117,7 @@ $utopia->get('/v1/health/queue/webhooks') $utopia->get('/v1/health/queue/tasks') ->desc('Check the number of pending task messages') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueTasks') @@ -131,7 +131,7 @@ $utopia->get('/v1/health/queue/tasks') $utopia->get('/v1/health/queue/logs') ->desc('Check the number of pending log messages') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueLogs') @@ -145,7 +145,7 @@ $utopia->get('/v1/health/queue/logs') $utopia->get('/v1/health/queue/usage') ->desc('Check the number of pending usage messages') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueUsage') @@ -159,7 +159,7 @@ $utopia->get('/v1/health/queue/usage') $utopia->get('/v1/health/queue/certificates') ->desc('Check the number of pending certificate messages') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getQueueCertificates') @@ -173,7 +173,7 @@ $utopia->get('/v1/health/queue/certificates') $utopia->get('/v1/health/storage/local') ->desc('Check File System Health') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getStorageLocal') @@ -186,9 +186,21 @@ $utopia->get('/v1/health/storage/local') if (!is_readable($device->getRoot().'/..')) { throw new Exception('Device is not readable'); } + + if (!is_writable($device->getRoot().'/../uploads')) { + throw new Exception('Device uploads dir is not writable'); + } + + if (!is_writable($device->getRoot().'/../cache')) { + throw new Exception('Device cache dir is not writable'); + } - if (!is_writable($device->getRoot().'/..')) { - throw new Exception('Device is not writable'); + if (!is_writable($device->getRoot().'/../config')) { + throw new Exception('Device config dir is not writable'); + } + + if (!is_writable($device->getRoot().'/../certificates')) { + throw new Exception('Device certificates dir is not writable'); } $response->json(['status' => 'OK']); @@ -197,7 +209,7 @@ $utopia->get('/v1/health/storage/local') $utopia->get('/v1/health/storage/anti-virus') ->desc('Check Anti virus Health') - ->label('scope', 'health.read') + ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') ->label('sdk.method', 'getStorageAntiVirus') diff --git a/tests/e2e/Services/Health/HealthBase.php b/tests/e2e/Services/Health/HealthBase.php index 7fb6cddd9..9a14fbfc2 100644 --- a/tests/e2e/Services/Health/HealthBase.php +++ b/tests/e2e/Services/Health/HealthBase.php @@ -95,7 +95,7 @@ trait HealthBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/health/quque/webhooks', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/webhooks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -116,7 +116,7 @@ trait HealthBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/health/quque/tasks', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/tasks', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -137,7 +137,7 @@ trait HealthBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/health/quque/logs', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/logs', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -158,7 +158,7 @@ trait HealthBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/health/quque/usage', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/usage', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []); @@ -179,7 +179,7 @@ trait HealthBase /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/health/quque/certificates', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/health/queue/certificates', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), []);