diff --git a/packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/GenericFunctions.test.ts b/packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/GenericFunctions.test.ts new file mode 100644 index 0000000000..2cfbfb8429 --- /dev/null +++ b/packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/GenericFunctions.test.ts @@ -0,0 +1,30 @@ +import { mockDeep, type DeepMockProxy } from 'jest-mock-extended'; +import type { IExecuteFunctions, ILoadOptionsFunctions, INode } from 'n8n-workflow'; + +import { getWorkflowInfo } from './GenericFunctions'; + +jest.mock('fs/promises', () => ({ + readFile: jest.fn().mockResolvedValue('sensitive data'), +})); + +describe('ExecuteWorkflow node - GenericFunctions', () => { + let executeFunctionsMock: DeepMockProxy; + + beforeEach(() => { + jest.clearAllMocks(); + executeFunctionsMock = mockDeep(); + }); + + describe('getWorkflowInfo', () => { + it('should throw an error without the file content when source is localFile and the file is not json', async () => { + executeFunctionsMock.getNode.mockReturnValue({ + typeVersion: 1, + } as INode); + executeFunctionsMock.getNodeParameter.mockReturnValue('path/to/file'); + + await expect(getWorkflowInfo.call(executeFunctionsMock, 'localFile', 0)).rejects.toThrow( + 'The file content is not valid JSON', + ); + }); + }); +}); diff --git a/packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/GenericFunctions.ts b/packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/GenericFunctions.ts index 450a268dfa..7ce2c867e2 100644 --- a/packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ExecuteWorkflow/ExecuteWorkflow/GenericFunctions.ts @@ -45,7 +45,9 @@ export async function getWorkflowInfo( throw error; } - workflowInfo.code = jsonParse(workflowJson); + workflowInfo.code = jsonParse(workflowJson, { + errorMessage: 'The file content is not valid JSON', // pass a custom error message to not expose the file contents + }); } else if (source === 'parameter') { // Read workflow from parameter const workflowJson = this.getNodeParameter('workflowJson', itemIndex) as string;