Files
dawnline/tests/ucode/devices.test.uc
T
Aemeath f8130e39a8
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
Dawnline 0.18.0
- Add V2RayTun to a device's set-up on Android: its awg:// link as a code and to copy, in the portal and in the admin (phones, tablets and other devices), with the server's IP, which its Android app needs; not with the Maximum disguise. Its Windows app is ready but stays off until it gives the tunnel the server's DNS.
- Portal: show V2RayTun's Telegram channel beside Google Play.
- Make WireGuard part of AmneziaWG's choice when the disguise is off: the same file and code, both apps named in the steps, WireGuard's store a tap away; a router still picks its package.
- Portal: Reconnect asks again what the device is and about LAN Bypass, and LAN Bypass switches from a device's ⋯ menu, in a group of its own between the copy actions and Rename, Reconnect, Remove (the keys stay; the device takes its updated configuration).
- Turn LAN Bypass on by default for new devices, in the portal and the admin.
- Portal: an app's name too long for the picker fades at its edge and glides to its end on hover or tap; two store buttons stack where they do not fit side by side; the month chart's "Today" stays inside its axis.
- Write to the router's system log by level (Settings → Logs & history → System log: errors, warnings, normal, verbose): the service starting and stopping, every apply with its time, network, firewall, nftables and peer changes, changed settings and portal errors, in English whatever the admin's language, with keys masked.
- Activity: say what a device's change on the portal was (LAN Bypass on or off, its type).
- Demo: build again after a force-pushed main instead of failing on the commit that is gone.
2026-11-05 13:56:20 +03:00

87 lines
4.0 KiB
Ucode

// The admin's device methods (dawnline.rpc.people over dawnline.devices): what
// counts as handing a configuration out, and New keys as setting the device up
// again. The real calls on the fixture: the stand-in awg makes the keys, the
// sync's nft and awg steps fail harmlessly in the container. /etc/config/dawnline
// and the issued and reconnect marks are put back after.
import { readfile, writefile, unlink } from 'fs';
import { DATA_DIR, RUN_DIR, ensure_dir } from 'dawnline.util';
import * as core from 'dawnline.core';
import * as awg from 'dawnline.awg';
import * as people from 'dawnline.rpc.people';
import * as devices from 'dawnline.devices';
const CONFIG = '/etc/config/dawnline';
const ISSUED = `${DATA_DIR}/issued.json`;
const RECONNECT = `${DATA_DIR}/reconnect.json`;
const EVENTS = `${RUN_DIR}/events.json`;
// fn(), then the files as they were, whatever fn did.
function kept(paths, fn) {
let had = map(paths, (p) => readfile(p));
let err = null;
try {
fn();
}
catch (e) {
err = e;
}
for (let i = 0; i < length(paths); i++)
had[i] == null ? unlink(paths[i]) : writefile(paths[i], had[i]);
if (err)
die(err.message ?? `${err}`);
}
function call(name, args) {
return people.methods[name].call({ args });
}
test('device_config: a look marks nothing, a delivery does', () => {
ensure_dir(DATA_DIR, 0o700);
kept([ ISSUED ], () => {
let old = sprintf('%J', { alice_phone: '00000000' });
writefile(ISSUED, old);
ok(index(call('device_config', { id: 'alice_phone' }).conf ?? '', '[Peer]') >= 0, 'the configuration comes back');
eq(readfile(ISSUED), old, 'without issue: issued.json left alone');
call('device_config', { id: 'alice_phone', issue: false });
eq(readfile(ISSUED), old, 'issue false: the same');
call('device_config', { id: 'alice_phone', issue: true });
let m = core.load();
eq(awg.issued().alice_phone, awg.config_fingerprint(m, m.devices.alice_phone), 'issue: what it holds now counts as handed out');
eq(call('device_config', { id: 'nobody', issue: true }).error, 'Unknown device.', 'an unknown device');
});
});
test('device_rotate: New keys set the device up again', () => {
kept([ CONFIG, ISSUED, RECONNECT ], () => {
unlink(RECONNECT);
let before = core.load().devices.alice_phone;
let t0 = time();
let c = call('device_rotate', { id: 'alice_phone' });
ok(c.error == null && index(c.conf ?? '', '[Peer]') >= 0, `the new configuration comes back (${c.error})`);
let m = core.load();
ok(m.devices.alice_phone.preshared_key != before.preshared_key, 'new keys');
let at = awg.reconnects().alice_phone;
ok(at >= t0 && at <= time(), `a reconnect mark at the rotation (${at})`);
eq(awg.handshake_since(t0 - 30, at), 0, "the old keys' last handshake no longer counts: Not set up yet, with Connect");
eq(awg.issued().alice_phone, awg.config_fingerprint(m, m.devices.alice_phone), 'its new configuration is the one handed out');
});
eq(core.load().devices.alice_phone.private_key, '', 'the fixture is back');
});
test('portal: Reconnect changes what it is and LAN Bypass with the keys; LAN Bypass alone keeps them', () => {
ensure_dir(RUN_DIR);
kept([ CONFIG, ISSUED, RECONNECT, EVENTS ], () => {
let mine = { by: 'portal', person: 'alice' };
devices.reconnect('alice_phone', { ...mine, kind: 'tablet', lan_bypass: true });
let d = core.load().devices.alice_phone;
eq([ d.kind, d.lan_bypass ], [ 'tablet', true ], 'changed in the same write as the keys');
let keys = d.public_key;
devices.update('alice_phone', { lan_bypass: false }, mine);
d = core.load().devices.alice_phone;
eq([ d.lan_bypass, d.public_key ], [ false, keys ], 'LAN Bypass off, the keys as they were');
throws(() => devices.update('alice_phone', { mtu: '1400' }, mine), /^Only the admin can change how a device connects\.$/, "the MTU stays the admin's");
throws(() => devices.reconnect('alice_phone', { ...mine, kind: 'toaster' }), /^Unknown device type\.$/, 'not a kind');
throws(() => devices.update('alice_phone', { lan_bypass: true }, { by: 'portal', person: 'bob' }), /^Device not found\.$/, "another person's device");
});
});