mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): Remove temporary uploaded files from webhook calls (#18128)
Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
committed by
GitHub
parent
11dcef36df
commit
c610c3af3e
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable n8n-nodes-base/node-execute-block-wrong-error-thrown */
|
||||
import { createWriteStream } from 'fs';
|
||||
import { stat } from 'fs/promises';
|
||||
import { rm, stat } from 'fs/promises';
|
||||
import isbot from 'isbot';
|
||||
import type {
|
||||
IWebhookFunctions,
|
||||
@@ -363,6 +363,9 @@ export class Webhook extends Node {
|
||||
file.mimetype,
|
||||
);
|
||||
|
||||
// Delete original file to prevent tmp directory from growing too large
|
||||
await rm(file.filepath, { force: true });
|
||||
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
||||
import type { Request, Response } from 'express';
|
||||
import fs from 'fs/promises';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { IWebhookFunctions } from 'n8n-workflow';
|
||||
|
||||
import { Webhook } from '../Webhook.node';
|
||||
|
||||
jest.mock('fs/promises');
|
||||
const mockFs = jest.mocked(fs);
|
||||
|
||||
describe('Test Webhook Node', () => {
|
||||
new NodeTestHarness().setupTests();
|
||||
|
||||
@@ -33,11 +37,12 @@ describe('Test Webhook Node', () => {
|
||||
|
||||
it('should handle when files are present', async () => {
|
||||
req.body = {
|
||||
files: { file1: {} },
|
||||
files: { file1: { filepath: '/tmp/test.txt' } },
|
||||
};
|
||||
const returnData = await node.webhook(context);
|
||||
expect(returnData.workflowData?.[0][0].binary).not.toBeUndefined();
|
||||
expect(context.nodeHelpers.copyBinaryFile).toHaveBeenCalled();
|
||||
expect(mockFs.rm).toHaveBeenCalledWith('/tmp/test.txt', { force: true });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user