Files
portal-api/tests/Feature/Api/Internal/PortalMonitorVCenterTest.php
2026-10-17 13:04:35 +07:00

59 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Api\Internal;
use App\Http\Facade\SignRSA;
use App\Models\vCenter;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PortalMonitorVCenterTest extends TestCase
{
use RefreshDatabase;
public function test_rejects_requests_without_service_key(): void
{
config()->set('portal-monitor.config_api_key', 'service-key');
$this->getJson('/api/v1/internal/portal-monitor/vcenter')
->assertUnauthorized()
->assertJsonMissingPath('data');
}
public function test_returns_active_vcenter_credentials_from_module_vcenter(): void
{
config()->set('portal-monitor.config_api_key', 'service-key');
vCenter::query()->create([
'host' => '10.0.0.20',
'user' => 'monitor@example.local',
'password' => SignRSA::EncryptFunc('secret-value'),
'status' => 1,
]);
$this->withHeader('X-Portal-Monitor-Key', 'service-key')
->getJson('/api/v1/internal/portal-monitor/vcenter')
->assertOk()
->assertHeader('Cache-Control', 'no-store, private')
->assertJsonPath('data.host', '10.0.0.20')
->assertJsonPath('data.port', 443)
->assertJsonPath('data.username', 'monitor@example.local')
->assertJsonPath('data.password', 'secret-value');
}
public function test_returns_sanitized_error_when_no_active_vcenter_exists(): void
{
config()->set('portal-monitor.config_api_key', 'service-key');
$this->withHeader('X-Portal-Monitor-Key', 'service-key')
->getJson('/api/v1/internal/portal-monitor/vcenter')
->assertStatus(503)
->assertJson([
'error' => true,
'message' => 'Active vCenter configuration is unavailable',
]);
}
}