Merge branch 'develop' into feature/react-admin
This commit is contained in:
commit
a87fef37ec
77 changed files with 1082 additions and 839 deletions
|
@ -73,7 +73,7 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
{
|
||||
/** @var \Pterodactyl\Models\Server $server */
|
||||
[$user, $server] = $this->generateTestAccount($permissions);
|
||||
$this->assertSame(Server::STATUS_INSTALLED, $server->installed);
|
||||
$this->assertTrue($server->isInstalled());
|
||||
|
||||
$service = Mockery::mock(DaemonServerRepository::class);
|
||||
$this->app->instance(DaemonServerRepository::class, $service);
|
||||
|
@ -91,7 +91,7 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
->assertStatus(Response::HTTP_ACCEPTED);
|
||||
|
||||
$server = $server->refresh();
|
||||
$this->assertSame(Server::STATUS_INSTALLING, $server->installed);
|
||||
$this->assertSame(Server::STATUS_INSTALLING, $server->status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +107,7 @@ class SettingsControllerTest extends ClientApiIntegrationTestCase
|
|||
->assertStatus(Response::HTTP_FORBIDDEN);
|
||||
|
||||
$server = $server->refresh();
|
||||
$this->assertSame(Server::STATUS_INSTALLED, $server->installed);
|
||||
$this->assertTrue($server->isInstalled());
|
||||
}
|
||||
|
||||
public function renamePermissionsDataProvider(): array
|
||||
|
|
|
@ -145,7 +145,7 @@ class ServerCreationServiceTest extends IntegrationTestCase
|
|||
$this->assertSame($allocations[0]->id, $response->allocations[0]->id);
|
||||
$this->assertSame($allocations[4]->id, $response->allocations[1]->id);
|
||||
|
||||
$this->assertFalse($response->suspended);
|
||||
$this->assertFalse($response->isSuspended());
|
||||
$this->assertTrue($response->oom_disabled);
|
||||
$this->assertSame(0, $response->database_limit);
|
||||
$this->assertSame(0, $response->allocation_limit);
|
||||
|
|
|
@ -97,7 +97,7 @@ class StartupModificationServiceTest extends IntegrationTestCase
|
|||
$this->assertTrue($response->skip_scripts);
|
||||
// Make sure we don't revert back to a lurking bug that causes servers to get marked
|
||||
// as not installed when you modify the startup...
|
||||
$this->assertSame(1, $response->installed);
|
||||
$this->assertTrue($response->isInstalled());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Pterodactyl\Tests\Integration\Services\Servers;
|
|||
|
||||
use Mockery;
|
||||
use InvalidArgumentException;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Services\Servers\SuspensionService;
|
||||
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
||||
|
@ -26,7 +27,7 @@ class SuspensionServiceTest extends IntegrationTestCase
|
|||
|
||||
public function testServerIsSuspendedAndUnsuspended()
|
||||
{
|
||||
$server = $this->createServerModel(['suspended' => false]);
|
||||
$server = $this->createServerModel();
|
||||
|
||||
$this->repository->expects('setServer')->twice()->andReturnSelf();
|
||||
$this->repository->expects('suspend')->with(false)->andReturnUndefined();
|
||||
|
@ -34,30 +35,30 @@ class SuspensionServiceTest extends IntegrationTestCase
|
|||
$this->getService()->toggle($server, SuspensionService::ACTION_SUSPEND);
|
||||
|
||||
$server->refresh();
|
||||
$this->assertTrue($server->suspended);
|
||||
$this->assertTrue($server->isSuspended());
|
||||
|
||||
$this->repository->expects('suspend')->with(true)->andReturnUndefined();
|
||||
|
||||
$this->getService()->toggle($server, SuspensionService::ACTION_UNSUSPEND);
|
||||
|
||||
$server->refresh();
|
||||
$this->assertFalse($server->suspended);
|
||||
$this->assertFalse($server->isSuspended());
|
||||
}
|
||||
|
||||
public function testNoActionIsTakenIfSuspensionStatusIsUnchanged()
|
||||
{
|
||||
$server = $this->createServerModel(['suspended' => false]);
|
||||
$server = $this->createServerModel();
|
||||
|
||||
$this->getService()->toggle($server, SuspensionService::ACTION_UNSUSPEND);
|
||||
|
||||
$server->refresh();
|
||||
$this->assertFalse($server->suspended);
|
||||
$this->assertFalse($server->isSuspended());
|
||||
|
||||
$server->update(['suspended' => true]);
|
||||
$server->update(['status' => Server::STATUS_SUSPENDED]);
|
||||
$this->getService()->toggle($server, SuspensionService::ACTION_SUSPEND);
|
||||
|
||||
$server->refresh();
|
||||
$this->assertTrue($server->suspended);
|
||||
$this->assertTrue($server->isSuspended());
|
||||
}
|
||||
|
||||
public function testExceptionIsThrownIfInvalidActionsArePassed()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Pterodactyl\Tests\Integration;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Testing\Assert as PHPUnit;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
@ -35,4 +36,12 @@ class TestResponse extends IlluminateTestResponse
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function assertForbidden()
|
||||
{
|
||||
return self::assertStatus(Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Tests\Unit\Http\Middleware\Server;
|
||||
|
||||
use Mockery as m;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Pterodactyl\Http\Middleware\Server\AccessingValidServer;
|
||||
use Pterodactyl\Tests\Unit\Http\Middleware\MiddlewareTestCase;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
class AccessingValidServerTest extends MiddlewareTestCase
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Config\Repository|\Mockery\Mock
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Routing\ResponseFactory|\Mockery\Mock
|
||||
*/
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->config = m::mock(Repository::class);
|
||||
$this->repository = m::mock(ServerRepositoryInterface::class);
|
||||
$this->response = m::mock(ResponseFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an exception is thrown if the request is an API request and the server is suspended.
|
||||
*/
|
||||
public function testExceptionIsThrownIfServerIsSuspended()
|
||||
{
|
||||
$this->expectException(AccessDeniedHttpException::class);
|
||||
$this->expectExceptionMessage('Server is suspended and cannot be accessed.');
|
||||
|
||||
$model = Server::factory()->make(['suspended' => 1]);
|
||||
|
||||
$this->request->shouldReceive('route->parameter')->with('server')->once()->andReturn('123456');
|
||||
$this->request->shouldReceive('expectsJson')->withNoArgs()->once()->andReturn(true);
|
||||
|
||||
$this->repository->shouldReceive('getByUuid')->with('123456')->once()->andReturn($model);
|
||||
|
||||
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an exception is thrown if the request is an API request and the server is not installed.
|
||||
*/
|
||||
public function testExceptionIsThrownIfServerIsNotInstalled()
|
||||
{
|
||||
$this->expectException(ConflictHttpException::class);
|
||||
$this->expectExceptionMessage('Server is still completing the installation process.');
|
||||
|
||||
$model = Server::factory()->make(['installed' => 0]);
|
||||
|
||||
$this->request->shouldReceive('route->parameter')->with('server')->once()->andReturn('123456');
|
||||
$this->request->shouldReceive('expectsJson')->withNoArgs()->once()->andReturn(true);
|
||||
|
||||
$this->repository->shouldReceive('getByUuid')->with('123456')->once()->andReturn($model);
|
||||
|
||||
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the correct error pages are rendered depending on the status of the server.
|
||||
*
|
||||
* @dataProvider viewDataProvider
|
||||
*/
|
||||
public function testCorrectErrorPagesAreRendered(Server $model, string $page, int $httpCode)
|
||||
{
|
||||
$this->request->shouldReceive('route->parameter')->with('server')->once()->andReturn('123456');
|
||||
$this->request->shouldReceive('expectsJson')->withNoArgs()->once()->andReturn(false);
|
||||
$this->config->shouldReceive('get')->with('pterodactyl.json_routes', [])->once()->andReturn([]);
|
||||
$this->request->shouldReceive('is')->with(...[])->once()->andReturn(false);
|
||||
|
||||
$this->repository->shouldReceive('getByUuid')->with('123456')->once()->andReturn($model);
|
||||
$this->response->shouldReceive('view')->with($page, [], $httpCode)->once()->andReturn(true);
|
||||
|
||||
$response = $this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
$this->assertTrue($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the full middleware works correctly.
|
||||
*/
|
||||
public function testValidServerProcess()
|
||||
{
|
||||
$model = Server::factory()->make();
|
||||
|
||||
$this->request->shouldReceive('route->parameter')->with('server')->once()->andReturn('123456');
|
||||
$this->request->shouldReceive('expectsJson')->withNoArgs()->once()->andReturn(false);
|
||||
$this->config->shouldReceive('get')->with('pterodactyl.json_routes', [])->once()->andReturn([]);
|
||||
$this->request->shouldReceive('is')->with(...[])->once()->andReturn(false);
|
||||
|
||||
$this->repository->shouldReceive('getByUuid')->with('123456')->once()->andReturn($model);
|
||||
|
||||
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
|
||||
$this->assertRequestHasAttribute('server');
|
||||
$this->assertRequestAttributeEquals($model, 'server');
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide test data that checks that the correct view is returned for each model type.
|
||||
*/
|
||||
public function viewDataProvider(): array
|
||||
{
|
||||
// Without this we are unable to instantiate the factory builders for some reason.
|
||||
$this->refreshApplication();
|
||||
|
||||
return [
|
||||
[Server::factory()->make(['suspended' => 1]), 'errors.suspended', 403],
|
||||
[Server::factory()->make(['installed' => 0]), 'errors.installing', 409],
|
||||
[Server::factory()->make(['installed' => 2]), 'errors.installing', 409],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the middleware using mocked dependencies.
|
||||
*/
|
||||
private function getMiddleware(): AccessingValidServer
|
||||
{
|
||||
return new AccessingValidServer($this->config, $this->response, $this->repository);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue