-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-middleware.mjs
More file actions
68 lines (62 loc) · 2.44 KB
/
Copy pathtest-middleware.mjs
File metadata and controls
68 lines (62 loc) · 2.44 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
import http from 'http';
console.log('🧪 Testing middleware improvements...\n');
// Test 1: Valid list endpoint
http.get('http://localhost:3000/api/images/list', (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
console.log('✅ Test 1 - List Images (Valid)');
console.log(` Status: ${res.statusCode}`);
const images = JSON.parse(data);
console.log(` Found: ${images.length} images\n`);
});
}).on('error', err => console.error('❌ Error:', err.message));
// Test 2: Missing parameters (should be caught by validation middleware)
setTimeout(() => {
http.get('http://localhost:3000/api/images/?filename=test', (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
console.log('✅ Test 2 - Missing Parameters');
console.log(` Status: ${res.statusCode}`);
console.log(` Response: ${data}\n`);
});
}).on('error', err => console.error('❌ Error:', err.message));
}, 500);
// Test 3: Invalid dimensions (validation middleware)
setTimeout(() => {
http.get('http://localhost:3000/api/images/?filename=test&width=abc&height=200', (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
console.log('✅ Test 3 - Invalid Width (non-numeric)');
console.log(` Status: ${res.statusCode}`);
console.log(` Response: ${data}\n`);
});
}).on('error', err => console.error('❌ Error:', err.message));
}, 1000);
// Test 4: Dimensions too large
setTimeout(() => {
http.get('http://localhost:3000/api/images/?filename=test&width=5000&height=5000', (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
console.log('✅ Test 4 - Dimensions Exceed Max');
console.log(` Status: ${res.statusCode}`);
console.log(` Response: ${data}\n`);
});
}).on('error', err => console.error('❌ Error:', err.message));
}, 1500);
// Test 5: Invalid filename format
setTimeout(() => {
http.get('http://localhost:3000/api/images/?filename=test@evil&width=100&height=100', (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
console.log('✅ Test 5 - Invalid Filename Format');
console.log(` Status: ${res.statusCode}`);
console.log(` Response: ${data}\n`);
process.exit(0);
});
}).on('error', err => console.error('❌ Error:', err.message));
}, 2000);