mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Added tests
This commit is contained in:
@@ -801,6 +801,12 @@ return [
|
||||
'code' => 404,
|
||||
],
|
||||
|
||||
Exception::INVALID_HOST => [
|
||||
'name' => Exception::INVALID_HOST,
|
||||
'description' => 'Host not found.',
|
||||
'code' => 404,
|
||||
],
|
||||
|
||||
/** Providers */
|
||||
Exception::PROVIDER_NOT_FOUND => [
|
||||
'name' => Exception::PROVIDER_NOT_FOUND,
|
||||
|
||||
@@ -407,6 +407,9 @@ App::get('/v1/health/certificate')
|
||||
->action(function (string $domain, Response $response) {
|
||||
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => true)));
|
||||
$read = stream_socket_client("ssl://" . $domain . ":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
|
||||
if (!$read) {
|
||||
throw new Exception(Exception::INVALID_HOST, 'The domain is not valid.');
|
||||
}
|
||||
$certificate = stream_context_get_params($read);
|
||||
$certificateInfo = openssl_x509_parse($certificate['options']['ssl']['peer_certificate']);
|
||||
$sslExpiration = $certificateInfo['validTo_time_t'];
|
||||
@@ -415,6 +418,7 @@ App::get('/v1/health/certificate')
|
||||
if ($status == 'fail') {
|
||||
throw new Exception(Exception::CERTIFICATE_EXPIRED, 'The certificate of the domain has expired.');
|
||||
}
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'name' => 'certificate',
|
||||
'status' => $status,
|
||||
|
||||
@@ -240,6 +240,7 @@ class Exception extends \Exception
|
||||
/** Health */
|
||||
public const QUEUE_SIZE_EXCEEDED = 'queue_size_exceeded';
|
||||
public const CERTIFICATE_EXPIRED = 'certificate_expired';
|
||||
public const INVALID_HOST = 'invalid_host';
|
||||
|
||||
/** Provider */
|
||||
public const PROVIDER_NOT_FOUND = 'provider_not_found';
|
||||
|
||||
@@ -424,4 +424,56 @@ class HealthCustomServerTest extends Scope
|
||||
|
||||
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->assertNotEmpty($response['body']['status']);
|
||||
$this->assertIsString($response['body']['status']);
|
||||
$this->assertEquals('pass', $response['body']['status']);
|
||||
|
||||
$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->assertNotEmpty($response['body']['status']);
|
||||
$this->assertIsString($response['body']['status']);
|
||||
$this->assertEquals('pass', $response['body']['status']);
|
||||
|
||||
/**
|
||||
* 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=https://google.com', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), []);
|
||||
|
||||
$this->assertEquals(404, $response['headers']['status-code']);
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user