From a7d0a672d59bf8985a6fc0e61b49015fabd96513 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 15 May 2026 17:03:40 +0530 Subject: 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 --- tests/smoke.mjs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/smoke.mjs (limited to 'tests/smoke.mjs') diff --git a/tests/smoke.mjs b/tests/smoke.mjs new file mode 100644 index 0000000..19f96de --- /dev/null +++ b/tests/smoke.mjs @@ -0,0 +1,52 @@ +import { execSync } from 'child_process'; + +const PORT = process.argv[2] || '/dev/ttyACM0'; +const IP = process.env.TOLLGATE_IP || '192.168.4.1'; +const SSID = process.env.AP_SSID || 'TollGate'; + +console.log(`\n=== Smoke Test (30s) ===`); +console.log(`Port: ${PORT}, Portal IP: ${IP}, SSID: ${SSID}\n`); + +let passed = 0, failed = 0; +function assert(cond, msg) { + if (cond) { console.log(` ✓ ${msg}`); passed++; } + else { console.log(` ✗ ${msg}`); failed++; } +} + +function run(cmd) { + try { return execSync(cmd, { encoding: 'utf8', timeout: 10000 }); } + catch { return null; } +} + +// 1. Check AP visible +const scan = run('nmcli -t -f SSID dev wifi list 2>/dev/null'); +assert(scan && scan.includes(SSID), `SSID "${SSID}" visible`); + +// 2. Check we can reach portal +const portal = run(`curl -s --connect-timeout 5 http://${IP}/`); +assert(portal && portal.includes('TollGate'), 'Portal HTML loads'); + +// 3. Grant access +const grant = run(`curl -s http://${IP}/grant_access`); +assert(grant && grant.includes('granted'), 'Grant access works'); + +// Wait for DNS +const sleep = ms => new Promise(r => setTimeout(r, ms)); +await sleep(2000); + +// 4. Internet works +const ping = run('ping -c 1 -W 3 -I wlp59s0 1.1.1.1 2>/dev/null'); +assert(ping && !ping.includes('100% packet loss'), 'Internet works after grant'); + +// 5. Reset +const reset = run(`curl -s http://${IP}/reset_authentication`); +assert(reset && reset.includes('reset'), 'Reset auth works'); + +await sleep(2000); + +// 6. Internet blocked +const ping2 = run('ping -c 1 -W 3 -I wlp59s0 1.1.1.1 2>/dev/null'); +assert(!ping2 || ping2.includes('100% packet loss'), 'Internet blocked after reset'); + +console.log(`\n=== Smoke: ${passed} passed, ${failed} failed ===\n`); +process.exit(failed > 0 ? 1 : 0); -- cgit v1.2.3