Files
FOSSBilling/tests/Unit/Server/ManagerTest.php
Adam Daley c8439d0dc7 Fix Server_Manager::getPasswordLength() TypeError on non-int config (#4268)
Fix TypeError in Server_Manager::getPasswordLength()

_config['passwordLength'] is untyped, and stored server configs have
been observed carrying a numeric string rather than an int, which
violates this method's declared int return type. Cast defensively at
the boundary.

Confirmed live via Sentry (FOSSBILLING-MZA): ~7,800 occurrences since
June, still ongoing, always fatal to the whole cron run because the
error propagates out of order activation uncaught.
2026-09-02 16:46:32 +01:00

24 lines
784 B
PHP

<?php
declare(strict_types=1);
test('getPasswordLength returns the default when not configured', function (): void {
$manager = new Server_Manager_Custom([]);
expect($manager->getPasswordLength())->toBe(10);
});
test('getPasswordLength returns an int when configured with an int', function (): void {
$manager = new Server_Manager_Custom(['passwordLength' => 16]);
expect($manager->getPasswordLength())->toBe(16);
});
test('getPasswordLength coerces a numeric string to int', function (): void {
// Guards against FOSSBILLING-MZA: a numeric string stored in the server
// configuration must not violate the `int` return type.
$manager = new Server_Manager_Custom(['passwordLength' => '12']);
expect($manager->getPasswordLength())->toBe(12);
});