mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +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 */
|
/* eslint-disable n8n-nodes-base/node-execute-block-wrong-error-thrown */
|
||||||
import { createWriteStream } from 'fs';
|
import { createWriteStream } from 'fs';
|
||||||
import { stat } from 'fs/promises';
|
import { rm, stat } from 'fs/promises';
|
||||||
import isbot from 'isbot';
|
import isbot from 'isbot';
|
||||||
import type {
|
import type {
|
||||||
IWebhookFunctions,
|
IWebhookFunctions,
|
||||||
@@ -363,6 +363,9 @@ export class Webhook extends Node {
|
|||||||
file.mimetype,
|
file.mimetype,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Delete original file to prevent tmp directory from growing too large
|
||||||
|
await rm(file.filepath, { force: true });
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
|
import fs from 'fs/promises';
|
||||||
import { mock } from 'jest-mock-extended';
|
import { mock } from 'jest-mock-extended';
|
||||||
import type { IWebhookFunctions } from 'n8n-workflow';
|
import type { IWebhookFunctions } from 'n8n-workflow';
|
||||||
|
|
||||||
import { Webhook } from '../Webhook.node';
|
import { Webhook } from '../Webhook.node';
|
||||||
|
|
||||||
|
jest.mock('fs/promises');
|
||||||
|
const mockFs = jest.mocked(fs);
|
||||||
|
|
||||||
describe('Test Webhook Node', () => {
|
describe('Test Webhook Node', () => {
|
||||||
new NodeTestHarness().setupTests();
|
new NodeTestHarness().setupTests();
|
||||||
|
|
||||||
@@ -33,11 +37,12 @@ describe('Test Webhook Node', () => {
|
|||||||
|
|
||||||
it('should handle when files are present', async () => {
|
it('should handle when files are present', async () => {
|
||||||
req.body = {
|
req.body = {
|
||||||
files: { file1: {} },
|
files: { file1: { filepath: '/tmp/test.txt' } },
|
||||||
};
|
};
|
||||||
const returnData = await node.webhook(context);
|
const returnData = await node.webhook(context);
|
||||||
expect(returnData.workflowData?.[0][0].binary).not.toBeUndefined();
|
expect(returnData.workflowData?.[0][0].binary).not.toBeUndefined();
|
||||||
expect(context.nodeHelpers.copyBinaryFile).toHaveBeenCalled();
|
expect(context.nodeHelpers.copyBinaryFile).toHaveBeenCalled();
|
||||||
|
expect(mockFs.rm).toHaveBeenCalledWith('/tmp/test.txt', { force: true });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user