diff options
Diffstat (limited to 'tests/integration/network.mjs')
| -rw-r--r-- | tests/integration/network.mjs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/integration/network.mjs b/tests/integration/network.mjs new file mode 100644 index 0000000..dcd7a9a --- /dev/null +++ b/tests/integration/network.mjs | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | import { execSync } from 'child_process'; | ||
| 2 | |||
| 3 | const IP = process.env.TOLLGATE_IP || '10.192.45.1'; | ||
| 4 | let passed = 0, failed = 0; | ||
| 5 | |||
| 6 | function assert(condition, test) { | ||
| 7 | if (condition) { console.log(` ✓ ${test}`); passed++; } | ||
| 8 | else { console.log(` ✗ ${test}`); failed++; } | ||
| 9 | } | ||
| 10 | |||
| 11 | function run(cmd) { | ||
| 12 | try { return execSync(cmd, { encoding: 'utf8', timeout: 15000 }); } | ||
| 13 | catch { return null; } | ||
| 14 | } | ||
| 15 | |||
| 16 | console.log(`\n=== Network Tests (target: ${IP}) ===\n`); | ||
| 17 | |||
| 18 | // Test 1: AP visible in scan | ||
| 19 | console.log('Test 1: AP visible in scan'); | ||
| 20 | const scan = run('nmcli -t -f SSID dev wifi list 2>/dev/null'); | ||
| 21 | assert(scan && scan.includes('TollGate'), 'TollGate SSID visible in WiFi scan'); | ||
| 22 | |||
| 23 | // Test 2: DHCP lease | ||
| 24 | console.log('\nTest 2: DHCP lease / connectivity'); | ||
| 25 | const ip_show = run(`ip addr show | grep "inet ${IP.split('.').slice(0,3).join('.')}"`); | ||
| 26 | assert(ip_show !== null, `Has IP in ${IP.split('.').slice(0,3).join('.')}.* subnet`); | ||
| 27 | |||
| 28 | // Test 5: DNS hijack | ||
| 29 | console.log('\nTest 5: DNS hijack before auth'); | ||
| 30 | const ns1 = run(`nslookup random-test.example.com ${IP} 2>/dev/null`); | ||
| 31 | assert(ns1 && ns1.includes(IP), 'DNS resolves arbitrary domain to AP IP'); | ||
| 32 | |||
| 33 | // Test 6: No internet | ||
| 34 | console.log('\nTest 6: No internet before auth'); | ||
| 35 | const ping1 = run('ping -c 1 -W 3 1.1.1.1 2>/dev/null'); | ||
| 36 | assert(ping1 === null || ping1.includes('100% packet loss'), 'Internet blocked before auth'); | ||
| 37 | |||
| 38 | // Grant access for further tests | ||
| 39 | console.log('\nGranting access...'); | ||
| 40 | run(`curl -s http://${IP}/grant_access`); | ||
| 41 | |||
| 42 | import { execSync as exec } from 'child_process'; | ||
| 43 | await new Promise(r => setTimeout(r, 2000)); | ||
| 44 | |||
| 45 | // Test 10: DNS forward | ||
| 46 | console.log('Test 10: DNS forward after auth'); | ||
| 47 | const ns2 = run(`nslookup google.com ${IP} 2>/dev/null`); | ||
| 48 | assert(ns2 && !ns2.includes(IP) && ns2.includes('Address'), 'DNS resolves to real IPs'); | ||
| 49 | |||
| 50 | // Test 11: Internet | ||
| 51 | console.log('\nTest 11: Internet after auth'); | ||
| 52 | const ping2 = run('ping -c 2 -W 3 8.8.8.8'); | ||
| 53 | assert(ping2 && !ping2.includes('100% packet loss'), 'ping succeeds after auth'); | ||
| 54 | |||
| 55 | // Reset | ||
| 56 | console.log('\nResetting auth...'); | ||
| 57 | run(`curl -s http://${IP}/reset_authentication`); | ||
| 58 | await new Promise(r => setTimeout(r, 2000)); | ||
| 59 | |||
| 60 | // Test 14 | ||
| 61 | console.log('Test 14: Internet blocked after reset'); | ||
| 62 | const ping3 = run('ping -c 1 -W 3 8.8.8.8 2>/dev/null'); | ||
| 63 | assert(ping3 === null || ping3.includes('100% packet loss'), 'Internet blocked after reset'); | ||
| 64 | |||
| 65 | console.log(`\n=== Results: ${passed} passed, ${failed} failed ===\n`); | ||
| 66 | process.exit(failed > 0 ? 1 : 0); | ||