54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Support;
|
|
|
|
use App\Support\TlsHttpClientFactory;
|
|
use Tests\TestCase;
|
|
|
|
class TlsHttpClientFactoryTest extends TestCase
|
|
{
|
|
public function test_verify_true_and_no_ca_bundle_uses_default_verification(): void
|
|
{
|
|
config(['vmware.tls_verify' => true, 'vmware.ca_bundle' => null]);
|
|
|
|
$this->assertTrue(TlsHttpClientFactory::vCenter()->getOptions()['verify']);
|
|
}
|
|
|
|
public function test_verify_true_with_ca_bundle_pins_the_bundle_path(): void
|
|
{
|
|
config(['vmware.tls_verify' => true, 'vmware.ca_bundle' => '/etc/ssl/vcenter-ca.pem']);
|
|
|
|
$this->assertSame('/etc/ssl/vcenter-ca.pem', TlsHttpClientFactory::vCenter()->getOptions()['verify']);
|
|
}
|
|
|
|
public function test_verify_false_disables_verification(): void
|
|
{
|
|
config(['vmware.tls_verify' => false, 'vmware.ca_bundle' => '/etc/ssl/vcenter-ca.pem']);
|
|
|
|
$this->assertFalse(TlsHttpClientFactory::vCenter()->getOptions()['verify']);
|
|
}
|
|
|
|
public function test_plesk_reads_its_own_config(): void
|
|
{
|
|
config(['vmware.tls_verify' => false, 'services.plesk.tls_verify' => true, 'services.plesk.ca_bundle' => '/etc/ssl/plesk-ca.pem']);
|
|
|
|
$this->assertSame('/etc/ssl/plesk-ca.pem', TlsHttpClientFactory::plesk()->getOptions()['verify']);
|
|
}
|
|
|
|
public function test_curl_options_follow_vcenter_config(): void
|
|
{
|
|
config(['vmware.tls_verify' => true, 'vmware.ca_bundle' => '/etc/ssl/vcenter-ca.pem']);
|
|
$this->assertSame([
|
|
CURLOPT_SSL_VERIFYPEER => true,
|
|
CURLOPT_SSL_VERIFYHOST => 2,
|
|
CURLOPT_CAINFO => '/etc/ssl/vcenter-ca.pem',
|
|
], TlsHttpClientFactory::vCenterCurlOptions());
|
|
|
|
config(['vmware.tls_verify' => false]);
|
|
$this->assertSame([
|
|
CURLOPT_SSL_VERIFYPEER => false,
|
|
CURLOPT_SSL_VERIFYHOST => 0,
|
|
], TlsHttpClientFactory::vCenterCurlOptions());
|
|
}
|
|
}
|