Skip to content

Commit fb7ef2d

Browse files
committed
test post please ignore
1 parent 65d6380 commit fb7ef2d

File tree

3 files changed

+126
-24
lines changed

3 files changed

+126
-24
lines changed

app/Exceptions/DisplayException.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,39 @@
1010
namespace Pterodactyl\Exceptions;
1111

1212
use Log;
13+
use Throwable;
1314

1415
class DisplayException extends PterodactylException
1516
{
17+
/**
18+
* @var string
19+
*/
20+
protected $level;
21+
1622
/**
1723
* Exception constructor.
1824
*
19-
* @param string $message
20-
* @param mixed $log
25+
* @param string $message
26+
* @param Throwable|null $previous
27+
* @param string $level
28+
* @internal param mixed $log
2129
*/
22-
public function __construct($message, $log = null)
30+
public function __construct($message, Throwable $previous = null, $level = 'error')
2331
{
24-
if (! is_null($log)) {
25-
Log::error($log);
32+
$this->level = $level;
33+
34+
if (! is_null($previous)) {
35+
Log::{$level}($previous);
2636
}
2737

2838
parent::__construct($message);
2939
}
40+
41+
/**
42+
* @return string
43+
*/
44+
public function getErrorLevel()
45+
{
46+
return $this->level;
47+
}
3048
}

app/Services/Servers/StartupModificationService.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Pterodactyl\Services\Servers;
1111

12-
use Illuminate\Log\Writer;
1312
use Pterodactyl\Models\Server;
1413
use GuzzleHttp\Exception\RequestException;
1514
use Illuminate\Database\ConnectionInterface;
@@ -33,7 +32,7 @@ class StartupModificationService
3332
/**
3433
* @var \Illuminate\Database\ConnectionInterface
3534
*/
36-
protected $database;
35+
protected $connection;
3736

3837
/**
3938
* @var \Pterodactyl\Services\Servers\EnvironmentService
@@ -55,38 +54,30 @@ class StartupModificationService
5554
*/
5655
protected $validatorService;
5756

58-
/**
59-
* @var \Illuminate\Log\Writer
60-
*/
61-
protected $writer;
62-
6357
/**
6458
* StartupModificationService constructor.
6559
*
66-
* @param \Illuminate\Database\ConnectionInterface $database
60+
* @param \Illuminate\Database\ConnectionInterface $connection
6761
* @param \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface $daemonServerRepository
6862
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
6963
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
7064
* @param \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface $serverVariableRepository
7165
* @param \Pterodactyl\Services\Servers\VariableValidatorService $validatorService
72-
* @param \Illuminate\Log\Writer $writer
7366
*/
7467
public function __construct(
75-
ConnectionInterface $database,
68+
ConnectionInterface $connection,
7669
DaemonServerRepositoryInterface $daemonServerRepository,
7770
EnvironmentService $environmentService,
7871
ServerRepositoryInterface $repository,
7972
ServerVariableRepositoryInterface $serverVariableRepository,
80-
VariableValidatorService $validatorService,
81-
Writer $writer
73+
VariableValidatorService $validatorService
8274
) {
8375
$this->daemonServerRepository = $daemonServerRepository;
84-
$this->database = $database;
76+
$this->connection = $connection;
8577
$this->environmentService = $environmentService;
8678
$this->repository = $repository;
8779
$this->serverVariableRepository = $serverVariableRepository;
8880
$this->validatorService = $validatorService;
89-
$this->writer = $writer;
9081
}
9182

9283
/**
@@ -126,7 +117,7 @@ public function handle($server, array $data)
126117
$hasServiceChanges = true;
127118
}
128119

129-
$this->database->beginTransaction();
120+
$this->connection->beginTransaction();
130121
if (isset($data['environment'])) {
131122
$validator = $this->validatorService->isAdmin($this->admin)
132123
->setFields($data['environment'])
@@ -168,14 +159,12 @@ public function handle($server, array $data)
168159

169160
try {
170161
$this->daemonServerRepository->setNode($server->node_id)->setAccessServer($server->uuid)->update($daemonData);
171-
$this->database->commit();
162+
$this->connection->commit();
172163
} catch (RequestException $exception) {
173164
$response = $exception->getResponse();
174-
$this->writer->warning($exception);
175-
176165
throw new DisplayException(trans('admin/server.exceptions.daemon_exception', [
177166
'code' => is_null($response) ? 'E_CONN_REFUSED' : $response->getStatusCode(),
178-
]));
167+
]), $exception, 'warning');
179168
}
180169
}
181170
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* This software is licensed under the terms of the MIT license.
7+
* https://opensource.org/licenses/MIT
8+
*/
9+
10+
namespace Tests\Unit\Services\Servers;
11+
12+
use Mockery as m;
13+
use Tests\TestCase;
14+
use Pterodactyl\Models\Server;
15+
use Illuminate\Database\ConnectionInterface;
16+
use Pterodactyl\Services\Servers\EnvironmentService;
17+
use Pterodactyl\Services\Servers\VariableValidatorService;
18+
use Pterodactyl\Services\Servers\StartupModificationService;
19+
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
20+
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
21+
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepository;
22+
23+
class StartupModificationServiceTest extends TestCase
24+
{
25+
/**
26+
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface|\Mockery\Mock
27+
*/
28+
protected $daemonServerRepository;
29+
30+
/**
31+
* @var \Illuminate\Database\ConnectionInterface|\Mockery\Mock
32+
*/
33+
protected $connection;
34+
35+
/**
36+
* @var \Pterodactyl\Services\Servers\EnvironmentService|\Mockery\Mock
37+
*/
38+
protected $environmentService;
39+
40+
/**
41+
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
42+
*/
43+
protected $repository;
44+
45+
/**
46+
* @var \Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface|\Mockery\Mock
47+
*/
48+
protected $serverVariableRepository;
49+
50+
/**
51+
* @var \Pterodactyl\Services\Servers\StartupModificationService
52+
*/
53+
protected $service;
54+
55+
/**
56+
* @var \Pterodactyl\Services\Servers\VariableValidatorService|\Mockery\Mock
57+
*/
58+
protected $validatorService;
59+
60+
/**
61+
* Setup tests.
62+
*/
63+
public function setUp()
64+
{
65+
parent::setUp();
66+
67+
$this->daemonServerRepository = m::mock(DaemonServerRepository::class);
68+
$this->connection = m::mock(ConnectionInterface::class);
69+
$this->environmentService = m::mock(EnvironmentService::class);
70+
$this->repository = m::mock(ServerRepositoryInterface::class);
71+
$this->serverVariableRepository = m::mock(ServerVariableRepositoryInterface::class);
72+
$this->validatorService = m::mock(VariableValidatorService::class);
73+
74+
$this->service = new StartupModificationService(
75+
$this->connection,
76+
$this->daemonServerRepository,
77+
$this->environmentService,
78+
$this->repository,
79+
$this->serverVariableRepository,
80+
$this->validatorService
81+
);
82+
}
83+
84+
/**
85+
* Test startup is modified when user is not an administrator.
86+
*
87+
* @todo this test works, but not for the right reasons...
88+
*/
89+
public function testStartupIsModifiedAsNonAdmin()
90+
{
91+
$model = factory(Server::class)->make();
92+
93+
$this->assertTrue(true);
94+
}
95+
}

0 commit comments

Comments
 (0)