Update egg import/update logic to all use the same pathwaus

This commit is contained in:
DaneEveritt 2022-05-15 14:40:19 -04:00
parent 6554164252
commit cca0010a00
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
12 changed files with 271 additions and 334 deletions

View file

@ -25,7 +25,9 @@ class ServerCreationServiceTest extends IntegrationTestCase
use WithFaker;
/** @var \Mockery\MockInterface */
private $daemonServerRepository;
protected $daemonServerRepository;
protected Egg $bungeecord;
/**
* Stub the calls to Wings so that we don't actually hit those API endpoints.
@ -34,6 +36,12 @@ class ServerCreationServiceTest extends IntegrationTestCase
{
parent::setUp();
/* @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->bungeecord = Egg::query()
->where('author', 'support@pterodactyl.io')
->where('name', 'Bungeecord')
->firstOrFail();
$this->daemonServerRepository = Mockery::mock(DaemonServerRepository::class);
$this->swap(DaemonServerRepository::class, $this->daemonServerRepository);
}
@ -67,7 +75,7 @@ class ServerCreationServiceTest extends IntegrationTestCase
$allocations[0]->port,
]);
$egg = $this->cloneEggAndVariables(Egg::query()->findOrFail(1));
$egg = $this->cloneEggAndVariables($this->bungeecord);
// We want to make sure that the validator service runs as an admin, and not as a regular
// user when saving variables.
$egg->variables()->first()->update([
@ -178,7 +186,7 @@ class ServerCreationServiceTest extends IntegrationTestCase
'cpu' => 0,
'startup' => 'java server2.jar',
'image' => 'java:8',
'egg_id' => 1,
'egg_id' => $this->bungeecord->id,
'environment' => [
'BUNGEE_VERSION' => '123',
'SERVER_JARFILE' => 'server2.jar',

View file

@ -3,7 +3,6 @@
namespace Pterodactyl\Tests\Integration\Services\Servers;
use Exception;
use Pterodactyl\Models\Egg;
use Pterodactyl\Models\Nest;
use Pterodactyl\Models\User;
use Pterodactyl\Models\Server;
@ -23,8 +22,7 @@ class StartupModificationServiceTest extends IntegrationTestCase
*/
public function testNonAdminCanModifyServerVariables()
{
// Theoretically lines up with the Bungeecord Minecraft egg.
$server = $this->createServerModel(['egg_id' => 1]);
$server = $this->createServerModel();
try {
$this->app->make(StartupModificationService::class)->handle($server, [

View file

@ -11,13 +11,25 @@ use Pterodactyl\Services\Servers\VariableValidatorService;
class VariableValidatorServiceTest extends IntegrationTestCase
{
protected Egg $egg;
public function setUp(): void
{
parent::setUp();
/* @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->egg = Egg::query()
->where('author', 'support@pterodactyl.io')
->where('name', 'Bungeecord')
->firstOrFail();
}
/**
* Test that enviornment variables for a server are validated as expected.
*/
public function testEnvironmentVariablesCanBeValidated()
{
/** @noinspection PhpParamsInspection */
$egg = $this->cloneEggAndVariables(Egg::query()->findOrFail(1));
$egg = $this->cloneEggAndVariables($this->egg);
try {
$this->getService()->handle($egg->id, [
@ -54,8 +66,7 @@ class VariableValidatorServiceTest extends IntegrationTestCase
*/
public function testNormalUserCannotValidateNonUserEditableVariables()
{
/** @noinspection PhpParamsInspection */
$egg = $this->cloneEggAndVariables(Egg::query()->findOrFail(1));
$egg = $this->cloneEggAndVariables($this->egg);
$egg->variables()->first()->update([
'user_editable' => false,
]);
@ -74,8 +85,7 @@ class VariableValidatorServiceTest extends IntegrationTestCase
public function testEnvironmentVariablesCanBeUpdatedAsAdmin()
{
/** @noinspection PhpParamsInspection */
$egg = $this->cloneEggAndVariables(Egg::query()->findOrFail(1));
$egg = $this->cloneEggAndVariables($this->egg);
$egg->variables()->first()->update([
'user_editable' => false,
]);
@ -107,8 +117,7 @@ class VariableValidatorServiceTest extends IntegrationTestCase
public function testNullableEnvironmentVariablesCanBeUsedCorrectly()
{
/** @noinspection PhpParamsInspection */
$egg = $this->cloneEggAndVariables(Egg::query()->findOrFail(1));
$egg = $this->cloneEggAndVariables($this->egg);
$egg->variables()->where('env_variable', '!=', 'BUNGEE_VERSION')->delete();
$egg->variables()->update(['rules' => 'nullable|string']);