import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as plugins from '../plugins.js';
import { EInvoice, FormatDetector } from '../../../ts/index.js';
import { PerformanceTracker } from '../performance.tracker.js';
const performanceTracker = new PerformanceTracker('SEC-04: Input Validation');
tap.test('SEC-04: Input Validation - should validate and sanitize all inputs', async () => {
// Test 1: SQL Injection attempts in XML fields
const sqlInjection = await performanceTracker.measureAsync(
'sql-injection-prevention',
async () => {
const sqlPayloads = [
"'; DROP TABLE invoices; --",
"1' OR '1'='1",
"admin'--",
"1; DELETE FROM users WHERE 1=1; --",
"' UNION SELECT * FROM passwords --"
];
const results = [];
for (const payload of sqlPayloads) {
const maliciousXML = `
${payload}
${payload}
1
${payload}
`;
try {
const invoice = await EInvoice.fromXml(maliciousXML);
// If parsing succeeds, the payload should be preserved as-is in XML
// SQL injection is not a concern for XML processing
results.push({
payload,
parsed: true,
error: null
});
} catch (error) {
// Parsing might fail for invalid XML characters
results.push({
payload,
parsed: false,
error: error.message
});
}
}
return results;
}
);
console.log('SQL injection test results:', sqlInjection);
// For XML processing, SQL payloads should either parse or fail - both are acceptable
sqlInjection.forEach(result => {
expect(result.parsed !== undefined).toEqual(true);
});
// Test 2: XSS (Cross-Site Scripting) attempts
const xssAttempts = await performanceTracker.measureAsync(
'xss-prevention',
async () => {
const xssPayloads = [
'',
'
',
'