Parse url to get domain

This commit is contained in:
Khushboo Verma
2024-01-23 17:02:09 +05:30
parent ef3f39fc89
commit 1d7ec558e4
2 changed files with 15 additions and 7 deletions
+5
View File
@@ -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) {
@@ -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 [];
}
}