From 502b4ad25ce657ef3dd14d22c2f62ab0cf506579 Mon Sep 17 00:00:00 2001 From: Artur Kyryliuk Date: Mon, 2 Nov 2026 04:17:59 +0100 Subject: [PATCH] fix(tests): align thumbnail cache test with image allowlist in assets/cache (#2538) Co-Authored-By: Claude Opus 5.5 --- core/tests/Unit/PhpThumbCacheImagesTest.php | 26 ++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/core/tests/Unit/PhpThumbCacheImagesTest.php b/core/tests/Unit/PhpThumbCacheImagesTest.php index b2160d3669..eae138289e 100644 --- a/core/tests/Unit/PhpThumbCacheImagesTest.php +++ b/core/tests/Unit/PhpThumbCacheImagesTest.php @@ -76,12 +76,26 @@ function phpThumbRepoFile(string $relative): string expect($passes)->toBe($served); })->with('phpthumb cache paths'); -it('keeps the rest of assets/cache closed in the per-directory file', function () { - expect(phpThumbRepoFile('assets/cache/.htaccess')) - ->toContain('Require all denied') - ->not->toContain('FilesMatch') - ->not->toContain('granted'); -}); +it('keeps non-image cache files closed in both Apache authorization dialects', function (string $name, bool $served) { + $htaccess = phpThumbRepoFile('assets/cache/.htaccess'); + expect($htaccess)->toContain('Require all denied')->toContain('Deny from all'); + preg_match_all('/\s*(.*?)\s*<\/FilesMatch>/s', $htaccess, $rules, PREG_SET_ORDER); + + expect($rules)->toHaveCount(2); + foreach ($rules as $rule) { + expect(preg_match('~' . $rule[1] . '~', $name))->toBe($served ? 1 : 0); + } +})->with([ + 'JPEG image' => ['thumbnail.jpg', true], + 'PNG image' => ['thumbnail.PNG', true], + 'WebP image' => ['thumbnail.jpg.webp', true], + 'site cache' => ['siteCache.idx.php', false], + 'PHP with image prefix' => ['thumbnail.jpg.php', false], + 'JSON cache' => ['settings.json', false], + 'HTML' => ['page.html', false], + 'SVG' => ['image.svg', false], + 'server configuration' => ['.htaccess', false], +]); it('writes the same two-dialect .htaccess into the thumbnail folder as the one shipped there', function () { expect(HelperProcessor::CACHE_FOLDER_HTACCESS)