Deploy Ladill Hosting / deploy (push) Failing after 17s
Shared web hosting extracted from the platform monolith, with CI deploy to /var/www/ladill-hosting matching Bird/Domains/Email. Co-authored-by: Cursor <cursoragent@cursor.com>
151 lines
5.3 KiB
PHP
151 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Controllers\Hosting\HostingPanelController;
|
|
use App\Models\HostedSite;
|
|
use App\Models\HostingAccount;
|
|
use App\Models\HostingNode;
|
|
use App\Models\User;
|
|
use App\Services\Hosting\Providers\SharedNodeProvider;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\Request;
|
|
use Tests\TestCase;
|
|
|
|
class HostingPanelSslTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_ssl_request_marks_site_as_enabled_when_certificate_is_issued(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$node = HostingNode::create([
|
|
'name' => 'Local Node',
|
|
'hostname' => 'local-node',
|
|
'ip_address' => '127.0.0.1',
|
|
'type' => 'shared',
|
|
'provider' => 'local',
|
|
'status' => 'active',
|
|
'ssh_port' => '22',
|
|
]);
|
|
|
|
$account = HostingAccount::unguarded(function () use ($user, $node) {
|
|
return HostingAccount::create([
|
|
'user_id' => $user->id,
|
|
'hosting_node_id' => $node->id,
|
|
'username' => 'acctuser',
|
|
'primary_domain' => 'example.com',
|
|
'type' => 'shared',
|
|
'status' => 'active',
|
|
'php_version' => '8.2',
|
|
]);
|
|
});
|
|
|
|
$site = HostedSite::create([
|
|
'hosting_account_id' => $account->id,
|
|
'domain' => 'example.com',
|
|
'document_root' => '/home/acctuser/public_html/example.com',
|
|
'type' => 'primary',
|
|
'status' => 'active',
|
|
'ssl_enabled' => false,
|
|
]);
|
|
|
|
$provider = \Mockery::mock(SharedNodeProvider::class);
|
|
$provider->shouldReceive('requestLetsEncryptCertificate')
|
|
->once()
|
|
->withArgs(fn (HostedSite $passedSite): bool => $passedSite->is($site))
|
|
->andReturn(true);
|
|
|
|
$this->app->instance(SharedNodeProvider::class, $provider);
|
|
$session = $this->app['session.store'];
|
|
$session->start();
|
|
|
|
$request = Request::create(
|
|
'http://localhost/hosting/panel/' . $account->id . '/ssl/' . $site->id,
|
|
'POST',
|
|
[],
|
|
[],
|
|
[],
|
|
['HTTP_REFERER' => 'http://localhost/hosting/panel/' . $account->id . '/ssl']
|
|
);
|
|
$request->setUserResolver(fn (): User => $user);
|
|
$request->setLaravelSession($session);
|
|
|
|
$response = $this->app->make(HostingPanelController::class)->requestSsl($request, $account, $site);
|
|
|
|
$this->assertSame(302, $response->getStatusCode());
|
|
$this->assertSame(
|
|
'SSL certificate issued for example.com successfully.',
|
|
$session->get('success')
|
|
);
|
|
$this->assertTrue((bool) $site->fresh()->ssl_enabled);
|
|
}
|
|
|
|
public function test_ssl_request_surfaces_actionable_provider_failures(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$node = HostingNode::create([
|
|
'name' => 'Local Node',
|
|
'hostname' => 'local-node',
|
|
'ip_address' => '127.0.0.1',
|
|
'type' => 'shared',
|
|
'provider' => 'local',
|
|
'status' => 'active',
|
|
'ssh_port' => '22',
|
|
]);
|
|
|
|
$account = HostingAccount::unguarded(function () use ($user, $node) {
|
|
return HostingAccount::create([
|
|
'user_id' => $user->id,
|
|
'hosting_node_id' => $node->id,
|
|
'username' => 'acctuser',
|
|
'primary_domain' => 'example.com',
|
|
'type' => 'shared',
|
|
'status' => 'active',
|
|
'php_version' => '8.2',
|
|
]);
|
|
});
|
|
|
|
$site = HostedSite::create([
|
|
'hosting_account_id' => $account->id,
|
|
'domain' => 'example.com',
|
|
'document_root' => '/home/acctuser/public_html/example.com',
|
|
'type' => 'primary',
|
|
'status' => 'active',
|
|
'ssl_enabled' => false,
|
|
]);
|
|
|
|
$provider = \Mockery::mock(SharedNodeProvider::class);
|
|
$provider->shouldReceive('requestLetsEncryptCertificate')
|
|
->once()
|
|
->withArgs(fn (HostedSite $passedSite): bool => $passedSite->is($site))
|
|
->andThrow(new \RuntimeException('Local hosting administration requires passwordless sudo or a valid root SSH key on the hosting node.'));
|
|
|
|
$this->app->instance(SharedNodeProvider::class, $provider);
|
|
$session = $this->app['session.store'];
|
|
$session->start();
|
|
|
|
$request = Request::create(
|
|
'http://localhost/hosting/panel/' . $account->id . '/ssl/' . $site->id,
|
|
'POST',
|
|
[],
|
|
[],
|
|
[],
|
|
['HTTP_REFERER' => 'http://localhost/hosting/panel/' . $account->id . '/ssl']
|
|
);
|
|
$request->setUserResolver(fn (): User => $user);
|
|
$request->setLaravelSession($session);
|
|
|
|
$response = $this->app->make(HostingPanelController::class)->requestSsl($request, $account, $site);
|
|
|
|
$this->assertSame(302, $response->getStatusCode());
|
|
$this->assertSame(
|
|
'Failed to issue SSL certificate: Local hosting administration requires passwordless sudo or a valid root SSH key on the hosting node.',
|
|
$session->get('error')
|
|
);
|
|
$this->assertFalse((bool) $site->fresh()->ssl_enabled);
|
|
}
|
|
}
|