appwrite/tests/e2e/Services/Health/HealthCustomServerTest.php

545 lines
20 KiB
PHP
Raw Normal View History

2020-01-12 15:20:51 +00:00
<?php
namespace Tests\E2E\Services\Health;
2020-05-01 10:43:31 +00:00
use Tests\E2E\Client;
2020-01-12 15:20:51 +00:00
use Tests\E2E\Scopes\ProjectCustom;
2024-03-06 17:34:21 +00:00
use Tests\E2E\Scopes\Scope;
2020-06-07 06:00:14 +00:00
use Tests\E2E\Scopes\SideServer;
2020-01-12 15:20:51 +00:00
2020-12-26 12:10:14 +00:00
class HealthCustomServerTest extends Scope
2020-01-12 15:20:51 +00:00
{
use HealthBase;
use ProjectCustom;
2020-06-07 06:00:14 +00:00
use SideServer;
2020-05-01 10:43:31 +00:00
2021-10-26 13:19:28 +00:00
public function testHTTPSuccess(): array
2020-05-01 10:43:31 +00:00
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
2021-12-16 12:19:04 +00:00
$this->assertEquals('pass', $response['body']['status']);
$this->assertIsInt($response['body']['ping']);
$this->assertLessThan(100, $response['body']['ping']);
2020-05-01 10:43:31 +00:00
return [];
}
2021-10-26 13:19:28 +00:00
public function testDBSuccess(): array
2020-05-01 10:43:31 +00:00
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/db', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('pass', $response['body']['statuses'][0]['status']);
$this->assertIsInt($response['body']['statuses'][0]['ping']);
$this->assertLessThan(100, $response['body']['statuses'][0]['ping']);
2020-05-01 10:43:31 +00:00
return [];
}
2021-10-26 13:19:28 +00:00
public function testCacheSuccess(): array
2020-05-01 10:43:31 +00:00
{
/**
* Test for SUCCESS
*/
2020-12-26 15:10:45 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/cache', array_merge([
2020-05-01 10:43:31 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('pass', $response['body']['statuses'][0]['status']);
$this->assertIsInt($response['body']['statuses'][0]['ping']);
$this->assertLessThan(100, $response['body']['statuses'][0]['ping']);
return [];
}
public function testPubSubSuccess(): array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/pubsub', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('pass', $response['body']['statuses'][0]['status']);
$this->assertIsInt($response['body']['statuses'][0]['ping']);
$this->assertLessThan(100, $response['body']['statuses'][0]['ping']);
2020-05-01 10:43:31 +00:00
return [];
}
2021-10-26 13:19:28 +00:00
public function testTimeSuccess(): array
2020-05-01 10:43:31 +00:00
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/time', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
2021-12-16 12:19:04 +00:00
$this->assertIsInt($response['body']['remoteTime']);
$this->assertIsInt($response['body']['localTime']);
$this->assertNotEmpty($response['body']['remoteTime']);
$this->assertNotEmpty($response['body']['localTime']);
2020-05-01 10:43:31 +00:00
$this->assertLessThan(10, $response['body']['diff']);
2023-10-15 17:41:09 +00:00
return [];
}
public function testWebhooksSuccess(): array
{
2020-05-01 10:43:31 +00:00
/**
2023-10-15 17:41:09 +00:00
* Test for SUCCESS
2020-05-01 10:43:31 +00:00
*/
2023-10-15 17:41:09 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/webhooks', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2020-05-01 10:43:31 +00:00
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
2023-11-13 13:39:33 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/webhooks?threshold=0', array_merge([
2023-11-13 13:07:11 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2023-10-03 08:40:34 +00:00
return [];
}
2023-10-15 17:41:09 +00:00
public function testLogsSuccess(): array
2023-10-03 08:40:34 +00:00
{
2020-05-01 10:43:31 +00:00
/**
2023-10-03 08:40:34 +00:00
* Test for SUCCESS
2020-05-01 10:43:31 +00:00
*/
2023-10-15 17:41:09 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/logs', array_merge([
2023-10-03 08:40:34 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2021-10-26 13:19:28 +00:00
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
2023-11-13 13:39:33 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/logs?threshold=0', array_merge([
2023-11-13 13:07:11 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2023-10-15 17:41:09 +00:00
return [];
}
public function testCertificatesSuccess(): array
{
2020-05-01 10:43:31 +00:00
/**
2023-10-15 17:41:09 +00:00
* Test for SUCCESS
2020-05-01 10:43:31 +00:00
*/
2023-10-15 17:41:09 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/certificates', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2020-05-01 10:43:31 +00:00
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
2023-11-13 13:39:33 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/certificates?threshold=0', array_merge([
2023-11-13 13:07:11 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2023-10-03 08:40:34 +00:00
return [];
}
2023-10-15 17:41:09 +00:00
public function testFunctionsSuccess(): array
2023-10-03 08:40:34 +00:00
{
/**
* Test for SUCCESS
*/
2023-10-15 17:41:09 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/functions', array_merge([
2023-10-03 08:40:34 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
2023-11-13 13:39:33 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/functions?threshold=0', array_merge([
2023-11-13 13:07:11 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2023-10-15 17:41:09 +00:00
return [];
}
public function testBuildsSuccess(): array
{
2020-05-01 10:43:31 +00:00
/**
2023-10-15 17:41:09 +00:00
* Test for SUCCESS
2020-05-01 10:43:31 +00:00
*/
2023-10-15 17:41:09 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/builds', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2023-10-03 08:40:34 +00:00
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
2023-11-13 13:39:33 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/builds?threshold=0', array_merge([
2023-11-13 13:07:11 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2023-10-03 08:40:34 +00:00
return [];
}
2023-10-15 17:41:09 +00:00
public function testDatabasesSuccess(): array
2023-10-03 08:40:34 +00:00
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/queue/databases', array_merge([
2023-10-03 08:40:34 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
2023-10-19 09:25:38 +00:00
'name' => 'database_db_main',
]);
2023-10-03 08:40:34 +00:00
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_GET, '/health/queue/databases', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'name' => 'database_db_main',
2023-11-13 13:39:33 +00:00
'threshold' => '0'
2023-11-13 13:07:11 +00:00
]);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2023-10-15 17:41:09 +00:00
return [];
}
public function testDeletesSuccess(): array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/queue/deletes', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
2023-11-13 13:39:33 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/deletes?threshold=0', array_merge([
2023-11-13 13:07:11 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2023-10-15 17:41:09 +00:00
return [];
}
public function testMailsSuccess(): array
{
2023-10-03 08:40:34 +00:00
/**
2023-10-15 17:41:09 +00:00
* Test for SUCCESS
2023-10-03 08:40:34 +00:00
*/
2023-10-15 17:41:09 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/mails', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
2023-11-13 13:39:33 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/mails?threshold=0', array_merge([
2023-11-13 13:07:11 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2023-10-15 17:41:09 +00:00
return [];
}
public function testMessagingSuccess(): array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/queue/messaging', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
2023-11-13 13:39:33 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/messaging?threshold=0', array_merge([
2023-11-13 13:07:11 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2023-10-15 17:41:09 +00:00
return [];
}
public function testMigrationsSuccess(): array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/queue/migrations', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
2021-10-26 13:19:28 +00:00
2023-11-13 13:07:11 +00:00
/**
* Test for FAILURE
*/
2023-11-13 13:39:33 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/migrations?threshold=0', array_merge([
2023-11-13 13:07:11 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2023-11-16 18:49:43 +00:00
$this->assertEquals(503, $response['headers']['status-code']);
2023-11-13 13:07:11 +00:00
2020-05-01 10:43:31 +00:00
return [];
}
2021-10-26 13:19:28 +00:00
public function testStorageLocalSuccess(): array
2020-05-01 10:43:31 +00:00
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/storage/local', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
2021-12-16 12:19:04 +00:00
$this->assertEquals('pass', $response['body']['status']);
$this->assertIsInt($response['body']['ping']);
2024-02-15 06:27:24 +00:00
$this->assertLessThan(100, $response['body']['ping']);
return [];
}
public function testStorageSuccess(): array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/storage', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
2020-05-01 10:43:31 +00:00
$this->assertEquals(200, $response['headers']['status-code']);
2021-12-16 12:19:04 +00:00
$this->assertEquals('pass', $response['body']['status']);
$this->assertIsInt($response['body']['ping']);
$this->assertLessThan(100, $response['body']['ping']);
2020-05-01 10:43:31 +00:00
return [];
}
2021-10-26 13:19:28 +00:00
public function testStorageAntiVirusSuccess(): array
2020-05-01 10:43:31 +00:00
{
/**
* Test for SUCCESS
*/
2020-05-18 12:34:28 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/anti-virus', array_merge([
2020-05-01 10:43:31 +00:00
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
2021-03-20 08:50:30 +00:00
$this->assertNotEmpty($response['body']['status']);
$this->assertIsString($response['body']['status']);
$this->assertIsString($response['body']['version']);
2020-05-01 10:43:31 +00:00
return [];
}
public function testCertificateValidity(): array
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/certificate?domain=www.google.com', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('/CN=www.google.com', $response['body']['name']);
$this->assertEquals('www.google.com', $response['body']['subjectSN']);
2024-10-22 06:52:38 +00:00
$this->assertContains($response['body']['issuerOrganisation'], ['Let\'s Encrypt', 'Google Trust Services']);
$this->assertIsInt($response['body']['validFrom']);
$this->assertIsInt($response['body']['validTo']);
$response = $this->client->call(Client::METHOD_GET, '/health/certificate?domain=appwrite.io', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('/CN=appwrite.io', $response['body']['name']);
$this->assertEquals('appwrite.io', $response['body']['subjectSN']);
2024-10-22 07:00:24 +00:00
$this->assertContains($response['body']['issuerOrganisation'], ['Let\'s Encrypt', 'Google Trust Services']);
$this->assertIsInt($response['body']['validFrom']);
$this->assertIsInt($response['body']['validTo']);
$response = $this->client->call(Client::METHOD_GET, '/health/certificate?domain=https://google.com', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_GET, '/health/certificate?domain=localhost', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(400, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_GET, '/health/certificate?domain=doesnotexist.com', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(404, $response['headers']['status-code']);
$response = $this->client->call(Client::METHOD_GET, '/health/certificate?domain=www.google.com/usr/src/local', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(400, $response['headers']['status-code']);
2024-02-06 10:34:58 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/certificate?domain=', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(400, $response['headers']['status-code']);
return [];
}
2025-02-06 04:48:40 +00:00
public function testStatsResources()
{
/**
* Test for SUCCESS
*/
$response = $this->client->call(Client::METHOD_GET, '/health/queue/stats-resources', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
/**
* Test for FAILURE
*/
$response = $this->client->call(Client::METHOD_GET, '/health/queue/stats-resources?threshold=0', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(503, $response['headers']['status-code']);
}
public function testUsageSuccess()
{
/**
* Test for SUCCESS
*/
2025-02-06 03:58:46 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/stats-usage', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertIsInt($response['body']['size']);
$this->assertLessThan(100, $response['body']['size']);
/**
* Test for FAILURE
*/
2025-02-06 03:58:46 +00:00
$response = $this->client->call(Client::METHOD_GET, '/health/queue/stats-usage?threshold=0', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(503, $response['headers']['status-code']);
}
2021-10-26 13:19:28 +00:00
}