57 lines
2.9 KiB
PHP
57 lines
2.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/** Prüft die App-Downloads (includes/app_downloads.php): per FTP abgelegte Dateien, Prüfsumme mit Zwischenspeicher, Ordnerschutz. */
|
|
|
|
$dir = sys_get_temp_dir() . '/deskhub-apps-' . bin2hex(random_bytes(4));
|
|
putenv('DESKHUB_APPS_DIR=' . $dir);
|
|
putenv('DESKHUB_SQLITE_PATH=:memory:');
|
|
require_once dirname(__DIR__) . '/includes/bootstrap.php';
|
|
|
|
$failures = [];
|
|
$check = function (bool $ok, string $what) use (&$failures): void {
|
|
if (!$ok) $failures[] = $what;
|
|
};
|
|
|
|
$check(app_download_info('android') === null && app_download_info('windows') === null, 'ohne Dateien ist nichts hinterlegt (Ordner existiert noch nicht)');
|
|
$check(app_download_info('ios') === null && app_download_info('../x') === null, 'unbekannte Plattform liefert nichts');
|
|
|
|
$check(app_downloads_prepare_dir() && is_dir($dir), 'Ordner wird angelegt');
|
|
$check(is_file($dir . '/.htaccess') && str_contains((string) file_get_contents($dir . '/.htaccess'), 'Require all denied'), 'Ordner ist per .htaccess gesperrt');
|
|
$check(app_download_info('android') === null, 'leerer Ordner: nichts hinterlegt');
|
|
|
|
$apk = 'PK' . random_bytes(4000);
|
|
file_put_contents($dir . '/DeskHub.apk', $apk);
|
|
$info = app_download_info('android');
|
|
$check($info !== null && $info['size'] === strlen($apk) && $info['sha256'] === hash('sha256', $apk), 'per FTP abgelegte APK wird erkannt, Größe und Prüfsumme stimmen');
|
|
$check($info && $info['filename'] === 'DeskHub.apk' && $info['mime'] === 'application/vnd.android.package-archive' && $info['modified_at'] !== '', 'Dateiname, Typ und Datum');
|
|
$check(app_download_info('windows') === null, 'die andere Plattform bleibt leer');
|
|
|
|
$exe = 'MZ' . random_bytes(6000);
|
|
file_put_contents($dir . '/DeskHub-Setup.exe', $exe);
|
|
$check(app_download_info('windows')['sha256'] === hash('sha256', $exe), 'Windows-Datei wird erkannt');
|
|
|
|
// Zwischenspeicher: gleiche Datei -> gleiche Prüfsumme ohne Neuberechnung; geänderte Datei -> neue Prüfsumme
|
|
$cacheValue = get_setting('app_android_hash_cache', '');
|
|
app_download_info('android');
|
|
$check(get_setting('app_android_hash_cache', '') === $cacheValue && $cacheValue !== '', 'Prüfsumme wird zwischengespeichert');
|
|
$apk2 = 'PK' . random_bytes(5000);
|
|
file_put_contents($dir . '/DeskHub.apk', $apk2);
|
|
touch($dir . '/DeskHub.apk', time() + 5);
|
|
$info2 = app_download_info('android');
|
|
$check($info2['sha256'] === hash('sha256', $apk2) && $info2['size'] === strlen($apk2), 'ausgetauschte Datei bekommt eine neue Prüfsumme');
|
|
|
|
file_put_contents($dir . '/DeskHub.apk', 'PK');
|
|
$check(app_download_info('android') === null, 'abgebrochene/winzige Datei wird nicht angeboten');
|
|
|
|
$check(app_format_size(110 * 1048576) === '110,0 MB' && app_format_size(2048) === '2 KB', 'Größenformat');
|
|
|
|
foreach (scandir($dir) ?: [] as $e) { if ($e !== '.' && $e !== '..') @unlink($dir . '/' . $e); }
|
|
@rmdir($dir);
|
|
|
|
if ($failures) {
|
|
fwrite(STDERR, "Fehlgeschlagen:\n - " . implode("\n - ", $failures) . "\n");
|
|
exit(1);
|
|
}
|
|
echo "App downloads checks passed.\n";
|