Merge branch 'develop' into feature/api-v1
# Conflicts: # app/Contracts/Repository/RepositoryInterface.php # app/Repositories/Eloquent/EloquentRepository.php # app/Services/Nodes/NodeUpdateService.php # tests/Unit/Services/Nodes/NodeUpdateServiceTest.php
This commit is contained in:
commit
800e2df6b2
187 changed files with 1878 additions and 3143 deletions
|
@ -84,7 +84,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -123,7 +123,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -149,7 +149,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => 'my.alias.net',
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -177,7 +177,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -202,7 +202,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
|
||||
$this->repository->shouldReceive('insertIgnore')->with([
|
||||
[
|
||||
|
@ -212,7 +212,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node->id, $data);
|
||||
|
@ -303,7 +303,7 @@ class AssignmentServiceTest extends TestCase
|
|||
'ip_alias' => null,
|
||||
'server_id' => null,
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->node, $data);
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Tests\Unit\Services\Allocations;
|
|||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Tests\Traits\MocksRequestException;
|
||||
|
@ -68,13 +69,12 @@ class SetDefaultAllocationServiceTest extends TestCase
|
|||
|
||||
$this->repository->shouldReceive('findWhere')->with([['server_id', '=', $model->id]])->once()->andReturn($allocations);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->serverRepository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->serverRepository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->serverRepository->shouldReceive('update')->with($model->id, [
|
||||
'allocation_id' => $allocations->first()->id,
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(new Response);
|
||||
|
||||
$this->daemonRepository->shouldReceive('setAccessServer')->with($model->uuid)->once()->andReturnSelf();
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($model->node_id)->once()->andReturnSelf();
|
||||
$this->daemonRepository->shouldReceive('setServer')->with($model)->once()->andReturnSelf();
|
||||
$this->daemonRepository->shouldReceive('update')->with([
|
||||
'build' => [
|
||||
'default' => [
|
||||
|
@ -85,7 +85,7 @@ class SetDefaultAllocationServiceTest extends TestCase
|
|||
return $item->pluck('port');
|
||||
})->toArray(),
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(new Response);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$response = $this->getService()->handle($useModel ? $model : 1234, $allocations->first()->id);
|
||||
|
@ -118,12 +118,12 @@ class SetDefaultAllocationServiceTest extends TestCase
|
|||
|
||||
$this->repository->shouldReceive('findWhere')->with([['server_id', '=', $model->id]])->once()->andReturn(collect([$allocation]));
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->serverRepository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->serverRepository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->serverRepository->shouldReceive('update')->with($model->id, [
|
||||
'allocation_id' => $allocation->id,
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(new Response);
|
||||
|
||||
$this->daemonRepository->shouldReceive('setAccessServer->setNode->update')->once()->andThrow($this->getExceptionMock());
|
||||
$this->daemonRepository->shouldReceive('setServer->update')->once()->andThrow($this->getExceptionMock());
|
||||
$this->connection->shouldReceive('rollBack')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
try {
|
||||
|
|
|
@ -43,7 +43,7 @@ class PermissionServiceTest extends TestCase
|
|||
*/
|
||||
public function test_create_function()
|
||||
{
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('create')->with(['key_id' => 1, 'permission' => 'test-permission'])
|
||||
->once()->andReturn(true);
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ class DaemonKeyCreationServiceTest extends TestCase
|
|||
->shouldReceive('addMinutes')->with(100)->once()->andReturnSelf()
|
||||
->shouldReceive('toDateTimeString')->withNoArgs()->once()->andReturn('00:00:00');
|
||||
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('create')->with([
|
||||
'user_id' => 1,
|
||||
'server_id' => 2,
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace Tests\Unit\Services\DaemonKeys;
|
|||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Log\Writer;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\DaemonKey;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
@ -97,9 +98,9 @@ class DaemonKeyDeletionServiceTest extends TestCase
|
|||
['server_id', '=', $server->id],
|
||||
])->once()->andReturn($key);
|
||||
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturnNull();
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturn(1);
|
||||
$this->daemonRepository->shouldReceive('setServer')->with($server)->once()->andReturnSelf()
|
||||
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturn(new Response);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($server, 100);
|
||||
|
@ -121,9 +122,9 @@ class DaemonKeyDeletionServiceTest extends TestCase
|
|||
['server_id', '=', $server->id],
|
||||
])->once()->andReturn($key);
|
||||
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturnNull();
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturn(1);
|
||||
$this->daemonRepository->shouldReceive('setServer')->with($server)->once()->andReturnSelf()
|
||||
->shouldReceive('revokeAccessKey')->with($key->secret)->once()->andReturn(new Response);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($server->id, 100);
|
||||
|
@ -144,8 +145,8 @@ class DaemonKeyDeletionServiceTest extends TestCase
|
|||
['server_id', '=', $server->id],
|
||||
])->once()->andReturn($key);
|
||||
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturnNull();
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andThrow($this->exception);
|
||||
$this->repository->shouldReceive('delete')->with($key->id)->once()->andReturn(1);
|
||||
$this->daemonRepository->shouldReceive('setServer')->with($server)->once()->andThrow($this->exception);
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('rollBack')->withNoArgs()->once()->andReturnNull();
|
||||
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
|
||||
|
|
|
@ -70,7 +70,7 @@ class DaemonKeyUpdateServiceTest extends TestCase
|
|||
->shouldReceive('addMinutes')->with(100)->once()->andReturnSelf()
|
||||
->shouldReceive('toDateTimeString')->withNoArgs()->once()->andReturn('00:00:00');
|
||||
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('update')->with(123, [
|
||||
'secret' => $secret,
|
||||
'expires_at' => '00:00:00',
|
||||
|
|
|
@ -4,8 +4,9 @@ namespace Tests\Unit\Services\DaemonKeys;
|
|||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Models\Server;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\DaemonKey;
|
||||
use Tests\Traits\MocksRequestException;
|
||||
use Pterodactyl\Contracts\Repository\DaemonKeyRepositoryInterface;
|
||||
|
@ -43,13 +44,13 @@ class RevokeMultipleDaemonKeysServiceTest extends TestCase
|
|||
public function testSuccessfulKeyRevocation()
|
||||
{
|
||||
$user = factory(User::class)->make();
|
||||
$server = factory(Server::class)->make();
|
||||
$node = factory(Node::class)->make();
|
||||
$key = factory(DaemonKey::class)->make(['user_id' => $user->id]);
|
||||
$key->setRelation('server', $server);
|
||||
$key->setRelation('node', $node);
|
||||
|
||||
$this->repository->shouldReceive('getKeysForRevocation')->with($user)->once()->andReturn(collect([$key]));
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($server->node_id)->once()->andReturnSelf();
|
||||
$this->daemonRepository->shouldReceive('revokeAccessKey')->with([$key->secret])->once()->andReturnNull();
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($node)->once()->andReturnSelf();
|
||||
$this->daemonRepository->shouldReceive('revokeAccessKey')->with([$key->secret])->once()->andReturn(new Response);
|
||||
|
||||
$this->repository->shouldReceive('deleteKeys')->with([$key->id])->once()->andReturnNull();
|
||||
|
||||
|
@ -67,9 +68,9 @@ class RevokeMultipleDaemonKeysServiceTest extends TestCase
|
|||
$this->configureExceptionMock();
|
||||
|
||||
$user = factory(User::class)->make();
|
||||
$server = factory(Server::class)->make();
|
||||
$node = factory(Node::class)->make();
|
||||
$key = factory(DaemonKey::class)->make(['user_id' => $user->id]);
|
||||
$key->setRelation('server', $server);
|
||||
$key->setRelation('node', $node);
|
||||
|
||||
$this->repository->shouldReceive('getKeysForRevocation')->with($user)->once()->andReturn(collect([$key]));
|
||||
$this->daemonRepository->shouldReceive('setNode->revokeAccessKey')->with([$key->secret])->once()->andThrow($this->getExceptionMock());
|
||||
|
@ -86,9 +87,9 @@ class RevokeMultipleDaemonKeysServiceTest extends TestCase
|
|||
$this->configureExceptionMock();
|
||||
|
||||
$user = factory(User::class)->make();
|
||||
$server = factory(Server::class)->make();
|
||||
$node = factory(Node::class)->make();
|
||||
$key = factory(DaemonKey::class)->make(['user_id' => $user->id]);
|
||||
$key->setRelation('server', $server);
|
||||
$key->setRelation('node', $node);
|
||||
|
||||
$this->repository->shouldReceive('getKeysForRevocation')->with($user)->once()->andReturn(collect([$key]));
|
||||
$this->daemonRepository->shouldReceive('setNode->revokeAccessKey')->with([$key->secret])->once()->andThrow($this->getExceptionMock());
|
||||
|
@ -98,8 +99,8 @@ class RevokeMultipleDaemonKeysServiceTest extends TestCase
|
|||
$service = $this->getService();
|
||||
$service->handle($user, true);
|
||||
$this->assertNotEmpty($service->getExceptions());
|
||||
$this->assertArrayHasKey($server->node_id, $service->getExceptions());
|
||||
$this->assertSame(array_get($service->getExceptions(), $server->node_id), $this->getExceptionMock());
|
||||
$this->assertArrayHasKey($node->id, $service->getExceptions());
|
||||
$this->assertSame(array_get($service->getExceptions(), $node->id), $this->getExceptionMock());
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -63,14 +63,14 @@ class DatabasePasswordServiceTest extends TestCase
|
|||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->encrypter->shouldReceive('encrypt')->with('test123')->once()->andReturn('enc123');
|
||||
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('update')->with($model->id, ['password' => 'enc123'])->once()->andReturn(true);
|
||||
|
||||
$this->repository->shouldReceive('dropUser')->with($model->username, $model->remote)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('createUser')->with($model->username, $model->remote, 'test123')->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('assignUserToDatabase')->with($model->database, $model->username, $model->remote)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('flush')->withNoArgs()->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('dropUser')->with($model->username, $model->remote)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('createUser')->with($model->username, $model->remote, 'test123')->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('assignUserToDatabase')->with($model->database, $model->username, $model->remote)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('flush')->withNoArgs()->once()->andReturn(true);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturn(true);
|
||||
|
||||
$response = $this->getService()->handle($useModel ? $model : 1234, 'test123');
|
||||
$this->assertNotEmpty($response);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
namespace Tests\Unit\Services\Services\Options;
|
||||
|
||||
use Exception;
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\Egg;
|
||||
|
@ -53,7 +52,7 @@ class EggUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testEggIsUpdatedWhenNoConfigFromIsProvided()
|
||||
{
|
||||
$this->repository->shouldReceive('withoutFresh->update')
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')
|
||||
->with($this->model->id, ['test_field' => 'field_value'])->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model, ['test_field' => 'field_value']);
|
||||
|
@ -71,7 +70,7 @@ class EggUpdateServiceTest extends TestCase
|
|||
['id', '=', 1],
|
||||
])->once()->andReturn(1);
|
||||
|
||||
$this->repository->shouldReceive('withoutFresh->update')
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')
|
||||
->with($this->model->id, ['config_from' => 1])->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model, ['config_from' => 1]);
|
||||
|
@ -103,7 +102,7 @@ class EggUpdateServiceTest extends TestCase
|
|||
public function testIntegerCanBePassedInPlaceOfModel()
|
||||
{
|
||||
$this->repository->shouldReceive('find')->with($this->model->id)->once()->andReturn($this->model);
|
||||
$this->repository->shouldReceive('withoutFresh->update')
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')
|
||||
->with($this->model->id, ['test_field' => 'field_value'])->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model->id, ['test_field' => 'field_value']);
|
||||
|
|
|
@ -66,7 +66,7 @@ class InstallScriptServiceTest extends TestCase
|
|||
$this->data['copy_script_from'] = 1;
|
||||
|
||||
$this->repository->shouldReceive('isCopiableScript')->with(1, $this->model->nest_id)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->model->id, $this->data)->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model, $this->data);
|
||||
|
@ -93,7 +93,7 @@ class InstallScriptServiceTest extends TestCase
|
|||
*/
|
||||
public function testUpdateWithoutNewCopyScriptFromAttribute()
|
||||
{
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->model->id, $this->data)->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model, $this->data);
|
||||
|
@ -105,7 +105,7 @@ class InstallScriptServiceTest extends TestCase
|
|||
public function testFunctionAcceptsIntegerInPlaceOfModel()
|
||||
{
|
||||
$this->repository->shouldReceive('find')->with($this->model->id)->once()->andReturn($this->model);
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->model->id, $this->data)->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model->id, $this->data);
|
||||
|
|
|
@ -81,13 +81,13 @@ class EggUpdateImporterServiceTest extends TestCase
|
|||
'name' => $egg->name,
|
||||
]), true, true)->once()->andReturn($egg);
|
||||
|
||||
$this->variableRepository->shouldReceive('withoutFresh->updateOrCreate')->with([
|
||||
$this->variableRepository->shouldReceive('withoutFreshModel->updateOrCreate')->with([
|
||||
'egg_id' => $egg->id,
|
||||
'env_variable' => $variable->env_variable,
|
||||
], collect($variable)->except(['egg_id', 'env_variable'])->toArray())->once()->andReturnNull();
|
||||
|
||||
$this->variableRepository->shouldReceive('withColumns')->with(['id', 'env_variable'])->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([['egg_id', '=', $egg->id]])->once()->andReturn([$variable]);
|
||||
$this->variableRepository->shouldReceive('setColumns')->with(['id', 'env_variable'])->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([['egg_id', '=', $egg->id]])->once()->andReturn(collect([$variable]));
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
@ -121,18 +121,18 @@ class EggUpdateImporterServiceTest extends TestCase
|
|||
'name' => $egg->name,
|
||||
]), true, true)->once()->andReturn($egg);
|
||||
|
||||
$this->variableRepository->shouldReceive('withoutFresh->updateOrCreate')->with([
|
||||
$this->variableRepository->shouldReceive('withoutFreshModel->updateOrCreate')->with([
|
||||
'egg_id' => $egg->id,
|
||||
'env_variable' => $variable1->env_variable,
|
||||
], collect($variable1)->except(['egg_id', 'env_variable'])->toArray())->once()->andReturnNull();
|
||||
|
||||
$this->variableRepository->shouldReceive('withColumns')->with(['id', 'env_variable'])->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([['egg_id', '=', $egg->id]])->once()->andReturn([$variable1, $variable2]);
|
||||
$this->variableRepository->shouldReceive('setColumns')->with(['id', 'env_variable'])->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([['egg_id', '=', $egg->id]])->once()->andReturn(collect([$variable1, $variable2]));
|
||||
|
||||
$this->variableRepository->shouldReceive('deleteWhere')->with([
|
||||
['egg_id', '=', $egg->id],
|
||||
['env_variable', '=', $variable2->env_variable],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(1);
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class VariableUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testVariableIsUpdatedWhenNoEnvironmentVariableIsPassed()
|
||||
{
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->model->id, [
|
||||
'user_viewable' => false,
|
||||
'user_editable' => false,
|
||||
|
@ -61,7 +61,7 @@ class VariableUpdateServiceTest extends TestCase
|
|||
public function testVariableIdCanBePassedInPlaceOfModel()
|
||||
{
|
||||
$this->repository->shouldReceive('find')->with($this->model->id)->once()->andReturn($this->model);
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->model->id, [
|
||||
'user_viewable' => false,
|
||||
'user_editable' => false,
|
||||
|
@ -76,14 +76,14 @@ class VariableUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testVariableIsUpdatedWhenValidEnvironmentVariableIsPassed()
|
||||
{
|
||||
$this->repository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([
|
||||
['env_variable', '=', 'TEST_VAR_123'],
|
||||
['egg_id', '=', $this->model->option_id],
|
||||
['id', '!=', $this->model->id],
|
||||
])->once()->andReturn(0);
|
||||
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->model->id, [
|
||||
'user_viewable' => false,
|
||||
'user_editable' => false,
|
||||
|
@ -101,7 +101,7 @@ class VariableUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testNullOptionValueIsPassedAsArray()
|
||||
{
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->model->id, [
|
||||
'user_viewable' => false,
|
||||
'user_editable' => false,
|
||||
|
@ -116,14 +116,14 @@ class VariableUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testDataPassedIntoHandlerTakesLowerPriorityThanDataSet()
|
||||
{
|
||||
$this->repository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([
|
||||
['env_variable', '=', 'TEST_VAR_123'],
|
||||
['egg_id', '=', $this->model->option_id],
|
||||
['id', '!=', $this->model->id],
|
||||
])->once()->andReturn(0);
|
||||
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->model->id, [
|
||||
'user_viewable' => false,
|
||||
'user_editable' => false,
|
||||
|
@ -138,7 +138,7 @@ class VariableUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionIsThrownIfEnvironmentVariableIsNotUnique()
|
||||
{
|
||||
$this->repository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([
|
||||
['env_variable', '=', 'TEST_VAR_123'],
|
||||
['egg_id', '=', $this->model->option_id],
|
||||
|
|
|
@ -43,7 +43,7 @@ class NestUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testAuthorArrayKeyIsRemovedIfPassed()
|
||||
{
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with(1, ['otherfield' => 'value'])->once()->andReturnNull();
|
||||
|
||||
$this->service->handle(1, ['author' => 'author1', 'otherfield' => 'value']);
|
||||
|
@ -54,7 +54,7 @@ class NestUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testServiceIsUpdatedWhenNoAuthorKeyIsPassed()
|
||||
{
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with(1, ['otherfield' => 'value'])->once()->andReturnNull();
|
||||
|
||||
$this->service->handle(1, ['otherfield' => 'value']);
|
||||
|
|
|
@ -62,14 +62,11 @@ class NodeDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testNodeIsDeletedIfNoServersAreAttached()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['node_id', '=', 1]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with(1)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with(1)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle(1),
|
||||
'Assert that deletion returns a positive boolean value.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle(1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +76,7 @@ class NodeDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionIsThrownIfServersAreAttachedToNode()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['node_id', '=', 1]])->once()->andReturn(1);
|
||||
$this->translator->shouldReceive('trans')->with('exceptions.node.servers_attached')->once()->andReturnNull();
|
||||
$this->repository->shouldNotReceive('delete');
|
||||
|
@ -94,13 +91,10 @@ class NodeDeletionServiceTest extends TestCase
|
|||
{
|
||||
$node = factory(Node::class)->make();
|
||||
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['node_id', '=', $node->id]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with($node->id)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with($node->id)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle($node),
|
||||
'Assert that deletion returns a positive boolean value.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle($node));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use Tests\TestCase;
|
|||
use Illuminate\Log\Writer;
|
||||
use phpmock\phpunit\PHPMock;
|
||||
use Pterodactyl\Models\Node;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Services\Nodes\NodeUpdateService;
|
||||
|
@ -84,13 +85,14 @@ class NodeUpdateServiceTest extends TestCase
|
|||
$this->getFunctionMock('\\Pterodactyl\\Services\\Nodes', 'str_random')
|
||||
->expects($this->once())->willReturn('random_string');
|
||||
|
||||
$this->repository->->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
'daemonSecret' => 'random_string',
|
||||
])->andReturn($this->node);
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
'daemonSecret' => 'random_string',
|
||||
])->andReturn(true);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node->id)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturnNull();
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
|
||||
$response = $this->service->handle($this->node, ['name' => 'NewName', 'reset_secret' => true]);
|
||||
$this->assertInstanceOf(Node::class, $response);
|
||||
|
@ -102,12 +104,13 @@ class NodeUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testNodeIsUpdatedAndDaemonSecretIsNotChanged()
|
||||
{
|
||||
$this->repository->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
])->andReturn($this->node);
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
])->andReturn(true);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node->id)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturnNull();
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
|
||||
$response = $this->service->handle($this->node, ['name' => 'NewName']);
|
||||
$this->assertInstanceOf(Node::class, $response);
|
||||
|
@ -119,11 +122,12 @@ class NodeUpdateServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionCausedByDaemonIsHandled()
|
||||
{
|
||||
$this->repository->->shouldReceive('update')->with($this->node->id, [
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
])->andReturn(true);
|
||||
])->andReturn(new Response);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node->id)->once()->andThrow($this->exception);
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node)->once()->andThrow($this->exception);
|
||||
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
|
||||
|
@ -145,13 +149,13 @@ class NodeUpdateServiceTest extends TestCase
|
|||
public function testFunctionCanAcceptANodeIdInPlaceOfModel()
|
||||
{
|
||||
$this->repository->shouldReceive('find')->with($this->node->id)->once()->andReturn($this->node);
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->node->id, [
|
||||
'name' => 'NewName',
|
||||
])->andReturn(true);
|
||||
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node->id)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturnNull();
|
||||
$this->configRepository->shouldReceive('setNode')->with($this->node)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
|
||||
|
||||
$this->assertTrue($this->service->handle($this->node->id, ['name' => 'NewName']));
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ class PackDeletionServiceTest extends TestCase
|
|||
|
||||
$this->serverRepository->shouldReceive('findCountWhere')->with([['pack_id', '=', $model->id]])->once()->andReturn(0);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($model->id)->once()->andReturn(1);
|
||||
$this->storage->shouldReceive('disk')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('deleteDirectory')->with('packs/' . $model->uuid)->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
@ -91,11 +91,11 @@ class PackDeletionServiceTest extends TestCase
|
|||
{
|
||||
$model = factory(Pack::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'uuid'])->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'uuid'])->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with($model->id)->once()->andReturn($model);
|
||||
$this->serverRepository->shouldReceive('findCountWhere')->with([['pack_id', '=', $model->id]])->once()->andReturn(0);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($model->id)->once()->andReturn(1);
|
||||
$this->storage->shouldReceive('disk')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('deleteDirectory')->with('packs/' . $model->uuid)->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
|
|
@ -53,7 +53,7 @@ class PackUpdateServiceTest extends TestCase
|
|||
public function testPackIsUpdated()
|
||||
{
|
||||
$model = factory(Pack::class)->make();
|
||||
$this->repository->shouldReceive('withoutFresh->update')->with($model->id, [
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
|
||||
'locked' => false,
|
||||
'visible' => false,
|
||||
'selectable' => false,
|
||||
|
@ -85,9 +85,9 @@ class PackUpdateServiceTest extends TestCase
|
|||
{
|
||||
$model = factory(Pack::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'egg_id'])->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'egg_id'])->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with($model->id)->once()->andReturn($model);
|
||||
$this->repository->shouldReceive('withoutFresh->update')->with($model->id, [
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
|
||||
'locked' => false,
|
||||
'visible' => false,
|
||||
'selectable' => false,
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
<?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\Schedules;
|
||||
|
||||
use Mockery as m;
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
use Cron\CronExpression;
|
||||
use Pterodactyl\Models\Task;
|
||||
|
@ -46,8 +40,8 @@ class ProcessScheduleServiceTest extends TestCase
|
|||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Carbon::setTestNow(Carbon::now());
|
||||
|
||||
$this->cron = m::mock('overload:' . CronExpression::class);
|
||||
$this->repository = m::mock(ScheduleRepositoryInterface::class);
|
||||
$this->runnerService = m::mock(RunTaskService::class);
|
||||
|
||||
|
@ -64,14 +58,12 @@ class ProcessScheduleServiceTest extends TestCase
|
|||
'sequence_id' => 1,
|
||||
])]));
|
||||
|
||||
$this->repository->shouldReceive('loadTasks')->with($model)->once()->andReturn($model);
|
||||
|
||||
$formatted = sprintf('%s %s %s * %s *', $model->cron_minute, $model->cron_hour, $model->cron_day_of_month, $model->cron_day_of_week);
|
||||
|
||||
$this->cron->shouldReceive('factory')->with($formatted)->once()->andReturnSelf()
|
||||
->shouldReceive('getNextRunDate')->withNoArgs()->once()->andReturn('00:00:00');
|
||||
|
||||
$this->repository->shouldReceive('update')->with($model->id, [
|
||||
'is_processing' => true,
|
||||
'next_run_at' => '00:00:00',
|
||||
'next_run_at' => CronExpression::factory($formatted)->getNextRunDate(),
|
||||
]);
|
||||
|
||||
$this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull();
|
||||
|
@ -80,58 +72,23 @@ class ProcessScheduleServiceTest extends TestCase
|
|||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that passing a schedule model without a tasks relation is handled.
|
||||
*/
|
||||
public function testScheduleModelWithoutTasksIsHandled()
|
||||
{
|
||||
$nonRelationModel = factory(Schedule::class)->make();
|
||||
$model = clone $nonRelationModel;
|
||||
$model->setRelation('tasks', collect([$task = factory(Task::class)->make([
|
||||
'sequence_id' => 1,
|
||||
])]));
|
||||
|
||||
$formatted = sprintf('%s %s %s * %s *', $model->cron_minute, $model->cron_hour, $model->cron_day_of_month, $model->cron_day_of_week);
|
||||
|
||||
$this->repository->shouldReceive('getScheduleWithTasks')->with($nonRelationModel->id)->once()->andReturn($model);
|
||||
$this->cron->shouldReceive('factory')->with($formatted)->once()->andReturnSelf()
|
||||
->shouldReceive('getNextRunDate')->withNoArgs()->once()->andReturn('00:00:00');
|
||||
|
||||
$this->repository->shouldReceive('update')->with($model->id, [
|
||||
'is_processing' => true,
|
||||
'next_run_at' => '00:00:00',
|
||||
]);
|
||||
|
||||
$this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($nonRelationModel);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a task ID can be passed in place of the task model.
|
||||
*/
|
||||
public function testPassingScheduleIdInPlaceOfModelIsHandled()
|
||||
public function testScheduleRunTimeCanBeOverridden()
|
||||
{
|
||||
$model = factory(Schedule::class)->make();
|
||||
$model->setRelation('tasks', collect([$task = factory(Task::class)->make([
|
||||
'sequence_id' => 1,
|
||||
])]));
|
||||
|
||||
$formatted = sprintf('%s %s %s * %s *', $model->cron_minute, $model->cron_hour, $model->cron_day_of_month, $model->cron_day_of_week);
|
||||
|
||||
$this->repository->shouldReceive('getScheduleWithTasks')->with($model->id)->once()->andReturn($model);
|
||||
$this->cron->shouldReceive('factory')->with($formatted)->once()->andReturnSelf()
|
||||
->shouldReceive('getNextRunDate')->withNoArgs()->once()->andReturn('00:00:00');
|
||||
$this->repository->shouldReceive('loadTasks')->with($model)->once()->andReturn($model);
|
||||
|
||||
$this->repository->shouldReceive('update')->with($model->id, [
|
||||
'is_processing' => true,
|
||||
'next_run_at' => '00:00:00',
|
||||
'next_run_at' => Carbon::now()->addSeconds(15)->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($model->id);
|
||||
$this->service->setRunTimeOverride(Carbon::now()->addSeconds(15))->handle($model);
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
<?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\Schedules;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Cron\CronExpression;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
@ -54,7 +47,6 @@ class ScheduleCreationServiceTest extends TestCase
|
|||
parent::setUp();
|
||||
|
||||
$this->connection = m::mock(ConnectionInterface::class);
|
||||
$this->cron = m::mock('overload:\Cron\CronExpression');
|
||||
$this->repository = m::mock(ScheduleRepositoryInterface::class);
|
||||
$this->taskCreationService = m::mock(TaskCreationService::class);
|
||||
|
||||
|
@ -69,18 +61,15 @@ class ScheduleCreationServiceTest extends TestCase
|
|||
$schedule = factory(Schedule::class)->make();
|
||||
$server = factory(Server::class)->make();
|
||||
|
||||
$this->cron->shouldReceive('factory')->with('* * * * * *')->once()->andReturnSelf()
|
||||
->shouldReceive('getNextRunDate')->withNoArgs()->once()->andReturn('nextDate');
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('create')->with([
|
||||
'server_id' => $server->id,
|
||||
'next_run_at' => 'nextDate',
|
||||
'test_data' => 'test_value',
|
||||
'next_run_at' => CronExpression::factory('* * * * * *')->getNextRunDate(),
|
||||
'test_key' => 'value',
|
||||
])->once()->andReturn($schedule);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$response = $this->service->handle($server, ['test_data' => 'test_value']);
|
||||
$this->assertNotEmpty($response);
|
||||
$response = $this->service->handle($server, ['test_key' => 'value', 'server_id' => '123abc']);
|
||||
$this->assertInstanceOf(Schedule::class, $response);
|
||||
$this->assertEquals($schedule, $response);
|
||||
}
|
||||
|
@ -93,14 +82,13 @@ class ScheduleCreationServiceTest extends TestCase
|
|||
$schedule = factory(Schedule::class)->make();
|
||||
$server = factory(Server::class)->make();
|
||||
|
||||
$this->cron->shouldReceive('factory')->with('* * * * * *')->once()->andReturnSelf()
|
||||
->shouldReceive('getNextRunDate')->withNoArgs()->once()->andReturn('nextDate');
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('create')->with([
|
||||
'next_run_at' => 'nextDate',
|
||||
'server_id' => $server->id,
|
||||
'test_data' => 'test_value',
|
||||
'next_run_at' => CronExpression::factory('* * * * * *')->getNextRunDate(),
|
||||
'test_key' => 'value',
|
||||
])->once()->andReturn($schedule);
|
||||
|
||||
$this->taskCreationService->shouldReceive('handle')->with($schedule, [
|
||||
'time_interval' => 'm',
|
||||
'time_value' => 10,
|
||||
|
@ -111,62 +99,10 @@ class ScheduleCreationServiceTest extends TestCase
|
|||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$response = $this->service->handle($server, ['test_data' => 'test_value'], [
|
||||
$response = $this->service->handle($server, ['test_key' => 'value'], [
|
||||
['time_interval' => 'm', 'time_value' => 10, 'action' => 'test', 'payload' => 'testpayload'],
|
||||
]);
|
||||
$this->assertNotEmpty($response);
|
||||
$this->assertInstanceOf(Schedule::class, $response);
|
||||
$this->assertEquals($schedule, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an ID can be passed in place of the server model.
|
||||
*/
|
||||
public function testIdCanBePassedInPlaceOfServerModel()
|
||||
{
|
||||
$schedule = factory(Schedule::class)->make();
|
||||
|
||||
$this->cron->shouldReceive('factory')->with('* * * * * *')->once()->andReturnSelf()
|
||||
->shouldReceive('getNextRunDate')->withNoArgs()->once()->andReturn('nextDate');
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('create')->with([
|
||||
'next_run_at' => 'nextDate',
|
||||
'server_id' => 1234,
|
||||
'test_data' => 'test_value',
|
||||
])->once()->andReturn($schedule);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$response = $this->service->handle(1234, ['test_data' => 'test_value']);
|
||||
$this->assertNotEmpty($response);
|
||||
$this->assertInstanceOf(Schedule::class, $response);
|
||||
$this->assertEquals($schedule, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an exception is raised if invalid data is passed.
|
||||
*
|
||||
* @dataProvider invalidServerArgumentProvider
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testExceptionIsThrownIfServerIsInvalid($attribute)
|
||||
{
|
||||
$this->service->handle($attribute, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of invalid server data to test aganist.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function invalidServerArgumentProvider()
|
||||
{
|
||||
return [
|
||||
[123.456],
|
||||
['server'],
|
||||
['abc123'],
|
||||
['123_test'],
|
||||
[new Node()],
|
||||
[Server::class],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ class TaskCreationServiceTest extends TestCase
|
|||
{
|
||||
$schedule = factory(Schedule::class)->make();
|
||||
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('create')->with([
|
||||
'schedule_id' => $schedule->id,
|
||||
'sequence_id' => 1,
|
||||
|
@ -108,7 +108,7 @@ class TaskCreationServiceTest extends TestCase
|
|||
*/
|
||||
public function testIdCanBePassedInPlaceOfScheduleModel()
|
||||
{
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('create')->with([
|
||||
'schedule_id' => 1234,
|
||||
'sequence_id' => 1,
|
||||
|
|
|
@ -1,42 +1,28 @@
|
|||
<?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 Exception;
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Log\Writer;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Services\Servers\ContainerRebuildService;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
|
||||
|
||||
class ContainerRebuildServiceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
|
||||
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface|\Mockery\Mock
|
||||
*/
|
||||
protected $daemonServerRepository;
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \GuzzleHttp\Exception\RequestException
|
||||
*/
|
||||
protected $exception;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Models\Server
|
||||
*/
|
||||
|
@ -47,11 +33,6 @@ class ContainerRebuildServiceTest extends TestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
|
@ -59,81 +40,33 @@ class ContainerRebuildServiceTest extends TestCase
|
|||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->daemonServerRepository = m::mock(DaemonServerRepositoryInterface::class);
|
||||
$this->exception = m::mock(RequestException::class)->makePartial();
|
||||
$this->repository = m::mock(ServerRepositoryInterface::class);
|
||||
$this->writer = m::mock(Writer::class);
|
||||
|
||||
$this->server = factory(Server::class)->make(['node_id' => 1]);
|
||||
|
||||
$this->service = new ContainerRebuildService(
|
||||
$this->daemonServerRepository,
|
||||
$this->repository,
|
||||
$this->writer
|
||||
);
|
||||
$this->service = new ContainerRebuildService($this->repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a server is marked for rebuild when it's model is passed to the function.
|
||||
* Test that a server is marked for rebuild.
|
||||
*/
|
||||
public function testServerShouldBeMarkedForARebuildWhenModelIsPassed()
|
||||
public function testServerIsMarkedForRebuild()
|
||||
{
|
||||
$this->repository->shouldNotReceive('find');
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->server->uuid)->once()->andReturnSelf()
|
||||
->shouldReceive('rebuild')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf()
|
||||
->shouldReceive('rebuild')->withNoArgs()->once()->andReturn(new Response);
|
||||
|
||||
$this->service->rebuild($this->server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a server is marked for rebuild when the ID of the server is passed to the function.
|
||||
*/
|
||||
public function testServerShouldBeMarkedForARebuildWhenServerIdIsPassed()
|
||||
{
|
||||
$this->repository->shouldReceive('find')->with($this->server->id)->once()->andReturn($this->server);
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->server->uuid)->once()->andReturnSelf()
|
||||
->shouldReceive('rebuild')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->rebuild($this->server->id);
|
||||
$this->service->handle($this->server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an exception thrown by guzzle is rendered as a displayable exception.
|
||||
*/
|
||||
public function testExceptionThrownByGuzzleShouldBeReRenderedAsDisplayable()
|
||||
{
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)
|
||||
->once()->andThrow($this->exception);
|
||||
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
|
||||
|
||||
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
|
||||
|
||||
try {
|
||||
$this->service->rebuild($this->server);
|
||||
} catch (Exception $exception) {
|
||||
$this->assertInstanceOf(DisplayException::class, $exception);
|
||||
$this->assertEquals(
|
||||
trans('admin/server.exceptions.daemon_exception', ['code' => 400]),
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an exception thrown by something other than guzzle is not transformed to a displayable.
|
||||
*
|
||||
* @expectedException \Exception
|
||||
* @expectedException \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function testExceptionNotThrownByGuzzleShouldNotBeTransformedToDisplayable()
|
||||
public function testExceptionThrownByGuzzle()
|
||||
{
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)
|
||||
->once()->andThrow(new Exception());
|
||||
$this->repository->shouldReceive('setServer')->with($this->server)->once()->andThrow($this->exception);
|
||||
|
||||
$this->service->rebuild($this->server);
|
||||
$this->service->handle($this->server);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use Exception;
|
|||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Log\Writer;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
@ -103,7 +104,7 @@ class DetailsModificationServiceTest extends TestCase
|
|||
$data = ['owner_id' => 1, 'name' => 'New Name', 'description' => 'New Description'];
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($server->id, [
|
||||
'owner_id' => $data['owner_id'],
|
||||
'name' => $data['name'],
|
||||
|
@ -129,7 +130,7 @@ class DetailsModificationServiceTest extends TestCase
|
|||
|
||||
$this->repository->shouldReceive('find')->with($server->id)->once()->andReturn($server);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($server->id, [
|
||||
'owner_id' => $data['owner_id'],
|
||||
'name' => $data['name'],
|
||||
|
@ -155,7 +156,7 @@ class DetailsModificationServiceTest extends TestCase
|
|||
$data = ['owner_id' => 2, 'name' => 'New Name', 'description' => 'New Description'];
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($server->id, [
|
||||
'owner_id' => $data['owner_id'],
|
||||
'name' => $data['name'],
|
||||
|
@ -178,18 +179,17 @@ class DetailsModificationServiceTest extends TestCase
|
|||
$server = factory(Server::class)->make(['node_id' => 1]);
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($server->id, [
|
||||
'image' => 'new/image',
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($server->uuid)->once()->andReturnSelf()
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($server)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with([
|
||||
'build' => [
|
||||
'image' => 'new/image',
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(new Response);
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
@ -206,18 +206,17 @@ class DetailsModificationServiceTest extends TestCase
|
|||
|
||||
$this->repository->shouldReceive('find')->with($server->id)->once()->andReturn($server);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($server->id, [
|
||||
'image' => 'new/image',
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($server->uuid)->once()->andReturnSelf()
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($server)->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with([
|
||||
'build' => [
|
||||
'image' => 'new/image',
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(new Response);
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
@ -233,12 +232,12 @@ class DetailsModificationServiceTest extends TestCase
|
|||
$server = factory(Server::class)->make(['node_id' => 1]);
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($server->id, [
|
||||
'image' => 'new/image',
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->andThrow($this->exception);
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->andThrow($this->exception);
|
||||
$this->connection->shouldReceive('rollBack')->withNoArgs()->once()->andReturnNull();
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
|
||||
|
@ -266,7 +265,7 @@ class DetailsModificationServiceTest extends TestCase
|
|||
$server = factory(Server::class)->make(['node_id' => 1]);
|
||||
|
||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($server->id, [
|
||||
'image' => 'new/image',
|
||||
])->once()->andReturnNull();
|
||||
|
|
|
@ -12,11 +12,10 @@ namespace Tests\Unit\Services\Servers;
|
|||
use Exception;
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Log\Writer;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Services\Servers\ReinstallServerService;
|
||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface as DaemonServerRepositoryInterface;
|
||||
|
@ -53,11 +52,6 @@ class ReinstallServerServiceTest extends TestCase
|
|||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Log\Writer
|
||||
*/
|
||||
protected $writer;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
|
@ -69,15 +63,13 @@ class ReinstallServerServiceTest extends TestCase
|
|||
$this->database = m::mock(ConnectionInterface::class);
|
||||
$this->exception = m::mock(RequestException::class)->makePartial();
|
||||
$this->repository = m::mock(ServerRepositoryInterface::class);
|
||||
$this->writer = m::mock(Writer::class);
|
||||
|
||||
$this->server = factory(Server::class)->make(['node_id' => 1]);
|
||||
|
||||
$this->service = new ReinstallServerService(
|
||||
$this->database,
|
||||
$this->daemonServerRepository,
|
||||
$this->repository,
|
||||
$this->writer
|
||||
$this->repository
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -89,14 +81,13 @@ class ReinstallServerServiceTest extends TestCase
|
|||
$this->repository->shouldNotReceive('find');
|
||||
|
||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->server->id, [
|
||||
'installed' => 0,
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->server->uuid)->once()->andReturnSelf()
|
||||
->shouldReceive('reinstall')->withNoArgs()->once()->andReturnNull();
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf()
|
||||
->shouldReceive('reinstall')->withNoArgs()->once()->andReturn(new Response);
|
||||
$this->database->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->reinstall($this->server);
|
||||
|
@ -110,14 +101,13 @@ class ReinstallServerServiceTest extends TestCase
|
|||
$this->repository->shouldReceive('find')->with($this->server->id)->once()->andReturn($this->server);
|
||||
|
||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->server->id, [
|
||||
'installed' => 0,
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->server->uuid)->once()->andReturnSelf()
|
||||
->shouldReceive('reinstall')->withNoArgs()->once()->andReturnNull();
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf()
|
||||
->shouldReceive('reinstall')->withNoArgs()->once()->andReturn(new Response);
|
||||
$this->database->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->reinstall($this->server->id);
|
||||
|
@ -125,32 +115,20 @@ class ReinstallServerServiceTest extends TestCase
|
|||
|
||||
/**
|
||||
* Test that an exception thrown by guzzle is rendered as a displayable exception.
|
||||
*
|
||||
* @expectedException \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
||||
*/
|
||||
public function testExceptionThrownByGuzzleShouldBeReRenderedAsDisplayable()
|
||||
{
|
||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->server->id, [
|
||||
'installed' => 0,
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)
|
||||
->once()->andThrow($this->exception);
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andThrow($this->exception);
|
||||
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('getStatusCode')->withNoArgs()->once()->andReturn(400);
|
||||
|
||||
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
|
||||
|
||||
try {
|
||||
$this->service->reinstall($this->server);
|
||||
} catch (Exception $exception) {
|
||||
$this->assertInstanceOf(DisplayException::class, $exception);
|
||||
$this->assertEquals(
|
||||
trans('admin/server.exceptions.daemon_exception', ['code' => 400]),
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
$this->service->reinstall($this->server);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,13 +139,12 @@ class ReinstallServerServiceTest extends TestCase
|
|||
public function testExceptionNotThrownByGuzzleShouldNotBeTransformedToDisplayable()
|
||||
{
|
||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->server->id, [
|
||||
'installed' => 0,
|
||||
])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)
|
||||
->once()->andThrow(new Exception());
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andThrow(new Exception());
|
||||
|
||||
$this->service->reinstall($this->server);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Tests\Unit\Services\Servers;
|
|||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\User;
|
||||
use Tests\Traits\MocksUuids;
|
||||
use Pterodactyl\Models\Server;
|
||||
|
@ -116,7 +117,7 @@ class ServerCreationServiceTest extends TestCase
|
|||
'egg_id' => $model->egg_id,
|
||||
]))->once()->andReturn($model);
|
||||
|
||||
$this->allocationRepository->shouldReceive('assignAllocationsToServer')->with($model->id, [$model->allocation_id])->once()->andReturnNull();
|
||||
$this->allocationRepository->shouldReceive('assignAllocationsToServer')->with($model->id, [$model->allocation_id])->once()->andReturn(1);
|
||||
|
||||
$this->validatorService->shouldReceive('setUserLevel')->with(User::USER_LEVEL_ADMIN)->once()->andReturnNull();
|
||||
$this->validatorService->shouldReceive('handle')->with($model->egg_id, [])->once()->andReturn(
|
||||
|
@ -129,10 +130,13 @@ class ServerCreationServiceTest extends TestCase
|
|||
'variable_id' => 123,
|
||||
'variable_value' => 'var1-value',
|
||||
],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
$this->configurationStructureService->shouldReceive('handle')->with($model)->once()->andReturn(['test' => 'struct']);
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($model->node_id)->once()->andReturnSelf();
|
||||
$node = factory(Node::class)->make();
|
||||
$this->nodeRepository->shouldReceive('find')->with($model->node_id)->once()->andReturn($node);
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($node)->once()->andReturnSelf();
|
||||
$this->daemonServerRepository->shouldReceive('create')->with(['test' => 'struct'], ['start_on_completion' => false])->once();
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
@ -154,11 +158,14 @@ class ServerCreationServiceTest extends TestCase
|
|||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('create')->once()->andReturn($model);
|
||||
$this->allocationRepository->shouldReceive('assignAllocationsToServer')->once()->andReturnNull();
|
||||
$this->allocationRepository->shouldReceive('assignAllocationsToServer')->once()->andReturn(1);
|
||||
$this->validatorService->shouldReceive('setUserLevel')->once()->andReturnNull();
|
||||
$this->validatorService->shouldReceive('handle')->once()->andReturn(collect([]));
|
||||
$this->configurationStructureService->shouldReceive('handle')->once()->andReturn([]);
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($model->node_id)->once()->andThrow($this->exception);
|
||||
|
||||
$node = factory(Node::class)->make();
|
||||
$this->nodeRepository->shouldReceive('find')->with($model->node_id)->once()->andReturn($node);
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($node)->once()->andThrow($this->exception);
|
||||
$this->connection->shouldReceive('rollBack')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
try {
|
||||
|
|
|
@ -13,6 +13,7 @@ use Exception;
|
|||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Log\Writer;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
@ -111,18 +112,17 @@ class ServerDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testServerCanBeDeletedWithoutForce()
|
||||
{
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->model->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->model->uuid)->once()->andReturnSelf()
|
||||
->shouldReceive('delete')->withNoArgs()->once()->andReturnNull();
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->model)->once()->andReturnSelf()
|
||||
->shouldReceive('delete')->withNoArgs()->once()->andReturn(new Response);
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->databaseRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->databaseRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([
|
||||
['server_id', '=', $this->model->id],
|
||||
])->once()->andReturn(collect([(object) ['id' => 50]]));
|
||||
|
||||
$this->databaseManagementService->shouldReceive('delete')->with(50)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturn(1);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model);
|
||||
|
@ -133,20 +133,19 @@ class ServerDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testServerShouldBeDeletedEvenWhenFailureOccursIfForceIsSet()
|
||||
{
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->model->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->model->uuid)->once()->andReturnSelf()
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->model)->once()->andReturnSelf()
|
||||
->shouldReceive('delete')->withNoArgs()->once()->andThrow($this->exception);
|
||||
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnNull();
|
||||
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->databaseRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->databaseRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([
|
||||
['server_id', '=', $this->model->id],
|
||||
])->once()->andReturn(collect([(object) ['id' => 50]]));
|
||||
|
||||
$this->databaseManagementService->shouldReceive('delete')->with(50)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturn(1);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->withForce()->handle($this->model);
|
||||
|
@ -157,7 +156,7 @@ class ServerDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionShouldBeThrownIfDaemonReturnsAnErrorAndForceIsNotSet()
|
||||
{
|
||||
$this->daemonServerRepository->shouldReceive('setNode->setAccessServer->delete')->once()->andThrow($this->exception);
|
||||
$this->daemonServerRepository->shouldReceive('setServer->delete')->once()->andThrow($this->exception);
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnNull();
|
||||
$this->writer->shouldReceive('warning')->with($this->exception)->once()->andReturnNull();
|
||||
|
||||
|
@ -176,21 +175,20 @@ class ServerDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testIntegerCanBePassedInPlaceOfServerModel()
|
||||
{
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'uuid'])->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'uuid'])->once()->andReturnSelf()
|
||||
->shouldReceive('find')->with($this->model->id)->once()->andReturn($this->model);
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->model->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->model->uuid)->once()->andReturnSelf()
|
||||
->shouldReceive('delete')->withNoArgs()->once()->andReturnNull();
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->model)->once()->andReturnSelf()
|
||||
->shouldReceive('delete')->withNoArgs()->once()->andReturn(new Response);
|
||||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->databaseRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->databaseRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findWhere')->with([
|
||||
['server_id', '=', $this->model->id],
|
||||
])->once()->andReturn(collect([(object) ['id' => 50]]));
|
||||
|
||||
$this->databaseManagementService->shouldReceive('delete')->with(50)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($this->model->id)->once()->andReturn(1);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->service->handle($this->model->id);
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace Tests\Unit\Services\Servers;
|
|||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\User;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Services\Servers\EnvironmentService;
|
||||
|
@ -81,18 +82,17 @@ class StartupModificationServiceTest extends TestCase
|
|||
collect([(object) ['id' => 1, 'value' => 'stored-value']])
|
||||
);
|
||||
|
||||
$this->serverVariableRepository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->serverVariableRepository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->serverVariableRepository->shouldReceive('updateOrCreate')->with([
|
||||
'server_id' => $model->id,
|
||||
'variable_id' => 1,
|
||||
], ['variable_value' => 'stored-value'])->once()->andReturnNull();
|
||||
|
||||
$this->environmentService->shouldReceive('handle')->with($model)->once()->andReturn(['env']);
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($model->node_id)->once()->andReturnSelf();
|
||||
$this->daemonServerRepository->shouldReceive('setAccessServer')->with($model->uuid)->once()->andReturnSelf();
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($model)->once()->andReturnSelf();
|
||||
$this->daemonServerRepository->shouldReceive('update')->with([
|
||||
'build' => ['env|overwrite' => ['env']],
|
||||
])->once()->andReturnSelf();
|
||||
])->once()->andReturn(new Response);
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
@ -116,7 +116,7 @@ class StartupModificationServiceTest extends TestCase
|
|||
collect([(object) ['id' => 1, 'value' => 'stored-value']])
|
||||
);
|
||||
|
||||
$this->serverVariableRepository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->serverVariableRepository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf();
|
||||
$this->serverVariableRepository->shouldReceive('updateOrCreate')->with([
|
||||
'server_id' => $model->id,
|
||||
'variable_id' => 1,
|
||||
|
@ -135,8 +135,7 @@ class StartupModificationServiceTest extends TestCase
|
|||
|
||||
$this->environmentService->shouldReceive('handle')->with($model)->once()->andReturn(['env']);
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($model->node_id)->once()->andReturnSelf();
|
||||
$this->daemonServerRepository->shouldReceive('setAccessServer')->with($model->uuid)->once()->andReturnSelf();
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($model)->once()->andReturnSelf();
|
||||
$this->daemonServerRepository->shouldReceive('update')->with([
|
||||
'build' => [
|
||||
'env|overwrite' => ['env'],
|
||||
|
@ -147,7 +146,7 @@ class StartupModificationServiceTest extends TestCase
|
|||
'pack' => 'xyz987',
|
||||
'skip_scripts' => false,
|
||||
],
|
||||
])->once()->andReturnSelf();
|
||||
])->once()->andReturn(new Response);
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ use Exception;
|
|||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Log\Writer;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
|
@ -101,12 +102,11 @@ class SuspensionServiceTest extends TestCase
|
|||
$this->server->suspended = 0;
|
||||
|
||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->server->id, ['suspended' => true])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->server->uuid)->once()->andReturnSelf()
|
||||
->shouldReceive('suspend')->withNoArgs()->once()->andReturnNull();
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf()
|
||||
->shouldReceive('suspend')->withNoArgs()->once()->andReturn(new Response);
|
||||
$this->database->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->assertTrue($this->service->toggle($this->server));
|
||||
|
@ -120,12 +120,11 @@ class SuspensionServiceTest extends TestCase
|
|||
$this->server->suspended = 1;
|
||||
|
||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->server->id, ['suspended' => false])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)->once()->andReturnSelf()
|
||||
->shouldReceive('setAccessServer')->with($this->server->uuid)->once()->andReturnSelf()
|
||||
->shouldReceive('unsuspend')->withNoArgs()->once()->andReturnNull();
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf()
|
||||
->shouldReceive('unsuspend')->withNoArgs()->once()->andReturn(new Response);
|
||||
$this->database->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->assertTrue($this->service->toggle($this->server, 'unsuspend'));
|
||||
|
@ -159,10 +158,10 @@ class SuspensionServiceTest extends TestCase
|
|||
$this->server->suspended = 0;
|
||||
|
||||
$this->database->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('update')->with($this->server->id, ['suspended' => true])->once()->andReturnNull();
|
||||
|
||||
$this->daemonServerRepository->shouldReceive('setNode')->with($this->server->node_id)
|
||||
$this->daemonServerRepository->shouldReceive('setServer')->with($this->server)
|
||||
->once()->andThrow($this->exception);
|
||||
|
||||
$this->exception->shouldReceive('getResponse')->withNoArgs()->once()->andReturnSelf()
|
||||
|
|
|
@ -49,10 +49,10 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
$user = factory(User::class)->make(['root_admin' => 0]);
|
||||
$server = factory(Server::class)->make(['node_id' => 1, 'owner_id' => $user->id]);
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('getByUuid')->with($server->uuidShort)->once()->andReturn($server);
|
||||
|
||||
$this->keyProviderService->shouldReceive('handle')->with($server, $user)->once()->andReturn('server_token');
|
||||
|
@ -74,10 +74,10 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
$user = factory(User::class)->make(['root_admin' => 1]);
|
||||
$server = factory(Server::class)->make(['node_id' => 1, 'owner_id' => $user->id + 1]);
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('getByUuid')->with($server->uuidShort)->once()->andReturn($server);
|
||||
|
||||
$this->keyProviderService->shouldReceive('handle')->with($server, $user)->once()->andReturn('server_token');
|
||||
|
@ -110,7 +110,7 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
{
|
||||
$user = factory(User::class)->make();
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->getService()->handle($user->username, 'wrongpassword', 1, '1234');
|
||||
|
@ -123,7 +123,7 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionIsThrownIfNoUserAccountIsFound()
|
||||
{
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', 'something']])->once()->andThrow(new RecordNotFoundException);
|
||||
|
||||
$this->getService()->handle('something', 'password', 1, '1234');
|
||||
|
@ -140,10 +140,10 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
$user = factory(User::class)->make(['root_admin' => 0]);
|
||||
$server = factory(Server::class)->make(['node_id' => 1, 'owner_id' => $user->id + 1]);
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('getByUuid')->with($server->uuidShort)->once()->andReturn($server);
|
||||
|
||||
$this->getService()->handle($user->username, 'password', 1, $server->uuidShort);
|
||||
|
@ -160,10 +160,10 @@ class AuthenticateUsingPasswordServiceTest extends TestCase
|
|||
$user = factory(User::class)->make(['root_admin' => 0]);
|
||||
$server = factory(Server::class)->make(['node_id' => 2, 'owner_id' => $user->id]);
|
||||
|
||||
$this->userRepository->shouldReceive('withColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('setColumns')->with(['id', 'root_admin', 'password'])->once()->andReturnSelf();
|
||||
$this->userRepository->shouldReceive('findFirstWhere')->with([['username', '=', $user->username]])->once()->andReturn($user);
|
||||
|
||||
$this->repository->shouldReceive('withColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('setColumns')->with(['id', 'node_id', 'owner_id', 'uuid'])->once()->andReturnSelf();
|
||||
$this->repository->shouldReceive('getByUuid')->with($server->uuidShort)->once()->andReturn($server);
|
||||
|
||||
$this->getService()->handle($user->username, 'password', 1, $server->uuidShort);
|
||||
|
|
|
@ -44,11 +44,11 @@ class PermissionCreationServiceTest extends TestCase
|
|||
{
|
||||
$permissions = ['reset-sftp', 'view-sftp'];
|
||||
|
||||
$this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf()
|
||||
$this->repository->shouldReceive('withoutFreshModel')->withNoArgs()->once()->andReturnSelf()
|
||||
->shouldReceive('insert')->with([
|
||||
['subuser_id' => 1, 'permission' => 'reset-sftp'],
|
||||
['subuser_id' => 1, 'permission' => 'view-sftp'],
|
||||
])->once()->andReturnNull();
|
||||
])->once()->andReturn(true);
|
||||
|
||||
$this->service->handle(1, $permissions);
|
||||
$this->assertTrue(true);
|
||||
|
|
|
@ -55,7 +55,7 @@ class SubuserDeletionServiceTest extends TestCase
|
|||
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->keyDeletionService->shouldReceive('handle')->with($subuser->server_id, $subuser->user_id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($subuser->id)->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('delete')->with($subuser->id)->once()->andReturn(1);
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
$this->getService()->handle($subuser);
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace Tests\Unit\Services\Subusers;
|
|||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use Pterodactyl\Models\User;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Subuser;
|
||||
use Tests\Traits\MocksRequestException;
|
||||
|
@ -86,12 +87,12 @@ class SubuserUpdateServiceTest extends TestCase
|
|||
|
||||
$this->repository->shouldReceive('loadServerAndUserRelations')->with($subuser)->once()->andReturn($subuser);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->permissionRepository->shouldReceive('deleteWhere')->with([['subuser_id', '=', $subuser->id]])->once()->andReturnNull();
|
||||
$this->permissionRepository->shouldReceive('deleteWhere')->with([['subuser_id', '=', $subuser->id]])->once()->andReturn(1);
|
||||
$this->permissionService->shouldReceive('handle')->with($subuser->id, ['some-permission'])->once()->andReturnNull();
|
||||
|
||||
$this->keyProviderService->shouldReceive('handle')->with($subuser->server, $subuser->user, false)->once()->andReturn('test123');
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($subuser->server->node_id)->once()->andReturnSelf();
|
||||
$this->daemonRepository->shouldReceive('revokeAccessKey')->with('test123')->once()->andReturnNull();
|
||||
$this->daemonRepository->shouldReceive('setServer')->with($subuser->server)->once()->andReturnSelf();
|
||||
$this->daemonRepository->shouldReceive('revokeAccessKey')->with('test123')->once()->andReturn(new Response);
|
||||
|
||||
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
|
@ -112,11 +113,11 @@ class SubuserUpdateServiceTest extends TestCase
|
|||
|
||||
$this->repository->shouldReceive('loadServerAndUserRelations')->with($subuser)->once()->andReturn($subuser);
|
||||
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
|
||||
$this->permissionRepository->shouldReceive('deleteWhere')->with([['subuser_id', '=', $subuser->id]])->once()->andReturnNull();
|
||||
$this->permissionRepository->shouldReceive('deleteWhere')->with([['subuser_id', '=', $subuser->id]])->once()->andReturn(1);
|
||||
$this->permissionService->shouldReceive('handle')->with($subuser->id, [])->once()->andReturnNull();
|
||||
|
||||
$this->keyProviderService->shouldReceive('handle')->with($subuser->server, $subuser->user, false)->once()->andReturn('test123');
|
||||
$this->daemonRepository->shouldReceive('setNode')->with($subuser->server->node_id)->once()->andThrow($this->getExceptionMock());
|
||||
$this->daemonRepository->shouldReceive('setServer')->with($subuser->server)->once()->andThrow($this->getExceptionMock());
|
||||
$this->connection->shouldReceive('rollBack')->withNoArgs()->once()->andReturnNull();
|
||||
|
||||
try {
|
||||
|
|
|
@ -63,7 +63,7 @@ class ToggleTwoFactorServiceTest extends TestCase
|
|||
$model = factory(User::class)->make(['totp_secret' => self::USER_TOTP_SECRET, 'use_totp' => false]);
|
||||
|
||||
$this->google2FA->shouldReceive('verifyKey')->with(self::DECRYPTED_USER_SECRET, 'test-token', self::TEST_WINDOW_INT)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('withoutFresh->update')->with($model->id, [
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
|
||||
'totp_authenticated_at' => Carbon::now(),
|
||||
'use_totp' => true,
|
||||
])->once()->andReturnNull();
|
||||
|
@ -79,7 +79,7 @@ class ToggleTwoFactorServiceTest extends TestCase
|
|||
$model = factory(User::class)->make(['totp_secret' => self::USER_TOTP_SECRET, 'use_totp' => true]);
|
||||
|
||||
$this->google2FA->shouldReceive('verifyKey')->with(self::DECRYPTED_USER_SECRET, 'test-token', self::TEST_WINDOW_INT)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('withoutFresh->update')->with($model->id, [
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
|
||||
'totp_authenticated_at' => Carbon::now(),
|
||||
'use_totp' => false,
|
||||
])->once()->andReturnNull();
|
||||
|
@ -95,7 +95,7 @@ class ToggleTwoFactorServiceTest extends TestCase
|
|||
$model = factory(User::class)->make(['totp_secret' => self::USER_TOTP_SECRET, 'use_totp' => false]);
|
||||
|
||||
$this->google2FA->shouldReceive('verifyKey')->with(self::DECRYPTED_USER_SECRET, 'test-token', self::TEST_WINDOW_INT)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('withoutFresh->update')->with($model->id, [
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
|
||||
'totp_authenticated_at' => Carbon::now(),
|
||||
'use_totp' => false,
|
||||
])->once()->andReturnNull();
|
||||
|
|
|
@ -58,7 +58,7 @@ class TwoFactorSetupServiceTest extends TestCase
|
|||
$this->config->shouldReceive('get')->with('app.name')->once()->andReturn('CompanyName');
|
||||
$this->google2FA->shouldReceive('getQRCodeGoogleUrl')->with('CompanyName', $model->email, 'secretKey')->once()->andReturn('http://url.com');
|
||||
$this->encrypter->shouldReceive('encrypt')->with('secretKey')->once()->andReturn('encryptedSecret');
|
||||
$this->repository->shouldReceive('withoutFresh->update')->with($model->id, ['totp_secret' => 'encryptedSecret'])->once()->andReturnNull();
|
||||
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, ['totp_secret' => 'encryptedSecret'])->once()->andReturnNull();
|
||||
|
||||
$response = $this->getService()->handle($model);
|
||||
$this->assertNotEmpty($response);
|
||||
|
|
|
@ -68,14 +68,11 @@ class UserDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testUserIsDeletedIfNoServersAreAttachedToAccount()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle($this->user->id),
|
||||
'Assert that service responds true.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle($this->user->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,7 +82,7 @@ class UserDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testExceptionIsThrownIfServersAreAttachedToAccount()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(1);
|
||||
$this->translator->shouldReceive('trans')->with('admin/user.exceptions.user_has_servers')->once()->andReturnNull();
|
||||
|
||||
|
@ -97,13 +94,10 @@ class UserDeletionServiceTest extends TestCase
|
|||
*/
|
||||
public function testModelCanBePassedInPlaceOfUserId()
|
||||
{
|
||||
$this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf()
|
||||
$this->serverRepository->shouldReceive('setColumns')->with('id')->once()->andReturnSelf()
|
||||
->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true);
|
||||
$this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(1);
|
||||
|
||||
$this->assertTrue(
|
||||
$this->service->handle($this->user),
|
||||
'Assert that service responds true.'
|
||||
);
|
||||
$this->assertEquals(1, $this->service->handle($this->user));
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue