Fix exception when passing location IDs to creation service; closes #2529
This commit is contained in:
parent
f54151e0f6
commit
839e277763
2 changed files with 32 additions and 4 deletions
|
@ -4,7 +4,6 @@ namespace Pterodactyl\Services\Deployment;
|
||||||
|
|
||||||
use Webmozart\Assert\Assert;
|
use Webmozart\Assert\Assert;
|
||||||
use Pterodactyl\Models\Node;
|
use Pterodactyl\Models\Node;
|
||||||
use Illuminate\Support\LazyCollection;
|
|
||||||
use Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException;
|
use Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException;
|
||||||
|
|
||||||
class FindViableNodesService
|
class FindViableNodesService
|
||||||
|
@ -32,7 +31,7 @@ class FindViableNodesService
|
||||||
*/
|
*/
|
||||||
public function setLocations(array $locations): self
|
public function setLocations(array $locations): self
|
||||||
{
|
{
|
||||||
Assert::allInteger($locations, 'An array of location IDs should be provided when calling setLocations.');
|
Assert::allIntegerish($locations, 'An array of location IDs should be provided when calling setLocations.');
|
||||||
|
|
||||||
$this->locations = $locations;
|
$this->locations = $locations;
|
||||||
|
|
||||||
|
@ -97,8 +96,8 @@ class FindViableNodesService
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = $query->groupBy('nodes.id')
|
$results = $query->groupBy('nodes.id')
|
||||||
->havingRaw('(IFNULL(SUM(servers.memory), 0) + ?) <= (nodes.memory * (1 + (nodes.memory_overallocate / 100)))', [ $this->memory ])
|
->havingRaw('(IFNULL(SUM(servers.memory), 0) + ?) <= (nodes.memory * (1 + (nodes.memory_overallocate / 100)))', [$this->memory])
|
||||||
->havingRaw('(IFNULL(SUM(servers.disk), 0) + ?) <= (nodes.disk * (1 + (nodes.disk_overallocate / 100)))', [ $this->disk ])
|
->havingRaw('(IFNULL(SUM(servers.disk), 0) + ?) <= (nodes.disk * (1 + (nodes.disk_overallocate / 100)))', [$this->disk])
|
||||||
->get()
|
->get()
|
||||||
->toBase();
|
->toBase();
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Tests\Integration\Services\Deployment;
|
namespace Pterodactyl\Tests\Integration\Services\Deployment;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Pterodactyl\Models\Node;
|
use Pterodactyl\Models\Node;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
|
@ -39,6 +40,34 @@ class FindViableNodesServiceTest extends IntegrationTestCase
|
||||||
$this->getService()->setDisk(10)->handle();
|
$this->getService()->setDisk(10)->handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that errors are not thrown back when passing in expected values.
|
||||||
|
*
|
||||||
|
* @see https://github.com/pterodactyl/panel/issues/2529
|
||||||
|
*/
|
||||||
|
public function testNoExceptionIsThrownIfStringifiedIntegersArePassedForLocations()
|
||||||
|
{
|
||||||
|
$this->getService()->setLocations([1, 2, 3]);
|
||||||
|
$this->getService()->setLocations(['1', '2', '3']);
|
||||||
|
$this->getService()->setLocations(['1', 2, 3]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->getService()->setLocations(['a']);
|
||||||
|
$this->assertTrue(false, 'This expectation should not be called.');
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
|
||||||
|
$this->assertSame('An array of location IDs should be provided when calling setLocations.', $exception->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->getService()->setLocations(['1.2', '1', 2]);
|
||||||
|
$this->assertTrue(false, 'This expectation should not be called.');
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$this->assertInstanceOf(InvalidArgumentException::class, $exception);
|
||||||
|
$this->assertSame('An array of location IDs should be provided when calling setLocations.', $exception->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testExpectedNodeIsReturnedForLocation()
|
public function testExpectedNodeIsReturnedForLocation()
|
||||||
{
|
{
|
||||||
/** @var \Pterodactyl\Models\Location[] $locations */
|
/** @var \Pterodactyl\Models\Location[] $locations */
|
||||||
|
|
Loading…
Reference in a new issue