|
5 | 5 | use BookStack\Entities\Models\Book; |
6 | 6 | use BookStack\Entities\Models\Chapter; |
7 | 7 | use BookStack\Entities\Models\Page; |
| 8 | +use BookStack\Exceptions\ZipImportException; |
8 | 9 | use BookStack\Exports\ZipExports\ZipImportRunner; |
9 | 10 | use BookStack\Uploads\Image; |
10 | 11 | use Tests\TestCase; |
@@ -431,4 +432,56 @@ public function test_drawing_references_are_updated_within_content() |
431 | 432 |
|
432 | 433 | ZipTestHelper::deleteZipForImport($import); |
433 | 434 | } |
| 435 | + |
| 436 | + public function test_error_thrown_if_zip_item_exceeds_app_file_upload_limit() |
| 437 | + { |
| 438 | + $tempFile = tempnam(sys_get_temp_dir(), 'bs-zip-test'); |
| 439 | + file_put_contents($tempFile, str_repeat('a', 2500000)); |
| 440 | + $parent = $this->entities->chapter(); |
| 441 | + config()->set('app.upload_limit', 1); |
| 442 | + |
| 443 | + $import = ZipTestHelper::importFromData([], [ |
| 444 | + 'page' => [ |
| 445 | + 'name' => 'Page A', |
| 446 | + 'html' => '<p>Hello</p>', |
| 447 | + 'attachments' => [ |
| 448 | + [ |
| 449 | + 'name' => 'Text attachment', |
| 450 | + 'file' => 'file_attachment' |
| 451 | + ] |
| 452 | + ], |
| 453 | + ], |
| 454 | + ], [ |
| 455 | + 'file_attachment' => $tempFile, |
| 456 | + ]); |
| 457 | + |
| 458 | + $this->asAdmin(); |
| 459 | + |
| 460 | + $this->expectException(ZipImportException::class); |
| 461 | + $this->expectExceptionMessage('The file file_attachment must not exceed 1 MB.'); |
| 462 | + |
| 463 | + $this->runner->run($import, $parent); |
| 464 | + ZipTestHelper::deleteZipForImport($import); |
| 465 | + } |
| 466 | + |
| 467 | + public function test_error_thrown_if_zip_data_exceeds_app_file_upload_limit() |
| 468 | + { |
| 469 | + $parent = $this->entities->chapter(); |
| 470 | + config()->set('app.upload_limit', 1); |
| 471 | + |
| 472 | + $import = ZipTestHelper::importFromData([], [ |
| 473 | + 'page' => [ |
| 474 | + 'name' => 'Page A', |
| 475 | + 'html' => '<p>' . str_repeat('a', 2500000) . '</p>', |
| 476 | + ], |
| 477 | + ]); |
| 478 | + |
| 479 | + $this->asAdmin(); |
| 480 | + |
| 481 | + $this->expectException(ZipImportException::class); |
| 482 | + $this->expectExceptionMessage('ZIP data.json content exceeds the configured application maximum upload size.'); |
| 483 | + |
| 484 | + $this->runner->run($import, $parent); |
| 485 | + ZipTestHelper::deleteZipForImport($import); |
| 486 | + } |
434 | 487 | } |
0 commit comments