1
0
Fork 0
mirror of synced 2024-06-26 10:10:57 +12:00

Improved health check tests

This commit is contained in:
Eldad Fux 2020-01-12 17:20:51 +02:00
parent 3686171d6e
commit 2f843943e1
9 changed files with 220 additions and 26 deletions

View file

@ -138,7 +138,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
]);
$role = Auth::USER_ROLE_APP;
$scopes = $key->getAttribute('scopes', []);
$scopes = array_merge($roles[$role]['scopes'], $key->getAttribute('scopes', []));
Authorization::disable(); // Cancel security segmentation for API keys.
}

View file

@ -82,6 +82,6 @@ return [
],
ROLE_APP => [
'label' => 'Application',
'scopes' => ['public'],
'scopes' => ['health.read'],
],
];

View file

@ -2,7 +2,6 @@
namespace Tests\E2E\Services\Avatars;
use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;

View file

@ -0,0 +1,154 @@
<?php
namespace Tests\E2E\Services\Health;
use Tests\E2E\Client;
trait HealthBase
{
public function testHTTPSuccess():array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('OK', $response['body']['status']);
/**
* Test for FAILURE
*/
return [];
}
public function testDBSuccess():array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/db', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('OK', $response['body']['status']);
/**
* Test for FAILURE
*/
return [];
}
public function testCacheSuccess():array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/db', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('OK', $response['body']['status']);
/**
* Test for FAILURE
*/
return [];
}
public function testTimeSuccess():array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/time', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['remote']);
$this->assertIsInt($response['body']['local']);
$this->assertNotEmpty($response['body']['remote']);
$this->assertNotEmpty($response['body']['local']);
$this->assertLessThan(10, $response['body']['diff']);
/**
* Test for FAILURE
*/
return [];
}
public function testWebhooksSuccess():array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/webhooks', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(10, $response['body']['size']);
/**
* Test for FAILURE
*/
return [];
}
public function xtestStorageLocalSuccess():array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/storage/local', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('OK', $response['body']['status']);
/**
* Test for FAILURE
*/
return [];
}
public function testStorageAntiVirusSuccess():array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/storage/anti-virus', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('online', $response['body']['status']);
$this->assertStringStartsWith('ClamAV ', $response['body']['version']);
/**
* Test for FAILURE
*/
return [];
}
}

View file

@ -0,0 +1,14 @@
<?php
namespace Tests\E2E\Services\Health;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\ProjectConsole;
use Tests\E2E\Scopes\SideClient;
class HealthConsoleClientTest extends Scope
{
use HealthBase;
use ProjectConsole;
use SideClient;
}

View file

@ -0,0 +1,14 @@
<?php
namespace Tests\E2E\Services\Health;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\SideClient;
class HealthCustomClientTest extends Scope
{
use HealthBase;
use ProjectCustom;
use SideClient;
}

View file

@ -0,0 +1,15 @@
<?php
namespace Tests\E2E\Services\Health;
use Tests\E2E\Client;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;
class HealthCustomServerTest extends Scope
{
use HealthBase;
use ProjectCustom;
use SideServer;
}

View file

@ -12,6 +12,4 @@ class LocaleCustomServerTest extends Scope
use LocaleBase;
use ProjectCustom;
use SideServer;
///$this->getHeaders()
}

View file

@ -8,10 +8,10 @@ class ConsoleHealthTest extends BaseConsole
{
public function testHTTPSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health', [
'origin' => 'http://localhost',
$response = $this->client->call(Client::METHOD_GET, '/health', array_merge([
'content-type' => 'application/json',
], []);
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('OK', $response['body']['status']);
@ -19,10 +19,10 @@ class ConsoleHealthTest extends BaseConsole
public function testDBSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/db', [
'origin' => 'http://localhost',
$response = $this->client->call(Client::METHOD_GET, '/health/db', array_merge([
'content-type' => 'application/json',
], []);
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('OK', $response['body']['status']);
@ -30,10 +30,10 @@ class ConsoleHealthTest extends BaseConsole
public function testCacheSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/db', [
'origin' => 'http://localhost',
$response = $this->client->call(Client::METHOD_GET, '/health/db', array_merge([
'content-type' => 'application/json',
], []);
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('OK', $response['body']['status']);
@ -41,10 +41,10 @@ class ConsoleHealthTest extends BaseConsole
public function testTimeSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/time', [
'origin' => 'http://localhost',
$response = $this->client->call(Client::METHOD_GET, '/health/time', array_merge([
'content-type' => 'application/json',
], []);
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['remote']);
@ -56,10 +56,10 @@ class ConsoleHealthTest extends BaseConsole
public function testWebhooksSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/webhooks', [
'origin' => 'http://localhost',
$response = $this->client->call(Client::METHOD_GET, '/health/webhooks', array_merge([
'content-type' => 'application/json',
], []);
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
@ -68,10 +68,10 @@ class ConsoleHealthTest extends BaseConsole
public function xtestStorageLocalSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/storage/local', [
'origin' => 'http://localhost',
$response = $this->client->call(Client::METHOD_GET, '/health/storage/local', array_merge([
'content-type' => 'application/json',
], []);
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('OK', $response['body']['status']);
@ -79,10 +79,10 @@ class ConsoleHealthTest extends BaseConsole
public function testStorageAntiVirusSuccess(): void
{
$response = $this->client->call(Client::METHOD_GET, '/health/storage/anti-virus', [
'origin' => 'http://localhost',
$response = $this->client->call(Client::METHOD_GET, '/health/storage/anti-virus', array_merge([
'content-type' => 'application/json',
], []);
'x-appwrite-project' => $this->getProject()['$uid'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('online', $response['body']['status']);