From 1d7ec558e4bab6067452cbb2e9c7b4c57f819786 Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:02:09 +0530 Subject: [PATCH] Parse url to get domain --- app/controllers/api/health.php | 5 +++++ .../Services/Health/HealthCustomServerTest.php | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 7fcd249a9f..8ffe02a658 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -405,6 +405,11 @@ 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); + } + $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) { diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index d93a8eb598..37058e9c8d 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -450,6 +450,16 @@ class HealthCustomServerTest extends Scope $this->assertIsString($response['body']['status']); $this->assertEquals('pass', $response['body']['status']); + $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']); + $this->assertNotEmpty($response['body']['status']); + $this->assertIsString($response['body']['status']); + $this->assertEquals('pass', $response['body']['status']); + /** * Test for FAILURE */ @@ -467,13 +477,6 @@ class HealthCustomServerTest extends Scope $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 []; } }