Files
ladill-servers/tests/Feature/HardenHostingAccountIsolationCommandTest.php
T
isaaccladandCursor b6c8ac343f Extract Ladill Servers as standalone app at servers.ladill.com.
VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-06 19:18:30 +00:00

86 lines
2.9 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\HostingAccount;
use App\Models\HostingProduct;
use App\Models\User;
use App\Services\Hosting\Providers\SharedNodeProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class HardenHostingAccountIsolationCommandTest extends TestCase
{
use RefreshDatabase;
public function test_it_hardens_a_single_shared_account(): void
{
$user = User::factory()->create();
$product = HostingProduct::create([
'name' => 'Isolation Test Product',
'slug' => 'isolation-test-' . str()->random(6),
'category' => HostingProduct::CATEGORY_SHARED,
'type' => HostingProduct::TYPE_SINGLE_DOMAIN,
'price_monthly' => 10,
'currency' => 'GHS',
'disk_gb' => 10,
'max_domains' => 1,
'is_active' => true,
'is_visible' => true,
]);
$account = HostingAccount::create([
'user_id' => $user->id,
'hosting_product_id' => $product->id,
'username' => 'isolateacct',
'primary_domain' => 'example.test',
'type' => HostingAccount::TYPE_SHARED,
'status' => HostingAccount::STATUS_ACTIVE,
]);
$provider = \Mockery::mock(SharedNodeProvider::class);
$provider->shouldReceive('hardenAccountFilesystem')->once()->withArgs(
fn (HostingAccount $candidate): bool => $candidate->id === $account->id
);
$this->app->instance(SharedNodeProvider::class, $provider);
$this->artisan('hosting:harden-account-isolation', [
'--account' => $account->id,
])->assertExitCode(0);
}
public function test_it_supports_dry_run_without_touching_accounts(): void
{
$user = User::factory()->create();
$product = HostingProduct::create([
'name' => 'Isolation Test Product',
'slug' => 'isolation-dry-run-' . str()->random(6),
'category' => HostingProduct::CATEGORY_SHARED,
'type' => HostingProduct::TYPE_SINGLE_DOMAIN,
'price_monthly' => 10,
'currency' => 'GHS',
'disk_gb' => 10,
'max_domains' => 1,
'is_active' => true,
'is_visible' => true,
]);
HostingAccount::create([
'user_id' => $user->id,
'hosting_product_id' => $product->id,
'username' => 'dryrunacct',
'primary_domain' => 'dry-run.test',
'type' => HostingAccount::TYPE_SHARED,
'status' => HostingAccount::STATUS_ACTIVE,
]);
$provider = \Mockery::mock(SharedNodeProvider::class);
$provider->shouldNotReceive('hardenAccountFilesystem');
$this->app->instance(SharedNodeProvider::class, $provider);
$this->artisan('hosting:harden-account-isolation', [
'--dry-run' => true,
])->assertExitCode(0);
}
}