63 lines
3.3 KiB
PHP
63 lines
3.3 KiB
PHP
<?php
|
|
/** preland#11: старый бренд запрещён независимо от обновления manifest. */
|
|
declare(strict_types=1);
|
|
$root = dirname(__DIR__);
|
|
$oldBlob = '91267982e1ad373b6ebd5fb2b761b34fe2a0c2a5';
|
|
foreach (['docs/logo.svg', 'docs/logo-alt.svg'] as $file) {
|
|
$body = str_replace("\r\n", "\n", file_get_contents($root . '/' . $file));
|
|
if (sha1('blob ' . strlen($body) . chr(0) . $body) === $oldBlob) {
|
|
fwrite(STDERR, "FAILED: {$file} содержит запрещённую заглушку бренда\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
require $root . '/bin/release-assets.php';
|
|
validateReleaseAssets($root);
|
|
$files = releaseFiles($root);
|
|
foreach (['docs/logo.svg', 'docs/logo-alt.svg', 'docs/privacy_policy.pdf', 'template.php'] as $file) {
|
|
if (!in_array($file, $files, true)) throw new RuntimeException('Не включён ' . $file);
|
|
}
|
|
foreach ($files as $file) {
|
|
if (preg_match('~^(tests/|bin/|release/|docs/superpowers/|config\.json$|[0-9]+/)~', $file)) {
|
|
throw new RuntimeException('В кодовую поставку попал защищённый/служебный файл ' . $file);
|
|
}
|
|
}
|
|
// Повреждение/удаление ресурса и подмена manifest не должны проходить preflight.
|
|
$fixture = sys_get_temp_dir() . '/preland11-' . bin2hex(random_bytes(6));
|
|
mkdir($fixture);
|
|
$copy = static function (string $relative) use ($root, $fixture): void {
|
|
$target = $fixture . '/' . $relative;
|
|
if (!is_dir(dirname($target))) mkdir(dirname($target), 0700, true);
|
|
copy($root . '/' . $relative, $target);
|
|
};
|
|
$manifest = json_decode(file_get_contents($root . '/release/assets.json'), true, 512, JSON_THROW_ON_ERROR);
|
|
foreach (array_keys($manifest['files']) as $file) $copy($file);
|
|
$copy('release/assets.json');
|
|
try {
|
|
validateReleaseAssets($fixture);
|
|
$mustFail = static function (callable $mutate) use ($fixture): void {
|
|
$mutate();
|
|
try { validateReleaseAssets($fixture); } catch (RuntimeException $e) { return; }
|
|
throw new RuntimeException('Повреждённый ресурс принят');
|
|
};
|
|
$mustFail(fn() => file_put_contents($fixture . '/docs/logo.svg', 'broken'));
|
|
$copy('docs/logo.svg');
|
|
$mustFail(fn() => unlink($fixture . '/docs/public_offer.pdf'));
|
|
$copy('docs/public_offer.pdf');
|
|
$mustFail(function () use ($fixture, $manifest): void {
|
|
unset($manifest['files']['docs/logo-alt.svg']);
|
|
file_put_contents($fixture . '/release/assets.json', json_encode($manifest));
|
|
});
|
|
$copy('release/assets.json');
|
|
$mustFail(function () use ($fixture, $manifest): void {
|
|
$body = '<svg>WBE70</svg>';
|
|
file_put_contents($fixture . '/docs/logo.svg', $body);
|
|
$manifest['files']['docs/logo.svg']['sha256'] = hash('sha256', $body);
|
|
file_put_contents($fixture . '/release/assets.json', json_encode($manifest));
|
|
});
|
|
} finally {
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($fixture, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
|
|
foreach ($iterator as $item) $item->isDir() ? rmdir($item->getPathname()) : unlink($item->getPathname());
|
|
rmdir($fixture);
|
|
}
|
|
echo "OK: текущие ресурсы, повреждение/удаление/подмена manifest и состав поставки\n";
|