first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import { mockDeep } from 'jest-mock-extended';
|
||||
import type { IExecuteFunctions } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
||||
|
||||
import { Xml } from '../../Xml.node';
|
||||
|
||||
describe('Test XML Node', () => {
|
||||
new NodeTestHarness().setupTests();
|
||||
});
|
||||
|
||||
describe('Xml Node - options validation', () => {
|
||||
const FORBIDDEN_KEYS = ['__proto__', 'constructor', 'prototype'];
|
||||
|
||||
let xmlNode: Xml;
|
||||
let mockExecuteFunctions: ReturnType<typeof mockDeep<IExecuteFunctions>>;
|
||||
|
||||
beforeEach(() => {
|
||||
xmlNode = new Xml();
|
||||
mockExecuteFunctions = mockDeep<IExecuteFunctions>();
|
||||
mockExecuteFunctions.getNode.mockReturnValue({
|
||||
id: 'xml-node',
|
||||
name: 'XML',
|
||||
type: 'n8n-nodes-base.xml',
|
||||
typeVersion: 1,
|
||||
position: [0, 0],
|
||||
parameters: {},
|
||||
});
|
||||
mockExecuteFunctions.getInputData.mockReturnValue([
|
||||
{ json: { data: '<root foo="bar">x</root>' } },
|
||||
]);
|
||||
});
|
||||
|
||||
const setupGetNodeParameter = (mode: string, options: Record<string, unknown>) => {
|
||||
mockExecuteFunctions.getNodeParameter.mockImplementation(
|
||||
(parameterName: string, _itemIndex: number, fallbackValue?: unknown) => {
|
||||
if (parameterName === 'mode') return mode;
|
||||
if (parameterName === 'dataPropertyName') return 'data';
|
||||
if (parameterName === 'options') return options;
|
||||
return fallbackValue as object;
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
describe('attrkey validation', () => {
|
||||
test.each(FORBIDDEN_KEYS)(
|
||||
'should reject invalid attrkey "%s" in xmlToJson mode',
|
||||
async (forbiddenKey) => {
|
||||
setupGetNodeParameter('xmlToJson', { attrkey: forbiddenKey, mergeAttrs: false });
|
||||
|
||||
await expect(xmlNode.execute.call(mockExecuteFunctions)).rejects.toThrow(
|
||||
`The "Attribute Key" option value "${forbiddenKey}" is not allowed`,
|
||||
);
|
||||
await expect(xmlNode.execute.call(mockExecuteFunctions)).rejects.toThrow(
|
||||
NodeOperationError,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test.each(FORBIDDEN_KEYS)(
|
||||
'should reject invalid attrkey "%s" in jsonToxml mode',
|
||||
async (forbiddenKey) => {
|
||||
setupGetNodeParameter('jsonToxml', { attrkey: forbiddenKey });
|
||||
|
||||
await expect(xmlNode.execute.call(mockExecuteFunctions)).rejects.toThrow(
|
||||
`The "Attribute Key" option value "${forbiddenKey}" is not allowed`,
|
||||
);
|
||||
await expect(xmlNode.execute.call(mockExecuteFunctions)).rejects.toThrow(
|
||||
NodeOperationError,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('charkey validation', () => {
|
||||
test.each(FORBIDDEN_KEYS)(
|
||||
'should reject invalid charkey "%s" in xmlToJson mode',
|
||||
async (forbiddenKey) => {
|
||||
setupGetNodeParameter('xmlToJson', { charkey: forbiddenKey });
|
||||
|
||||
await expect(xmlNode.execute.call(mockExecuteFunctions)).rejects.toThrow(
|
||||
`The "Character Key" option value "${forbiddenKey}" is not allowed`,
|
||||
);
|
||||
await expect(xmlNode.execute.call(mockExecuteFunctions)).rejects.toThrow(
|
||||
NodeOperationError,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test.each(FORBIDDEN_KEYS)(
|
||||
'should reject invalid charkey "%s" in jsonToxml mode',
|
||||
async (forbiddenKey) => {
|
||||
setupGetNodeParameter('jsonToxml', { charkey: forbiddenKey });
|
||||
|
||||
await expect(xmlNode.execute.call(mockExecuteFunctions)).rejects.toThrow(
|
||||
`The "Character Key" option value "${forbiddenKey}" is not allowed`,
|
||||
);
|
||||
await expect(xmlNode.execute.call(mockExecuteFunctions)).rejects.toThrow(
|
||||
NodeOperationError,
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user