Skip to content

Commit eafc440

Browse files
committed
Fix broken unit tests
1 parent 8b9c246 commit eafc440

File tree

3 files changed

+6
-28
lines changed

3 files changed

+6
-28
lines changed

app/Http/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Illuminate\Foundation\Http\Kernel as HttpKernel;
1818
use Pterodactyl\Http\Middleware\Api\AuthenticateKey;
1919
use Illuminate\Routing\Middleware\SubstituteBindings;
20-
use Pterodactyl\Http\Middleware\AccessingValidServer;
2120
use Pterodactyl\Http\Middleware\Api\SetSessionDriver;
2221
use Illuminate\Session\Middleware\AuthenticateSession;
2322
use Illuminate\View\Middleware\ShareErrorsFromSession;
@@ -28,6 +27,7 @@
2827
use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings;
2928
use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
3029
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
30+
use Pterodactyl\Http\Middleware\Server\AccessingValidServer;
3131
use Pterodactyl\Http\Middleware\Server\AuthenticateAsSubuser;
3232
use Pterodactyl\Http\Middleware\Api\Daemon\DaemonAuthenticate;
3333
use Pterodactyl\Http\Middleware\Server\SubuserBelongsToServer;

app/Http/Middleware/Server/AccessingValidServer.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22

3-
namespace Pterodactyl\Http\Middleware;
3+
namespace Pterodactyl\Http\Middleware\Server;
44

55
use Closure;
66
use Illuminate\Http\Request;
77
use Pterodactyl\Models\Server;
8-
use Illuminate\Contracts\Session\Session;
98
use Illuminate\Contracts\Routing\ResponseFactory;
109
use Illuminate\Contracts\Config\Repository as ConfigRepository;
1110
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
@@ -29,29 +28,21 @@ class AccessingValidServer
2928
*/
3029
private $response;
3130

32-
/**
33-
* @var \Illuminate\Contracts\Session\Session
34-
*/
35-
private $session;
36-
3731
/**
3832
* AccessingValidServer constructor.
3933
*
4034
* @param \Illuminate\Contracts\Config\Repository $config
4135
* @param \Illuminate\Contracts\Routing\ResponseFactory $response
4236
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
43-
* @param \Illuminate\Contracts\Session\Session $session
4437
*/
4538
public function __construct(
4639
ConfigRepository $config,
4740
ResponseFactory $response,
48-
ServerRepositoryInterface $repository,
49-
Session $session
41+
ServerRepositoryInterface $repository
5042
) {
5143
$this->config = $config;
5244
$this->repository = $repository;
5345
$this->response = $response;
54-
$this->session = $session;
5546
}
5647

5748
/**
@@ -61,7 +52,6 @@ public function __construct(
6152
* @param \Closure $next
6253
* @return \Illuminate\Http\Response|mixed
6354
*
64-
* @throws \Illuminate\Auth\AuthenticationException
6555
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
6656
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
6757
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
@@ -90,10 +80,6 @@ public function handle(Request $request, Closure $next)
9080
return $this->response->view('errors.installing', [], 409);
9181
}
9282

93-
// Store the server in the session.
94-
// @todo remove from session. use request attributes.
95-
$this->session->now('server_data.model', $server);
96-
9783
// Add server to the request attributes. This will replace sessions
9884
// as files are updated.
9985
$request->attributes->set('server', $server);

tests/Unit/Http/Middleware/Server/AccessingValidServerTest.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
use Mockery as m;
66
use Pterodactyl\Models\Server;
7-
use Illuminate\Contracts\Session\Session;
87
use Illuminate\Contracts\Config\Repository;
98
use Illuminate\Contracts\Routing\ResponseFactory;
109
use Tests\Unit\Http\Middleware\MiddlewareTestCase;
11-
use Pterodactyl\Http\Middleware\AccessingValidServer;
10+
use Pterodactyl\Http\Middleware\Server\AccessingValidServer;
1211
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
1312

1413
class AccessingValidServerTest extends MiddlewareTestCase
@@ -28,11 +27,6 @@ class AccessingValidServerTest extends MiddlewareTestCase
2827
*/
2928
private $response;
3029

31-
/**
32-
* @var \Illuminate\Contracts\Session\Session|\Mockery\Mock
33-
*/
34-
private $session;
35-
3630
/**
3731
* Setup tests.
3832
*/
@@ -43,7 +37,6 @@ public function setUp()
4337
$this->config = m::mock(Repository::class);
4438
$this->repository = m::mock(ServerRepositoryInterface::class);
4539
$this->response = m::mock(ResponseFactory::class);
46-
$this->session = m::mock(Session::class);
4740
}
4841

4942
/**
@@ -114,7 +107,6 @@ public function testValidServerProcess()
114107
$this->request->shouldReceive('is')->with(...[])->once()->andReturn(false);
115108

116109
$this->repository->shouldReceive('getByUuid')->with('123456')->once()->andReturn($model);
117-
$this->session->shouldReceive('now')->with('server_data.model', $model)->once()->andReturnNull();
118110

119111
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
120112
$this->assertRequestHasAttribute('server');
@@ -141,10 +133,10 @@ public function viewDataProvider(): array
141133
/**
142134
* Return an instance of the middleware using mocked dependencies.
143135
*
144-
* @return \Pterodactyl\Http\Middleware\AccessingValidServer
136+
* @return \Pterodactyl\Http\Middleware\Server\AccessingValidServer
145137
*/
146138
private function getMiddleware(): AccessingValidServer
147139
{
148-
return new AccessingValidServer($this->config, $this->response, $this->repository, $this->session);
140+
return new AccessingValidServer($this->config, $this->response, $this->repository);
149141
}
150142
}

0 commit comments

Comments
 (0)