X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/da1a66abd384911085d595e4ef06d36430a38a27..refs/pull/4467/head:/tests/TestCase.php diff --git a/tests/TestCase.php b/tests/TestCase.php index abee1d3b3..0ab0792bd 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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; @@ -46,6 +47,7 @@ abstract class TestCase extends BaseTestCase $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. @@ -213,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'); } /**