Merge branch 'develop' into dane/restore-backups

This commit is contained in:
Dane Everitt 2021-01-25 19:16:40 -08:00
commit 663143de0b
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
575 changed files with 6080 additions and 6864 deletions

View file

@ -32,7 +32,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$created = factory(Allocation::class)->create([
$created = Allocation::factory()->create([
'node_id' => $server->node_id,
'ip' => $server->allocation->ip,
]);
@ -74,7 +74,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
config()->set('pterodactyl.client_features.allocations.range_start', 5000);
config()->set('pterodactyl.client_features.allocations.range_end', 5001);
factory(Allocation::class)->create([
Allocation::factory()->create([
'server_id' => $server2->id,
'node_id' => $server->node_id,
'ip' => $server->allocation->ip,
@ -92,8 +92,8 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
config()->set('pterodactyl.client_features.allocations.range_start', 5000);
config()->set('pterodactyl.client_features.allocations.range_end', 5005);
for ($i = 5000; $i <= 5005; $i++) {
factory(Allocation::class)->create([
for ($i = 5000; $i <= 5005; ++$i) {
Allocation::factory()->create([
'ip' => $server->allocation->ip,
'port' => $i,
'node_id' => $server->node_id,
@ -115,7 +115,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
factory(Allocation::class)->times(5)->create(['node_id' => $server->node_id]);
Allocation::factory()->times(5)->create(['node_id' => $server->node_id]);
$this->expectException(NoAutoAllocationSpaceAvailableException::class);
$this->expectExceptionMessage('Cannot assign additional allocation: no more space available on node.');

View file

@ -3,7 +3,6 @@
namespace Pterodactyl\Tests\Integration\Services\Databases;
use Mockery;
use Exception;
use BadMethodCallException;
use InvalidArgumentException;
use Pterodactyl\Models\Database;
@ -63,9 +62,9 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
public function testDatabaseCannotBeCreatedIfServerHasReachedLimit()
{
$server = $this->createServerModel(['database_limit' => 2]);
$host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]);
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
factory(Database::class)->times(2)->create(['server_id' => $server->id, 'database_host_id' => $host->id]);
Database::factory()->times(2)->create(['server_id' => $server->id, 'database_host_id' => $host->id]);
$this->expectException(TooManyDatabasesException::class);
@ -96,9 +95,9 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
$name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id);
$host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]);
$host2 = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]);
factory(Database::class)->create([
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$host2 = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
Database::factory()->create([
'database' => $name,
'database_host_id' => $host->id,
'server_id' => $server->id,
@ -125,7 +124,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
$name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id);
$host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]);
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$this->repository->expects('createDatabase')->with($name);
@ -167,7 +166,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
$this->assertInstanceOf(Database::class, $response);
$this->assertSame($response->server_id, $server->id);
$this->assertRegExp('/^(u[\d]+_)(\w){10}$/', $username);
$this->assertMatchesRegularExpression('/^(u[\d]+_)(\w){10}$/', $username);
$this->assertSame($username, $secondUsername);
$this->assertSame(24, strlen($password));
@ -183,11 +182,11 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
$name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id);
$host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]);
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$this->repository->expects('createDatabase')->with($name)->andThrows(new BadMethodCallException);
$this->repository->expects('createDatabase')->with($name)->andThrows(new BadMethodCallException());
$this->repository->expects('dropDatabase')->with($name);
$this->repository->expects('dropUser')->withAnyArgs()->andThrows(new InvalidArgumentException);
$this->repository->expects('dropUser')->withAnyArgs()->andThrows(new InvalidArgumentException());
$this->expectException(BadMethodCallException::class);
@ -200,9 +199,6 @@ class DatabaseManagementServiceTest extends IntegrationTestCase
$this->assertDatabaseMissing('databases', ['server_id' => $server->id]);
}
/**
* @return array
*/
public function invalidDataDataProvider(): array
{
return [

View file

@ -7,7 +7,6 @@ use Pterodactyl\Models\Node;
use InvalidArgumentException;
use Pterodactyl\Models\Database;
use Pterodactyl\Models\DatabaseHost;
use Symfony\Component\VarDumper\Cloner\Data;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
use Pterodactyl\Services\Databases\DatabaseManagementService;
use Pterodactyl\Services\Databases\DeployServerDatabaseService;
@ -53,7 +52,7 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/^Expected a non-empty value\. Got: /',);
$this->expectExceptionMessageMatches('/^Expected a non-empty value\. Got: /', );
$this->getService()->handle($server, $data);
}
@ -65,8 +64,8 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$node = factory(Node::class)->create(['location_id' => $server->location->id]);
factory(DatabaseHost::class)->create(['node_id' => $node->id]);
$node = Node::factory()->create(['location_id' => $server->location->id]);
DatabaseHost::factory()->create(['node_id' => $node->id]);
config()->set('pterodactyl.client_features.databases.allow_random', false);
@ -100,15 +99,15 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$node = factory(Node::class)->create(['location_id' => $server->location->id]);
factory(DatabaseHost::class)->create(['node_id' => $node->id]);
$host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]);
$node = Node::factory()->create(['location_id' => $server->location->id]);
DatabaseHost::factory()->create(['node_id' => $node->id]);
$host = DatabaseHost::factory()->create(['node_id' => $server->node_id]);
$this->managementService->expects('create')->with($server, [
'database_host_id' => $host->id,
'database' => "s{$server->id}_something",
'remote' => '%',
])->andReturns(new Database);
])->andReturns(new Database());
$response = $this->getService()->handle($server, [
'database' => 'something',
@ -127,14 +126,14 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
$node = factory(Node::class)->create(['location_id' => $server->location->id]);
$host = factory(DatabaseHost::class)->create(['node_id' => $node->id]);
$node = Node::factory()->create(['location_id' => $server->location->id]);
$host = DatabaseHost::factory()->create(['node_id' => $node->id]);
$this->managementService->expects('create')->with($server, [
'database_host_id' => $host->id,
'database' => "s{$server->id}_something",
'remote' => '%',
])->andReturns(new Database);
])->andReturns(new Database());
$response = $this->getService()->handle($server, [
'database' => 'something',
@ -144,9 +143,6 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase
$this->assertInstanceOf(Database::class, $response);
}
/**
* @return array
*/
public function invalidDataProvider(): array
{
return [

View file

@ -6,8 +6,8 @@ use Exception;
use Pterodactyl\Models\Node;
use InvalidArgumentException;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Location;
use Pterodactyl\Models\Database;
use Pterodactyl\Models\Location;
use Illuminate\Support\Collection;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
use Pterodactyl\Services\Deployment\FindViableNodesService;
@ -71,24 +71,24 @@ class FindViableNodesServiceTest extends IntegrationTestCase
public function testExpectedNodeIsReturnedForLocation()
{
/** @var \Pterodactyl\Models\Location[] $locations */
$locations = factory(Location::class)->times(2)->create();
$locations = Location::factory()->times(2)->create();
/** @var \Pterodactyl\Models\Node[] $nodes */
$nodes = [
// This node should never be returned once we've completed the initial test which
// runs without a location filter.
factory(Node::class)->create([
Node::factory()->create([
'location_id' => $locations[0]->id,
'memory' => 2048,
'disk' => 1024 * 100,
]),
factory(Node::class)->create([
Node::factory()->create([
'location_id' => $locations[1]->id,
'memory' => 1024,
'disk' => 10240,
'disk_overallocate' => 10,
]),
factory(Node::class)->create([
Node::factory()->create([
'location_id' => $locations[1]->id,
'memory' => 1024 * 4,
'memory_overallocate' => 50,
@ -112,7 +112,7 @@ class FindViableNodesServiceTest extends IntegrationTestCase
// Helper, I am lazy.
$base = function () use ($locations) {
return $this->getService()->setLocations([ $locations[1]->id ])->setDisk(512);
return $this->getService()->setLocations([$locations[1]->id])->setDisk(512);
};
// Expect that we can create this server on either node since the disk and memory

View file

@ -23,7 +23,7 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
public function testScheduleWithNoTasksReturnsException()
{
$server = $this->createServerModel();
$schedule = factory(Schedule::class)->create(['server_id' => $server->id]);
$schedule = Schedule::factory()->create(['server_id' => $server->id]);
$this->expectException(DisplayException::class);
$this->expectExceptionMessage('Cannot process schedule for task execution: no tasks are registered.');
@ -39,13 +39,13 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Schedule $schedule */
$schedule = factory(Schedule::class)->create([
$schedule = Schedule::factory()->create([
'server_id' => $server->id,
'cron_minute' => 'hodor', // this will break the getNextRunDate() function.
]);
/** @var \Pterodactyl\Models\Task $task */
$task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]);
$task = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]);
$this->expectException(InvalidArgumentException::class);
@ -68,10 +68,10 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Schedule $schedule */
$schedule = factory(Schedule::class)->create(['server_id' => $server->id]);
$schedule = Schedule::factory()->create(['server_id' => $server->id]);
/** @var \Pterodactyl\Models\Task $task */
$task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'time_offset' => 10, 'sequence_id' => 1]);
$task = Task::factory()->create(['schedule_id' => $schedule->id, 'time_offset' => 10, 'sequence_id' => 1]);
$this->getService()->handle($schedule, $now);
@ -100,16 +100,16 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Schedule $schedule */
$schedule = factory(Schedule::class)->create(['server_id' => $server->id]);
$schedule = Schedule::factory()->create(['server_id' => $server->id]);
/** @var \Pterodactyl\Models\Task $task */
$task2 = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 4]);
$task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 2]);
$task3 = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 3]);
$task2 = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 4]);
$task = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 2]);
$task3 = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 3]);
$this->getService()->handle($schedule);
Bus::assertDispatched(RunTaskJob::class, function (RunTaskJob $job) use ($task) {
Bus::assertDispatched(RunTaskJob::class, function (RunTaskJob $job) use ($task) {
return $task->id === $job->task->id;
});
@ -131,9 +131,9 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Schedule $schedule */
$schedule = factory(Schedule::class)->create(['server_id' => $server->id, 'last_run_at' => null]);
$schedule = Schedule::factory()->create(['server_id' => $server->id, 'last_run_at' => null]);
/** @var \Pterodactyl\Models\Task $task */
$task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]);
$task = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]);
$dispatcher->expects('dispatchNow')->andThrows(new Exception('Test thrown exception'));
@ -151,9 +151,6 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
$this->assertDatabaseHas('tasks', ['id' => $task->id, 'is_queued' => false]);
}
/**
* @return array
*/
public function dispatchNowDataProvider(): array
{
return [[true], [false]];

View file

@ -36,7 +36,7 @@ class BuildModificationServiceTest extends IntegrationTestCase
$server2 = $this->createServerModel();
/** @var \Pterodactyl\Models\Allocation[] $allocations */
$allocations = factory(Allocation::class)->times(4)->create(['node_id' => $server->node_id, 'notes' => 'Random notes']);
$allocations = Allocation::factory()->times(4)->create(['node_id' => $server->node_id, 'notes' => 'Random notes']);
$initialAllocationId = $server->allocation_id;
$allocations[0]->update(['server_id' => $server->id, 'notes' => 'Test notes']);
@ -83,7 +83,7 @@ class BuildModificationServiceTest extends IntegrationTestCase
{
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Allocation[] $allocations */
$allocations = factory(Allocation::class)->times(4)->create(['node_id' => $server->node_id]);
$allocations = Allocation::factory()->times(4)->create(['node_id' => $server->node_id]);
$allocations[0]->update(['server_id' => $server->id]);
@ -155,8 +155,8 @@ class BuildModificationServiceTest extends IntegrationTestCase
public function testNoExceptionIsThrownIfOnlyRemovingAllocation()
{
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Allocation[] $allocations */
$allocation = factory(Allocation::class)->create(['node_id' => $server->node_id, 'server_id' => $server->id]);
/** @var \Pterodactyl\Models\Allocation $allocation */
$allocation = Allocation::factory()->create(['node_id' => $server->node_id, 'server_id' => $server->id]);
$this->daemonServerRepository->expects('setServer->update')->andReturnUndefined();
@ -178,8 +178,8 @@ class BuildModificationServiceTest extends IntegrationTestCase
public function testAllocationInBothAddAndRemoveIsAdded()
{
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Allocation[] $allocations */
$allocation = factory(Allocation::class)->create(['node_id' => $server->node_id]);
/** @var \Pterodactyl\Models\Allocation $allocation */
$allocation = Allocation::factory()->create(['node_id' => $server->node_id]);
$this->daemonServerRepository->expects('setServer->update')->andReturnUndefined();
@ -197,9 +197,10 @@ class BuildModificationServiceTest extends IntegrationTestCase
public function testUsingSameAllocationIdMultipleTimesDoesNotError()
{
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Allocation[] $allocations */
$allocation = factory(Allocation::class)->create(['node_id' => $server->node_id, 'server_id' => $server->id]);
$allocation2 = factory(Allocation::class)->create(['node_id' => $server->node_id]);
/** @var \Pterodactyl\Models\Allocation $allocation */
$allocation = Allocation::factory()->create(['node_id' => $server->node_id, 'server_id' => $server->id]);
/** @var \Pterodactyl\Models\Allocation $allocation2 */
$allocation2 = Allocation::factory()->create(['node_id' => $server->node_id]);
$this->daemonServerRepository->expects('setServer->update')->andReturnUndefined();
@ -219,8 +220,8 @@ class BuildModificationServiceTest extends IntegrationTestCase
public function testThatUpdatesAreRolledBackIfExceptionIsEncountered()
{
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Allocation[] $allocations */
$allocation = factory(Allocation::class)->create(['node_id' => $server->node_id]);
/** @var \Pterodactyl\Models\Allocation $allocation */
$allocation = Allocation::factory()->create(['node_id' => $server->node_id]);
$this->daemonServerRepository->expects('setServer->update')->andThrows(new DisplayException('Test'));

View file

@ -4,16 +4,16 @@ namespace Pterodactyl\Tests\Integration\Services\Servers;
use Mockery;
use Pterodactyl\Models\Egg;
use GuzzleHttp\Psr7\Request;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\User;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Location;
use Pterodactyl\Models\Allocation;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Validation\ValidationException;
use GuzzleHttp\Exception\BadResponseException;
use Illuminate\Validation\ValidationException;
use Pterodactyl\Models\Objects\DeploymentObject;
use Pterodactyl\Tests\Integration\IntegrationTestCase;
use Pterodactyl\Services\Servers\ServerCreationService;
@ -48,15 +48,18 @@ class ServerCreationServiceTest extends IntegrationTestCase
public function testServerIsCreatedWithDeploymentObject()
{
/** @var \Pterodactyl\Models\User $user */
$user = factory(User::class)->create();
$user = User::factory()->create();
/** @var \Pterodactyl\Models\Location $location */
$location = Location::factory()->create();
/** @var \Pterodactyl\Models\Node $node */
$node = factory(Node::class)->create([
'location_id' => factory(Location::class)->create()->id,
$node = Node::factory()->create([
'location_id' => $location->id,
]);
/** @var \Pterodactyl\Models\Allocation[]|\Illuminate\Database\Eloquent\Collection $allocations */
$allocations = factory(Allocation::class)->times(5)->create([
$allocations = Allocation::factory()->times(5)->create([
'node_id' => $node->id,
]);
@ -156,15 +159,18 @@ class ServerCreationServiceTest extends IntegrationTestCase
public function testErrorEncounteredByWingsCausesServerToBeDeleted()
{
/** @var \Pterodactyl\Models\User $user */
$user = factory(User::class)->create();
$user = User::factory()->create();
/** @var \Pterodactyl\Models\Location $location */
$location = Location::factory()->create();
/** @var \Pterodactyl\Models\Node $node */
$node = factory(Node::class)->create([
'location_id' => factory(Location::class)->create()->id,
$node = Node::factory()->create([
'location_id' => $location->id,
]);
/** @var \Pterodactyl\Models\Allocation $allocation */
$allocation = factory(Allocation::class)->create([
$allocation = Allocation::factory()->create([
'node_id' => $node->id,
]);

View file

@ -6,6 +6,7 @@ use Mockery;
use Exception;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Database;
use Pterodactyl\Models\DatabaseHost;
use GuzzleHttp\Exception\BadResponseException;
@ -65,7 +66,7 @@ class ServerDeletionServiceTest extends IntegrationTestCase
$this->expectException(DaemonConnectionException::class);
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andThrows(
new DaemonConnectionException(new BadResponseException('Bad request', new Request('GET', '/test')))
new DaemonConnectionException(new BadResponseException('Bad request', new Request('GET', '/test'), new Response()))
);
$this->getService()->handle($server);
@ -113,17 +114,17 @@ class ServerDeletionServiceTest extends IntegrationTestCase
public function testExceptionWhileDeletingStopsProcess()
{
$server = $this->createServerModel();
$host = factory(DatabaseHost::class)->create();
$host = DatabaseHost::factory()->create();
/** @var \Pterodactyl\Models\Database $db */
$db = factory(Database::class)->create(['database_host_id' => $host->id, 'server_id' => $server->id]);
$db = Database::factory()->create(['database_host_id' => $host->id, 'server_id' => $server->id]);
$server->refresh();
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andReturnUndefined();
$this->databaseManagementService->expects('delete')->with(Mockery::on(function ($value) use ($db) {
return $value instanceof Database && $value->id === $db->id;
}))->andThrows(new Exception);
}))->andThrows(new Exception());
$this->expectException(Exception::class);
$this->getService()->handle($server);
@ -138,17 +139,17 @@ class ServerDeletionServiceTest extends IntegrationTestCase
public function testExceptionWhileDeletingDatabasesDoesNotAbortIfForceDeleted()
{
$server = $this->createServerModel();
$host = factory(DatabaseHost::class)->create();
$host = DatabaseHost::factory()->create();
/** @var \Pterodactyl\Models\Database $db */
$db = factory(Database::class)->create(['database_host_id' => $host->id, 'server_id' => $server->id]);
$db = Database::factory()->create(['database_host_id' => $host->id, 'server_id' => $server->id]);
$server->refresh();
$this->daemonServerRepository->expects('setServer->delete')->withNoArgs()->andReturnUndefined();
$this->databaseManagementService->expects('delete')->with(Mockery::on(function ($value) use ($db) {
return $value instanceof Database && $value->id === $db->id;
}))->andThrows(new Exception);
}))->andThrows(new Exception());
$this->getService()->withForce(true)->handle($server);

View file

@ -3,10 +3,9 @@
namespace Pterodactyl\Tests\Integration\Services\Servers;
use Exception;
use Ramsey\Uuid\Uuid;
use Pterodactyl\Models\Egg;
use Pterodactyl\Models\User;
use Pterodactyl\Models\Nest;
use Pterodactyl\Models\User;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\ServerVariable;
use Illuminate\Validation\ValidationException;

View file

@ -92,7 +92,6 @@ class VariableValidatorServiceTest extends IntegrationTestCase
$this->assertArrayHasKey('environment.BUNGEE_VERSION', $exception->errors());
}
$response = $this->getService()->setUserLevel(User::USER_LEVEL_ADMIN)->handle($egg->id, [
'BUNGEE_VERSION' => '123',
'SERVER_JARFILE' => 'server.jar',