upleb.uk

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

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