From 10e2e6e379f6aa42a26445bbfdcec67dad1411d8 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 30 Dec 2017 19:56:42 -0600 Subject: [PATCH] close #841 --- CHANGELOG.md | 5 ++++ .../Variables/VariableCreationService.php | 9 +----- .../Eggs/Variables/VariableUpdateService.php | 9 +----- .../Variables/VariableCreationServiceTest.php | 28 +++++++++++++------ .../Variables/VariableUpdateServiceTest.php | 25 ++++++++++++----- 5 files changed, 45 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dc64f1cc..8c4563986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ This file is a running track of new features and fixes to each version of the pa This project follows [Semantic Versioning](http://semver.org) guidelines. +## v0.7.0-beta.4 (Derelict Dermodactylus) +### Fixed +* `[beta.3]` — Fixes a bug with the default environment file that was causing an inability to perform a fresh install when running package discovery. +* `[beta.3]` — Fixes an edge case caused by the Laravel 5.5 upgrade that would try to perform an in_array check aganist a null value. + ## v0.7.0-beta.3 (Derelict Dermodactylus) ### Fixed * `[beta.2]` — Fixes a bug that would cause an endless exception message stream in the console when attemping to setup environment settings in certain instances. diff --git a/app/Services/Eggs/Variables/VariableCreationService.php b/app/Services/Eggs/Variables/VariableCreationService.php index 920ca312e..47d6a57ab 100644 --- a/app/Services/Eggs/Variables/VariableCreationService.php +++ b/app/Services/Eggs/Variables/VariableCreationService.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Services\Eggs\Variables; @@ -49,7 +42,7 @@ class VariableCreationService )); } - $options = array_get($data, 'options', []); + $options = array_get($data, 'options') ?? []; return $this->repository->create(array_merge($data, [ 'egg_id' => $egg, diff --git a/app/Services/Eggs/Variables/VariableUpdateService.php b/app/Services/Eggs/Variables/VariableUpdateService.php index 9c4f67fa7..0249e4fba 100644 --- a/app/Services/Eggs/Variables/VariableUpdateService.php +++ b/app/Services/Eggs/Variables/VariableUpdateService.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Services\Eggs\Variables; @@ -69,7 +62,7 @@ class VariableUpdateService } } - $options = array_get($data, 'options', []); + $options = array_get($data, 'options') ?? []; return $this->repository->withoutFresh()->update($variable->id, array_merge($data, [ 'user_viewable' => in_array('user_viewable', $options), diff --git a/tests/Unit/Services/Eggs/Variables/VariableCreationServiceTest.php b/tests/Unit/Services/Eggs/Variables/VariableCreationServiceTest.php index 320d85aa5..968a76743 100644 --- a/tests/Unit/Services/Eggs/Variables/VariableCreationServiceTest.php +++ b/tests/Unit/Services/Eggs/Variables/VariableCreationServiceTest.php @@ -1,17 +1,9 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Tests\Unit\Services\Eggs\Variables; use Mockery as m; use Tests\TestCase; -use Pterodactyl\Models\Egg; use Pterodactyl\Models\EggVariable; use Pterodactyl\Services\Eggs\Variables\VariableCreationService; use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface; @@ -73,6 +65,26 @@ class VariableCreationServiceTest extends TestCase $this->assertInstanceOf(EggVariable::class, $this->service->handle(1, $data)); } + /** + * Test that an empty (null) value passed in the option key is handled + * properly as an array. + * + * @see https://github.com/Pterodactyl/Panel/issues/841 + */ + public function testNullOptionValueIsPassedAsArray() + { + $data = ['env_variable' => 'TEST_VAR_123', 'options' => null]; + $this->repository->shouldReceive('create')->with([ + 'egg_id' => 1, + 'user_viewable' => false, + 'user_editable' => false, + 'env_variable' => 'TEST_VAR_123', + 'options' => null, + ])->once()->andReturn(new EggVariable); + + $this->assertInstanceOf(EggVariable::class, $this->service->handle(1, $data)); + } + /** * Test that all of the reserved variables defined in the model trigger an exception. * diff --git a/tests/Unit/Services/Eggs/Variables/VariableUpdateServiceTest.php b/tests/Unit/Services/Eggs/Variables/VariableUpdateServiceTest.php index 48703f8e4..bf1f209ae 100644 --- a/tests/Unit/Services/Eggs/Variables/VariableUpdateServiceTest.php +++ b/tests/Unit/Services/Eggs/Variables/VariableUpdateServiceTest.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Tests\Unit\Services\Eggs\Variables; @@ -100,6 +93,24 @@ class VariableUpdateServiceTest extends TestCase $this->assertTrue($this->service->handle($this->model, ['env_variable' => 'TEST_VAR_123'])); } + /** + * Test that an empty (null) value passed in the option key is handled + * properly as an array. + * + * @see https://github.com/Pterodactyl/Panel/issues/841 + */ + public function testNullOptionValueIsPassedAsArray() + { + $this->repository->shouldReceive('withoutFresh')->withNoArgs()->once()->andReturnSelf() + ->shouldReceive('update')->with($this->model->id, [ + 'user_viewable' => false, + 'user_editable' => false, + 'options' => null, + ])->once()->andReturn(true); + + $this->assertTrue($this->service->handle($this->model, ['options' => null])); + } + /** * Test that data passed into the handler is overwritten inside the handler. */