2018-05-26 18:00:28 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-23 20:09:16 +00:00
|
|
|
namespace Pterodactyl\Tests\Unit\Http\Middleware;
|
2018-05-26 18:00:28 +00:00
|
|
|
|
|
|
|
use Mockery as m;
|
2022-10-14 16:59:20 +00:00
|
|
|
use Mockery\MockInterface;
|
2018-05-26 18:00:28 +00:00
|
|
|
use Pterodactyl\Models\Node;
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
use Illuminate\Contracts\Routing\ResponseFactory;
|
|
|
|
use Pterodactyl\Http\Middleware\MaintenanceMiddleware;
|
|
|
|
|
|
|
|
class MaintenanceMiddlewareTest extends MiddlewareTestCase
|
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
private MockInterface $response;
|
2018-05-26 18:00:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup tests.
|
|
|
|
*/
|
2020-05-09 16:00:52 +00:00
|
|
|
public function setUp(): void
|
2018-05-26 18:00:28 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->response = m::mock(ResponseFactory::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a node not in maintenance mode continues through the request cycle.
|
|
|
|
*/
|
|
|
|
public function testHandle()
|
|
|
|
{
|
2021-01-23 20:09:16 +00:00
|
|
|
$server = Server::factory()->make();
|
|
|
|
$node = Node::factory()->make(['maintenance' => 0]);
|
2018-05-26 18:00:28 +00:00
|
|
|
|
|
|
|
$server->setRelation('node', $node);
|
|
|
|
$this->setRequestAttribute('server', $server);
|
|
|
|
|
|
|
|
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that a node in maintenance mode returns an error view.
|
|
|
|
*/
|
|
|
|
public function testHandleInMaintenanceMode()
|
|
|
|
{
|
2021-01-23 20:09:16 +00:00
|
|
|
$server = Server::factory()->make();
|
|
|
|
$node = Node::factory()->make(['maintenance_mode' => 1]);
|
2018-05-26 18:00:28 +00:00
|
|
|
|
|
|
|
$server->setRelation('node', $node);
|
|
|
|
$this->setRequestAttribute('server', $server);
|
|
|
|
|
|
|
|
$this->response->shouldReceive('view')
|
|
|
|
->once()
|
|
|
|
->with('errors.maintenance')
|
2021-01-23 20:33:34 +00:00
|
|
|
->andReturn(new Response());
|
2018-05-26 18:00:28 +00:00
|
|
|
|
|
|
|
$response = $this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
|
|
|
$this->assertInstanceOf(Response::class, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getMiddleware(): MaintenanceMiddleware
|
|
|
|
{
|
|
|
|
return new MaintenanceMiddleware($this->response);
|
|
|
|
}
|
|
|
|
}
|