mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-30 12:18:43 +09:00
Harden request URL handling in bootstrap and stabilize Theme API not-found test assertions (#3511)
* Initial plan * fix: harden index URL handling and relax brittle theme API error assertions Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/1a498284-9424-42d6-8e7f-dfe061a51478 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * chore: address review nits in index and theme admin test Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/1a498284-9424-42d6-8e7f-dfe061a51478 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * fix: keep url fallback type-safe when parse_url fails Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/1a498284-9424-42d6-8e7f-dfe061a51478 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * test: clarify 740 error code reference in theme admin test Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/1a498284-9424-42d6-8e7f-dfe061a51478 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> * fix: add explicit null fallback for parsed request path Agent-Logs-Url: https://github.com/FOSSBilling/FOSSBilling/sessions/1a498284-9424-42d6-8e7f-dfe061a51478 Co-authored-by: admdly <2807620+admdly@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: admdly <2807620+admdly@users.noreply.github.com>
This commit is contained in:
1 parent
fa6c2f86a5
commit
e6601c7054
2 files changed
+13
-7
No files matched your search
+10
-4
@@ -25,7 +25,7 @@ if ((bool) ($config['debug_and_monitoring']['debug'] ?? false)) {
|
||||
$timeCollector = $debugBar->getCollector('time');
|
||||
|
||||
if (!$timeCollector instanceof TimeDataCollector) {
|
||||
throw new RuntimeException('Time collector not found in debug bar.');
|
||||
throw new \RuntimeException('Time collector not found in debug bar.');
|
||||
}
|
||||
|
||||
// PDO collector
|
||||
@@ -53,11 +53,17 @@ if ((bool) ($config['debug_and_monitoring']['debug'] ?? false)) {
|
||||
}
|
||||
|
||||
// Get the request URL
|
||||
$rawUrl = $_GET['_url'] ?? parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH);
|
||||
if (isset($_GET['_url']) && is_string($_GET['_url'])) {
|
||||
$rawUrl = $_GET['_url'];
|
||||
} else {
|
||||
$rawUrl = parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH) ?? '/';
|
||||
}
|
||||
$url = is_string($rawUrl) ? $rawUrl : '/';
|
||||
|
||||
// Validate and normalize URL path before using it in routing logic
|
||||
if ($url === '' || $url[0] !== '/' || preg_match('/[\x00-\x1F\x7F]/', $url) === 1) {
|
||||
if ($url === '') {
|
||||
$url = '/';
|
||||
} elseif ($url[0] !== '/' || preg_match('/[\x00-\x1F\x7F]/', $url) === 1) {
|
||||
$url = '/';
|
||||
}
|
||||
|
||||
@@ -88,7 +94,7 @@ $timeCollector?->stopMeasure('session_start');
|
||||
|
||||
if (strncasecmp((string) $url, ADMIN_PREFIX, strlen(ADMIN_PREFIX)) === 0) {
|
||||
define('ADMIN_AREA', true);
|
||||
$urlWithoutQueryString = preg_replace('/\?.+/', '', (string) $url);
|
||||
$urlWithoutQueryString = parse_url((string) $url, PHP_URL_PATH) ?? (string) $url;
|
||||
$adminRelativeUrl = str_replace(ADMIN_PREFIX, '', (string) $urlWithoutQueryString);
|
||||
$appUrl = $adminRelativeUrl;
|
||||
$app = new Box_AppAdmin([], $debugBar);
|
||||
|
||||
@@ -40,12 +40,12 @@ final class AdminTest extends TestCase
|
||||
$result = Request::makeRequest('admin/theme/non_existing_action');
|
||||
$this->assertSame(404, $result->getStatusCode(), 'Invalid theme action should return HTTP 404.');
|
||||
$this->assertFalse($result->wasSuccessful(), 'Invalid theme action should not be successful.');
|
||||
$this->assertSame(740, $result->getErrorCode(), 'Invalid theme action should return error code 740.');
|
||||
// API not-found actions/endpoints are mapped to error code 740 (see src/library/Api/Handler.php).
|
||||
$expectedNotFoundErrorCode = 740;
|
||||
$this->assertSame($expectedNotFoundErrorCode, $result->getErrorCode(), 'Invalid theme action should return the API not-found error code.');
|
||||
|
||||
$errorMessage = $result->getErrorMessage();
|
||||
$this->assertIsString($errorMessage, 'Error message should be a string.');
|
||||
$this->assertNotSame('', trim($errorMessage), 'Error message should not be empty.');
|
||||
$this->assertStringContainsString('non_existing_action', $errorMessage, 'Error message should reference the invalid action or endpoint.');
|
||||
$this->assertStringContainsString('does not exist', $errorMessage, 'Invalid theme action should report a missing endpoint/action.');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user