test post please ignore
This commit is contained in:
parent
65d63804ab
commit
fb7ef2d775
3 changed files with 126 additions and 24 deletions
|
@ -10,21 +10,39 @@
|
||||||
namespace Pterodactyl\Exceptions;
|
namespace Pterodactyl\Exceptions;
|
||||||
|
|
||||||
use Log;
|
use Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class DisplayException extends PterodactylException
|
class DisplayException extends PterodactylException
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception constructor.
|
* Exception constructor.
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param mixed $log
|
* @param Throwable|null $previous
|
||||||
|
* @param string $level
|
||||||
|
* @internal param mixed $log
|
||||||
*/
|
*/
|
||||||
public function __construct($message, $log = null)
|
public function __construct($message, Throwable $previous = null, $level = 'error')
|
||||||
{
|
{
|
||||||
if (! is_null($log)) {
|
$this->level = $level;
|
||||||
Log::error($log);
|
|
||||||
|
if (! is_null($previous)) {
|
||||||
|
Log::{$level}($previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($message);
|
parent::__construct($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getErrorLevel()
|
||||||
|
{
|
||||||
|
return $this->level;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Services\Servers;
|
namespace Pterodactyl\Services\Servers;
|
||||||
|
|
||||||
use Illuminate\Log\Writer;
|
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
|
@ -33,7 +32,7 @@ class StartupModificationService
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Database\ConnectionInterface
|
* @var \Illuminate\Database\ConnectionInterface
|
||||||
*/
|
*/
|
||||||
protected $database;
|
protected $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Services\Servers\EnvironmentService
|
* @var \Pterodactyl\Services\Servers\EnvironmentService
|
||||||
|
@ -55,38 +54,30 @@ class StartupModificationService
|
||||||
*/
|
*/
|
||||||
protected $validatorService;
|
protected $validatorService;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Illuminate\Log\Writer
|
|
||||||
*/
|
|
||||||
protected $writer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StartupModificationService constructor.
|
* StartupModificationService constructor.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\ConnectionInterface $database
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||||
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
|
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
|
||||||
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
|
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
|
||||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||||
* @param \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface $serverVariableRepository
|
* @param \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface $serverVariableRepository
|
||||||
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
|
||||||
* @param \Illuminate\Log\Writer $writer
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ConnectionInterface $database,
|
ConnectionInterface $connection,
|
||||||
DaemonServerRepositoryInterface $daemonServerRepository,
|
DaemonServerRepositoryInterface $daemonServerRepository,
|
||||||
EnvironmentService $environmentService,
|
EnvironmentService $environmentService,
|
||||||
ServerRepositoryInterface $repository,
|
ServerRepositoryInterface $repository,
|
||||||
ServerVariableRepositoryInterface $serverVariableRepository,
|
ServerVariableRepositoryInterface $serverVariableRepository,
|
||||||
VariableValidatorService $validatorService,
|
VariableValidatorService $validatorService
|
||||||
Writer $writer
|
|
||||||
) {
|
) {
|
||||||
$this->daemonServerRepository = $daemonServerRepository;
|
$this->daemonServerRepository = $daemonServerRepository;
|
||||||
$this->database = $database;
|
$this->connection = $connection;
|
||||||
$this->environmentService = $environmentService;
|
$this->environmentService = $environmentService;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
$this->serverVariableRepository = $serverVariableRepository;
|
$this->serverVariableRepository = $serverVariableRepository;
|
||||||
$this->validatorService = $validatorService;
|
$this->validatorService = $validatorService;
|
||||||
$this->writer = $writer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,7 +117,7 @@ class StartupModificationService
|
||||||
$hasServiceChanges = true;
|
$hasServiceChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->database->beginTransaction();
|
$this->connection->beginTransaction();
|
||||||
if (isset($data['environment'])) {
|
if (isset($data['environment'])) {
|
||||||
$validator = $this->validatorService->isAdmin($this->admin)
|
$validator = $this->validatorService->isAdmin($this->admin)
|
||||||
->setFields($data['environment'])
|
->setFields($data['environment'])
|
||||||
|
@ -168,14 +159,12 @@ class StartupModificationService
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update($daemonData);
|
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update($daemonData);
|
||||||
$this->database->commit();
|
$this->connection->commit();
|
||||||
} catch (RequestException $exception) {
|
} catch (RequestException $exception) {
|
||||||
$response = $exception->getResponse();
|
$response = $exception->getResponse();
|
||||||
$this->writer->warning($exception);
|
|
||||||
|
|
||||||
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
|
||||||
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
|
||||||
]));
|
]), $exception, 'warning');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Pterodactyl - Panel
|
||||||
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||||
|
*
|
||||||
|
* This software is licensed under the terms of the MIT license.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Tests\Unit\Services\Servers;
|
||||||
|
|
||||||
|
use Mockery as m;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Pterodactyl\Models\Server;
|
||||||
|
use Illuminate\Database\ConnectionInterface;
|
||||||
|
use Pterodactyl\Services\Servers\EnvironmentService;
|
||||||
|
use Pterodactyl\Services\Servers\VariableValidatorService;
|
||||||
|
use Pterodactyl\Services\Servers\StartupModificationService;
|
||||||
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||||
|
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
|
||||||
|
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepository;
|
||||||
|
|
||||||
|
class StartupModificationServiceTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface|\Mockery\Mock
|
||||||
|
*/
|
||||||
|
protected $daemonServerRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
|
||||||
|
*/
|
||||||
|
protected $connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Services\Servers\EnvironmentService|\Mockery\Mock
|
||||||
|
*/
|
||||||
|
protected $environmentService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
|
||||||
|
*/
|
||||||
|
protected $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface|\Mockery\Mock
|
||||||
|
*/
|
||||||
|
protected $serverVariableRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Services\Servers\StartupModificationService
|
||||||
|
*/
|
||||||
|
protected $service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Pterodactyl\Services\Servers\VariableValidatorService|\Mockery\Mock
|
||||||
|
*/
|
||||||
|
protected $validatorService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup tests.
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->daemonServerRepository = m::mock(DaemonServerRepository::class);
|
||||||
|
$this->connection = m::mock(ConnectionInterface::class);
|
||||||
|
$this->environmentService = m::mock(EnvironmentService::class);
|
||||||
|
$this->repository = m::mock(ServerRepositoryInterface::class);
|
||||||
|
$this->serverVariableRepository = m::mock(ServerVariableRepositoryInterface::class);
|
||||||
|
$this->validatorService = m::mock(VariableValidatorService::class);
|
||||||
|
|
||||||
|
$this->service = new StartupModificationService(
|
||||||
|
$this->connection,
|
||||||
|
$this->daemonServerRepository,
|
||||||
|
$this->environmentService,
|
||||||
|
$this->repository,
|
||||||
|
$this->serverVariableRepository,
|
||||||
|
$this->validatorService
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test startup is modified when user is not an administrator.
|
||||||
|
*
|
||||||
|
* @todo this test works, but not for the right reasons...
|
||||||
|
*/
|
||||||
|
public function testStartupIsModifiedAsNonAdmin()
|
||||||
|
{
|
||||||
|
$model = factory(Server::class)->make();
|
||||||
|
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue