mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-31 19:03:43 +01:00
The suite ran on in-memory SQLite, an engine production never uses: it hid column lengths, MySQL-only syntax and type coercion (the identity bug fixed in the previous commit passed CI that way). SQLite is gone: - TestDb connects only to MariaDB/MySQL (XCVM_TEST_DB_DSN/_USER/_PASS; root over the local socket, else 127.0.0.1:3306). Each instance gets a throwaway schema, dropped with it, in the installer's sql_mode, with an explicit connect timeout (a boot under test can zero default_socket_timeout). - InstallSchema and the tests take the production DDL as is: the SQLite reducers, the keys they re-added, the faked information_schema and the sqliteCreateFunction() stand-ins are removed; test DDL is MySQL DDL. - ReplicaBootTest, DbConnectRefusalTest and LazyDatabaseHandlerTest reach the test server instead of SQLite files; RecordingFinalizer no longer swallows an information_schema failure "for tests on SQLite". - `make test-db` starts a throwaway mariadb:11.4 (tmpfs) for a machine without a server; the CI PHPUnit job gets the same as a service. The suite also runs on a panel host with the bundled PHP and its own php.ini: tests reach the code through MAIN_HOME, not `<repo>/src`; repository checks and process-isolated tests (ionCube Loader + OPcache CLI segfault on a script read from stdin) are in the skip-on-panel group; xcvm_test_child_php() starts a child that fakes \XC_VM without the real extension; Redis-down tests use RedisManager::useConnector() instead of an eval'd \XC_VM. Stale opt-in tests fixed on the way: the real-agent provisioning test answers the agent-started check, the extension integration test sends the typed starts and reads the binary signature raw, a fake producer starts as PHP_BINARY, and the certbot test waits for the line its background command writes.
64 lines
2.6 KiB
PHP
64 lines
2.6 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use XcVm\Cli\Commands\LbInstallFlow;
|
|
|
|
/**
|
|
* server:install drives a node over SSH as a sudo-capable user, not root.
|
|
*
|
|
* - `sudo echo … >> /etc/fstab` runs only the echo under sudo; the redirect is
|
|
* the SSH user's own, so the fstab (and systemd, sysctl, nginx port) writes
|
|
* failed on every non-root install. Such writes go through `sudo tee`.
|
|
* - config_pack() was handed `port => ConfigReader::get('port')`, but
|
|
* ConfigReader holds only the `server` section, so every LB got DB port 0.
|
|
*/
|
|
final class LbInstallFlowRootWritesTest extends TestCase {
|
|
|
|
public function testSudoWriteRunsTheWriteItselfAsRoot(): void {
|
|
$this->assertSame(
|
|
"echo 'tmpfs /x tmpfs size=90% 0 0' | sudo tee -a '/etc/fstab' > /dev/null",
|
|
LbInstallFlow::sudoWrite('tmpfs /x tmpfs size=90% 0 0', '/etc/fstab', true)
|
|
);
|
|
$this->assertSame(
|
|
"echo 'listen 80;' | sudo tee '/home/xc_vm/bin/nginx/conf/ports/http.conf' > /dev/null",
|
|
LbInstallFlow::sudoWrite('listen 80;', '/home/xc_vm/bin/nginx/conf/ports/http.conf')
|
|
);
|
|
}
|
|
|
|
public function testSudoWriteWritesTheTextVerbatim(): void {
|
|
$rFile = sys_get_temp_dir() . '/xcvm_sudo_write_' . uniqid();
|
|
$rText = "\n" . 'on_play http://127.0.0.1:80/stream/rtmp; $HOME "q" \'s\'';
|
|
try {
|
|
foreach ([false, true] as $rAppend) {
|
|
$rLine = str_replace('sudo tee', 'tee', LbInstallFlow::sudoWrite($rText, $rFile, $rAppend));
|
|
exec($rLine, $rOut, $rCode);
|
|
$this->assertSame(0, $rCode);
|
|
}
|
|
$this->assertSame($rText . "\n" . $rText . "\n", file_get_contents($rFile));
|
|
} finally {
|
|
@unlink($rFile);
|
|
}
|
|
}
|
|
|
|
public function testNoSshFlowRedirectsASudoEcho(): void {
|
|
$rRoot = MAIN_HOME . 'Cli/Commands/';
|
|
foreach (['LbInstallFlow.php', 'ProxyInstallFlow.php', 'ServerInstallCommand.php'] as $rFile) {
|
|
$rSource = (string) file_get_contents($rRoot . $rFile);
|
|
$this->assertDoesNotMatchRegularExpression('/sudo echo[^\n]*>/', $rSource, $rFile);
|
|
}
|
|
}
|
|
|
|
public function testConfigPackIsNotHandedAPortFromTheServerSection(): void {
|
|
if (!defined('SERVER_ID')) {
|
|
define('SERVER_ID', 1);
|
|
}
|
|
$rServers = [SERVER_ID => ['server_ip' => '10.0.0.1'], 7 => ['server_ip' => '10.0.0.7']];
|
|
|
|
$rParams = LbInstallFlow::configPackParams($rServers, 7);
|
|
|
|
$this->assertArrayNotHasKey('port', $rParams, 'config_pack() packs its default DB port, 3306 (ADR-001), and refuses 0');
|
|
$this->assertSame(['hostname' => '10.0.0.1', 'database' => 'xc_vm', 'server_id' => 7, 'is_lb' => 1], $rParams);
|
|
$this->assertStringNotContainsString('ConfigReader::', (string) file_get_contents(MAIN_HOME . 'Cli/Commands/LbInstallFlow.php'));
|
|
}
|
|
}
|