update rm deadcode
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Support;
|
||||
|
||||
use App\Support\SshHostKeyVerifier;
|
||||
use phpseclib3\Net\SSH2;
|
||||
use RuntimeException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SshHostKeyVerifierTest extends TestCase
|
||||
{
|
||||
public function test_missing_known_hosts_is_rejected_while_tls_verification_is_on(): void
|
||||
{
|
||||
config(['vmware.tls_verify' => true, 'vmware.ssh_known_hosts' => null]);
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
||||
SshHostKeyVerifier::verify($this->createMock(SSH2::class), '10.0.0.1');
|
||||
}
|
||||
|
||||
public function test_missing_known_hosts_is_allowed_when_tls_verification_is_off(): void
|
||||
{
|
||||
config(['vmware.tls_verify' => false, 'vmware.ssh_known_hosts' => null]);
|
||||
|
||||
SshHostKeyVerifier::verify($this->createMock(SSH2::class), '10.0.0.1');
|
||||
|
||||
$this->addToAssertionCount(1);
|
||||
}
|
||||
|
||||
public function test_host_key_must_match_known_hosts_entry(): void
|
||||
{
|
||||
$knownHosts = tempnam(sys_get_temp_dir(), 'kh');
|
||||
file_put_contents($knownHosts, "10.0.0.1 ssh-ed25519 AAAAexpected\n");
|
||||
config(['vmware.tls_verify' => true, 'vmware.ssh_known_hosts' => $knownHosts]);
|
||||
|
||||
$matching = $this->createMock(SSH2::class);
|
||||
$matching->method('getServerPublicHostKey')->willReturn('ssh-ed25519 AAAAexpected');
|
||||
SshHostKeyVerifier::verify($matching, '10.0.0.1');
|
||||
|
||||
$spoofed = $this->createMock(SSH2::class);
|
||||
$spoofed->method('getServerPublicHostKey')->willReturn('ssh-ed25519 AAAAattacker');
|
||||
$this->expectException(RuntimeException::class);
|
||||
try {
|
||||
SshHostKeyVerifier::verify($spoofed, '10.0.0.1');
|
||||
} finally {
|
||||
unlink($knownHosts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user