You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/UserCopyRuntimeNoDatabaseCo...

49 lines
1.4 KiB
PHP

<?php
$root = dirname(__DIR__) . '/app/Services/UserCopy';
$runtimeFiles = [
'UserCopyCatalogException.php',
'UserCopyManifest.php',
'UserCopySourceCatalog.php',
'UserCopyRuntimeReader.php',
'UserCopyCatalog.php',
'UserCopyPageResolver.php',
'UserCopyViewRuntime.php',
];
$forbidden = [
'/Illuminate\\\\Database/',
'/\\bCapsule\\b/',
'/\\bPDO\\b/',
'/\\bPredis\\b/',
'/\\bRedis(?:Client)?\\b/',
'/\\bDB::/',
];
foreach ($runtimeFiles as $name) {
$file = $root . '/' . $name;
if (!is_file($file)) {
throw new RuntimeException('User copy runtime file is missing: ' . $name);
}
$source = file_get_contents($file);
if (!is_string($source)) {
throw new RuntimeException('Unable to read ' . $file);
}
foreach ($forbidden as $pattern) {
if (preg_match($pattern, $source) === 1) {
throw new RuntimeException(
basename($file) . ' introduced a runtime persistence dependency.'
);
}
}
}
$reader = file_get_contents($root . '/UserCopyRuntimeReader.php');
if (!is_string($reader)
|| preg_match('/\\b(?:fopen|fwrite|rename|mkdir|unlink)\\s*\\(/', $reader) === 1) {
throw new RuntimeException(
'The user copy runtime reader is no longer read-only.'
);
}
echo "User copy runtime stays filesystem-only and read-only.\n";