mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(core): Make parsing of content-type and content-disposition headers more flexible (#7217)
fixes #7149
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import nock from 'nock';
|
||||
import { join } from 'path';
|
||||
import { tmpdir } from 'os';
|
||||
import { readFileSync, mkdtempSync } from 'fs';
|
||||
import { BinaryDataManager } from '@/BinaryDataManager';
|
||||
import {
|
||||
getBinaryDataBuffer,
|
||||
parseIncomingMessage,
|
||||
proxyRequestToAxios,
|
||||
setBinaryDataBuffer,
|
||||
} from '@/NodeExecuteFunctions';
|
||||
import { mkdtempSync, readFileSync } from 'fs';
|
||||
import type { IncomingMessage } from 'http';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type {
|
||||
IBinaryData,
|
||||
@@ -11,12 +16,9 @@ import type {
|
||||
Workflow,
|
||||
WorkflowHooks,
|
||||
} from 'n8n-workflow';
|
||||
import { BinaryDataManager } from '@/BinaryDataManager';
|
||||
import {
|
||||
setBinaryDataBuffer,
|
||||
getBinaryDataBuffer,
|
||||
proxyRequestToAxios,
|
||||
} from '@/NodeExecuteFunctions';
|
||||
import nock from 'nock';
|
||||
import { tmpdir } from 'os';
|
||||
import { join } from 'path';
|
||||
import { initLogger } from './helpers/utils';
|
||||
|
||||
const temporaryDir = mkdtempSync(join(tmpdir(), 'n8n'));
|
||||
@@ -136,6 +138,75 @@ describe('NodeExecuteFunctions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseIncomingMessage', () => {
|
||||
it('parses valid content-type header', () => {
|
||||
const message = mock<IncomingMessage>({
|
||||
headers: { 'content-type': 'application/json', 'content-disposition': undefined },
|
||||
});
|
||||
parseIncomingMessage(message);
|
||||
|
||||
expect(message.contentType).toEqual('application/json');
|
||||
});
|
||||
|
||||
it('parses valid content-type header with parameters', () => {
|
||||
const message = mock<IncomingMessage>({
|
||||
headers: {
|
||||
'content-type': 'application/json; charset=utf-8',
|
||||
'content-disposition': undefined,
|
||||
},
|
||||
});
|
||||
parseIncomingMessage(message);
|
||||
|
||||
expect(message.contentType).toEqual('application/json');
|
||||
});
|
||||
|
||||
it('parses valid content-disposition header with filename*', () => {
|
||||
const message = mock<IncomingMessage>({
|
||||
headers: {
|
||||
'content-type': undefined,
|
||||
'content-disposition':
|
||||
'attachment; filename="screenshot%20(1).png"; filename*=UTF-8\'\'screenshot%20(1).png',
|
||||
},
|
||||
});
|
||||
parseIncomingMessage(message);
|
||||
|
||||
expect(message.contentDisposition).toEqual({
|
||||
filename: 'screenshot (1).png',
|
||||
type: 'attachment',
|
||||
});
|
||||
});
|
||||
|
||||
it('parses valid content-disposition header with filename and trailing ";"', () => {
|
||||
const message = mock<IncomingMessage>({
|
||||
headers: {
|
||||
'content-type': undefined,
|
||||
'content-disposition': 'inline; filename="screenshot%20(1).png";',
|
||||
},
|
||||
});
|
||||
parseIncomingMessage(message);
|
||||
|
||||
expect(message.contentDisposition).toEqual({
|
||||
filename: 'screenshot (1).png',
|
||||
type: 'inline',
|
||||
});
|
||||
});
|
||||
|
||||
it('parses non standard content-disposition with missing type', () => {
|
||||
const message = mock<IncomingMessage>({
|
||||
headers: {
|
||||
'content-type': undefined,
|
||||
'content-disposition': 'filename="screenshot%20(1).png";',
|
||||
},
|
||||
});
|
||||
parseIncomingMessage(message);
|
||||
|
||||
expect(message.contentDisposition).toEqual({
|
||||
filename: 'screenshot (1).png',
|
||||
type: 'attachment',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('proxyRequestToAxios', () => {
|
||||
const baseUrl = 'http://example.de';
|
||||
const workflow = mock<Workflow>();
|
||||
|
||||
Reference in New Issue
Block a user