From eafc4408eb1000e015fefe3808af7250febb3d03 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 14 Jul 2018 21:49:49 -0700 Subject: [PATCH] Fix broken unit tests --- app/Http/Kernel.php | 2 +- .../Middleware/Server/AccessingValidServer.php | 18 ++---------------- .../Server/AccessingValidServerTest.php | 14 +++----------- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 2383363c3..7d19dc43c 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -17,7 +17,6 @@ use Pterodactyl\Http\Middleware\LanguageMiddleware; use Illuminate\Foundation\Http\Kernel as HttpKernel; use Pterodactyl\Http\Middleware\Api\AuthenticateKey; use Illuminate\Routing\Middleware\SubstituteBindings; -use Pterodactyl\Http\Middleware\AccessingValidServer; use Pterodactyl\Http\Middleware\Api\SetSessionDriver; use Illuminate\Session\Middleware\AuthenticateSession; use Illuminate\View\Middleware\ShareErrorsFromSession; @@ -28,6 +27,7 @@ use Pterodactyl\Http\Middleware\Api\AuthenticateIPAccess; use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings; use Illuminate\Foundation\Http\Middleware\ValidatePostSize; use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; +use Pterodactyl\Http\Middleware\Server\AccessingValidServer; use Pterodactyl\Http\Middleware\Server\AuthenticateAsSubuser; use Pterodactyl\Http\Middleware\Api\Daemon\DaemonAuthenticate; use Pterodactyl\Http\Middleware\Server\SubuserBelongsToServer; diff --git a/app/Http/Middleware/Server/AccessingValidServer.php b/app/Http/Middleware/Server/AccessingValidServer.php index ddca28251..894dcaa1e 100644 --- a/app/Http/Middleware/Server/AccessingValidServer.php +++ b/app/Http/Middleware/Server/AccessingValidServer.php @@ -1,11 +1,10 @@ config = $config; $this->repository = $repository; $this->response = $response; - $this->session = $session; } /** @@ -61,7 +52,6 @@ class AccessingValidServer * @param \Closure $next * @return \Illuminate\Http\Response|mixed * - * @throws \Illuminate\Auth\AuthenticationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException @@ -90,10 +80,6 @@ class AccessingValidServer return $this->response->view('errors.installing', [], 409); } - // Store the server in the session. - // @todo remove from session. use request attributes. - $this->session->now('server_data.model', $server); - // Add server to the request attributes. This will replace sessions // as files are updated. $request->attributes->set('server', $server); diff --git a/tests/Unit/Http/Middleware/Server/AccessingValidServerTest.php b/tests/Unit/Http/Middleware/Server/AccessingValidServerTest.php index 8bafebe9f..67f61d688 100644 --- a/tests/Unit/Http/Middleware/Server/AccessingValidServerTest.php +++ b/tests/Unit/Http/Middleware/Server/AccessingValidServerTest.php @@ -4,11 +4,10 @@ namespace Tests\Unit\Http\Middleware\Server; use Mockery as m; use Pterodactyl\Models\Server; -use Illuminate\Contracts\Session\Session; use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Routing\ResponseFactory; use Tests\Unit\Http\Middleware\MiddlewareTestCase; -use Pterodactyl\Http\Middleware\AccessingValidServer; +use Pterodactyl\Http\Middleware\Server\AccessingValidServer; use Pterodactyl\Contracts\Repository\ServerRepositoryInterface; class AccessingValidServerTest extends MiddlewareTestCase @@ -28,11 +27,6 @@ class AccessingValidServerTest extends MiddlewareTestCase */ private $response; - /** - * @var \Illuminate\Contracts\Session\Session|\Mockery\Mock - */ - private $session; - /** * Setup tests. */ @@ -43,7 +37,6 @@ class AccessingValidServerTest extends MiddlewareTestCase $this->config = m::mock(Repository::class); $this->repository = m::mock(ServerRepositoryInterface::class); $this->response = m::mock(ResponseFactory::class); - $this->session = m::mock(Session::class); } /** @@ -114,7 +107,6 @@ class AccessingValidServerTest extends MiddlewareTestCase $this->request->shouldReceive('is')->with(...[])->once()->andReturn(false); $this->repository->shouldReceive('getByUuid')->with('123456')->once()->andReturn($model); - $this->session->shouldReceive('now')->with('server_data.model', $model)->once()->andReturnNull(); $this->getMiddleware()->handle($this->request, $this->getClosureAssertions()); $this->assertRequestHasAttribute('server'); @@ -141,10 +133,10 @@ class AccessingValidServerTest extends MiddlewareTestCase /** * Return an instance of the middleware using mocked dependencies. * - * @return \Pterodactyl\Http\Middleware\AccessingValidServer + * @return \Pterodactyl\Http\Middleware\Server\AccessingValidServer */ private function getMiddleware(): AccessingValidServer { - return new AccessingValidServer($this->config, $this->response, $this->repository, $this->session); + return new AccessingValidServer($this->config, $this->response, $this->repository); } }