-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-validation.js
More file actions
83 lines (75 loc) · 2.65 KB
/
test-validation.js
File metadata and controls
83 lines (75 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Quick validation test script
import {
ValidationError,
validateFetchDataOptions,
validateArticleCode,
validateTableName,
validateStringArray,
validateNumber
} from './dist-electron/validators/inputValidators.js';
console.log('🧪 Testing Validation System...\n');
// Test 1: Valid inputs
try {
console.log('✅ Test 1: Valid fetch options');
const validOptions = validateFetchDataOptions({ limit: 100, offset: 0, orderBy: 'ARTICLESCODE' });
console.log(' Result:', validOptions);
} catch (error) {
console.log('❌ Unexpected error:', error.message);
}
// Test 2: Invalid table name
try {
console.log('\n❌ Test 2: Invalid table name (should fail)');
validateTableName('DROP TABLE users;');
console.log(' ERROR: Should have thrown validation error!');
} catch (error) {
if (error instanceof ValidationError) {
console.log(' ✅ Correctly caught validation error:', error.message);
} else {
console.log(' ❌ Unexpected error type:', error);
}
}
// Test 3: SQL injection attempt in article code
try {
console.log('\n❌ Test 3: SQL injection in article code (should fail)');
validateArticleCode("'; DROP TABLE articles; --");
console.log(' ERROR: Should have thrown validation error!');
} catch (error) {
if (error instanceof ValidationError) {
console.log(' ✅ Correctly caught validation error:', error.message);
} else {
console.log(' ❌ Unexpected error type:', error);
}
}
// Test 4: Valid number validation
try {
console.log('\n✅ Test 4: Valid number validation');
const validNumber = validateNumber(500, 'limit', { min: 1, max: 1000, integer: true });
console.log(' Result:', validNumber);
} catch (error) {
console.log('❌ Unexpected error:', error.message);
}
// Test 5: Invalid number (too large)
try {
console.log('\n❌ Test 5: Invalid number - too large (should fail)');
validateNumber(50000, 'limit', { min: 1, max: 1000, integer: true });
console.log(' ERROR: Should have thrown validation error!');
} catch (error) {
if (error instanceof ValidationError) {
console.log(' ✅ Correctly caught validation error:', error.message);
} else {
console.log(' ❌ Unexpected error type:', error);
}
}
// Test 6: Valid table name that was failing
try {
console.log('\n✅ Test 6: Valid table name - ArticlesDimUDF');
const validTableName = validateTableName('ArticlesDimUDF');
console.log(' Result:', validTableName);
} catch (error) {
if (error instanceof ValidationError) {
console.log(' ❌ Still failing:', error.message);
} else {
console.log(' ❌ Unexpected error type:', error);
}
}
console.log('\n🎉 Validation system tests completed!');