|
7 | 7 | use BookStack\Entities\Tools\PageContent;
|
8 | 8 | use BookStack\Uploads\Attachment;
|
9 | 9 | use BookStack\Uploads\Image;
|
| 10 | +use FilesystemIterator; |
10 | 11 | use Illuminate\Support\Carbon;
|
11 | 12 | use Illuminate\Testing\TestResponse;
|
12 | 13 | use Tests\TestCase;
|
@@ -60,6 +61,24 @@ public function test_export_metadata()
|
60 | 61 | $this->assertEquals($instanceId, $zipInstanceId);
|
61 | 62 | }
|
62 | 63 |
|
| 64 | + public function test_export_leaves_no_temp_files() |
| 65 | + { |
| 66 | + $tempDir = sys_get_temp_dir(); |
| 67 | + $startTempFileCount = iterator_count((new FileSystemIterator($tempDir, FilesystemIterator::SKIP_DOTS))); |
| 68 | + |
| 69 | + $page = $this->entities->pageWithinChapter(); |
| 70 | + $this->asEditor(); |
| 71 | + $pageResp = $this->get($page->getUrl("/export/zip")); |
| 72 | + $pageResp->streamedContent(); |
| 73 | + $pageResp->assertOk(); |
| 74 | + $this->get($page->chapter->getUrl("/export/zip"))->assertOk(); |
| 75 | + $this->get($page->book->getUrl("/export/zip"))->assertOk(); |
| 76 | + |
| 77 | + $afterTempFileCount = iterator_count((new FileSystemIterator($tempDir, FilesystemIterator::SKIP_DOTS))); |
| 78 | + |
| 79 | + $this->assertEquals($startTempFileCount, $afterTempFileCount); |
| 80 | + } |
| 81 | + |
63 | 82 | public function test_page_export()
|
64 | 83 | {
|
65 | 84 | $page = $this->entities->page();
|
@@ -404,6 +423,28 @@ public function test_links_in_markdown_are_parsed()
|
404 | 423 | $this->assertStringContainsString("[Link to chapter]([[bsexport:chapter:{$chapter->id}]])", $pageData['markdown']);
|
405 | 424 | }
|
406 | 425 |
|
| 426 | + public function test_exports_rate_limited_low_for_guest_viewers() |
| 427 | + { |
| 428 | + $this->setSettings(['app-public' => 'true']); |
| 429 | + |
| 430 | + $page = $this->entities->page(); |
| 431 | + for ($i = 0; $i < 4; $i++) { |
| 432 | + $this->get($page->getUrl("/export/zip"))->assertOk(); |
| 433 | + } |
| 434 | + $this->get($page->getUrl("/export/zip"))->assertStatus(429); |
| 435 | + } |
| 436 | + |
| 437 | + public function test_exports_rate_limited_higher_for_logged_in_viewers() |
| 438 | + { |
| 439 | + $this->asAdmin(); |
| 440 | + |
| 441 | + $page = $this->entities->page(); |
| 442 | + for ($i = 0; $i < 10; $i++) { |
| 443 | + $this->get($page->getUrl("/export/zip"))->assertOk(); |
| 444 | + } |
| 445 | + $this->get($page->getUrl("/export/zip"))->assertStatus(429); |
| 446 | + } |
| 447 | + |
407 | 448 | protected function extractZipResponse(TestResponse $response): ZipResultData
|
408 | 449 | {
|
409 | 450 | $zipData = $response->streamedContent();
|
|
0 commit comments