update rm deadcode
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Enums\Product\ProductBillingCycle;
|
||||
use App\Helpers\OrderHelper;
|
||||
use App\Models\DomainPricing;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BillingPricingTest extends TestCase
|
||||
{
|
||||
public function test_cycle_to_months_covers_every_enum_case(): void
|
||||
{
|
||||
$expected = [
|
||||
'onetime' => 1,
|
||||
'monthly' => 1,
|
||||
'quarterly' => 3,
|
||||
'semi_annually' => 6,
|
||||
'annually' => 12,
|
||||
'biennially' => 24,
|
||||
'triennially' => 36,
|
||||
];
|
||||
|
||||
foreach (ProductBillingCycle::cases() as $case) {
|
||||
$this->assertSame($expected[$case->value], OrderHelper::cycleToMonths($case->value));
|
||||
}
|
||||
}
|
||||
|
||||
public function test_cycle_to_months_throws_on_unknown_value(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
OrderHelper::cycleToMonths('semiannually');
|
||||
}
|
||||
|
||||
public function test_cycle_to_months_throws_on_null(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
OrderHelper::cycleToMonths(null);
|
||||
}
|
||||
|
||||
/** @dataProvider domainPriceProvider */
|
||||
public function test_domain_price_formula(int $setupFee, int $firstYear, int $renewal, int $years, int $expected): void
|
||||
{
|
||||
$pricing = new DomainPricing([
|
||||
'setup_fee' => (string) $setupFee,
|
||||
'first_year' => $firstYear,
|
||||
'recurring_fee' => (string) $renewal,
|
||||
]);
|
||||
|
||||
$this->assertSame($expected, $pricing->orderPrice($years));
|
||||
}
|
||||
|
||||
public static function domainPriceProvider(): array
|
||||
{
|
||||
return [
|
||||
'years=1, no setup fee' => [0, 200000, 350000, 1, 200000],
|
||||
'years=1, with setup fee' => [50000, 200000, 350000, 1, 250000],
|
||||
'years=3, no setup fee' => [0, 200000, 350000, 3, 900000],
|
||||
'years=3, with setup fee' => [50000, 200000, 350000, 3, 950000],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Models;
|
||||
|
||||
use App\Models\ReinstallLog;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ReinstallLogPlainPasswordTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_plain_password_is_stored_encrypted_and_reads_back_transparently(): void
|
||||
{
|
||||
$log = ReinstallLog::create([
|
||||
'product_id' => 1,
|
||||
'product_type' => ReinstallLog::PRODUCT_TYPE_VPS,
|
||||
'status' => ReinstallLog::STATUS_PENDING,
|
||||
'plain_password' => 'S3cr3t!pass',
|
||||
]);
|
||||
|
||||
$raw = DB::table('reinstall_logs')->where('id', $log->id)->value('plain_password');
|
||||
|
||||
$this->assertNotSame('S3cr3t!pass', $raw);
|
||||
$this->assertSame('S3cr3t!pass', $log->fresh()->plain_password);
|
||||
}
|
||||
|
||||
public function test_backfill_migration_is_idempotent(): void
|
||||
{
|
||||
DB::table('reinstall_logs')->insert([
|
||||
'product_id' => 1,
|
||||
'product_type' => ReinstallLog::PRODUCT_TYPE_VPS,
|
||||
'status' => ReinstallLog::STATUS_PENDING,
|
||||
'plain_password' => 'plaintext-legacy-row',
|
||||
]);
|
||||
|
||||
$migration = require database_path('migrations/2026_09_26_100000_encrypt_reinstall_logs_plain_password.php');
|
||||
$migration->up();
|
||||
$migration->up();
|
||||
|
||||
$row = DB::table('reinstall_logs')->where('plain_password', '!=', '')->whereNotNull('plain_password')->first();
|
||||
$this->assertSame('plaintext-legacy-row', \Illuminate\Support\Facades\Crypt::decryptString($row->plain_password));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\VCenter;
|
||||
|
||||
use App\Http\Services\vCenter\Client;
|
||||
use App\Http\Services\vCenter\PowerShellService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PowerShellServiceSecretLoggingTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const SECRET = 'S3cr3t!pass';
|
||||
|
||||
/** @var array<int, array<int, mixed>> */
|
||||
private array $capturedLogs = [];
|
||||
|
||||
public function test_change_ip_vm_linux_never_logs_the_guest_password(): void
|
||||
{
|
||||
$this->interceptLogs();
|
||||
|
||||
(new PowerShellService(new Client()))->changeIpVM(
|
||||
vmName: 'vm-test',
|
||||
vmwareId: 'vm-3340',
|
||||
ipAddress: '10.0.0.5',
|
||||
gateway: '10.0.0.1',
|
||||
osType: 'linux',
|
||||
guestUser: 'root',
|
||||
guestPassword: self::SECRET,
|
||||
);
|
||||
|
||||
$this->assertLogsNeverContainSecret();
|
||||
}
|
||||
|
||||
public function test_change_ip_vm_windows_never_logs_the_guest_password(): void
|
||||
{
|
||||
$this->interceptLogs();
|
||||
|
||||
(new PowerShellService(new Client()))->changeIpVM(
|
||||
vmName: 'vm-test',
|
||||
vmwareId: 'vm-3340',
|
||||
ipAddress: '10.0.0.5',
|
||||
gateway: '10.0.0.1',
|
||||
osType: 'windows',
|
||||
guestUser: 'administrator',
|
||||
guestPassword: self::SECRET,
|
||||
);
|
||||
|
||||
$this->assertLogsNeverContainSecret();
|
||||
}
|
||||
|
||||
private function interceptLogs(): void
|
||||
{
|
||||
$collect = function (...$args): void {
|
||||
$this->capturedLogs[] = $args;
|
||||
};
|
||||
|
||||
Log::shouldReceive('channel')->andReturnSelf();
|
||||
Log::shouldReceive('info')->andReturnUsing($collect);
|
||||
Log::shouldReceive('warning')->andReturnUsing($collect);
|
||||
Log::shouldReceive('error')->andReturnUsing($collect);
|
||||
}
|
||||
|
||||
private function assertLogsNeverContainSecret(): void
|
||||
{
|
||||
$this->assertNotEmpty($this->capturedLogs, 'Expected at least one log call to have been made.');
|
||||
|
||||
foreach ($this->capturedLogs as $call) {
|
||||
$this->assertStringNotContainsString(self::SECRET, (string) json_encode($call));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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