diff options
Diffstat (limited to 'tests/integration/smoke.mjs')
| -rw-r--r-- | tests/integration/smoke.mjs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/integration/smoke.mjs b/tests/integration/smoke.mjs new file mode 100644 index 0000000..f89eeac --- /dev/null +++ b/tests/integration/smoke.mjs | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | import { execSync } from 'child_process'; | ||
| 2 | |||
| 3 | const PORT = process.argv[2] || '/dev/ttyACM0'; | ||
| 4 | const IP = process.env.TOLLGATE_IP || '10.192.45.1'; | ||
| 5 | const SSID = process.env.AP_SSID || 'TollGate'; | ||
| 6 | |||
| 7 | console.log(`\n=== Smoke Test (30s) ===`); | ||
| 8 | console.log(`Port: ${PORT}, Portal IP: ${IP}, SSID: ${SSID}\n`); | ||
| 9 | |||
| 10 | let passed = 0, failed = 0; | ||
| 11 | function assert(cond, msg) { | ||
| 12 | if (cond) { console.log(` ✓ ${msg}`); passed++; } | ||
| 13 | else { console.log(` ✗ ${msg}`); failed++; } | ||
| 14 | } | ||
| 15 | |||
| 16 | function run(cmd) { | ||
| 17 | try { return execSync(cmd, { encoding: 'utf8', timeout: 10000 }); } | ||
| 18 | catch { return null; } | ||
| 19 | } | ||
| 20 | |||
| 21 | // 1. Check AP visible | ||
| 22 | const scan = run('nmcli -t -f SSID dev wifi list 2>/dev/null'); | ||
| 23 | assert(scan && scan.includes(SSID), `SSID "${SSID}" visible`); | ||
| 24 | |||
| 25 | // 2. Check we can reach portal | ||
| 26 | const portal = run(`curl -s --connect-timeout 5 http://${IP}/`); | ||
| 27 | assert(portal && portal.includes('TollGate'), 'Portal HTML loads'); | ||
| 28 | |||
| 29 | // 3. Grant access | ||
| 30 | const grant = run(`curl -s http://${IP}/grant_access`); | ||
| 31 | assert(grant && grant.includes('granted'), 'Grant access works'); | ||
| 32 | |||
| 33 | // Wait for DNS | ||
| 34 | const sleep = ms => new Promise(r => setTimeout(r, ms)); | ||
| 35 | await sleep(2000); | ||
| 36 | |||
| 37 | // 4. Internet works | ||
| 38 | const ping = run('ping -c 1 -W 3 -I wlp59s0 1.1.1.1 2>/dev/null'); | ||
| 39 | assert(ping && !ping.includes('100% packet loss'), 'Internet works after grant'); | ||
| 40 | |||
| 41 | // 5. Reset | ||
| 42 | const reset = run(`curl -s http://${IP}/reset_authentication`); | ||
| 43 | assert(reset && reset.includes('reset'), 'Reset auth works'); | ||
| 44 | |||
| 45 | await sleep(2000); | ||
| 46 | |||
| 47 | // 6. Internet blocked | ||
| 48 | const ping2 = run('ping -c 1 -W 3 -I wlp59s0 1.1.1.1 2>/dev/null'); | ||
| 49 | assert(!ping2 || ping2.includes('100% packet loss'), 'Internet blocked after reset'); | ||
| 50 | |||
| 51 | console.log(`\n=== Smoke: ${passed} passed, ${failed} failed ===\n`); | ||
| 52 | process.exit(failed > 0 ? 1 : 0); | ||