fix: Prevent empty path in webhooks (#16864)

Co-authored-by: Roman Davydchuk <roman.davydchuk@n8n.io>
This commit is contained in:
Michael Kret
2025-07-04 10:07:40 +03:00
committed by GitHub
parent 7317f67797
commit bd69907477
6 changed files with 129 additions and 10 deletions

View File

@@ -21,8 +21,10 @@ import {
isDefaultNodeName,
makeNodeName,
isTool,
getNodeWebhookPath,
} from '../src/node-helpers';
import type { Workflow } from '../src/workflow';
import { mock } from 'vitest-mock-extended';
describe('NodeHelpers', () => {
describe('getNodeParameters', () => {
@@ -4382,6 +4384,7 @@ describe('NodeHelpers', () => {
test(testData.description, () => {
// If this test has a custom mock return value, configure it
if (testData.mockReturnValue) {
// eslint-disable-next-line @typescript-eslint/unbound-method
vi.mocked(workflowMock.expression.getSimpleParameterValue).mockReturnValueOnce(
testData.mockReturnValue,
);
@@ -5611,4 +5614,48 @@ describe('NodeHelpers', () => {
expect(result).toBe(false);
});
});
describe('getNodeWebhookPath', () => {
const mockWorkflowId = 'workflow-123';
const mockPath = 'test-path';
it('should return path when restartWebhook is true', () => {
const node = mock<INode>({ name: 'TestNode' });
const result = getNodeWebhookPath(mockWorkflowId, node, mockPath, false, true);
expect(result).toBe(mockPath);
});
it('should return path when node has webhookId and isFullPath is true', () => {
const node = mock<INode>({ name: 'TestNode', webhookId: 'webhook-456' });
const result = getNodeWebhookPath(mockWorkflowId, node, mockPath, true, false);
expect(result).toBe(mockPath);
});
it('should return webhookId when node has webhookId, isFullPath is true, and path is empty', () => {
const node = mock<INode>({ name: 'TestNode', webhookId: 'webhook-456' });
const result = getNodeWebhookPath(mockWorkflowId, node, '', true, false);
expect(result).toBe('webhook-456');
});
it('should return webhookId/path when node has webhookId and isFullPath is false', () => {
const node = mock<INode>({ name: 'TestNode', webhookId: 'webhook-456' });
const result = getNodeWebhookPath(mockWorkflowId, node, mockPath, false, false);
expect(result).toBe('webhook-456/test-path');
});
it('should return workflowId/nodename/path when node has no webhookId', () => {
const node = mock<INode>({ name: 'TestNode', webhookId: undefined });
const result = getNodeWebhookPath(mockWorkflowId, node, mockPath, false, false);
expect(result).toBe('workflow-123/testnode/test-path');
});
});
});