]> BookStack Code Mirror - bookstack/blob - tests/Api/ApiConfigTest.php
Add support Windows Authentication via SAML
[bookstack] / tests / Api / ApiConfigTest.php
1 <?php
2
3 namespace Tests;
4
5 use BookStack\Auth\Permissions\RolePermission;
6 use Carbon\Carbon;
7
8 class ApiConfigTest extends TestCase
9 {
10     use TestsApi;
11
12     protected $endpoint = '/api/books';
13
14     public function test_default_item_count_reflected_in_listing_requests()
15     {
16         $this->actingAsApiEditor();
17
18         config()->set(['api.default_item_count' => 5]);
19         $resp = $this->get($this->endpoint);
20         $resp->assertJsonCount(5, 'data');
21
22         config()->set(['api.default_item_count' => 1]);
23         $resp = $this->get($this->endpoint);
24         $resp->assertJsonCount(1, 'data');
25     }
26
27     public function test_default_item_count_does_not_limit_count_param()
28     {
29         $this->actingAsApiEditor();
30         config()->set(['api.default_item_count' => 1]);
31         $resp = $this->get($this->endpoint . '?count=5');
32         $resp->assertJsonCount(5, 'data');
33     }
34
35     public function test_max_item_count_limits_listing_requests()
36     {
37         $this->actingAsApiEditor();
38
39         config()->set(['api.max_item_count' => 2]);
40         $resp = $this->get($this->endpoint);
41         $resp->assertJsonCount(2, 'data');
42
43         $resp = $this->get($this->endpoint . '?count=5');
44         $resp->assertJsonCount(2, 'data');
45     }
46
47     public function test_requests_per_min_alters_rate_limit()
48     {
49         $resp = $this->actingAsApiEditor()->get($this->endpoint);
50         $resp->assertHeader('x-ratelimit-limit', 180);
51
52         config()->set(['api.requests_per_minute' => 10]);
53
54         $resp = $this->actingAsApiEditor()->get($this->endpoint);
55         $resp->assertHeader('x-ratelimit-limit', 10);
56     }
57
58 }