Path: blob/1.0-develop/tests/Integration/Api/Remote/ServerTransferControllerTest.php
14044 views
<?php12namespace Pterodactyl\Tests\Integration\Api\Remote;34use Pterodactyl\Models\Node;5use Pterodactyl\Models\Location;6use Pterodactyl\Models\Allocation;7use Pterodactyl\Models\ServerTransfer;8use Pterodactyl\Tests\Integration\IntegrationTestCase;910class ServerTransferControllerTest extends IntegrationTestCase11{12protected ServerTransfer $transfer;1314public function setup(): void15{16parent::setUp();1718$server = $this->createServerModel();1920$new = Node::factory()21->for(Location::factory())22->has(Allocation::factory())23->create();2425$this->transfer = ServerTransfer::factory()->for($server)->create([26'old_allocation' => $server->allocation_id,27'new_allocation' => $new->allocations->first()->id,28'new_node' => $new->id,29'old_node' => $server->node_id,30]);31}3233public function testSuccessStatusUpdateCanBeSentFromNewNode(): void34{35$server = $this->transfer->server;36$newNode = $this->transfer->newNode;3738$this39->withHeader('Authorization', "Bearer $newNode->daemon_token_id." . $newNode->getDecryptedKey())40->postJson("/api/remote/servers/{$server->uuid}/transfer/success")41->assertNoContent();4243$this->assertTrue($this->transfer->refresh()->successful);44}4546public function testFailureStatusUpdateCanBeSentFromOldNode(): void47{48$server = $this->transfer->server;49$oldNode = $this->transfer->oldNode;5051$this->withHeader('Authorization', "Bearer $oldNode->daemon_token_id." . $oldNode->getDecryptedKey())52->postJson("/api/remote/servers/{$server->uuid}/transfer/failure")53->assertNoContent();5455$this->assertFalse($this->transfer->refresh()->successful);56}5758public function testFailureStatusUpdateCanBeSentFromNewNode(): void59{60$server = $this->transfer->server;61$newNode = $this->transfer->newNode;6263$this->withHeader('Authorization', "Bearer $newNode->daemon_token_id." . $newNode->getDecryptedKey())64->postJson("/api/remote/servers/{$server->uuid}/transfer/failure")65->assertNoContent();6667$this->assertFalse($this->transfer->refresh()->successful);68}6970public function testSuccessStatusUpdateCannotBeSentFromOldNode(): void71{72$server = $this->transfer->server;73$oldNode = $this->transfer->oldNode;7475$this->withHeader('Authorization', "Bearer $oldNode->daemon_token_id." . $oldNode->getDecryptedKey())76->postJson("/api/remote/servers/{$server->uuid}/transfer/success")77->assertForbidden()78->assertJsonPath('errors.0.code', 'HttpForbiddenException')79->assertJsonPath('errors.0.detail', 'Requesting node does not have permission to access this server.');8081$this->assertNull($this->transfer->refresh()->successful);82}8384public function testSuccessStatusUpdateCannotBeSentFromUnauthorizedNode(): void85{86$server = $this->transfer->server;87$node = Node::factory()->for(Location::factory())->create();8889$this->withHeader('Authorization', "Bearer $node->daemon_token_id." . $node->getDecryptedKey())90->postJson("/api/remote/servers/$server->uuid/transfer/success")91->assertForbidden()92->assertJsonPath('errors.0.code', 'HttpForbiddenException')93->assertJsonPath('errors.0.detail', 'Requesting node does not have permission to access this server.');9495$this->assertNull($this->transfer->refresh()->successful);96}9798public function testFailureStatusUpdateCannotBeSentFromUnauthorizedNode(): void99{100$server = $this->transfer->server;101$node = Node::factory()->for(Location::factory())->create();102103$this->withHeader('Authorization', "Bearer $node->daemon_token_id." . $node->getDecryptedKey())104->postJson("/api/remote/servers/$server->uuid/transfer/failure")->assertForbidden()105->assertJsonPath('errors.0.code', 'HttpForbiddenException')106->assertJsonPath('errors.0.detail', 'Requesting node does not have permission to access this server.');107108$this->assertNull($this->transfer->refresh()->successful);109}110}111112113