From cec96062e34944bbd41cef258ff6687f561042f0 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 7 Aug 2021 16:08:29 -0700 Subject: [PATCH] Get client API tests back into passing order --- .../Api/Client/SubstituteClientApiBindings.php | 9 ++++----- app/Http/Requests/Api/ApiRequest.php | 1 + app/Http/Requests/Api/Client/WebsocketTokenRequest.php | 6 ++++++ .../Api/Client/Server/WebsocketControllerTest.php | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Http/Middleware/Api/Client/SubstituteClientApiBindings.php b/app/Http/Middleware/Api/Client/SubstituteClientApiBindings.php index 244654cdd..7ab63948f 100644 --- a/app/Http/Middleware/Api/Client/SubstituteClientApiBindings.php +++ b/app/Http/Middleware/Api/Client/SubstituteClientApiBindings.php @@ -36,11 +36,11 @@ class SubstituteClientApiBindings }); $this->router->bind('allocation', function ($value, $route) { - return $this->server($route)->allocations()->where('id', $value)->firstOrFail(); + return $this->server($route)->allocations()->findOrFail($value); }); $this->router->bind('schedule', function ($value, $route) { - return $this->server($route)->schedule()->where('id', $value)->firstOrFail(); + return $this->server($route)->schedule()->findOrFail($value); }); $this->router->bind('task', function ($value, $route) { @@ -51,14 +51,13 @@ class SubstituteClientApiBindings ->where('schedules.server_id', $route->parameter('server')->id); }) ->where('schedules.id', $route->parameter('schedule')->id) - ->where('tasks.id', $value) - ->firstOrFail(); + ->findOrFail($value); }); $this->router->bind('database', function ($value, $route) { $id = Container::getInstance()->make(HashidsInterface::class)->decodeFirst($value); - return $this->server($route)->where('id', $id)->firstOrFail(); + return $this->server($route)->databases()->findOrFail($id); }); $this->router->bind('backup', function ($value, $route) { diff --git a/app/Http/Requests/Api/ApiRequest.php b/app/Http/Requests/Api/ApiRequest.php index 253a61691..c76b434dd 100644 --- a/app/Http/Requests/Api/ApiRequest.php +++ b/app/Http/Requests/Api/ApiRequest.php @@ -3,6 +3,7 @@ namespace Pterodactyl\Http\Requests\Api; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Auth\Access\AuthorizationException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** diff --git a/app/Http/Requests/Api/Client/WebsocketTokenRequest.php b/app/Http/Requests/Api/Client/WebsocketTokenRequest.php index fad5bdc6e..3849b6e88 100644 --- a/app/Http/Requests/Api/Client/WebsocketTokenRequest.php +++ b/app/Http/Requests/Api/Client/WebsocketTokenRequest.php @@ -3,6 +3,7 @@ namespace Pterodactyl\Http\Requests\Api\Client; use Pterodactyl\Models\Permission; +use Illuminate\Auth\Access\AuthorizationException; class WebsocketTokenRequest extends ClientApiRequest { @@ -10,4 +11,9 @@ class WebsocketTokenRequest extends ClientApiRequest { return Permission::ACTION_WEBSOCKET_CONNECT; } + + protected function failedAuthorization() + { + throw new AuthorizationException('You do not have permission to connect to this server\'s websocket.'); + } } diff --git a/tests/Integration/Api/Client/Server/WebsocketControllerTest.php b/tests/Integration/Api/Client/Server/WebsocketControllerTest.php index d6c2119b6..b0dc19854 100644 --- a/tests/Integration/Api/Client/Server/WebsocketControllerTest.php +++ b/tests/Integration/Api/Client/Server/WebsocketControllerTest.php @@ -23,7 +23,7 @@ class WebsocketControllerTest extends ClientApiIntegrationTestCase $this->actingAs($user)->getJson("/api/client/servers/{$server->uuid}/websocket") ->assertStatus(Response::HTTP_FORBIDDEN) - ->assertJsonPath('errors.0.code', 'HttpForbiddenException') + ->assertJsonPath('errors.0.code', 'AccessDeniedHttpException') ->assertJsonPath('errors.0.detail', 'You do not have permission to connect to this server\'s websocket.'); }