Merge branch 'develop' into feature/fixed-seeders

This commit is contained in:
Dane Everitt 2017-11-04 12:50:32 -05:00
commit 233cbfda09
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 41 additions and 46 deletions

View file

@ -3,10 +3,10 @@
namespace Tests\Unit\Http\Middleware\Server;
use Mockery as m;
use Illuminate\Http\Response;
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\Contracts\Repository\ServerRepositoryInterface;
@ -23,6 +23,11 @@ class AccessingValidServerTest extends MiddlewareTestCase
*/
private $repository;
/**
* @var \Illuminate\Contracts\Routing\ResponseFactory|\Mockery\Mock
*/
private $response;
/**
* @var \Illuminate\Contracts\Session\Session|\Mockery\Mock
*/
@ -37,30 +42,15 @@ 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);
}
/**
* Test that an exception is thrown if the request is an API request and no server is found.
*
* @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
* @expectedExceptionMessage The requested server was not found on the system.
*/
public function testExceptionIsThrownIfNoServerIsFoundAndIsAPIRequest()
{
$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()->andReturnNull();
$this->getMiddleware()->handle($this->request, $this->getClosureAssertions());
}
/**
* Test that an exception is thrown if the request is an API request and the server is suspended.
*
* @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* @expectedExceptionMessage Server is suspended.
* @expectedExceptionMessage Server is suspended and cannot be accessed.
*/
public function testExceptionIsThrownIfServerIsSuspended()
{
@ -77,8 +67,8 @@ class AccessingValidServerTest extends MiddlewareTestCase
/**
* Test that an exception is thrown if the request is an API request and the server is not installed.
*
* @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* @expectedExceptionMessage Server is not marked as installed.
* @expectedException \Symfony\Component\HttpKernel\Exception\ConflictHttpException
* @expectedExceptionMessage Server is still completing the installation process.
*/
public function testExceptionIsThrownIfServerIsNotInstalled()
{
@ -97,7 +87,7 @@ class AccessingValidServerTest extends MiddlewareTestCase
*
* @dataProvider viewDataProvider
*/
public function testCorrectErrorPagesAreRendered(Server $model = null, string $page, int $httpCode)
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);
@ -105,11 +95,10 @@ class AccessingValidServerTest extends MiddlewareTestCase
$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->assertInstanceOf(Response::class, $response);
$this->assertEquals($page, $response->getOriginalContent()->getName(), 'Assert that the correct view is returned.');
$this->assertEquals($httpCode, $response->getStatusCode(), 'Assert that the correct HTTP code is returned.');
$this->assertTrue($response);
}
/**
@ -143,10 +132,9 @@ class AccessingValidServerTest extends MiddlewareTestCase
$this->refreshApplication();
return [
[null, 'errors.404', 404],
[factory(Server::class)->make(['suspended' => 1]), 'errors.suspended', 403],
[factory(Server::class)->make(['installed' => 0]), 'errors.installing', 403],
[factory(Server::class)->make(['installed' => 2]), 'errors.installing', 403],
[factory(Server::class)->make(['installed' => 0]), 'errors.installing', 409],
[factory(Server::class)->make(['installed' => 2]), 'errors.installing', 409],
];
}
@ -157,6 +145,6 @@ class AccessingValidServerTest extends MiddlewareTestCase
*/
private function getMiddleware(): AccessingValidServer
{
return new AccessingValidServer($this->config, $this->repository, $this->session);
return new AccessingValidServer($this->config, $this->response, $this->repository, $this->session);
}
}

View file

@ -41,9 +41,10 @@ class ServerConfigurationStructureServiceTest extends TestCase
public function testCorrectStructureIsReturned()
{
$model = factory(Server::class)->make();
$model->allocation = factory(Allocation::class)->make();
$model->allocations = collect(factory(Allocation::class)->times(2)->make());
$model->egg = factory(Egg::class)->make();
$model->setRelation('pack', null);
$model->setRelation('allocation', factory(Allocation::class)->make());
$model->setRelation('allocations', collect(factory(Allocation::class)->times(2)->make()));
$model->setRelation('egg', factory(Egg::class)->make());
$portListing = $model->allocations->groupBy('ip')->map(function ($item) {
return $item->pluck('port');