]> BookStack Code Mirror - bookstack/blobdiff - tests/TestCase.php
Fixed OIDC Logout
[bookstack] / tests / TestCase.php
index 9e4b1df419e5a3e9cbe158716f0ac2a2faf93344..0ab0792bd00228dfb306b7216e7f61a66be894e3 100644 (file)
@@ -5,6 +5,7 @@ namespace Tests;
 use BookStack\Entities\Models\Entity;
 use BookStack\Settings\SettingService;
 use BookStack\Uploads\HttpFetcher;
+use BookStack\Users\Models\User;
 use GuzzleHttp\Client;
 use GuzzleHttp\Handler\MockHandler;
 use GuzzleHttp\HandlerStack;
@@ -23,6 +24,7 @@ use Monolog\Logger;
 use Psr\Http\Client\ClientInterface;
 use Ssddanbrown\AssertHtml\TestsHtml;
 use Tests\Helpers\EntityProvider;
+use Tests\Helpers\FileProvider;
 use Tests\Helpers\PermissionsProvider;
 use Tests\Helpers\TestServiceProvider;
 use Tests\Helpers\UserRoleProvider;
@@ -36,13 +38,16 @@ abstract class TestCase extends BaseTestCase
     protected EntityProvider $entities;
     protected UserRoleProvider $users;
     protected PermissionsProvider $permissions;
+    protected FileProvider $files;
 
     protected function setUp(): void
     {
         $this->entities = new EntityProvider();
         $this->users = new UserRoleProvider();
         $this->permissions = new PermissionsProvider($this->users);
+        $this->files = new FileProvider();
 
+        User::clearDefault();
         parent::setUp();
 
         // We can uncomment the below to run tests with failings upon deprecations.
@@ -210,18 +215,14 @@ abstract class TestCase extends BaseTestCase
      */
     private function isPermissionError($response): bool
     {
+        if ($response->status() === 403 && $response instanceof JsonResponse) {
+            $errMessage = $response->getData(true)['error']['message'] ?? '';
+            return $errMessage === 'You do not have permission to perform the requested action.';
+        }
+
         return $response->status() === 302
-            && (
-                (
-                    $response->headers->get('Location') === url('/')
-                    && strpos(session()->pull('error', ''), 'You do not have permission to access') === 0
-                )
-                ||
-                (
-                    $response instanceof JsonResponse &&
-                    $response->json(['error' => 'You do not have permission to perform the requested action.'])
-                )
-            );
+            && $response->headers->get('Location') === url('/')
+            && str_starts_with(session()->pull('error', ''), 'You do not have permission to access');
     }
 
     /**