Files
pterodactyl-panel/tests/Unit/Config/EnvironmentFlagsTest.php
T
2026-10-12 05:18:57 -04:00

62 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Pterodactyl\Tests\Pest\Unit\Config\EnvironmentFlagsTest;
use Pterodactyl\Tests\TestCase;
uses(TestCase::class);
test('boolean settings read 1 and 0 from the environment as booleans', function (string $value, bool $expected): void {
$keys = ['RECAPTCHA_ENABLED', 'PTERODACTYL_CLIENT_ALLOCATIONS_ENABLED', 'PTERODACTYL_TELEMETRY_ENABLED'];
$previous = array_map(fn (string $key): mixed => $_SERVER[$key] ?? null, array_combine($keys, $keys));
foreach ($keys as $key) {
$_SERVER[$key] = $value;
}
try {
$recaptcha = require config_path('recaptcha.php');
$pterodactyl = require config_path('pterodactyl.php');
expect($recaptcha['enabled'])->toBe($expected)
->and($pterodactyl['client_features']['allocations']['enabled'])->toBe($expected)
->and($pterodactyl['telemetry']['enabled'])->toBe($expected);
} finally {
foreach ($previous as $key => $original) {
if ($original === null) {
unset($_SERVER[$key]);
} else {
$_SERVER[$key] = $original;
}
}
}
})->with([['1', true], ['0', false], ['true', true], ['false', false]]);
test('numeric settings read from the environment as integers', function () {
$keys = ['MAIL_PORT', 'APP_2FA_REQUIRED', 'GUZZLE_TIMEOUT', 'BACKUP_MAX_PART_SIZE'];
$previous = array_map(fn (string $key): mixed => $_SERVER[$key] ?? null, array_combine($keys, $keys));
foreach ($keys as $key) {
$_SERVER[$key] = '2';
}
try {
$mail = require config_path('mail.php');
$pterodactyl = require config_path('pterodactyl.php');
$backups = require config_path('backups.php');
expect($mail['mailers']['smtp']['port'])->toBe(2)
->and($pterodactyl['auth']['2fa_required'])->toBe(2)
->and($pterodactyl['guzzle']['timeout'])->toBe(2)
->and($backups['max_part_size'])->toBe(2);
} finally {
foreach ($previous as $key => $original) {
if ($original === null) {
unset($_SERVER[$key]);
} else {
$_SERVER[$key] = $original;
}
}
}
});