Added protection against too big uploads

This commit is contained in:
Marcin Kurczewski 2014-09-16 18:10:01 +02:00
parent c155cc3e5c
commit ef451d93ac
3 changed files with 18 additions and 0 deletions

View file

@ -12,6 +12,7 @@ activationBodyPath = mail/activation.txt
[database] [database]
dsn = sqlite:db.sqlite dsn = sqlite:db.sqlite
maxPostSize = 10485760 ;10mb
[security] [security]
secret = change secret = change

View file

@ -77,6 +77,9 @@ class PostService
if (!$content) if (!$content)
throw new \DomainException('File cannot be empty.'); throw new \DomainException('File cannot be empty.');
if (strlen($content) > $this->config->database->maxPostSize)
throw new \DomainException('Upload is too big.');
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($content); $mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($content);
if (\Szurubooru\Helpers\MimeHelper::isFlash($mime)) if (\Szurubooru\Helpers\MimeHelper::isFlash($mime))

View file

@ -20,6 +20,7 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractTestCase
$this->authServiceMock = $this->mock(\Szurubooru\Services\AuthService::class); $this->authServiceMock = $this->mock(\Szurubooru\Services\AuthService::class);
$this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class); $this->timeServiceMock = $this->mock(\Szurubooru\Services\TimeService::class);
$this->fileServiceMock = $this->mock(\Szurubooru\Services\FileService::class); $this->fileServiceMock = $this->mock(\Szurubooru\Services\FileService::class);
$this->configMock->set('database/maxPostSize', 1000000);
} }
@ -143,6 +144,19 @@ class PostServiceTest extends \Szurubooru\Tests\AbstractTestCase
$this->postService->createPost($formData); $this->postService->createPost($formData);
} }
public function testTooBigUpload()
{
$formData = new \Szurubooru\FormData\UploadFormData;
$formData->safety = \Szurubooru\Entities\Post::POST_SAFETY_SAFE;
$formData->tags = ['test'];
$formData->content = 'aa';
$this->configMock->set('database/maxPostSize', 1);
$this->setExpectedException(\Exception::class, 'Upload is too big');
$this->postService = $this->getPostService();
$this->postService->createPost($formData);
}
public function testAnonymousUploads() public function testAnonymousUploads()
{ {