Limit each image to 1 MB.

UPLOAD_MAX_MB changes the limit, and UPLOAD_MAX_MB=none removes it.
This commit is contained in:
tim
2026-09-26 15:27:51 +02:00
parent c4fcef21aa
commit 504d363642
5 changed files with 86 additions and 5 deletions
+8 -2
View File
@@ -112,6 +112,12 @@ class SubmitTest extends PageTestCase {
$this->assertSame(array(), $this->queries('/^INSERT/'));
}
public function testATooLargeImageIsRefused(): void {
$page = $this->previewImage(array(), str_pad(TestCase::png(), 1024 * 1024 + 1, "\0"));
$this->assertStringContainsString('a.png is larger than 1 MB. Please choose a smaller image.', $page['body']);
$this->assertSame(array(), $this->uploads());
}
public function testAnArrayActionIsIgnored(): void {
$page = $this->post('/publish', array('action' => array('post')));
$this->assertSame(200, $page['status']);
@@ -128,10 +134,10 @@ class SubmitTest extends PageTestCase {
}
// Preview the story with an image; returns the answer
private function previewImage(array $fields = array()): array {
private function previewImage(array $fields = array(), ?string $image = NULL): array {
$token = $this->csrfToken($this->get('/publish')['body']);
return $this->postFiles('/publish', $this->story($fields + array('action' => 'preview', 'csrf_token' => $token, 'g-recaptcha-response' => 'pass')),
array('upload' => array('a.png', TestCase::png())));
array('upload' => array('a.png', $image ?? TestCase::png())));
}
public function testAPreviewKeepsTheImageForTheSession(): void {