mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-11-01 03:03:23 +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.
54 lines
2.0 KiB
PHP
54 lines
2.0 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Stream-link tokens go through Encryption::mintToken / readToken, which seal
|
|
* them when secure_stream_tokens is on. Calling the legacy encrypt()/decrypt()
|
|
* directly for a token quietly brings back the format that can be read and
|
|
* forged through padding errors, so only the uses that are not stream links —
|
|
* deterministic encryption of stored data — may do that.
|
|
*/
|
|
#[Group('skip-on-panel')]
|
|
final class StreamTokenCallSitesTest extends TestCase {
|
|
/**
|
|
* Stored data that must stay deterministic: HMAC keys are looked up by
|
|
* ciphertext, image cache names are reversed by the self-heal, and
|
|
* cluster:rotate-stream-secret re-encrypts both under the new secret.
|
|
*/
|
|
private const LEGACY_ALLOWED = array(
|
|
'Core/Auth/AuthService.php',
|
|
'Domain/Cluster/StreamSecretRotation.php',
|
|
'Core/Util/Encryption.php',
|
|
'Core/Util/ImageUtils.php',
|
|
'Cli/Commands/ToolsCommand.php',
|
|
);
|
|
|
|
public function testOnlyStoredDataUsesTheLegacyCipherDirectly(): void {
|
|
// Source-wide guard: scans the repo's src/ tree. On a flat deployment
|
|
// (/home/xc_vm) there is no such directory and the app root is mixed with
|
|
// runtime/test files, so this static guard only runs in the repo layout.
|
|
$rRoot = MAIN_HOME;
|
|
if (!is_dir($rRoot)) {
|
|
$this->markTestSkipped('source-tree guard runs only in the repo layout');
|
|
}
|
|
$rOffenders = array();
|
|
$rIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rRoot, FilesystemIterator::SKIP_DOTS));
|
|
foreach ($rIterator as $rFile) {
|
|
$rPath = $rFile->getPathname();
|
|
if (substr($rPath, -4) !== '.php' || strpos($rPath, '/vendor/') !== false) {
|
|
continue;
|
|
}
|
|
$rRelative = substr($rPath, strlen($rRoot));
|
|
if (in_array($rRelative, self::LEGACY_ALLOWED, true)) {
|
|
continue;
|
|
}
|
|
if (preg_match('/Encryption::(encrypt|decrypt)\s*\(/', (string) file_get_contents($rPath))) {
|
|
$rOffenders[] = $rRelative;
|
|
}
|
|
}
|
|
$this->assertSame(array(), $rOffenders, 'use Encryption::mintToken / readToken for stream-link tokens');
|
|
}
|
|
}
|