From 43f32f6d5a8fb5e008005b3df99e4076e0dd73eb Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sun, 6 Feb 2022 05:05:17 +0000 Subject: [PATCH] Added attachment API file size limit test Created while testing for #3248, Was not something that's currently failing within BookStack but will still add for coverage. --- tests/Api/AttachmentsApiTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Api/AttachmentsApiTest.php b/tests/Api/AttachmentsApiTest.php index bfa47343e..79b4ae98c 100644 --- a/tests/Api/AttachmentsApiTest.php +++ b/tests/Api/AttachmentsApiTest.php @@ -102,6 +102,30 @@ class AttachmentsApiTest extends TestCase unlink(storage_path($newItem->path)); } + public function test_upload_limit_restricts_attachment_uploads() + { + $this->actingAsApiAdmin(); + /** @var Page $page */ + $page = Page::query()->first(); + + config()->set('app.upload_limit', 1); + + $file = tmpfile(); + $filePath = stream_get_meta_data($file)['uri']; + fwrite($file, str_repeat('a', 1200000)); + $file = new UploadedFile($filePath, 'test.txt', 'text/plain', null, true); + + $details = [ + 'name' => 'My attachment', + 'uploaded_to' => $page->id, + ]; + $resp = $this->call('POST', $this->baseEndpoint, $details, [], ['file' => $file]); + $resp->assertStatus(422); + $resp->assertJson($this->validationResponse([ + "file" => ["The file may not be greater than 1000 kilobytes."] + ])); + } + public function test_name_needed_to_create() { $this->actingAsApiAdmin();