Improved health check tests
This commit is contained in:
parent
3686171d6e
commit
2f843943e1
9 changed files with 220 additions and 26 deletions
|
@ -138,7 +138,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$role = Auth::USER_ROLE_APP;
|
$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.
|
Authorization::disable(); // Cancel security segmentation for API keys.
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,6 @@ return [
|
||||||
],
|
],
|
||||||
ROLE_APP => [
|
ROLE_APP => [
|
||||||
'label' => 'Application',
|
'label' => 'Application',
|
||||||
'scopes' => ['public'],
|
'scopes' => ['health.read'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Tests\E2E\Services\Avatars;
|
namespace Tests\E2E\Services\Avatars;
|
||||||
|
|
||||||
use Tests\E2E\Client;
|
|
||||||
use Tests\E2E\Scopes\ProjectCustom;
|
use Tests\E2E\Scopes\ProjectCustom;
|
||||||
use Tests\E2E\Scopes\Scope;
|
use Tests\E2E\Scopes\Scope;
|
||||||
use Tests\E2E\Scopes\SideServer;
|
use Tests\E2E\Scopes\SideServer;
|
||||||
|
|
154
tests/e2e/Services/Health/HealthBase.php
Normal file
154
tests/e2e/Services/Health/HealthBase.php
Normal 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 [];
|
||||||
|
}
|
||||||
|
}
|
14
tests/e2e/Services/Health/HealthConsoleClientTest.php
Normal file
14
tests/e2e/Services/Health/HealthConsoleClientTest.php
Normal 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;
|
||||||
|
}
|
14
tests/e2e/Services/Health/HealthCustomClientTest.php
Normal file
14
tests/e2e/Services/Health/HealthCustomClientTest.php
Normal 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;
|
||||||
|
}
|
15
tests/e2e/Services/Health/HealthCustomServerTest.php
Normal file
15
tests/e2e/Services/Health/HealthCustomServerTest.php
Normal 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;
|
||||||
|
}
|
|
@ -12,6 +12,4 @@ class LocaleCustomServerTest extends Scope
|
||||||
use LocaleBase;
|
use LocaleBase;
|
||||||
use ProjectCustom;
|
use ProjectCustom;
|
||||||
use SideServer;
|
use SideServer;
|
||||||
|
|
||||||
///$this->getHeaders()
|
|
||||||
}
|
}
|
|
@ -8,10 +8,10 @@ class ConsoleHealthTest extends BaseConsole
|
||||||
{
|
{
|
||||||
public function testHTTPSuccess(): void
|
public function testHTTPSuccess(): void
|
||||||
{
|
{
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/health', [
|
$response = $this->client->call(Client::METHOD_GET, '/health', array_merge([
|
||||||
'origin' => 'http://localhost',
|
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], []);
|
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertEquals('OK', $response['body']['status']);
|
$this->assertEquals('OK', $response['body']['status']);
|
||||||
|
@ -19,10 +19,10 @@ class ConsoleHealthTest extends BaseConsole
|
||||||
|
|
||||||
public function testDBSuccess(): void
|
public function testDBSuccess(): void
|
||||||
{
|
{
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/health/db', [
|
$response = $this->client->call(Client::METHOD_GET, '/health/db', array_merge([
|
||||||
'origin' => 'http://localhost',
|
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], []);
|
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertEquals('OK', $response['body']['status']);
|
$this->assertEquals('OK', $response['body']['status']);
|
||||||
|
@ -30,10 +30,10 @@ class ConsoleHealthTest extends BaseConsole
|
||||||
|
|
||||||
public function testCacheSuccess(): void
|
public function testCacheSuccess(): void
|
||||||
{
|
{
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/health/db', [
|
$response = $this->client->call(Client::METHOD_GET, '/health/db', array_merge([
|
||||||
'origin' => 'http://localhost',
|
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], []);
|
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertEquals('OK', $response['body']['status']);
|
$this->assertEquals('OK', $response['body']['status']);
|
||||||
|
@ -41,10 +41,10 @@ class ConsoleHealthTest extends BaseConsole
|
||||||
|
|
||||||
public function testTimeSuccess(): void
|
public function testTimeSuccess(): void
|
||||||
{
|
{
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/health/time', [
|
$response = $this->client->call(Client::METHOD_GET, '/health/time', array_merge([
|
||||||
'origin' => 'http://localhost',
|
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], []);
|
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertIsInt($response['body']['remote']);
|
$this->assertIsInt($response['body']['remote']);
|
||||||
|
@ -56,10 +56,10 @@ class ConsoleHealthTest extends BaseConsole
|
||||||
|
|
||||||
public function testWebhooksSuccess(): void
|
public function testWebhooksSuccess(): void
|
||||||
{
|
{
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/health/webhooks', [
|
$response = $this->client->call(Client::METHOD_GET, '/health/webhooks', array_merge([
|
||||||
'origin' => 'http://localhost',
|
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], []);
|
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertIsInt($response['body']['size']);
|
$this->assertIsInt($response['body']['size']);
|
||||||
|
@ -68,10 +68,10 @@ class ConsoleHealthTest extends BaseConsole
|
||||||
|
|
||||||
public function xtestStorageLocalSuccess(): void
|
public function xtestStorageLocalSuccess(): void
|
||||||
{
|
{
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/health/storage/local', [
|
$response = $this->client->call(Client::METHOD_GET, '/health/storage/local', array_merge([
|
||||||
'origin' => 'http://localhost',
|
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], []);
|
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertEquals('OK', $response['body']['status']);
|
$this->assertEquals('OK', $response['body']['status']);
|
||||||
|
@ -79,10 +79,10 @@ class ConsoleHealthTest extends BaseConsole
|
||||||
|
|
||||||
public function testStorageAntiVirusSuccess(): void
|
public function testStorageAntiVirusSuccess(): void
|
||||||
{
|
{
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/health/storage/anti-virus', [
|
$response = $this->client->call(Client::METHOD_GET, '/health/storage/anti-virus', array_merge([
|
||||||
'origin' => 'http://localhost',
|
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
], []);
|
'x-appwrite-project' => $this->getProject()['$uid'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertEquals('online', $response['body']['status']);
|
$this->assertEquals('online', $response['body']['status']);
|
||||||
|
|
Loading…
Reference in a new issue