upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/network.mjs
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-15 17:03:40 +0530
committerYour Name <you@example.com>2026-05-15 17:03:40 +0530
commita7d0a672d59bf8985a6fc0e61b49015fabd96513 (patch)
tree46814d1757649a640f53805a8d9dfc1b0f354289 /tests/network.mjs
parent8a2307a5ced6da94cc674602219d5a68a1246264 (diff)
Phase 1 working: captive portal, DNS hijack, NAT-based access control
- Fix WiFi init order: netif creation before esp_wifi_init, set mode before set_config - Replace broken netif input filter with NAPT on/off per authentication state - NAPT disabled by default, enabled when client granted, disabled on revoke - Fix test helpers: use -I wlp59s0 for ping, handle nslookup exit code 1 - All 20 API tests pass, all 6 smoke tests pass
Diffstat (limited to 'tests/network.mjs')
-rw-r--r--tests/network.mjs66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/network.mjs b/tests/network.mjs
new file mode 100644
index 0000000..2d302ef
--- /dev/null
+++ b/tests/network.mjs
@@ -0,0 +1,66 @@
1import { execSync } from 'child_process';
2
3const IP = process.env.TOLLGATE_IP || '192.168.4.1';
4let passed = 0, failed = 0;
5
6function assert(condition, test) {
7 if (condition) { console.log(` ✓ ${test}`); passed++; }
8 else { console.log(` ✗ ${test}`); failed++; }
9}
10
11function run(cmd) {
12 try { return execSync(cmd, { encoding: 'utf8', timeout: 15000 }); }
13 catch { return null; }
14}
15
16console.log(`\n=== Network Tests (target: ${IP}) ===\n`);
17
18// Test 1: AP visible in scan
19console.log('Test 1: AP visible in scan');
20const scan = run('nmcli -t -f SSID dev wifi list 2>/dev/null');
21assert(scan && scan.includes('TollGate'), 'TollGate SSID visible in WiFi scan');
22
23// Test 2: DHCP lease
24console.log('\nTest 2: DHCP lease / connectivity');
25const ip_show = run(`ip addr show | grep "inet ${IP.split('.').slice(0,3).join('.')}"`);
26assert(ip_show !== null, `Has IP in ${IP.split('.').slice(0,3).join('.')}.* subnet`);
27
28// Test 5: DNS hijack
29console.log('\nTest 5: DNS hijack before auth');
30const ns1 = run(`nslookup random-test.example.com ${IP} 2>/dev/null`);
31assert(ns1 && ns1.includes(IP), 'DNS resolves arbitrary domain to AP IP');
32
33// Test 6: No internet
34console.log('\nTest 6: No internet before auth');
35const ping1 = run('ping -c 1 -W 3 1.1.1.1 2>/dev/null');
36assert(ping1 === null || ping1.includes('100% packet loss'), 'Internet blocked before auth');
37
38// Grant access for further tests
39console.log('\nGranting access...');
40run(`curl -s http://${IP}/grant_access`);
41
42import { execSync as exec } from 'child_process';
43await new Promise(r => setTimeout(r, 2000));
44
45// Test 10: DNS forward
46console.log('Test 10: DNS forward after auth');
47const ns2 = run(`nslookup google.com ${IP} 2>/dev/null`);
48assert(ns2 && !ns2.includes(IP) && ns2.includes('Address'), 'DNS resolves to real IPs');
49
50// Test 11: Internet
51console.log('\nTest 11: Internet after auth');
52const ping2 = run('ping -c 2 -W 3 8.8.8.8');
53assert(ping2 && !ping2.includes('100% packet loss'), 'ping succeeds after auth');
54
55// Reset
56console.log('\nResetting auth...');
57run(`curl -s http://${IP}/reset_authentication`);
58await new Promise(r => setTimeout(r, 2000));
59
60// Test 14
61console.log('Test 14: Internet blocked after reset');
62const ping3 = run('ping -c 1 -W 3 8.8.8.8 2>/dev/null');
63assert(ping3 === null || ping3.includes('100% packet loss'), 'Internet blocked after reset');
64
65console.log(`\n=== Results: ${passed} passed, ${failed} failed ===\n`);
66process.exit(failed > 0 ? 1 : 0);