mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-04 21:35:47 -05:00
admin tag checks
This commit is contained in:
@@ -133,6 +133,7 @@ class PterodactylDocumentation
|
||||
'force_outgoing_ip' => 'Whether servers should use their allocation IP for outgoing traffic.',
|
||||
'fqdn' => 'The fully qualified domain name.',
|
||||
'host' => 'The database host address.',
|
||||
'ignore_tags' => "Whether to place the server on a node whose egg tags the egg does not share. The node's deployment tags are never checked here.",
|
||||
'ignored' => 'Whether this item should be ignored.',
|
||||
'import_file' => 'The file to import.',
|
||||
'io' => 'The block IO weight.',
|
||||
|
||||
@@ -38,6 +38,7 @@ class TransferController extends AdminApiController
|
||||
#[BodyParam('node_id', 'integer', 'The destination node ID.', required: true, example: 2)]
|
||||
#[BodyParam('allocation_id', 'integer', 'The primary allocation ID on the destination node.', required: true, example: 10)]
|
||||
#[BodyParam('allocation_additional', 'integer[]', 'Additional allocation IDs on the destination node.', required: false, example: [11, 12])]
|
||||
#[BodyParam('ignore_tags', 'boolean', 'Whether to move the server to a node whose egg tags its egg does not share.', required: false, example: false)]
|
||||
#[ScribeResponse(status: 204, description: 'Server transfer started.')]
|
||||
#[ScribeResponse(self::TRANSFER_NOT_VIABLE_ERROR, status: 400, description: 'The destination node cannot fit the server or the server cannot currently be transferred.')]
|
||||
public function __invoke(TransferServerRequest $request, InitiatesTransfers $transfers, Server $server): Response
|
||||
|
||||
@@ -13,6 +13,9 @@ use Pterodactyl\Enum\Permissions;
|
||||
use Pterodactyl\Http\Requests\Api\Admin\AdminApiRequest;
|
||||
use Pterodactyl\Http\Requests\Concerns\FiltersDeployTags;
|
||||
use Pterodactyl\Http\Requests\Concerns\ValidatesExtensionFields;
|
||||
use Pterodactyl\Http\Requests\Concerns\ValidatesNodeAcceptsEgg;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Objects\DeploymentObject;
|
||||
use Pterodactyl\Models\Server;
|
||||
|
||||
@@ -22,6 +25,7 @@ class StoreServerRequest extends AdminApiRequest
|
||||
use ValidatesExtensionFields {
|
||||
actionInput as private inputWithExtensions;
|
||||
}
|
||||
use ValidatesNodeAcceptsEgg;
|
||||
|
||||
public function permissions(): array
|
||||
{
|
||||
@@ -80,6 +84,7 @@ class StoreServerRequest extends AdminApiRequest
|
||||
'deploy.tags.*' => ['string'],
|
||||
|
||||
'start_on_completion' => $rules['start_on_completion'],
|
||||
'ignore_tags' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -96,7 +101,7 @@ class StoreServerRequest extends AdminApiRequest
|
||||
$input['image'] = $input['docker_image'] ?? null;
|
||||
$input['allocation_id'] = $input['primary_allocation_id'] ?? null;
|
||||
$input['allocation_additional'] = $input['secondary_allocations_ids'] ?? null;
|
||||
unset($input['docker_image'], $input['primary_allocation_id'], $input['secondary_allocations_ids'], $input['deploy']);
|
||||
unset($input['docker_image'], $input['primary_allocation_id'], $input['secondary_allocations_ids'], $input['deploy'], $input['ignore_tags']);
|
||||
|
||||
return $input;
|
||||
}
|
||||
@@ -106,7 +111,7 @@ class StoreServerRequest extends AdminApiRequest
|
||||
*/
|
||||
public function after(): array
|
||||
{
|
||||
return [$this->validateDeployTagsExist(...)];
|
||||
return [$this->validateDeployTagsExist(...), $this->validateAllocationAcceptsEgg(...)];
|
||||
}
|
||||
|
||||
/** Build a deployment object from the deploy payload, or null when absent. */
|
||||
@@ -132,4 +137,20 @@ class StoreServerRequest extends AdminApiRequest
|
||||
{
|
||||
return Server::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* A deployment picks a node that accepts the egg itself, so only a chosen allocation is
|
||||
* checked.
|
||||
*/
|
||||
private function validateAllocationAcceptsEgg(Validator $validator): void
|
||||
{
|
||||
if ($validator->errors()->isNotEmpty() || $this->has('deploy')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$validated = $validator->safe();
|
||||
$node = Allocation::query()->findOrFail($validated->integer('primary_allocation_id'))->node;
|
||||
|
||||
$this->validateNodeAcceptsEgg($validator, 'primary_allocation_id', $node, Egg::query()->findOrFail($validated->integer('egg_id')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,17 @@ use Closure;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Pterodactyl\Actions\Transfers\InitiateTransfer;
|
||||
use Pterodactyl\Enum\Permissions;
|
||||
use Pterodactyl\Http\Requests\Concerns\ValidatesNodeAcceptsEgg;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Validation\Concerns\ValidatesArrayExistence;
|
||||
|
||||
class TransferServerRequest extends ServerWriteRequest
|
||||
{
|
||||
use ValidatesArrayExistence;
|
||||
use ValidatesNodeAcceptsEgg;
|
||||
|
||||
public function permissions(): array
|
||||
{
|
||||
@@ -28,11 +32,12 @@ class TransferServerRequest extends ServerWriteRequest
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return InitiateTransfer::rules($this->parameter('server', Server::class));
|
||||
return [...InitiateTransfer::rules($this->parameter('server', Server::class)), 'ignore_tags' => ['sometimes', 'boolean']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Chosen allocations must exist, belong to the target node and be unassigned.
|
||||
* Chosen allocations must exist, belong to the target node and be unassigned, and the
|
||||
* target node must accept the server's egg.
|
||||
*
|
||||
* @return list<Closure(Validator): void>
|
||||
*/
|
||||
@@ -41,6 +46,11 @@ class TransferServerRequest extends ServerWriteRequest
|
||||
return [function (Validator $validator): void {
|
||||
$this->validateArrayExistence($validator, 'allocation_additional', Allocation::query());
|
||||
InitiateTransfer::validateAllocations($validator);
|
||||
|
||||
if ($validator->errors()->isEmpty()) {
|
||||
$egg = Egg::query()->findOrFail($this->parameter('server', Server::class)->egg_id);
|
||||
$this->validateNodeAcceptsEgg($validator, 'node_id', Node::query()->findOrFail($validator->safe()->integer('node_id')), $egg);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Api\Admin\Servers;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Pterodactyl\Actions\Servers\UpdateServerStartup;
|
||||
use Pterodactyl\Enum\Permissions;
|
||||
use Pterodactyl\Http\Requests\Concerns\ValidatesNodeAcceptsEgg;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\User;
|
||||
|
||||
class UpdateServerStartupRequest extends ServerWriteRequest
|
||||
{
|
||||
use ValidatesNodeAcceptsEgg;
|
||||
|
||||
public function permissions(): array
|
||||
{
|
||||
return [Permissions::AdminServersUpdate];
|
||||
@@ -22,6 +29,23 @@ class UpdateServerStartupRequest extends ServerWriteRequest
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return UpdateServerStartup::rules(User::USER_LEVEL_ADMIN);
|
||||
return [...UpdateServerStartup::rules(User::USER_LEVEL_ADMIN), 'ignore_tags' => ['sometimes', 'boolean']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Moving the server to another egg needs a node that accepts it.
|
||||
*
|
||||
* @return list<Closure(Validator): void>
|
||||
*/
|
||||
public function after(): array
|
||||
{
|
||||
return [function (Validator $validator): void {
|
||||
$server = $this->parameter('server', Server::class);
|
||||
if ($validator->errors()->isNotEmpty() || $validator->safe()->integer('egg_id') === $server->egg_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->validateNodeAcceptsEgg($validator, 'egg_id', $server->node, Egg::query()->findOrFail($validator->safe()->integer('egg_id')));
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pterodactyl\Http\Requests\Concerns;
|
||||
|
||||
use Illuminate\Validation\Validator;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Tag;
|
||||
|
||||
/**
|
||||
* Lets an Admin API request that places a server on a node refuse a node that does not
|
||||
* accept the egg, unless `ignore_tags` is set. Only the egg half of the deploy gate is
|
||||
* checked: servers do not keep the deploy tags that a node's reservations match.
|
||||
*/
|
||||
trait ValidatesNodeAcceptsEgg
|
||||
{
|
||||
protected function validateNodeAcceptsEgg(Validator $validator, string $field, Node $node, Egg $egg): void
|
||||
{
|
||||
if ($this->boolean('ignore_tags') || $node->acceptsEgg($egg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tags = $node->eggTags->map(fn (Tag $tag): string => $tag->effectiveName())->implode(', ');
|
||||
|
||||
$validator->errors()->add($field, "{$node->name} only accepts eggs tagged {$tags}.");
|
||||
}
|
||||
}
|
||||
@@ -239,6 +239,15 @@ class Node extends Model implements Identifiable
|
||||
->withPivotValue('kind', 'deployment');
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this node accepts the egg, as NodeBuilder::forEggTags() decides it: a node
|
||||
* without egg tags accepts every egg, any other needs a tag in common with it.
|
||||
*/
|
||||
public function acceptsEgg(Egg $egg): bool
|
||||
{
|
||||
return $this->eggTags->isEmpty() || $this->eggTags->intersect($egg->tags)->isNotEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an additional server of the given size fits within this node's
|
||||
* (over)allocatable memory and disk.
|
||||
|
||||
+12
@@ -1619,6 +1619,10 @@ export type AdminCreateServerRequest = {
|
||||
* Whether the server should start when the operation completes.
|
||||
*/
|
||||
start_on_completion?: boolean;
|
||||
/**
|
||||
* Whether to place the server on a node whose egg tags the egg does not share. The node's deployment tags are never checked here.
|
||||
*/
|
||||
ignore_tags?: boolean;
|
||||
secondary_allocations_ids?: Array<number>;
|
||||
extensions?: ExtensionFields;
|
||||
};
|
||||
@@ -1712,6 +1716,10 @@ export type AdminUpdateServerStartupRequest = {
|
||||
* Whether install scripts should be skipped.
|
||||
*/
|
||||
skip_scripts?: boolean;
|
||||
/**
|
||||
* Whether to place the server on a node whose egg tags the egg does not share. The node's deployment tags are never checked here.
|
||||
*/
|
||||
ignore_tags?: boolean;
|
||||
};
|
||||
export type AdminUpdateServerSuspensionRequest = {
|
||||
/**
|
||||
@@ -1732,6 +1740,10 @@ export type AdminTransferServerRequest = {
|
||||
* Additional allocation IDs on the destination node.
|
||||
*/
|
||||
allocation_additional?: Array<number>;
|
||||
/**
|
||||
* Whether to move the server to a node whose egg tags its egg does not share.
|
||||
*/
|
||||
ignore_tags?: boolean;
|
||||
};
|
||||
export type AdminCreateServerDatabaseRequest = {
|
||||
/**
|
||||
|
||||
@@ -1782,6 +1782,10 @@ export type AdminCreateServerRequest = {
|
||||
* Whether the server should start when the operation completes.
|
||||
*/
|
||||
start_on_completion?: boolean;
|
||||
/**
|
||||
* Whether to place the server on a node whose egg tags the egg does not share. The node's deployment tags are never checked here.
|
||||
*/
|
||||
ignore_tags?: boolean;
|
||||
secondary_allocations_ids?: Array<number>;
|
||||
extensions?: ExtensionFields;
|
||||
};
|
||||
@@ -1878,6 +1882,10 @@ export type AdminUpdateServerStartupRequest = {
|
||||
* Whether install scripts should be skipped.
|
||||
*/
|
||||
skip_scripts?: boolean;
|
||||
/**
|
||||
* Whether to place the server on a node whose egg tags the egg does not share. The node's deployment tags are never checked here.
|
||||
*/
|
||||
ignore_tags?: boolean;
|
||||
};
|
||||
|
||||
export type AdminUpdateServerSuspensionRequest = {
|
||||
@@ -1900,6 +1908,10 @@ export type AdminTransferServerRequest = {
|
||||
* Additional allocation IDs on the destination node.
|
||||
*/
|
||||
allocation_additional?: Array<number>;
|
||||
/**
|
||||
* Whether to move the server to a node whose egg tags its egg does not share.
|
||||
*/
|
||||
ignore_tags?: boolean;
|
||||
};
|
||||
|
||||
export type AdminCreateServerDatabaseRequest = {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
PUT /api/admin/servers/1/startup
|
||||
422 application/json
|
||||
{"errors":[{"code":"ValidationException","status":"422","detail":"node-alpha only accepts eggs tagged Minecraft.","meta":{"source_field":"egg_id","rule":""}}]}
|
||||
|
||||
PUT /api/admin/servers/1/startup
|
||||
200 application/json
|
||||
{"object":"server","attributes":{"id":1,"external_id":"ext-survival","uuid":"5e7f0001-0000-4000-8000-000000000001","identifier":"5e7f0001","name":"Survival","description":"Main survival world","status":null,"suspended":false,"limits":{"memory":2048,"swap":512,"disk":10240,"io":500,"cpu":200,"threads":"0-3","oom_disabled":true},"feature_limits":{"databases":5,"allocations":5,"backups":5},"user":2,"node":1,"allocation":1,"egg":3,"container":{"startup_command":"java -jar {{SERVER_JARFILE}}","image":"ghcr.io\/pterodactyl\/yolks:java_17","skip_scripts":true,"installed":1,"environment":{"STARTUP":"java -jar {{SERVER_JARFILE}}","P_SERVER_LOCATION":"us-east","P_SERVER_UUID":"5e7f0001-0000-4000-8000-000000000001","P_SERVER_ALLOCATION_LIMIT":5}},"relationships":[],"updated_at":"2026-03-04T05:06:07+00:00","created_at":"2026-01-02T03:04:05+00:00"}}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
POST /api/admin/servers
|
||||
422 application/json
|
||||
{"errors":[{"code":"ValidationException","status":"422","detail":"node-alpha only accepts eggs tagged Minecraft.","meta":{"source_field":"primary_allocation_id","rule":""}}]}
|
||||
|
||||
POST /api/admin/servers
|
||||
201 application/json
|
||||
{"object":"server","attributes":{"id":1001,"external_id":"ext-admin-created","uuid":"e45a916b-7b34-4394-9e17-48fad8d0185e","identifier":"e45a916b","name":"Admin Created","description":"Created by an admin.","status":"installing","suspended":false,"limits":{"memory":512,"swap":0,"disk":1024,"io":500,"cpu":0,"threads":null,"oom_disabled":true},"feature_limits":{"databases":0,"allocations":0,"backups":0},"user":2,"node":1,"allocation":4,"egg":3,"container":{"startup_command":"java -jar {{SERVER_JARFILE}}","image":"ghcr.io\/pterodactyl\/yolks:java_21","skip_scripts":false,"installed":0,"environment":{"STARTUP":"java -jar {{SERVER_JARFILE}}","P_SERVER_LOCATION":"us-east","P_SERVER_UUID":"e45a916b-7b34-4394-9e17-48fad8d0185e","P_SERVER_ALLOCATION_LIMIT":0}},"relationships":[],"updated_at":"2026-03-04T05:06:07+00:00","created_at":"2026-03-04T05:06:07+00:00","extensions":{}},"meta":{"resource":"https:\/\/panel.example.test\/api\/admin\/servers\/1001"}}
|
||||
@@ -4391,6 +4391,9 @@ components:
|
||||
start_on_completion:
|
||||
type: boolean
|
||||
description: 'Whether the server should start when the operation completes.'
|
||||
ignore_tags:
|
||||
type: boolean
|
||||
description: "Whether to place the server on a node whose egg tags the egg does not share. The node's deployment tags are never checked here."
|
||||
secondary_allocations_ids:
|
||||
type: array
|
||||
description: ''
|
||||
@@ -4509,6 +4512,9 @@ components:
|
||||
skip_scripts:
|
||||
type: boolean
|
||||
description: 'Whether install scripts should be skipped.'
|
||||
ignore_tags:
|
||||
type: boolean
|
||||
description: "Whether to place the server on a node whose egg tags the egg does not share. The node's deployment tags are never checked here."
|
||||
required:
|
||||
- startup
|
||||
- egg_id
|
||||
@@ -4534,6 +4540,9 @@ components:
|
||||
description: 'Additional allocation IDs on the destination node.'
|
||||
items:
|
||||
type: integer
|
||||
ignore_tags:
|
||||
type: boolean
|
||||
description: 'Whether to move the server to a node whose egg tags its egg does not share.'
|
||||
required:
|
||||
- node_id
|
||||
- allocation_id
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pterodactyl\Tests\Pest\Integration\Api\Admin\Servers\ServerTagCheckTest;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Tag;
|
||||
use Pterodactyl\Models\User;
|
||||
use Pterodactyl\Tests\Integration\Api\Admin\AdminApiIntegrationTestCase;
|
||||
use Pterodactyl\Tests\Support\Fakes\FakeDaemonServer;
|
||||
use Pterodactyl\Tests\Support\Fakes\FakeDaemonTransfer;
|
||||
|
||||
uses(AdminApiIntegrationTestCase::class);
|
||||
|
||||
function tag(string $slug): Tag
|
||||
{
|
||||
return Tag::query()->firstOrCreate(['slug' => $slug], ['name' => Str::headline($slug)]);
|
||||
}
|
||||
|
||||
function taggedEgg(Egg $egg, string $slug): Egg
|
||||
{
|
||||
$egg->tags()->sync([tag($slug)->id]);
|
||||
|
||||
return $egg;
|
||||
}
|
||||
|
||||
function bungeecord(): Egg
|
||||
{
|
||||
return Egg::query()->where('author', 'support@pterodactyl.io')->where('name', 'Bungeecord')->firstOrFail();
|
||||
}
|
||||
|
||||
function taggedNode(?string $eggTag = null, ?string $deploymentTag = null): Node
|
||||
{
|
||||
$node = Node::factory()->for(Location::factory())->create(['memory' => 102400, 'disk' => 102400]);
|
||||
if ($eggTag !== null) {
|
||||
$node->eggTags()->attach(tag($eggTag));
|
||||
}
|
||||
|
||||
if ($deploymentTag !== null) {
|
||||
$node->deploymentTags()->attach(tag($deploymentTag));
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
function serverPayload(Egg $egg, Allocation $allocation): array
|
||||
{
|
||||
return [
|
||||
'name' => 'Tagged Server',
|
||||
'owner_id' => User::factory()->create()->id,
|
||||
'egg_id' => $egg->id,
|
||||
'docker_image' => 'ghcr.io/pterodactyl/yolks:java_21',
|
||||
'startup' => 'java -jar server.jar',
|
||||
'environment' => ['BUNGEE_VERSION' => '123', 'SERVER_JARFILE' => 'server.jar'],
|
||||
'memory' => 512,
|
||||
'swap' => 0,
|
||||
'disk' => 1024,
|
||||
'io' => 500,
|
||||
'cpu' => 0,
|
||||
'database_limit' => 0,
|
||||
'allocation_limit' => 0,
|
||||
'backup_limit' => 0,
|
||||
'primary_allocation_id' => $allocation->id,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string, array{string|null, string|null}> */
|
||||
function acceptingNodes(): array
|
||||
{
|
||||
return [
|
||||
'a node sharing a tag with the egg' => ['tag-check-game', null],
|
||||
'a node without egg tags' => [null, null],
|
||||
'a node with only a reservation' => [null, 'tag-check-reserved'],
|
||||
];
|
||||
}
|
||||
|
||||
test('server create refuses a node that does not accept the egg unless tags are ignored', function (): void {
|
||||
$egg = taggedEgg(bungeecord(), 'tag-check-game');
|
||||
$node = taggedNode('tag-check-other');
|
||||
$allocation = Allocation::factory()->for($node)->create();
|
||||
$fake = new FakeDaemonServer;
|
||||
|
||||
$this->postJson(route('api.admin.servers.store'), serverPayload($egg, $allocation))
|
||||
->assertUnprocessable()
|
||||
->assertJsonCount(1, 'errors')
|
||||
->assertJsonPath('errors.0.meta.source_field', 'primary_allocation_id')
|
||||
->assertJsonPath('errors.0.detail', "{$node->name} only accepts eggs tagged Tag Check Other.");
|
||||
expect($fake->callsFor('create'))->toBe([]);
|
||||
|
||||
$this->postJson(route('api.admin.servers.store'), [...serverPayload($egg, $allocation), 'ignore_tags' => true])->assertCreated();
|
||||
$fake->assertCreated();
|
||||
});
|
||||
|
||||
test('server create accepts a node that accepts the egg', function (?string $eggTag, ?string $deploymentTag): void {
|
||||
$egg = taggedEgg(bungeecord(), 'tag-check-game');
|
||||
$allocation = Allocation::factory()->for(taggedNode($eggTag, $deploymentTag))->create();
|
||||
new FakeDaemonServer;
|
||||
|
||||
$this->postJson(route('api.admin.servers.store'), serverPayload($egg, $allocation))->assertCreated();
|
||||
})->with(acceptingNodes());
|
||||
|
||||
test('a transfer refuses a target node that does not accept the egg unless tags are ignored', function (): void {
|
||||
$server = $this->createServerModel();
|
||||
taggedEgg($server->egg, 'tag-check-game');
|
||||
$target = taggedNode('tag-check-other');
|
||||
$allocation = Allocation::factory()->for($target)->create(['server_id' => null]);
|
||||
$fake = new FakeDaemonTransfer;
|
||||
|
||||
$this->postJson(route('api.admin.servers.transfer', ['server' => $server->id]), ['node_id' => $target->id, 'allocation_id' => $allocation->id])
|
||||
->assertUnprocessable()
|
||||
->assertJsonCount(1, 'errors')
|
||||
->assertJsonPath('errors.0.meta.source_field', 'node_id')
|
||||
->assertJsonPath('errors.0.detail', "{$target->name} only accepts eggs tagged Tag Check Other.");
|
||||
$this->assertDatabaseMissing('server_transfers', ['server_id' => $server->id]);
|
||||
|
||||
$this->postJson(route('api.admin.servers.transfer', ['server' => $server->id]), ['node_id' => $target->id, 'allocation_id' => $allocation->id, 'ignore_tags' => true])->assertNoContent();
|
||||
$fake->assertNotified();
|
||||
});
|
||||
|
||||
test('a transfer accepts a target node that accepts the egg', function (?string $eggTag, ?string $deploymentTag): void {
|
||||
$server = $this->createServerModel();
|
||||
taggedEgg($server->egg, 'tag-check-game');
|
||||
$target = taggedNode($eggTag, $deploymentTag);
|
||||
$allocation = Allocation::factory()->for($target)->create(['server_id' => null]);
|
||||
new FakeDaemonTransfer;
|
||||
|
||||
$this->postJson(route('api.admin.servers.transfer', ['server' => $server->id]), ['node_id' => $target->id, 'allocation_id' => $allocation->id])->assertNoContent();
|
||||
})->with(acceptingNodes());
|
||||
|
||||
test('an egg change refuses an egg the server\'s node does not accept unless tags are ignored', function (): void {
|
||||
$server = $this->createServerModel(['node_id' => taggedNode('tag-check-game')->id]);
|
||||
$egg = taggedEgg($this->cloneEggAndVariables(bungeecord()), 'tag-check-other');
|
||||
new FakeDaemonServer;
|
||||
$payload = ['startup' => 'java -jar server.jar', 'egg_id' => $egg->id, 'docker_image' => 'java:11', 'skip_scripts' => false, 'environment' => ['BUNGEE_VERSION' => '123', 'SERVER_JARFILE' => 'server.jar']];
|
||||
|
||||
$this->putJson(route('api.admin.servers.startup', ['server' => $server->id]), $payload)
|
||||
->assertUnprocessable()
|
||||
->assertJsonCount(1, 'errors')
|
||||
->assertJsonPath('errors.0.meta.source_field', 'egg_id')
|
||||
->assertJsonPath('errors.0.detail', "{$server->node->name} only accepts eggs tagged Tag Check Game.");
|
||||
expect($server->refresh()->egg_id)->not->toBe($egg->id);
|
||||
|
||||
$this->putJson(route('api.admin.servers.startup', ['server' => $server->id]), [...$payload, 'ignore_tags' => true])->assertOk();
|
||||
expect($server->refresh()->egg_id)->toBe($egg->id);
|
||||
});
|
||||
|
||||
test('an egg change accepts an egg the server\'s node accepts', function (?string $eggTag, ?string $deploymentTag): void {
|
||||
$server = $this->createServerModel(['node_id' => taggedNode($eggTag, $deploymentTag)->id]);
|
||||
$egg = taggedEgg($this->cloneEggAndVariables(bungeecord()), 'tag-check-game');
|
||||
new FakeDaemonServer;
|
||||
|
||||
$this->putJson(route('api.admin.servers.startup', ['server' => $server->id]), ['startup' => 'java -jar server.jar', 'egg_id' => $egg->id, 'docker_image' => 'java:11', 'skip_scripts' => false, 'environment' => ['BUNGEE_VERSION' => '123', 'SERVER_JARFILE' => 'server.jar']])
|
||||
->assertOk();
|
||||
expect(Server::query()->findOrFail($server->id)->egg_id)->toBe($egg->id);
|
||||
})->with(acceptingNodes());
|
||||
|
||||
test('keeping the egg is not checked against the node', function (): void {
|
||||
$server = $this->createServerModel(['node_id' => taggedNode('tag-check-other')->id]);
|
||||
taggedEgg($server->egg, 'tag-check-game');
|
||||
|
||||
$this->putJson(route('api.admin.servers.startup', ['server' => $server->id]), ['startup' => 'java -jar server.jar', 'egg_id' => $server->egg_id, 'docker_image' => 'java:11', 'skip_scripts' => false, 'environment' => ['BUNGEE_VERSION' => '123', 'SERVER_JARFILE' => 'server.jar']])
|
||||
->assertOk();
|
||||
});
|
||||
@@ -150,6 +150,13 @@ function adminWrites(): array
|
||||
$node = ['name' => 'node-gamma', 'description' => 'Created by an admin', 'location_id' => 1, 'public' => true, 'fqdn' => 'gamma.example.test', 'scheme' => 'https', 'behind_proxy' => false, 'maintenance_mode' => false, 'memory' => 2048, 'memory_overallocate' => 0, 'disk' => 20480, 'disk_overallocate' => 0, 'upload_size' => 100, 'daemon_listen' => 8080, 'daemon_sftp' => 2022, 'daemon_base' => '/var/lib/pterodactyl/volumes'];
|
||||
$egg = ['name' => 'Created Egg', 'description' => 'A freshly created egg.', 'docker_images' => "Java 21|ghcr.io/pterodactyl/yolks:java_21\nJava 17|ghcr.io/pterodactyl/yolks:java_17", 'startup' => 'java -jar server.jar', 'config_stop' => 'stop', 'config_startup' => '{"done": ["Done"]}', 'config_logs' => '{}', 'config_files' => '{}', 'features' => ['eula', 'fastdl']];
|
||||
$environment = ['SERVER_JARFILE' => 'server.jar', 'BUILD_NUMBER' => '42', 'HIDDEN_TOKEN' => 'abc'];
|
||||
$server = [
|
||||
'name' => 'Admin Created', 'description' => 'Created by an admin.', 'external_id' => 'ext-admin-created', 'owner_id' => World::OWNER, 'egg_id' => 1,
|
||||
'docker_image' => 'ghcr.io/pterodactyl/yolks:java_21', 'startup' => 'java -jar {{SERVER_JARFILE}}', 'environment' => $environment,
|
||||
'memory' => 512, 'swap' => 0, 'disk' => 1024, 'io' => 500, 'cpu' => 0, 'threads' => null, 'database_limit' => 0, 'allocation_limit' => 0,
|
||||
'backup_limit' => 0, 'primary_allocation_id' => 4, 'start_on_completion' => false,
|
||||
];
|
||||
$startup = ['startup' => 'java -jar {{SERVER_JARFILE}}', 'egg_id' => 1, 'docker_image' => 'ghcr.io/pterodactyl/yolks:java_17', 'skip_scripts' => true, 'environment' => [...$environment, 'SERVER_JARFILE' => 'renamed.jar']];
|
||||
$mount = ['name' => 'Created Mount', 'description' => 'Created by an admin.', 'source' => '/mnt/created', 'target' => '/mnt/created-target', 'read_only' => true, 'user_mountable' => false];
|
||||
$export = fn (int $id): Closure => fn (): UploadedFile => UploadedFile::fake()->createWithContent('egg.json', App::make(ExportsEggs::class)->export(Egg::query()->findOrFail($id)));
|
||||
|
||||
@@ -181,18 +188,21 @@ function adminWrites(): array
|
||||
'write nodes allocations update' => [['requests' => [['PUT', ADMIN.'/nodes/1/allocations/4', ['alias' => 'renamed.example.test']]]]],
|
||||
'write nodes deployment tags' => [['requests' => [['PUT', ADMIN.'/nodes/1/deployment-tags', ['tags' => [3]]]]]],
|
||||
'write nodes tags' => [['requests' => [['PUT', ADMIN.'/nodes/1/tags', ['tags' => [1, 2]]]]]],
|
||||
'write servers store' => [['requests' => [['POST', ADMIN.'/servers', [
|
||||
'name' => 'Admin Created', 'description' => 'Created by an admin.', 'external_id' => 'ext-admin-created', 'owner_id' => World::OWNER, 'egg_id' => 1,
|
||||
'docker_image' => 'ghcr.io/pterodactyl/yolks:java_21', 'startup' => 'java -jar {{SERVER_JARFILE}}', 'environment' => $environment,
|
||||
'memory' => 512, 'swap' => 0, 'disk' => 1024, 'io' => 500, 'cpu' => 0, 'threads' => null, 'database_limit' => 0, 'allocation_limit' => 0,
|
||||
'backup_limit' => 0, 'primary_allocation_id' => 4, 'start_on_completion' => false,
|
||||
]]]]],
|
||||
'write servers store' => [['requests' => [['POST', ADMIN.'/servers', $server]]]],
|
||||
'write servers store tag check' => [['requests' => [
|
||||
['POST', ADMIN.'/servers', [...$server, 'egg_id' => 3]],
|
||||
['POST', ADMIN.'/servers', [...$server, 'egg_id' => 3, 'ignore_tags' => true]],
|
||||
]]],
|
||||
'write servers backups toggle' => [['requests' => [['POST', ADMIN.'/servers/1/backups/'.World::BACKUP_FAILED.'/toggle']]]],
|
||||
'write servers build' => [['requests' => [['PUT', ADMIN.'/servers/1/build', ['allocation_id' => 1, 'oom_disabled' => false, 'memory' => 1024, 'swap' => 0, 'io' => 500, 'cpu' => 100, 'threads' => null, 'disk' => 2048, 'database_limit' => 2, 'allocation_limit' => 3, 'backup_limit' => 4, 'add_allocation_ids' => [4], 'remove_allocation_ids' => [2]]]]]],
|
||||
'write servers databases store' => [['redact' => ['password'], 'requests' => [['POST', ADMIN.'/servers/1/databases', ['database' => 'admindb', 'remote' => '%', 'database_host_id' => 1, 'max_connections' => 25]]]]],
|
||||
'write servers databases rotate password' => [['redact' => ['password'], 'requests' => [['POST', ADMIN.'/servers/1/databases/1/rotate-password']]]],
|
||||
'write servers details' => [['requests' => [['PUT', ADMIN.'/servers/1/details', ['name' => 'Survival Admin', 'owner_id' => World::OWNER, 'external_id' => 'ext-survival-admin', 'description' => 'Updated by an admin.']]]]],
|
||||
'write servers startup' => [['requests' => [['PUT', ADMIN.'/servers/1/startup', ['startup' => 'java -jar {{SERVER_JARFILE}}', 'egg_id' => 1, 'docker_image' => 'ghcr.io/pterodactyl/yolks:java_17', 'skip_scripts' => true, 'environment' => [...$environment, 'SERVER_JARFILE' => 'renamed.jar']]]]]],
|
||||
'write servers startup' => [['requests' => [['PUT', ADMIN.'/servers/1/startup', $startup]]]],
|
||||
'write servers startup tag check' => [['requests' => [
|
||||
['PUT', ADMIN.'/servers/1/startup', [...$startup, 'egg_id' => 3]],
|
||||
['PUT', ADMIN.'/servers/1/startup', [...$startup, 'egg_id' => 3, 'ignore_tags' => true]],
|
||||
]]],
|
||||
'write tags store' => [['requests' => [['POST', ADMIN.'/tags', ['name' => 'Created Tag', 'slug' => 'created-tag', 'color' => '#123456']]]]],
|
||||
'write tags update' => [['requests' => [['PUT', ADMIN.'/tags/2', ['name' => 'Premium Plus', 'slug' => 'premium-plus', 'color' => '#654321']]]]],
|
||||
'write users store' => [['requests' => [['POST', ADMIN.'/users', ['username' => 'created', 'email' => 'created@example.test', 'name_first' => 'Cre', 'name_last' => 'Ated', 'external_id' => 'ext-created']]]]],
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Pterodactyl\Tests\Pest\Integration\Models\NodeDeploymentScopesTest;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Server;
|
||||
@@ -111,6 +112,11 @@ function accepts(array $nodeEggTags, array $nodeDeploymentTags, array $eggTags,
|
||||
$node = Node::factory()->withLocation()->create();
|
||||
$node->eggTags()->attach(array_map($tag, $nodeEggTags));
|
||||
$node->deploymentTags()->attach(array_map($tag, $nodeDeploymentTags));
|
||||
$egg = Egg::factory()->create();
|
||||
$egg->tags()->attach(array_map($tag, $eggTags));
|
||||
|
||||
// The in-memory check the admin API uses agrees with the query's egg half.
|
||||
expect($node->acceptsEgg($egg))->toBe(Node::query()->whereKey($node->id)->forEggTags($eggTags)->exists());
|
||||
|
||||
return Node::query()->whereKey($node->id)->forEggTags($eggTags)->forDeployTags($deployTags)->exists();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user