mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-04 12:02:33 +02:00
Port of Rosmi720/XC_VM@0d39e9bd. A mode-dropping deploy could leave core scripts non-executable and a php-fpm pool config missing, and an undefined HOST constant broke the unique-header cookie domain: - StartupCommand restores the executable bit on service/update/redis-server/ daemons.sh and regenerates any missing php-fpm pool config (1..4.conf) from the template on boot. - StreamAuthMiddleware derives the cookie domain through a HOST-guarded helper, so an undefined/empty host or a bare IP yields no domain instead of throwing or emitting a broken "." domain. Adapted to this tree: the added boot blocks were split into covered helpers (ensureExecutableScripts / ensurePhpFpmPoolConfigs / uniqueHeaderDomain) with unit tests to stay within the complexity ceiling, the sudo chown now runs only as root, and comments were translated to English.
55 lines
1.8 KiB
PHP
55 lines
1.8 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use XcVm\Cli\Commands\StartupCommand;
|
|
|
|
/**
|
|
* Coverage for the boot self-healing helpers extracted from StartupCommand:
|
|
* restoring the executable bit on core scripts and regenerating missing
|
|
* php-fpm pool configs from the template.
|
|
*/
|
|
final class StartupCommandRuntimeFilesTest extends TestCase {
|
|
|
|
private string $dir;
|
|
|
|
private function call(string $rMethod, ...$rArgs) {
|
|
$rM = new ReflectionMethod(StartupCommand::class, $rMethod);
|
|
$rM->setAccessible(true);
|
|
return $rM->invoke(null, ...$rArgs);
|
|
}
|
|
|
|
protected function setUp(): void {
|
|
$this->dir = sys_get_temp_dir() . '/xcvm_startup_' . uniqid() . '/';
|
|
mkdir($this->dir . 'bin/php/etc', 0777, true);
|
|
}
|
|
|
|
protected function tearDown(): void {
|
|
exec('rm -rf ' . escapeshellarg($this->dir));
|
|
}
|
|
|
|
public function testEnsureExecutableScriptsSetsBitAndSkipsMissing(): void {
|
|
file_put_contents($this->dir . 'service', "#!/bin/sh\n");
|
|
chmod($this->dir . 'service', 0644);
|
|
|
|
$this->call('ensureExecutableScripts', ['service', 'does-not-exist'], $this->dir);
|
|
|
|
$this->assertTrue(is_executable($this->dir . 'service'));
|
|
}
|
|
|
|
public function testEnsurePhpFpmPoolConfigsGeneratesOnlyMissing(): void {
|
|
file_put_contents($this->dir . 'bin/php/etc/template', 'id=#ID# path=#PATH#');
|
|
file_put_contents($this->dir . 'bin/php/etc/1.conf', 'KEEP'); // existing → untouched
|
|
|
|
$this->call('ensurePhpFpmPoolConfigs', $this->dir);
|
|
|
|
$this->assertSame('KEEP', file_get_contents($this->dir . 'bin/php/etc/1.conf'));
|
|
$this->assertSame('id=2 path=' . $this->dir, file_get_contents($this->dir . 'bin/php/etc/2.conf'));
|
|
$this->assertFileExists($this->dir . 'bin/php/etc/4.conf');
|
|
}
|
|
|
|
public function testEnsurePhpFpmPoolConfigsWithoutTemplateIsNoop(): void {
|
|
$this->call('ensurePhpFpmPoolConfigs', $this->dir);
|
|
$this->assertFileDoesNotExist($this->dir . 'bin/php/etc/1.conf');
|
|
}
|
|
}
|