mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(HTTP Request Tool Node): Relax binary data detection (#13048)
This commit is contained in:
@@ -237,6 +237,69 @@ describe('ToolHttpRequest', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should return the error when receiving text that contains a null character', async () => {
|
||||
helpers.httpRequest.mockResolvedValue({
|
||||
body: 'Hello\0World',
|
||||
headers: {
|
||||
'content-type': 'text/plain',
|
||||
},
|
||||
});
|
||||
|
||||
executeFunctions.getNodeParameter.mockImplementation((paramName: string) => {
|
||||
switch (paramName) {
|
||||
case 'method':
|
||||
return 'GET';
|
||||
case 'url':
|
||||
return 'https://httpbin.org/text/plain';
|
||||
case 'options':
|
||||
return {};
|
||||
case 'placeholderDefinitions.values':
|
||||
return [];
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
const { response } = await httpTool.supplyData.call(executeFunctions, 0);
|
||||
const res = await (response as N8nTool).invoke({});
|
||||
expect(helpers.httpRequest).toHaveBeenCalled();
|
||||
// Check that the returned string is formatted as an error message.
|
||||
expect(res).toContain('error');
|
||||
expect(res).toContain('Binary data is not supported');
|
||||
});
|
||||
|
||||
it('should return the error when receiving a JSON response containing a null character', async () => {
|
||||
// Provide a raw JSON string with a literal null character.
|
||||
helpers.httpRequest.mockResolvedValue({
|
||||
body: '{"message":"hello\0world"}',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
executeFunctions.getNodeParameter.mockImplementation((paramName: string) => {
|
||||
switch (paramName) {
|
||||
case 'method':
|
||||
return 'GET';
|
||||
case 'url':
|
||||
return 'https://httpbin.org/json';
|
||||
case 'options':
|
||||
return {};
|
||||
case 'placeholderDefinitions.values':
|
||||
return [];
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
const { response } = await httpTool.supplyData.call(executeFunctions, 0);
|
||||
const res = await (response as N8nTool).invoke({});
|
||||
expect(helpers.httpRequest).toHaveBeenCalled();
|
||||
// Check that the tool returns an error string rather than resolving to valid JSON.
|
||||
expect(res).toContain('error');
|
||||
expect(res).toContain('Binary data is not supported');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Optimize response', () => {
|
||||
|
||||
Reference in New Issue
Block a user