Large host files mounted via Docker volumes caused the storages page to become unusable — full file content was stored in the encrypted mediumText column and serialised into the Livewire payload, crashing the browser. - Add MAX_CONTENT_SIZE (5 MiB), BINARY_PLACEHOLDER, and TOO_LARGE_PLACEHOLDER constants to LocalFileVolume - Check remote file size via stat/wc before cat in loadStorageOnServer and saveStorageOnServer; store placeholder instead of content when limit exceeded - Expose is_too_large computed attribute (appended for Livewire serialisation) - Guard submit, instantSave, and syncData in FileStorage Livewire component - Truncate oversized content in Storage::refreshStorages to prevent payload bloat - Show distinct warning banner in file-storage blade; mark textarea readonly and hide Save/Convert buttons for too-large files - Add unit tests covering constants, computed flags, and toArray serialisation Fixes #4701
66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Unit tests for LocalFileVolume content size handling.
|
|
*
|
|
* Related Issue: #4701 - Storages page becomes unusable when Docker volumes
|
|
* mount large host files. Coolify previously stored full file content in the
|
|
* encrypted `content` mediumText column, then serialized it to the Livewire
|
|
* payload, crashing the browser.
|
|
*/
|
|
|
|
use App\Models\LocalFileVolume;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class);
|
|
|
|
it('exposes a 5 MiB content size limit', function () {
|
|
expect(LocalFileVolume::MAX_CONTENT_SIZE)->toBe(5_242_880);
|
|
});
|
|
|
|
it('exposes binary and too-large placeholder constants', function () {
|
|
expect(LocalFileVolume::BINARY_PLACEHOLDER)->toBe('[binary file]');
|
|
expect(LocalFileVolume::TOO_LARGE_PLACEHOLDER)->toBe('[file too large to display]');
|
|
});
|
|
|
|
it('flags is_too_large when content matches the placeholder', function () {
|
|
$volume = new LocalFileVolume;
|
|
$volume->content = LocalFileVolume::TOO_LARGE_PLACEHOLDER;
|
|
|
|
expect($volume->is_too_large)->toBeTrue();
|
|
expect($volume->is_binary)->toBeFalse();
|
|
});
|
|
|
|
it('flags is_binary when content matches the placeholder', function () {
|
|
$volume = new LocalFileVolume;
|
|
$volume->content = LocalFileVolume::BINARY_PLACEHOLDER;
|
|
|
|
expect($volume->is_binary)->toBeTrue();
|
|
expect($volume->is_too_large)->toBeFalse();
|
|
});
|
|
|
|
it('does not flag normal content as binary or too large', function () {
|
|
$volume = new LocalFileVolume;
|
|
$volume->content = "hello\nworld\n";
|
|
|
|
expect($volume->is_binary)->toBeFalse();
|
|
expect($volume->is_too_large)->toBeFalse();
|
|
});
|
|
|
|
it('does not flag empty content as binary or too large', function () {
|
|
$volume = new LocalFileVolume;
|
|
$volume->content = null;
|
|
|
|
expect($volume->is_binary)->toBeFalse();
|
|
expect($volume->is_too_large)->toBeFalse();
|
|
});
|
|
|
|
it('exposes the too-large flag via toArray for Livewire serialization', function () {
|
|
$volume = new LocalFileVolume;
|
|
$volume->content = LocalFileVolume::TOO_LARGE_PLACEHOLDER;
|
|
|
|
$array = $volume->toArray();
|
|
|
|
expect($array)->toHaveKey('is_too_large');
|
|
expect($array['is_too_large'])->toBeTrue();
|
|
});
|