+ $this->disableCookieEncryption();
+ $publicRole = Role::getSystemRole('public');
+ $accessApiPermission = RolePermission::getByName('access-api');
+ $publicRole->attachPermission($accessApiPermission);
+
+ $this->withCookie('bookstack_session', 'abc123');
+
+ // Test API access when not public
+ setting()->put('app-public', false);
+ $resp = $this->get($this->endpoint);
+ $resp->assertStatus(403);
+
+ // Test API access when public
+ setting()->put('app-public', true);
+ $resp = $this->get($this->endpoint);
+ $resp->assertStatus(200);
+ }
+
+ public function test_token_expiry_checked()
+ {
+ $editor = $this->users->editor();
+ $token = $editor->apiTokens()->first();
+
+ $resp = $this->get($this->endpoint, $this->apiAuthHeader());
+ $resp->assertStatus(200);
+ auth()->logout();
+
+ $token->expires_at = Carbon::now()->subDay()->format('Y-m-d');
+ $token->save();
+
+ $resp = $this->get($this->endpoint, $this->apiAuthHeader());
+ $resp->assertJson($this->errorResponse('The authorization token used has expired', 403));
+ }
+
+ public function test_email_confirmation_checked_using_api_auth()
+ {
+ $editor = $this->users->editor();