mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-12 15:53:46 -04:00
- Remove tests that only check markup, CSS, static text, wire:key strings, framework behavior, copied app logic, or expect(true) - Replace source-grep and Reflection checks of security fixes with tests that run the real code (shell quoting, locked properties, 403 checks, webhook fork trust, log redaction, Sentinel token cleanup) - Assert response bodies and unchanged data on API error paths - Run the Traefik version job through handle() instead of private methods - Update stale tests for scheduled task props, the default Postgres image, and the disabled transfer link of unvalidated servers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.2 KiB
PHP
62 lines
2.2 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Project\Shared\Terminal;
|
|
use App\Models\Server;
|
|
use App\Services\TerminalSessionService;
|
|
use Mockery\LegacyMockInterface;
|
|
|
|
function consoleModeServer(bool $nonRoot): Server
|
|
{
|
|
/** @var Server&LegacyMockInterface $server */
|
|
$server = Mockery::mock(Server::class)->makePartial();
|
|
$server->shouldReceive('isNonRoot')->andReturn($nonRoot);
|
|
|
|
return $server;
|
|
}
|
|
|
|
it('builds an interactive attach command with safe detach keys for console mode', function () {
|
|
$command = app(TerminalSessionService::class)->containerCommand(consoleModeServer(false), 'minecraft-abc123', 'attach');
|
|
|
|
expect($command)
|
|
// Primes the console with recent logs, then attaches for live output.
|
|
->toContain("docker logs --tail 200 'minecraft-abc123' 2>&1; ")
|
|
->toContain('exec docker attach --detach-keys="ctrl-p,ctrl-q" --sig-proxy=false \'minecraft-abc123\'');
|
|
});
|
|
|
|
it('prefixes sudo for non-root servers in console mode', function () {
|
|
$command = app(TerminalSessionService::class)->containerCommand(consoleModeServer(true), 'minecraft-abc123', 'attach');
|
|
|
|
expect($command)
|
|
->toStartWith('sudo docker logs --tail 200 ')
|
|
->toContain('exec sudo docker attach --detach-keys="ctrl-p,ctrl-q" --sig-proxy=false ');
|
|
});
|
|
|
|
it('keeps the interactive shell command for shell mode', function () {
|
|
$command = app(TerminalSessionService::class)->containerCommand(consoleModeServer(false), 'web-1', 'shell');
|
|
|
|
expect($command)
|
|
->toContain("docker exec -it 'web-1' sh -c")
|
|
->not->toContain('docker attach');
|
|
});
|
|
|
|
it('defaults to console mode when the container keeps stdin open', function () {
|
|
$terminal = new Terminal;
|
|
$terminal->attachAvailable = true;
|
|
|
|
expect($terminal->resolveMode(null))->toBe('attach');
|
|
});
|
|
|
|
it('defaults to shell mode when the container has no open stdin', function () {
|
|
$terminal = new Terminal;
|
|
$terminal->attachAvailable = false;
|
|
|
|
expect($terminal->resolveMode(null))->toBe('shell');
|
|
});
|
|
|
|
it('never selects console mode when attach is unavailable even if requested', function () {
|
|
$terminal = new Terminal;
|
|
$terminal->attachAvailable = false;
|
|
|
|
expect($terminal->resolveMode('attach'))->toBe('shell');
|
|
});
|