feat(HTTP Request Tool Node): Relax binary data detection (#13048)

This commit is contained in:
oleg
2025-02-05 12:14:31 +01:00
committed by GitHub
parent a7792684a6
commit b67a003e0b
2 changed files with 84 additions and 8 deletions

View File

@@ -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', () => {