test: unit tests for licensing, LAN IP, TLS identity and rediscovery

- local_backend/tests (pytest, 48 tests, <1s): license token verify/evaluate
  (tamper, other site/key, offline, grace, workday deferral, clock, transition),
  netinfo detection on fake sysfs (VPN/tunnel/WiFi/link-local), LAN-IP
  resolver priority + mismatch + staleness + override validation, TLS
  identity create/restart/renew-same-key/foreign cert (+ openssl pin check)
- waiter_pwa/tests (node --test, 7 tests): subnet candidates, scan picks only
  this venue, early stop, progress
- requirements-dev.txt (pytest), npm test, .pytest_cache ignored

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-28 23:33:16 +03:00
co-authored by Claude Opus 5.5
parent ffca0ace43
commit f00c99fd36
8 changed files with 368 additions and 1 deletions
+2 -1
View File
@@ -10,7 +10,8 @@
"preview": "vite preview",
"build:native": "vite build --mode native && cap sync android",
"apk:debug": "npm run build:native && node scripts/build-apk.mjs debug",
"apk:release": "npm run build:native && node scripts/build-apk.mjs release"
"apk:release": "npm run build:native && node scripts/build-apk.mjs release",
"test": "node --test \"tests/*.test.mjs\""
},
"dependencies": {
"@capacitor/android": "^8.5.2",
+56
View File
@@ -0,0 +1,56 @@
// Server rediscovery scan (src/native/rediscovery.js, plan step 5) — pure logic, fake network.
// Run: npm test
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { scanForVenue, subnetCandidates } from '../src/native/rediscovery.js'
test('same-/24 candidates, nearest first, old host excluded', () => {
const c = subnetCandidates('http://192.168.1.50')
assert.equal(c.length, 253)
assert.deepEqual(c.slice(0, 4), ['http://192.168.1.49', 'http://192.168.1.51', 'http://192.168.1.48', 'http://192.168.1.52'])
assert.ok(!c.includes('http://192.168.1.50'))
})
test('scheme and port are kept (plain HTTP and the TLS entry)', () => {
assert.equal(subnetCandidates('http://10.0.0.7:8080')[0], 'http://10.0.0.6:8080')
assert.equal(subnetCandidates('https://10.0.0.7:8443')[0], 'https://10.0.0.6:8443')
})
test('hostnames and garbage are never scanned', () => {
assert.deepEqual(subnetCandidates('http://waiter.example.gr'), [])
assert.deepEqual(subnetCandidates('not a url'), [])
})
const network = {
'http://192.168.1.12': { app: 'xenia-pos', site_id: 'OTHER-venue', api_version: 1 },
'http://192.168.1.77': { app: 'xenia-pos', site_id: 'MY-venue', api_version: 1 },
}
function fakeProbe() {
const calls = { n: 0 }
const probe = async origin => { calls.n++; await new Promise(r => setTimeout(r, 1)); return network[origin] ?? null }
return { probe, calls }
}
test('finds this venue at its new address and stops early', async () => {
const { probe, calls } = fakeProbe()
assert.equal(await scanForVenue('http://192.168.1.50', 'MY-venue', { probe, concurrency: 8 }), 'http://192.168.1.77')
assert.ok(calls.n < 253)
})
test('another venue\'s server is never chosen', async () => {
const { probe } = fakeProbe()
assert.equal(await scanForVenue('http://192.168.1.50', 'NOBODY', { probe, concurrency: 8 }), null)
})
test('no site id → no scan', async () => {
const { probe, calls } = fakeProbe()
assert.equal(await scanForVenue('http://192.168.1.50', null, { probe }), null)
assert.equal(calls.n, 0)
})
test('progress is reported for every probe', async () => {
const { probe } = fakeProbe()
let progress = 0
await scanForVenue('http://192.168.1.50', 'NOBODY', { probe, concurrency: 16, onProgress: () => progress++ })
assert.equal(progress, 253)
})