diff --git a/tests/Unit/OrderBySessionHardeningTest.php b/tests/Unit/OrderBySessionHardeningTest.php index d40d54bc42..a6ddf38922 100644 --- a/tests/Unit/OrderBySessionHardeningTest.php +++ b/tests/Unit/OrderBySessionHardeningTest.php @@ -14,11 +14,13 @@ expect($htmlUtilitySource)->toContain('cacti_build_sort_fragment($column, $direction)'); }); -test('get_order_string rebuilds ORDER BY from validated session sort_data', function () use ($htmlUtilitySource) { +test('get_order_string normalizes, validates and builds the sort fragment', function () use ($htmlUtilitySource) { $start = strpos($htmlUtilitySource, 'function get_order_string()'); expect($start)->not->toBeFalse(); - $body = substr($htmlUtilitySource, $start, 1800); - expect($body)->toContain("if (isset(\$_SESSION['sort_data'][\$page]) && is_array(\$_SESSION['sort_data'][\$page]))"); - expect($body)->toContain("\$_SESSION['sort_string'][\$page] = 'ORDER BY ' . implode(', ', \$order_parts);"); + $next = strpos($htmlUtilitySource, "\nfunction ", $start + 1); + $body = $next === false ? substr($htmlUtilitySource, $start) : substr($htmlUtilitySource, $start, $next - $start); + expect($body)->toContain("cacti_normalize_sort_column(get_nfilter_request_var('sort_column'))"); + expect($body)->toContain('cacti_build_sort_fragment($sort_column, $sort_dir)'); + expect($body)->toContain('validate_sort_column($request_column, $page)'); });