From 71b90650de0aa461d9b758d0e78afc985cbbe1f1 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 4 Nov 2017 12:49:05 -0500 Subject: [PATCH] Fix failing test suite --- .../Server/AccessingValidServer.php | 27 ++++++------ .../ServerConfigurationStructureService.php | 7 ++- .../pterodactyl/errors/suspended.blade.php | 2 +- .../Server/AccessingValidServerTest.php | 44 +++++++------------ ...erverConfigurationStructureServiceTest.php | 7 +-- 5 files changed, 41 insertions(+), 46 deletions(-) diff --git a/app/Http/Middleware/Server/AccessingValidServer.php b/app/Http/Middleware/Server/AccessingValidServer.php index 5137d7721..ddca28251 100644 --- a/app/Http/Middleware/Server/AccessingValidServer.php +++ b/app/Http/Middleware/Server/AccessingValidServer.php @@ -6,9 +6,10 @@ use Closure; use Illuminate\Http\Request; use Pterodactyl\Models\Server; use Illuminate\Contracts\Session\Session; +use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Contracts\Config\Repository as ConfigRepository; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\HttpKernel\Exception\ConflictHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; class AccessingValidServer @@ -23,6 +24,11 @@ class AccessingValidServer */ private $repository; + /** + * @var \Illuminate\Contracts\Routing\ResponseFactory + */ + private $response; + /** * @var \Illuminate\Contracts\Session\Session */ @@ -32,16 +38,19 @@ class AccessingValidServer * AccessingValidServer constructor. * * @param \Illuminate\Contracts\Config\Repository $config + * @param \Illuminate\Contracts\Routing\ResponseFactory $response * @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository * @param \Illuminate\Contracts\Session\Session $session */ public function __construct( ConfigRepository $config, + ResponseFactory $response, ServerRepositoryInterface $repository, Session $session ) { $this->config = $config; $this->repository = $repository; + $this->response = $response; $this->session = $session; } @@ -63,30 +72,22 @@ class AccessingValidServer $isApiRequest = $request->expectsJson() || $request->is(...$this->config->get('pterodactyl.json_routes', [])); $server = $this->repository->getByUuid($attributes instanceof Server ? $attributes->uuid : $attributes); - if (! $server) { - if ($isApiRequest) { - throw new NotFoundHttpException('The requested server was not found on the system.'); - } - - return response()->view('errors.404', [], 404); - } - if ($server->suspended) { if ($isApiRequest) { - throw new AccessDeniedHttpException('Server is suspended.'); + throw new AccessDeniedHttpException('Server is suspended and cannot be accessed.'); } - return response()->view('errors.suspended', [], 403); + return $this->response->view('errors.suspended', [], 403); } // Servers can have install statuses other than 1 or 0, so don't check // for a bool-type operator here. if ($server->installed !== 1) { if ($isApiRequest) { - throw new AccessDeniedHttpException('Server is not marked as installed.'); + throw new ConflictHttpException('Server is still completing the installation process.'); } - return response()->view('errors.installing', [], 403); + return $this->response->view('errors.installing', [], 409); } // Store the server in the session. diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index d91d9db95..21b52ad2a 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -54,6 +54,11 @@ class ServerConfigurationStructureService $server = $this->repository->getDataForCreation($server); } + $pack = $server->getRelation('pack'); + if (! is_null($pack)) { + $pack = $server->getRelation('pack')->uuid; + } + return [ 'uuid' => $server->uuid, 'build' => [ @@ -74,7 +79,7 @@ class ServerConfigurationStructureService ], 'service' => [ 'egg' => $server->egg->uuid, - 'pack' => object_get($server, 'pack.uuid'), + 'pack' => $pack, 'skip_scripts' => $server->skip_scripts, ], 'rebuild' => false, diff --git a/resources/themes/pterodactyl/errors/suspended.blade.php b/resources/themes/pterodactyl/errors/suspended.blade.php index f8b8fa449..86e804f69 100644 --- a/resources/themes/pterodactyl/errors/suspended.blade.php +++ b/resources/themes/pterodactyl/errors/suspended.blade.php @@ -17,7 +17,7 @@
-

401

+

403

@lang('base.errors.suspended.desc')