upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests/integration/api.mjs
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-17 17:18:43 +0530
committerYour Name <you@example.com>2026-05-17 17:18:43 +0530
commit8071741815f0b0938701e80a63e80b0ec94b2778 (patch)
tree2a1511480e0b58f4efb144aa9d10c9fba5eed034 /tests/integration/api.mjs
parent0c2c67b463d6a90aaa0bb69bf3c91dba1d9ec3ec (diff)
refactor: reorganize test suite, add integration tests for NAT filter
- Move integration tests (api, network, phase2, smoke) to tests/integration/ - Move Playwright specs (captive-portal, interop-happy-path) to tests/e2e/ - Move playwright.config.mjs to tests/e2e/ - Fix hardcoded IP fallbacks: 192.168.4.1 → 10.192.45.1 - Add test-reset-auth.mjs: reset→pay→allow→revoke→block cycle - Add test-session-expiry.mjs: pay→wait 65s→verify blocked (slow test) - Add test-dns-firewall.mjs: DNS hijack/forward + per-client NAT filter - Update Makefile with test-unit, test-integration, test-e2e, test-all targets - Update package.json scripts for new paths - Fix Playwright video: retain-on-failure instead of always-on - Update AGENTS.md: per-client NAT filter description - Update CHECKLIST.md: mark completed items, add Board B identity - Board B nsec: 9af47906... → SSID TollGate-b96d80, AP IP 10.185.47.1 - 186 unit tests passing
Diffstat (limited to 'tests/integration/api.mjs')
-rw-r--r--tests/integration/api.mjs79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/integration/api.mjs b/tests/integration/api.mjs
new file mode 100644
index 0000000..5218d7b
--- /dev/null
+++ b/tests/integration/api.mjs
@@ -0,0 +1,79 @@
1import { curl, curlBody, getPortalIP, canPing, canResolve, dnsResolvesToSelf } from './helpers/network.mjs';
2
3const IP = getPortalIP();
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
11async function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }
12
13console.log(`\n=== API Tests (target: ${IP}) ===\n`);
14
15// Test 3: Captive portal serves HTML
16console.log('Test 3: GET / returns portal HTML');
17const body3 = curlBody(`http://${IP}/`);
18assert(body3 && body3.includes('TollGate'), 'Portal HTML contains "TollGate"');
19assert(body3 && body3.includes('Grant Free Access'), 'Portal has Grant Access button');
20
21// Test 4: Captive detection URIs
22console.log('\nTest 4: Captive detection URIs');
23for (const uri of ['/generate_204', '/hotspot-detect.html', '/canonical.html', '/success.txt', '/ncsi.txt', '/connecttest.txt', '/wpad.dat', '/redirect']) {
24 const code = curl(`http://${IP}${uri}`);
25 assert(code === '200', `${uri} → 200`);
26}
27
28// Test 7: /whoami returns MAC
29console.log('\nTest 7: GET /whoami');
30const body7 = curlBody(`http://${IP}/whoami`);
31assert(body7 && body7.startsWith('mac='), '/whoami returns mac=...');
32
33// Test 8: /usage returns no session
34console.log('\nTest 8: GET /usage');
35const body8 = curlBody(`http://${IP}/usage`);
36assert(body8 && body8.includes('-1/-1'), '/usage returns -1/-1 before auth');
37
38// Test 5: DNS hijack before auth
39console.log('\nTest 5: DNS hijack before auth');
40assert(dnsResolvesToSelf('google.com'), 'DNS resolves google.com to AP IP');
41
42// Test 6: No internet before auth
43console.log('\nTest 6: No internet before auth');
44assert(!canPing('8.8.8.8', 1), 'ping 8.8.8.8 fails before auth');
45
46// Test 9: Grant access
47console.log('\nTest 9: GET /grant_access');
48const body9 = curlBody(`http://${IP}/grant_access`);
49assert(body9 && body9.includes('"granted"'), 'Grant access returns {"status":"granted"}');
50
51await sleep(2000);
52
53// Test 10: DNS forward after auth
54console.log('\nTest 10: DNS forward after auth');
55assert(canResolve('google.com'), 'DNS resolves normally after auth');
56
57// Test 11: Internet after auth
58console.log('\nTest 11: Internet after auth');
59assert(canPing('8.8.8.8'), 'ping 8.8.8.8 succeeds after auth');
60
61// Test 12: HTTP browsing works
62console.log('\nTest 12: HTTP browsing');
63const body12 = curlBody('http://example.com/');
64assert(body12 && (body12.includes('Example Domain') || body12.includes('example')), 'HTTP page loads');
65
66// Test 13: Reset auth
67console.log('\nTest 13: GET /reset_authentication');
68const body13 = curlBody(`http://${IP}/reset_authentication`);
69assert(body13 && body13.includes('"reset"'), 'Reset returns {"status":"reset"}');
70
71await sleep(2000);
72
73// Test 14: Internet blocked after reset
74console.log('\nTest 14: Internet blocked after reset');
75assert(!canPing('8.8.8.8', 1), 'ping fails after auth reset');
76
77// Summary
78console.log(`\n=== Results: ${passed} passed, ${failed} failed ===\n`);
79process.exit(failed > 0 ? 1 : 0);