From 2d02d51fecf2cbae6d4bf9658c8253649846ba50 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:03:45 +0530 Subject: [PATCH] Add more tests --- app/controllers/api/health.php | 9 ++++++++- tests/e2e/Services/Health/HealthCustomServerTest.php | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 8ffe02a658..fe275fdd09 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -405,7 +405,6 @@ App::get('/v1/health/certificate') ->param('domain', null, new Multiple([new Domain(), new PublicDomain()]), Multiple::TYPE_STRING, 'Domain name') ->inject('response') ->action(function (string $domain, Response $response) { - // Extract domain from URL if provided if (filter_var($domain, FILTER_VALIDATE_URL)) { $domain = parse_url($domain, PHP_URL_HOST); } @@ -417,6 +416,14 @@ App::get('/v1/health/certificate') } $certificate = stream_context_get_params($read); $certificateInfo = openssl_x509_parse($certificate['options']['ssl']['peer_certificate']); + $certificatePayload = [ + 'name' => $certificateInfo['name'], + 'subject' => $certificateInfo['subject'], + 'issuer' => $certificateInfo['issuer'], + 'validFrom' => $certificateInfo['validFrom_time_t'], + 'validTo' => $certificateInfo['validTo_time_t'], + 'signatureTypeSN' => $certificateInfo['signatureTypeSN'], + ]; $sslExpiration = $certificateInfo['validTo_time_t']; $status = ($sslExpiration < time()) ? 'fail' : 'pass'; diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 37058e9c8d..141029823e 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -477,6 +477,13 @@ class HealthCustomServerTest extends Scope $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']); + return []; } }