Files
api/services/nginx/app/tests/Unit/N8n/N8nRouteHelpersTest.php
T
Jeppe B 2a6a86c9c3 Resolve backend Qodana critical and high findings (#314)
Resolve recommended-profile Critical and High findings, retain narrow analyzer exceptions, and update the edge-broker WebSocket dependency to a non-vulnerable release.
2026-07-17 05:44:16 +02:00

46 lines
1.4 KiB
PHP

<?php
app_require('routes/moduleN8nRoute.php');
use routes\moduleN8nRoute;
function n8n_route_invoke_private(moduleN8nRoute $route, string $method, array $args = []): mixed
{
$reflection = new ReflectionClass($route);
$target = $reflection->getMethod($method);
return $target->invokeArgs($route, $args);
}
it('normalizes webhook methods and falls back to POST for unsupported verbs', function (): void {
$_SERVER['REQUEST_URI'] = '/modules/n8n/webhooks/trigger';
$route = new moduleN8nRoute();
expect(n8n_route_invoke_private($route, 'normalizeHttpMethod', ['patch']))->toBe('PATCH');
expect(n8n_route_invoke_private($route, 'normalizeHttpMethod', [' delete ']))->toBe('DELETE');
expect(n8n_route_invoke_private($route, 'normalizeHttpMethod', ['trace']))->toBe('POST');
});
it('filters request parameters down to the allowed n8n query keys', function (): void {
$_SERVER['REQUEST_URI'] = '/modules/n8n/workflows';
$route = new moduleN8nRoute();
$filtered = n8n_route_invoke_private($route, 'filterRequestParameters', [[
'active' => 'true',
'limit' => '25',
'cursor' => '',
'projectId' => 'abc123',
'ignored' => 'value',
], [
'active',
'limit',
'projectId',
]]);
expect($filtered)->toBe([
'active' => 'true',
'limit' => '25',
'projectId' => 'abc123',
]);
});