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.
This commit is contained in:
Dan Brown 2022-02-06 05:05:17 +00:00
parent 9d15688a43
commit 43f32f6d5a
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9

View File

@ -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();