mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-04 13:25:47 -05:00
validate enabled bool on extension install through admin
This commit is contained in:
@@ -47,4 +47,19 @@ class InstallExtensionRequest extends AdminApiRequest
|
||||
'enable' => $this->boolean('enable', false),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if (! $this->has('enable')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$enable = filter_var($this->input('enable'), FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE);
|
||||
if ($enable !== null) {
|
||||
$this->merge(['enable' => $enable]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +158,19 @@ test('install rejects a package with an invalid manifest', function (): void {
|
||||
|
||||
$this->assertDatabaseMissing('extensions', ['identifier' => 'Bad_Probe']);
|
||||
});
|
||||
test('install accepts multipart boolean strings for enable', function (string $enable): void {
|
||||
$this->post(route('api.admin.extensions.install'), ['package' => extensionPackage(['id' => 'Bad_Probe', 'name' => 'Bad', 'version' => '1.0.0']), 'enable' => $enable], ['Accept' => 'application/json'])
|
||||
->assertUnprocessable()
|
||||
->assertJsonPath('errors.0.code', 'InvalidExtensionException');
|
||||
})->with(['true', 'false', '1', '0']);
|
||||
test('install rejects a non boolean enable value', function (): void {
|
||||
$response = $this->post(route('api.admin.extensions.install'), ['package' => extensionPackage(['id' => 'admin-fixture', 'name' => 'Fixture', 'version' => '1.0.0']), 'enable' => 'maybe'], ['Accept' => 'application/json']);
|
||||
$response->assertUnprocessable();
|
||||
|
||||
$error = collect($response->json('errors'))->firstWhere('meta.source_field', 'enable');
|
||||
expect($error)->not->toBeNull();
|
||||
expect($error['meta']['rule'])->toBe('boolean');
|
||||
});
|
||||
test('non admin forbidden', function (string $method, string $routeName, array $parameters = []): void {
|
||||
writeExtension('admin-fixture');
|
||||
$this->actingAsNonAdmin();
|
||||
|
||||
Reference in New Issue
Block a user