Dawnline 0.14.0
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

- A device is renamed where its name stands on its card: a click on the
  name, Return or Space on it, or Rename in the ⋯ menu turns it into a
  field with the name selected. Return saves, and the words shimmer until
  the router answers. Esc or a click elsewhere puts the old name back. The
  rename window is gone, and the page no longer redraws under a name being
  edited
- Device names take up to 20 characters: letters of any language, digits,
  spaces and - _ . The router refuses anything else when a device is added
  or renamed, so a name can't carry symbols into configurations, file
  names or the AmneziaVPN key. The portal and the admin turn a character
  like that away as it is typed: the field shakes, its outline goes red
  and a short line says why. Suggested names (a phone's model, "Phone 2")
  are stripped of such characters and cut to fit. Names set before this
  stay as they are
- LAN Bypass: Add a device, in the portal and in the admin, has a switch
  that keeps the device's own local network (printer, TV, NAS) reachable
  while it is connected. It is off by default and stays as chosen; the
  admin's device drawer shows it. With home and internet access the switch
  says which addresses still lead to the home network
- Health warns when a server's home network is on one of the subnets home
  routers come with (192.168.0.x, 192.168.1.x and others). People with
  home access who connect from a network on the same addresses reach your
  home instead of their own, LAN Bypass or not
- The router tells when a device can't connect properly. After the problem
  lasts three minutes, the portal card and the admin drawer name it:
  can't finish connecting (the network may block it), connected but no
  data (an outdated configuration, and the card offers Reconnect), on two
  devices at once, or a connection that keeps dropping. Activity lists
  these under Problems, one line per device per hour, and says when the
  device connects normally again
- The set-up sheet's connection line follows what the device does:
  waiting, can't finish, connected, or connected but no data. The sheet
  closes by itself only once data comes through. On the device itself and
  for a router, the steps regroup to what fixes the problem: "Set it up
  again" when the handshake never finishes, "Add the connection again"
  ("Import the configuration again" for a router) when no data comes
- Set-up in the portal: a QR code too long for a camera to read gives its
  place to a code that opens the set-up link (a LAN Bypass configuration
  or a long AmneziaVPN key can be that long). A TV, box or NAS added from
  a phone gets the steps for setting up from another device. Back from
  "Open on the device" keeps the kind, LAN Bypass and the name typed. The
  packet-size note under the kinds is gone
- The portal on phones keeps its place: nothing jumps when an access row
  opens or folds, a notice comes or goes, or Safari redraws the cards. A
  reload, or coming back from the VPN app, opens where the page was. Cards
  glide to their new height, and an animation interrupted half-way goes on
  from where it is instead of snapping. A double click no longer closes
  the sheet it just opened
- In the admin, a device's drawer has its own MTU and keep-alive (empty
  means the server's), each with a Change dialog. A change touches only
  that device's configuration and restarts nothing on the router. Opening
  the drawer no longer counts as handing out the configuration: "Update
  config" stays until the new configuration is shown as a QR code,
  downloaded or copied ("Show the new configuration"). New keys set the
  device up again, as the portal's Reconnect does
- "Speed now" on a server's Overview is live: one point a second over the
  last two minutes, all there as soon as the Overview opens. The agent
  keeps those two minutes in memory and writes them out only while someone
  is looking
- Disguise values that AmneziaWG refuses or crashes on are stopped before
  they reach the kernel. That covers overlapping H1-H4, Jmin above Jmax,
  broken I1-I5 tags, padding under 12 with header protection, and more.
  Import and restore refuse them. After a hand edit in uci, the server's
  tunnel stays down and Health and the service log say why and what to do.
  Errors are full sentences in the reader's language
- The header protection key no longer shows in the status that read-only
  users can see: the Server page says only that the key is set, and each
  device's configuration still has it. The server no longer turns off
  WireGuard's protection against handshake floods (devices keep
  DisableCookies). A device can't be added with a server's own key
- An AmneziaWG update whose kernel module can't be swapped (another
  AmneziaWG interface holds the old one) no longer fails. It is installed,
  the tunnels come back on the old module, and Health and Components say
  the update starts after a reboot. On apk firmware, an install that apk
  left at the old version counts as failed. A module installed by hand is
  recorded, so after a firmware upgrade Health can tell that it is gone
- Dawnline reads only its own tunnels, each one separately. Another
  AmneziaWG interface on the router no longer slows the agent's
  once-a-second check, has its keys read or breaks Dawnline's reads. A
  portal request reads only that person's server: one process however many
  servers there are
- Fewer false disconnects: a tunnel that netifd sets up again no longer
  logs everyone as leaving and coming back, and a device with a long
  keep-alive stays online between handshakes. One configuration on two
  devices isn't logged as roaming every few seconds, and new keys end the
  old session at once. A tunnel that is missing devices is synced within a
  minute, and traffic across a tunnel restart is no longer undercounted
- Renaming a server no longer restarts its tunnel. If a tunnel's interface
  is edited outside Dawnline (LuCI, uci), the watchdog sets it up again
  with Dawnline's settings and names only the changed options. The routing
  rules for "Internet like a home device" change one at a time, new ones
  first, so traffic never falls between them. Health and the Server page
  warn when the address's AAAA record isn't this router's, or the router
  has no public IPv6: devices that prefer IPv6 fail to connect
- The README screenshots come in English and Russian; the portal's are
  taken from its demo. The demo has a switch beside × in the set-up sheet
  to show each state of the connection line. In Russian, long labels in
  the admin's wide option buttons wrap under their icon. DESIGN.md
  describes the switch, renaming on the card, the shimmer, the shake and
  how the portal scrolls. New tests cover link states, the meter, access,
  Health, firewall rules, network settings and packages
This commit is contained in:
Aemeath committed 2026-10-22 00:11:50 +03:00
1 parent 58492be021
commit dc0f159447
155 files changed
+11062 -1461

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
// dawnline.access: the Check access walk for a device that keeps its own
// local network out of the tunnel (lan_bypass), and the way its internet
// leaves, on a model and a network snapshot of the test's own (nothing read
// from the container).
import * as access from 'dawnline.access';
const KEY_TV = 'a8Z2wq0b8rQx3mN6kYyQ2G3bQm2kq5tY5m7Q0yq3m3c=', KEY_PHONE = 'b8Z2wq0b8rQx3mN6kYyQ2G3bQm2kq5tY5m7Q0yq3m3c=';
/** Bob (Internet only) on a server that sends everyone direct: a TV with lan_bypass and a phone without. */
function model() {
return {
settings: { portal_enabled: false },
servers: {
home: { id: 'home', name: 'Home', ifname: 'awghome', subnet: '10.9.0.0/29', private_key: 'k', enabled: true, lan_like: false,
auto_wan: false, wan_device: 'eth1', auto_lan: false, lan_devices: [ 'br-lan' ], mesh: 'all', device_mesh: true, dns: [] },
},
people: { bob: { id: 'bob', name: 'Bob', server: 'home', access: 'internet', services: [], devices: [ 'tv', 'phone' ] } },
devices: {
tv: { id: 'tv', person: 'bob', name: 'TV', address: '10.9.0.2', public_key: KEY_TV, lan_bypass: true },
phone: { id: 'phone', person: 'bob', name: 'Phone', address: '10.9.0.3', public_key: KEY_PHONE, lan_bypass: false },
},
services: {},
circles: {},
};
}
const CTX = {
states: { bob: 'active' },
dmp: { peers: {}, windows: {} },
snap: {
devices: {
'br-lan': { nets: [ '192.168.1.0/24' ], zone: 'lan', addrs: [ '192.168.1.1/24' ] },
eth1: { nets: [ '203.0.113.0/24' ], zone: 'wan', addrs: [ '203.0.113.7/24' ] },
awghome: { nets: [ '10.9.0.0/29' ], addrs: [ '10.9.0.1/29' ] },
},
lan: 'br-lan',
wan: 'eth1',
},
};
function last(r) {
return r.steps[length(r.steps) - 1];
}
test('check: a device with its local network outside the tunnel', () => {
let m = model();
let r = access.check(m, 'tv', '192.168.1.20', CTX);
eq([ r.ok, last(r).ok, last(r).title ], [ false, false, "Its configuration doesn't send it to the router" ],
'a home address: on its own network, not blocked in the tunnel');
ok(index(last(r).detail, "the device's own network handles it") >= 0, 'says where it goes');
r = access.check(m, 'tv', '192.168.1.1:80', CTX);
eq(last(r).title, "Its configuration doesn't send it to the router", 'the router\'s LAN address is on its own network too');
r = access.check(m, 'tv', '10.9.0.1:53', CTX);
eq([ r.ok, r.steps[1].title ], [ true, '10.9.0.1 is this router: DNS is open to everyone' ], 'its DNS stays in the tunnel');
r = access.check(m, 'tv', '8.8.8.8', CTX);
eq([ r.ok, last(r).title, last(r).detail ], [ true, '8.8.8.8 is on the internet', 'It leaves through eth1.' ], 'the internet through the tunnel');
r = access.check(m, 'phone', '192.168.1.20', CTX);
eq([ r.ok, last(r).title ], [ false, '192.168.1.20 is at home (br-lan)' ], 'without it: into the tunnel, and blocked there');
});
test('check: the way out is the server\'s', () => {
let m = model();
eq(last(access.check(m, 'phone', '8.8.8.8', CTX)).detail, 'It leaves through eth1.', 'direct');
m.servers.home.lan_like = true;
eq(last(access.check(m, 'phone', '8.8.8.8', CTX)).detail, 'It leaves like a home device would.', 'like a home device');
});
+429 -28
View File
@@ -1,10 +1,18 @@
// dawnline.awg: disguise presets against their own validation, the parser
// of `awg show all dump` on the output formats of AmneziaWG 1.0, 2.0 and 3.1
// (the stand-in awg in fixtures/bin prints the fixture put at AWG_DUMP),
// Reconnect, and a device's configuration from the fixture model.
// dawnline.awg: disguise presets against their own validation, the values
// AmneziaWG refuses (obf_unsafe, one case per rule), the parser of `awg show
// <ifname> dump` on the output formats of AmneziaWG 1.0, 2.0 and 3.1 and how
// each tunnel's read went (the stand-in awg in fixtures/bin prints the
// fixture put at AWG_DUMP), the devices a tunnel should hold, Reconnect, a
// device's configuration from the fixture model, what the server's interface
// and the read-only status get of it.
import { readfile, writefile, unlink } from 'fs';
import { cursor } from 'uci';
import { valid_key, cidr_any } from 'dawnline.util';
import * as awg from 'dawnline.awg';
import * as core from 'dawnline.core';
import * as backup from 'dawnline.backup';
import * as rpc_status from 'dawnline.rpc.status';
import * as nft from 'dawnline.nft';
const AWG_DUMP = '/tmp/dawnline-tests/awg-dump';
let fixtures = sourcepath(0, true) + '/fixtures';
@@ -34,7 +42,8 @@ test('obf_preset balanced', () => {
test('obf_preset max', () => {
let o = awg.obf_preset('max');
eq(o.header_protection_key, 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=', 'key from awg genkey');
ok(valid_key(o.header_protection_key), 'a header protection key');
ok(o.header_protection_key != awg.obf_preset('max').header_protection_key, 'made for each server, without awg genkey');
ok(+o.jc >= 4 && +o.jc <= 6, 'jc');
ok(substr(o.i1, 0, 3) == '<r ', 'DNS-like first packet');
eq([ o.random_trailers, o.disable_cookies, o.content_padding_addition ], [ 'on', 'on', '10-100' ], '3.1 options');
@@ -46,55 +55,279 @@ test('obf_preset max', () => {
shapes[awg.obf_preset('max').i1] = true;
ok(length(keys(shapes)) > 1, 'signature packets differ between servers');
// The preset passes the server's own validation (jmin/jmax may be small: 0.5.2).
eq(awg.obf_errors(o), [], 'max is valid');
for (let i = 0; i < 25; i++)
eq(awg.obf_errors(awg.obf_preset('max')), [], 'max is valid');
});
test('obf_errors', () => {
test('obf_errors: Dawnline\'s own bounds on top of obf_unsafe', () => {
eq(awg.obf_errors({}), [], 'nothing set');
eq(awg.obf_errors({ jc: '11' }), [ 'jc=11 (0-10)' ], 'jc range');
eq(awg.obf_errors(null), [], 'no values');
eq(awg.obf_errors({ jc: '11' }), [ 'Jc must be from 0 to 10.' ], 'jc range');
eq(awg.obf_errors({ jmin: '0', jmax: '0' }), [], 'zero junk sizes are allowed');
eq(awg.obf_errors({ jmin: '2000' }), [ 'jmin=2000 (0-1024)' ], 'jmin range');
eq(awg.obf_errors({ jmin: '200', jmax: '100' }), [ 'jmin > jmax' ], 'order');
eq(awg.obf_errors({ s1: '5', s2: '61' }), [ 's1 + 56 = s2' ], 'the handshake size clash');
eq(awg.obf_errors({ s4: '33' }), [ 's4=33 (0-32)' ], 's4 range');
eq(awg.obf_errors({ jc: 'x' }), [ 'jc=x (0-10)' ], 'not a number');
eq(awg.obf_errors({ h1: '7', h2: '7' }), [ 'h1-h4 must be distinct' ], 'duplicate headers');
eq(awg.obf_errors({ h1: '7-9', h2: 'abc' }), [ 'h2 must be a number or range' ], 'header ranges');
eq(awg.obf_errors({ jmin: '2000', jmax: '3000' }), [ 'Jmin must be from 0 to 1024.', 'Jmax must be from 0 to 1024.' ], 'junk sizes');
eq(awg.obf_errors({ s1: '5', s2: '61' }), [ 'S2 must not be S1 + 56: the handshake initiation and response would have the same size.' ],
'the handshake size clash');
eq(awg.obf_errors({ s4: '33' }), [ 'S4 must be from 0 to 32.' ], 's4 range');
// What AmneziaWG refuses comes first, said once.
eq(awg.obf_errors({ jc: 'x' }), [ 'Jc must be a whole number from 0 to 65535.' ], 'not a number');
eq(awg.obf_errors({ jmin: '200', jmax: '100' }), [ 'Jmin must not be larger than Jmax.' ], 'order');
eq(awg.obf_errors({ h1: '7', h2: '7' }), [ 'H1 and H2 overlap: each packet type needs values of its own.' ], 'duplicate headers');
eq(awg.obf_neutral({ jc: '0', jmin: '0', jmax: '0', s1: '0', s2: '0', h1: '1', h2: '2', h3: '3', h4: '4' }), true, 'off is neutral');
eq(awg.obf_neutral({ jc: '4', jmin: '64', jmax: '128' }), false, 'junk is not neutral');
});
// One case per rule of obf_unsafe: what an import, a restore or a hand edit must never hand to the kernel.
const HPK = 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=';
const MAX = { s1: '12', s2: '12', s3: '12', s4: '12', header_protection_key: HPK };
test('obf_unsafe: what the presets and older servers hold passes', () => {
eq(awg.obf_unsafe(null), [], 'no values');
eq(awg.obf_unsafe(awg.obf_preset('off')), [], 'off');
for (let i = 0; i < 25; i++) {
eq(awg.obf_unsafe(awg.obf_preset('balanced')), [], 'balanced');
eq(awg.obf_unsafe(awg.obf_preset('max')), [], 'max');
}
// Values from before 0.8 and hand-tuned ones the kernel takes: none of Dawnline's own bounds here.
let old = { jc: '12', jmin: '50', jmax: '1400', s1: '100', s2: '156', h1: '1234567', h2: '2345678', h3: '3456789', h4: '4567890' };
eq(awg.obf_unsafe(old), [], 'older and hand-tuned values');
ok(length(awg.obf_errors(old)) > 0, 'which a new server would not get');
});
test('obf_unsafe: 16-bit numbers', () => {
eq(awg.obf_unsafe({ jc: '65535', s4: '0' }), [], 'the ends');
eq(awg.obf_unsafe({ jc: '65536' }), [ 'Jc must be a whole number from 0 to 65535.' ], 'too large');
eq(awg.obf_unsafe({ s3: '-1' }), [ 'S3 must be a whole number from 0 to 65535.' ], 'negative');
eq(awg.obf_unsafe({ jmax: '1e3' }), [ 'Jmax must be a whole number from 0 to 65535.' ], 'not digits');
});
test('obf_unsafe: Jmin not above Jmax', () => {
eq(awg.obf_unsafe({ jmin: '50', jmax: '50' }), [], 'equal');
eq(awg.obf_unsafe({ jmin: '51', jmax: '50' }), [ 'Jmin must not be larger than Jmax.' ], 'the kernel would write past its junk buffer');
eq(awg.obf_unsafe({ jmin: '51' }), [], 'Jmax not given');
});
test('obf_unsafe: header values are numbers or ranges', () => {
eq(awg.obf_unsafe({ h1: '100-200', h2: '300', h3: '4294967295', h4: '0' }), [], 'numbers and ranges');
eq(awg.obf_unsafe({ h1: '200-100' }), [ 'H1 must be a number or a range like 100-200, up to 4294967295.' ], 'reversed');
eq(awg.obf_unsafe({ h2: '4294967296' }), [ 'H2 must be a number or a range like 100-200, up to 4294967295.' ], 'past 32 bits');
eq(awg.obf_unsafe({ h3: '5-6-7' }), [ 'H3 must be a number or a range like 100-200, up to 4294967295.' ], 'two dashes');
eq(awg.obf_unsafe({ h4: 'abc' }), [ 'H4 must be a number or a range like 100-200, up to 4294967295.' ], 'not a number');
});
test('obf_unsafe: header values do not overlap', () => {
eq(awg.obf_unsafe({ h1: '10-20', h2: '20-30', h3: '40', h4: '50' }), [ 'H1 and H2 overlap: each packet type needs values of its own.' ], 'a shared end');
eq(awg.obf_unsafe({ h1: '10-20', h2: '30', h3: '15', h4: '50' }), [ 'H1 and H3 overlap: each packet type needs values of its own.' ], 'one inside a range');
// One not given keeps WireGuard's type: 1-4.
eq(awg.obf_unsafe({ h1: '1-10' }), [ 'H1 and H2 overlap: each packet type needs values of its own.', 'H1 and H3 overlap: each packet type needs values of its own.',
'H1 and H4 overlap: each packet type needs values of its own.' ], 'over the default types');
eq(awg.obf_unsafe({ h1: '5-10' }), [], 'clear of them');
});
test('obf_unsafe: header protection needs a key and 12-byte padding', () => {
eq(awg.obf_unsafe(MAX), [], 'the 3.1 values');
eq(awg.obf_unsafe({ ...MAX, header_protection_key: 'abc' }), [ 'The header protection key is not a key.' ], 'not a key');
eq(awg.obf_unsafe({ ...MAX, s3: '11' }), [ 'S3 must be at least 12 with header protection.' ], 'too little padding');
eq(awg.obf_unsafe({ ...MAX, s4: null }), [ 'S4 must be at least 12 with header protection.' ], 'no padding');
eq(awg.obf_unsafe({ s1: '0', s2: '0' }), [], 'none needed without the key');
});
test('obf_unsafe: 3.1 timers and counts', () => {
eq(awg.obf_unsafe({ rekey_after_time: '100-120', rekey_timeout: '3', keepalive_timeout: '0', max_handshake_attempts: '0-0' }), [],
'numbers, ranges and 0 (the default)');
eq(awg.obf_unsafe({ rekey_timeout: '0-7' }), [ 'RekeyTimeout must be a number or a range like 5-15, from 1 to 65535.' ], 'a 0 in a range');
eq(awg.obf_unsafe({ keepalive_timeout: '15-5' }), [ 'KeepaliveTimeout must be a number or a range like 5-15, from 1 to 65535.' ], 'reversed');
eq(awg.obf_unsafe({ max_handshake_attempts: '70000' }), [ 'MaxHandshakeAttempts must be a number or a range like 5-15, from 1 to 65535.' ], 'past 16 bits');
eq(awg.obf_unsafe({ content_padding_addition: '0-100' }), [], 'padding may start at 0');
eq(awg.obf_unsafe({ content_padding_addition: '10-x' }), [ 'ContentPaddingAddition must be a number or a range like 10-100, up to 65535.' ], 'padding');
});
test('obf_unsafe: RejectAfterTime up to 180 seconds', () => {
eq(awg.obf_unsafe({ reject_after_time: '150-180' }), [], 'the preset');
eq(awg.obf_unsafe({ reject_after_time: '150-181' }), [ 'RejectAfterTime must be at most 180 seconds.' ], 'the kernel drops keys after 180 seconds');
});
test('obf_unsafe: switches', () => {
eq(awg.obf_unsafe({ random_trailers: 'on', disable_cookies: '0' }), [], 'on, off, 1, 0');
eq(awg.obf_unsafe({ random_trailers: 'yes' }), [ 'RandomTrailers must be on or off.' ], 'what the .conf parser refuses');
eq(awg.obf_unsafe({ disable_cookies: 'true' }), [ 'DisableCookies must be on or off.' ], 'the same for cookies');
});
test('obf_unsafe: signature packet tags', () => {
let bad = (name, tag) => `${name}: <${tag}> is not a tag AmneziaWG apps accept: use <b 0x…> with an even number of hex digits, <r N>, <rc N> or <rd N> with N from 1 to 1000, or <t>.`;
eq(awg.obf_unsafe({ i1: '<b 0xC0ffee><r 1><rc 1000><rd 12><t>', i2: 'text between tags <r 2> is skipped' }), [], 'every tag both parsers know');
eq(awg.obf_unsafe({ i1: '<b 0xabc>' }), [ bad('I1', 'b 0xabc') ], 'an odd number of hex digits');
eq(awg.obf_unsafe({ i1: '<b 0x>' }), [ bad('I1', 'b 0x') ], 'no bytes');
eq(awg.obf_unsafe({ i1: '<b ff00>' }), [ bad('I1', 'b ff00') ], 'no 0x (the kernel needs it)');
eq(awg.obf_unsafe({ i1: '<b 0xzz>' }), [ bad('I1', 'b 0xzz') ], 'not hex');
eq(awg.obf_unsafe({ i2: '<r -5>' }), [ bad('I2', 'r -5') ], 'a negative length writes past the packet');
eq(awg.obf_unsafe({ i2: '<rc 0>' }), [ bad('I2', 'rc 0') ], 'no length');
eq(awg.obf_unsafe({ i2: '<rd 1001>' }), [ bad('I2', 'rd 1001') ], 'too long');
eq(awg.obf_unsafe({ i3: '<r 5>' }), [ bad('I3', 'r 5') ], 'two spaces');
eq(awg.obf_unsafe({ i3: '<t >' }), [ bad('I3', 't ') ], 'a space after t');
eq(awg.obf_unsafe({ i4: '<c>' }), [ bad('I4', 'c') ], 'the kernel\'s counter, which amneziawg-go refuses');
for (let t in [ 'd', 'ds', 'dz' ])
eq(awg.obf_unsafe({ i4: `<${t}>` }), [ bad('I4', t) ], `amneziawg-go's <${t}>, which the kernel refuses`);
eq(awg.obf_unsafe({ i5: '<>' }), [ bad('I5', '') ], 'an empty tag');
eq(awg.obf_unsafe({ i5: '<r <5>' }), [ bad('I5', 'r <5') ], 'a tag inside a tag');
eq(awg.obf_unsafe({ i5: '<b 0x0102030405060708090a0b0c0d0e0f>' }), [], 'long tags are fine');
eq(awg.obf_unsafe({ i5: '<x 0x0102030405060708090a0b0c0d0e0f>' }), [ bad('I5', 'x 0x0102030405060708090a…') ], 'shown cut short');
eq(awg.obf_unsafe({ i1: '<r 5' }), [ 'I1 has a tag that is not closed with >.' ], 'not closed');
eq(awg.obf_unsafe({ i1: '<r 5><b 0x00> # note' }), [ 'I1 may not contain # or a line break.' ], 'a comment in a .conf');
eq(awg.obf_unsafe({ i1: '<r 5>\n<t>' }), [ 'I1 may not contain # or a line break.' ], 'a line break');
});
test('obf_unsafe: I1-I5 fit one configuration', () => {
// A tag of 100 characters.
let tag = '<b 0x';
for (let n = 0; n < 47; n++)
tag += 'ab';
tag += '>';
let many = (n) => {
let out = '';
for (let k = 0; k < n; k++)
out += tag;
return out;
};
let four = many(4);
eq(awg.obf_unsafe({ i1: four, i2: four, i3: four, i4: four, i5: four }), [], '2000 characters');
eq(awg.obf_unsafe({ i1: four, i2: four, i3: four, i4: four, i5: many(5) }), [ 'I1-I5 together must be at most 2000 characters, not 2100.' ], 'over 2000');
});
test('obf_unsafe: an import or restore with such values is refused', () => {
let dir = '/tmp/dawnline-tests/import';
let errs = (text) => {
system(`rm -rf ${dir}; mkdir -p ${dir}/.delta`);
writefile(`${dir}/dawnline`, text);
let c = cursor(dir, `${dir}/.delta`);
c.load('dawnline');
let out = backup.config_errors(c);
system(`rm -rf ${dir}`);
return out;
};
let fixture = readfile('/etc/config/dawnline');
let bad = errs(replace(fixture, "option jmax '128'", "option jmax '32'"));
ok(index(bad, 'Server Main: Jmin must not be larger than Jmax.') >= 0, `refused: ${join(' ', bad)}`);
eq(filter(errs(fixture), (e) => index(e, 'Jmin') >= 0), [], 'the fixture as it is');
});
// The stand-in's call log and failures (fixtures/bin/awg).
const AWG_CALLS = '/tmp/dawnline-tests/awg-calls';
const AWG_FAIL = '/tmp/dawnline-tests/awg-fail-';
const SERVER_KEY = 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=';
const PEER_ON = 'HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw=', PEER_NEW = 'TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0=';
// A fixture's lines as another interface's (`show all` prints the ifname first).
function lines_as(name, ifname) {
let out = '';
for (let l in split(readfile(`${fixtures}/awg-dump-${name}.txt`), '\n'))
if (l != '')
out += `${ifname}${substr(l, length('awgmain'))}\n`;
return out;
}
// lo is in every container's /sys/class/net (index 1), and is no AmneziaWG
// interface: the stand-in prints the fixture's lines for it, as for a tunnel.
function dump_of(name) {
writefile(AWG_DUMP, readfile(`${fixtures}/awg-dump-${name}.txt`));
return awg.dump();
writefile(AWG_DUMP, lines_as(name, 'lo'));
return awg.dump([ 'lo' ]);
}
test('dump: AmneziaWG 1.0 (14 interface fields)', () => {
let d = dump_of('1.0');
eq(d.ok, true, 'ok');
eq(d.ifaces, { awgmain: { public_key: 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=', port: 51820 } }, 'interface');
eq(d.peers['HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw='],
{ ifname: 'awgmain', endpoint: '203.0.113.7:41821', handshake: 1760000000, rx: 123456, tx: 654321 }, 'peer with a session');
eq(d.peers['TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0='],
{ ifname: 'awgmain', endpoint: '', handshake: 0, rx: 0, tx: 0 }, 'peer that never connected');
eq(d.reads, { lo: 'read' }, 'read');
eq(d.ifaces, { lo: { public_key: SERVER_KEY, port: 51820, ifindex: 1 } }, 'interface; its index is the epoch of its counters');
eq(d.peers[PEER_ON], { ifname: 'lo', endpoint: '203.0.113.7:41821', handshake: 1760000000, rx: 123456, tx: 654321 },
'peer with a session, with the ifname the lines leave out');
eq(d.peers[PEER_NEW], { ifname: 'lo', endpoint: '', handshake: 0, rx: 0, tx: 0 }, 'peer that never connected');
});
test('dump: AmneziaWG 2.0 (33 interface fields)', () => {
let d = dump_of('2.0');
eq(d.ifaces, { awgmain: { public_key: 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=', port: 51820 } }, 'interface');
eq(keys(d.peers), [ 'HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw=' ], 'one peer');
eq(d.ifaces, { lo: { public_key: SERVER_KEY, port: 51820, ifindex: 1 } }, 'interface');
eq(keys(d.peers), [ PEER_ON ], 'one peer');
});
test('dump: AmneziaWG 3.1 (33 interface fields, protection on)', () => {
let d = dump_of('3.1');
eq(d.ifaces, { awgmain: { public_key: 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=', port: 51820 } }, 'interface');
eq(d.ifaces, { lo: { public_key: SERVER_KEY, port: 51820, ifindex: 1 } }, 'interface');
eq(length(d.peers), 2, 'two peers');
});
test('dump: the tool fails', () => {
// awgmain is not in the container's /sys/class/net, as a tunnel netifd could not bring up.
test('dump: a tunnel that is not there is down, without a process', () => {
writefile(AWG_DUMP, readfile(`${fixtures}/awg-dump-1.0.txt`));
unlink(AWG_CALLS);
eq(awg.dump([ 'awgmain' ]), { ok: true, reads: { awgmain: 'down' }, ifaces: {}, peers: {} }, 'its counters are gone');
eq(readfile(AWG_CALLS), null, 'awg is not asked about a link the kernel does not have');
eq(awg.dump([]), { ok: true, reads: {}, ifaces: {}, peers: {} }, 'no tunnel runs');
});
test('dump: each tunnel on its own', () => {
writefile(AWG_DUMP, readfile(`${fixtures}/awg-dump-1.0.txt`) + lines_as('2.0', 'lo'));
let d = awg.dump([ 'awgmain', 'lo' ]);
eq([ d.ok, d.reads ], [ true, { awgmain: 'down', lo: 'read' } ], 'one down, one read');
eq(keys(d.ifaces), [ 'lo' ], 'only what was read');
eq(filter(values(d.peers), (p) => p.ifname != 'lo'), [], 'no peers of the one that is down');
});
// The tool says "Operation not supported" for lo on a real system.
test('dump: a tunnel that exists but cannot be read', () => {
writefile(AWG_DUMP, lines_as('2.0', 'lo'));
writefile(`${AWG_FAIL}lo`, 'Unable to access interface: Operation not supported\n');
let d = awg.dump([ 'awgmain', 'lo' ]);
unlink(`${AWG_FAIL}lo`);
eq(d.ok, false, 'not every tunnel was read');
eq(d.reads, { awgmain: 'down', lo: 'error' }, 'each on its own');
eq([ d.ifaces, d.peers ], [ {}, {} ], 'nothing of the failed one');
});
// The agent's watcher reads every second: with one server, one process.
test('dump: only the tunnels asked for, one process each', () => {
writefile(AWG_DUMP, lines_as('1.0', 'lo') + lines_as('2.0', 'wgclient'));
unlink(AWG_CALLS);
let d = awg.dump([ 'lo' ]);
// The tests after these find no tunnel, as on a router without AmneziaWG running.
unlink(AWG_DUMP);
let d = awg.dump();
eq(d, { ok: false, ifaces: {}, peers: {} }, 'nothing known');
eq(readfile(AWG_CALLS), 'show lo dump\n', 'one call, never `all`');
eq(keys(d.ifaces), [ 'lo' ], 'the other tunnel is not read');
eq(d.peers[PEER_ON].ifname, 'lo', 'its peers stand in for none of ours');
});
test('tunnel_devices: what sync_peers loads', () => {
let m = {
servers: { s: { public_key: SERVER_KEY } },
people: { a: { id: 'a', server: 's' }, b: { id: 'b', server: 's' }, c: { id: 'c', server: 'other' } },
devices: {
on: { person: 'a', public_key: PEER_ON, address: '10.9.0.2' },
own: { person: 'a', public_key: SERVER_KEY, address: '10.9.0.8' },
off: { person: 'a', public_key: PEER_NEW, address: '10.9.0.3', disabled: true },
paused: { person: 'b', public_key: SERVER_KEY, address: '10.9.0.4' },
elsewhere: { person: 'c', public_key: PEER_NEW, address: '10.9.0.5' },
badkey: { person: 'a', public_key: 'not a key', address: '10.9.0.6' },
badaddr: { person: 'a', public_key: PEER_NEW, address: '' },
nobody: { person: 'gone', public_key: PEER_NEW, address: '10.9.0.7' },
},
};
let st = { a: 'quota', b: 'paused', c: 'active' };
eq(map(awg.tunnel_devices(m, 's', st), (d) => d.address), [ '10.9.0.2' ],
'over the limit stays; off, paused, other servers, lines syncconf would refuse and the server\'s own key (ignored by the kernel) do not');
eq(map(awg.tunnel_devices(m, 'other', st), (d) => d.address), [ '10.9.0.5' ], 'the other server');
eq(awg.tunnel_devices(m, 'none', st), [], 'none');
});
test('peer_diff: by key, per tunnel', () => {
let dmp = { peers: {} };
dmp.peers[PEER_ON] = { ifname: 'awgmain' };
dmp.peers[SERVER_KEY] = { ifname: 'awgmain' };
dmp.peers[PEER_NEW] = { ifname: 'awgother' };
let devs = (...ks) => map(ks, (k) => ({ public_key: k }));
eq(awg.peer_diff(devs(PEER_ON, SERVER_KEY), dmp, 'awgmain'), { loaded: 2, missing: 0, extra: 0 }, 'the same');
eq(awg.peer_diff(devs(PEER_ON, PEER_NEW), dmp, 'awgmain'), { loaded: 2, missing: 1, extra: 1 },
'a stale peer standing in for a missing one');
eq(awg.peer_diff(devs(PEER_ON), dmp, 'awgmain'), { loaded: 2, missing: 0, extra: 1 }, 'one too many');
eq(awg.peer_diff(devs(PEER_NEW), dmp, 'awgdown'), { loaded: 0, missing: 1, extra: 0 }, 'a tunnel with no peers read');
eq(awg.peer_diff([], { peers: {} }, 'awgmain'), { loaded: 0, missing: 0, extra: 0 }, 'nothing either way');
});
test('handshake_since: Reconnect hides older handshakes', () => {
@@ -116,6 +349,60 @@ test('blocked reasons', () => {
// Files of older versions hold the English fragment after the name.
eq(awg.blocked_text(srv('has an invalid interface name "x"')), 'Home has an invalid interface name "x".', 'old fragment');
eq(awg.blocked_note({ code: 'ifname', ifname: 'x' }), 'has an invalid interface name "x"', 'the log keeps the fragment');
// Values AmneziaWG refuses: which ones, from the server's own when read.
let bad = { name: 'Home', obf: { jmin: '60', jmax: '50' }, blocked: { code: 'disguise_invalid' } };
eq(awg.blocked_text(bad), 'Home is kept down: its disguise has values AmneziaWG cannot take. Jmin must not be larger than Jmax.', 'invalid values');
eq(awg.blocked_text({ ...bad, obf: {} }), 'Home is kept down: its disguise has values AmneziaWG cannot take.', 'fixed since');
eq(awg.blocked_note(bad.blocked), 'is kept down: its disguise has values AmneziaWG cannot take', 'the log');
eq(awg.blocked_fix(bad.blocked), 'Choose a disguise on the Server page: it replaces the values set by hand.', 'what to do about it');
eq(awg.blocked_fix({ code: 'taken', ifname: 'wg0' }), 'Choose another interface name in the server settings.', 'what to do about a name');
});
test('netifd_options: the server keeps its defence against handshake floods', () => {
let m = core.load();
let srv = m.servers.main;
srv.obf = awg.obf_preset('max');
let o = awg.netifd_options(srv);
ok('awg_disable_cookies' in o, 'named, so netifd.sync takes it off an interface that had it');
eq(o.awg_disable_cookies, null, 'no DisableCookies on the server');
eq([ o.awg_header_protection_key, o.awg_jc, o.awg_i1, o.awg_random_trailers ], [ srv.obf.header_protection_key, srv.obf.jc, srv.obf.i1, 'on' ],
'the rest of the disguise stays');
ok(index(split(awg.client_config(m, m.devices.alice_phone).conf, '\n'), 'DisableCookies = on') >= 0, 'devices keep it');
});
test('client_config: one keep-alive for the .conf and the AmneziaVPN key', () => {
let m = core.load();
let srv = m.servers.main, dev = m.devices.alice_phone;
let ka = () => {
let c = awg.client_config(m, dev);
return [ match(c.conf, /\nPersistentKeepalive = ([^\n]*)\n/)?.[1], c.amnezia.persistent_keep_alive ];
};
eq(ka(), [ '25', '25' ], 'a number without header protection');
srv.obf = awg.obf_preset('max');
eq(ka(), [ '25-35', '25-35' ], 'jittered with 3.1');
srv.keepalive = 0;
eq(ka(), [ null, '0' ], 'off');
});
test('status: the header protection key stays out of what read-only users get', () => {
eq(awg.obf_public({ jc: '4', header_protection_key: HPK }), { jc: '4' }, 'obf_public');
eq(awg.obf_public(null), {}, 'no values');
// Server main on Maximum, as a uci change not committed (the fixture file stays as it is).
let c = cursor();
c.load('dawnline');
let o = awg.obf_preset('max');
for (let k, v in o)
c.set('dawnline', 'main', k, v);
c.save('dawnline');
let out = rpc_status.methods.status.call({ args: { days: 30 } });
c.revert('dawnline');
eq(out.error, null, 'status answers');
let srv = filter(out.servers ?? [], (x) => x.id == 'main')[0];
eq([ srv?.hpk, srv?.obf?.header_protection_key, srv?.obf?.disable_cookies ], [ true, null, 'on' ], 'whether there is a key, not which');
let text = sprintf('%J', out);
ok(index(text, o.header_protection_key) < 0, 'the key is nowhere in the answer');
let found = uniq(map(match(text, /[A-Za-z0-9+\/]{43}=/g) ?? [], (x) => x[0]));
eq(found, [ srv.public_key ], 'no key but the server\'s public one');
});
test('client_config: an IPv6 endpoint in brackets, without a regex', () => {
@@ -153,3 +440,117 @@ test('config_fingerprint leaves out the private key and the junk', () => {
ok(awg.config_fingerprint(m, dev) != f, 'another port');
eq(awg.config_fingerprint(m, null), null, 'no device');
});
/* ---------- a device's local network, MTU and keep-alive ---------- */
// Exactly the complement: aligned prefixes, none overlapping another or a
// private range, and all of them together the whole address space.
test('BYPASS4: every IPv4 address outside the private ranges, once', () => {
let nets = [ ...map(awg.BYPASS4, (n) => [ n, false ]), ...map(nft.PRIVATE4, (n) => [ n, true ]) ];
let total = 0;
for (let i = 0; i < length(nets); i++) {
let a = cidr_any(nets[i][0]);
ok(a && a.ip == a.net, `${nets[i][0]}: a prefix`);
total += a.size;
for (let j = i + 1; j < length(nets); j++) {
let b = cidr_any(nets[j][0]);
ok(a.net + a.size <= b.net || b.net + b.size <= a.net, `${nets[i][0]} and ${nets[j][0]} apart`);
}
}
eq(total, 4294967296, 'together: every address');
});
test('BYPASS6: every IPv6 address outside fc00::/7, fe80::/10 and ff00::/8, once', () => {
// Each of them is /16 or wider: the first 16 bits decide.
let span = (n) => {
let p = split(n, '/'), len = +p[1];
ok(len >= 1 && len <= 16 && substr(p[0], -2) == '::', `${n}: a prefix of the first 16 bits`);
let g = substr(p[0], 0, length(p[0]) - 2);
let start = g == '' ? 0 : hex(g), size = 1 << (16 - len);
ok(start % size == 0, `${n}: aligned`);
return [ start, size ];
};
let nets = map([ ...awg.BYPASS6, 'fc00::/7', 'fe80::/10', 'ff00::/8' ], span);
let total = 0;
for (let i = 0; i < length(nets); i++) {
total += nets[i][1];
for (let j = i + 1; j < length(nets); j++)
ok(nets[i][0] + nets[i][1] <= nets[j][0] || nets[j][0] + nets[j][1] <= nets[i][0], `${i} and ${j} apart`);
}
eq(total, 65536, 'together: every address');
});
test('allowed_ips: the local network outside the tunnel', () => {
let m = core.load();
let srv = m.servers.main;
// No home network from the container's own interfaces.
srv.auto_lan = false;
srv.lan_devices = [];
let alice = m.people.alice, bob = m.people.bob;
eq(awg.allowed_ips(m, srv, bob), [ '0.0.0.0/0', '::/0' ], 'no device: everything');
eq(awg.allowed_ips(m, srv, bob, { lan_bypass: false }), [ '0.0.0.0/0', '::/0' ], 'as before');
let dns = (list) => [ ...slice(list, 0, 2), '10.9.0.1/32', ...slice(list, 2) ];
eq(awg.allowed_ips(m, srv, bob, { lan_bypass: true }), [ ...dns(awg.BYPASS4), ...awg.BYPASS6 ], 'internet: the rest, and its DNS');
eq(awg.allowed_ips(m, srv, alice, { lan_bypass: true }), [ ...slice(awg.BYPASS4, 0, 2), '10.9.0.0/29', ...slice(awg.BYPASS4, 2), ...awg.BYPASS6 ],
'home too: the tunnel network with the other devices (the DNS is in it)');
srv.mesh = 'off';
srv.device_mesh = false;
eq(awg.allowed_ips(m, srv, alice, { lan_bypass: true }), [ ...dns(awg.BYPASS4), ...awg.BYPASS6 ], 'no mesh: the router');
srv.dns = [ '192.168.1.1', '192.168.1.53', 'fd00::53', '2001:4860:4860::8888', 'fe80::1' ];
let all = awg.allowed_ips(m, srv, bob, { lan_bypass: true });
ok(index(all, '192.168.1.1/32') >= 0 && index(all, '192.168.1.53/32') >= 0, 'every private IPv4 DNS server stays in the tunnel, not only the first');
eq(slice(all, length(all) - length(awg.BYPASS6) - 2), [ ...awg.BYPASS6, 'fd00::53/128', 'fe80::1/128' ],
'a private IPv6 one too; a public IPv6 one is in the rest already');
eq(length(all), length(awg.BYPASS4) + 2 + length(awg.BYPASS6) + 2, 'nothing else');
srv.dns = [ '1.1.1.1' ];
eq(awg.allowed_ips(m, srv, bob, { lan_bypass: true }), [ ...awg.BYPASS4, ...awg.BYPASS6 ], 'a public DNS is in the rest already');
alice.access = 'lan';
alice.dns_mode = 'home';
let lan = awg.allowed_ips(m, srv, alice, { lan_bypass: true });
eq(lan, awg.allowed_ips(m, srv, alice), 'Home only: the same either way');
let c = awg.client_config(m, { ...m.devices.alice_phone, person: 'bob', lan_bypass: true });
eq(c.amnezia.allowed_ips, [ ...awg.BYPASS4, ...awg.BYPASS6 ], 'in the AmneziaVPN key');
ok(index(c.conf, `AllowedIPs = ${join(', ', [ ...awg.BYPASS4, ...awg.BYPASS6 ])}\n`) >= 0, 'in the .conf');
});
test('keepalive_range and idle_handshake', () => {
let srv = { keepalive: 25, obf: {} };
eq(awg.keepalive_range(srv, {}), [ 25, 25 ], 'the server\'s, no range');
eq(awg.keepalive_range(srv, { keepalive: 120 }), [ 120, 120 ], 'the device\'s own');
eq(awg.keepalive_range(srv, { keepalive: 0 }), null, 'off for the device');
eq(awg.keepalive_range({ keepalive: 0, obf: {} }, {}), null, 'off on the server');
let max = { keepalive: 25, obf: awg.obf_preset('max') };
eq(awg.keepalive_range(max, {}), [ 25, 35 ], 'jittered with 3.1');
eq(awg.keepalive_range(max, { keepalive: 60 }), [ 60, 70 ], 'the device\'s own, jittered');
// The first keep-alive after the rekey time (120 s; RekeyAfterTime's upper end) starts a handshake.
eq(awg.idle_handshake(srv, {}), 145, 'within the rekey time: up to one keep-alive past it');
eq(awg.idle_handshake(max, {}), 155, 'Maximum: RekeyAfterTime 100-120, keep-alive up to 35');
eq(awg.idle_handshake(srv, { keepalive: 100 }), 220, 'every second keep-alive');
eq(awg.idle_handshake(srv, { keepalive: 300 }), 300, 'every keep-alive once they are further apart');
eq(awg.idle_handshake({ keepalive: 25, obf: { rekey_after_time: '200-400' } }, {}), 205, 'past 180 s the key is refused anyway');
eq(awg.idle_handshake(srv, { keepalive: 0 }), null, 'no keep-alive: none');
});
test('client_config: the device\'s own MTU and keep-alive', () => {
let m = core.load();
let dev = m.devices.alice_phone;
let line = (c, k) => match(c.conf, regexp(`\n${k} = ([^\n]*)\n`))?.[1];
let c = awg.client_config(m, dev);
eq([ line(c, 'MTU'), line(c, 'PersistentKeepalive'), c.amnezia.mtu ], [ '1280', '25', '1280' ], 'the server\'s (a phone)');
let fp = awg.config_fingerprint(m, dev);
let old = { ...dev };
delete old.mtu;
delete old.keepalive;
delete old.lan_bypass;
eq(awg.config_fingerprint(m, old), fp, 'a device without values of its own keeps its fingerprint (as before the options)');
dev.mtu = 1420;
dev.keepalive = 0;
c = awg.client_config(m, dev);
eq([ line(c, 'MTU'), line(c, 'PersistentKeepalive'), c.amnezia.mtu, c.amnezia.persistent_keep_alive ], [ '1420', null, '1420', '0' ],
'its own; keep-alive off');
ok(awg.config_fingerprint(m, dev) != fp, 'a change asks it to import again');
m.servers.main.obf = awg.obf_preset('max');
dev.keepalive = 120;
c = awg.client_config(m, dev);
eq([ line(c, 'PersistentKeepalive'), c.amnezia.persistent_keep_alive ], [ '120-130', '120-130' ], 'jittered with 3.1');
});
+59
View File
@@ -0,0 +1,59 @@
// dawnline.awg_builds: the AmneziaWG generation of package and kernel module
// versions, whether an installed update waits for a reboot (its old module
// stayed loaded) and the generation that really runs meanwhile, which is
// what caps() reports.
import * as builds from 'dawnline.awg_builds';
import * as awg from 'dawnline.awg';
// The live router's module (3.1) after an update from a 2.0 one that could not be swapped.
const KMOD_31 = '6.12.94.3.1.20260906-r1';
const WAITING = { reloaded: false, boot: 'boot-1', prev_gen: '2.0', prev_core: 98304 };
test('gen of package versions', () => {
eq(builds.gen(null), null, 'not installed');
eq(builds.gen('3.1.20260812-r1'), '3.1', 'amneziawg-tools 3.1');
eq(builds.gen('3.1.0-r1'), '3.1', 'luci-proto-amneziawg 3.1');
eq(builds.gen('1.0.20250722-r1'), '2.0', 'July 2025 on: 2.0');
eq(builds.gen('1.0.20250901'), '2.0', 'no release suffix');
eq(builds.gen('1.0.20250610-r1'), '1.0', 'before July 2025');
eq(builds.gen('1.0.20241112-r2'), '1.0', '2024');
});
test('gen of kernel module versions', () => {
eq(builds.gen(KMOD_31), '3.1', 'kernel release in front');
eq(builds.gen('6.12.94.3.1.20260906'), '3.1', 'no release suffix');
eq(builds.gen('6.6.73.1.0.20250722-r1'), '2.0', '2.0 module');
eq(builds.gen('6.6.73.1.0.20250612-r1'), '1.0', 'first generation module');
eq(builds.gen('5.15.150.1.0.20240711-r3'), '1.0', '2024 module on an older kernel');
eq(builds.gen('3.1.20260812'), '3.1', 'the version.h string of a 3.1 module');
});
test('pending: an update waits for a reboot', () => {
ok(builds.pending(WAITING, 'boot-1', 98304), 'the old module still loaded, same boot');
ok(!builds.pending(WAITING, 'boot-2', 98304), 'rebooted');
ok(!builds.pending(WAITING, 'boot-1', null), 'no module loaded: the next one is the new one');
ok(!builds.pending(WAITING, 'boot-1', 110592), 'another module loaded (reloaded by hand)');
ok(!builds.pending({ ...WAITING, reloaded: true }, 'boot-1', 98304), 'the install swapped it');
ok(!builds.pending({ ...WAITING, reloaded: null }, 'boot-1', 98304), 'a record of a module Dawnline did not install');
ok(!builds.pending({ osrelease: '6.12.94', source: 'slava', tag: 'v25.12.5', installed: 1 }, 'boot-1', 98304),
'a record from before boots were kept');
ok(!builds.pending({ ...WAITING, boot: null }, null, 98304), 'the kernel gave no boot id');
ok(!builds.pending(null, 'boot-1', 98304), 'no record');
});
test('caps: the generation that runs while a reboot is pending', () => {
eq(builds.running_gen(WAITING, 'boot-1', 98304, KMOD_31), '2.0', 'the 2.0 module runs, not the 3.1 package');
eq(builds.running_gen(WAITING, 'boot-2', 98304, KMOD_31), '3.1', 'after the reboot: the package');
eq(builds.running_gen(WAITING, 'boot-1', null, KMOD_31), '3.1', 'nothing loaded: the package loads');
eq(builds.running_gen(null, 'boot-1', 98304, KMOD_31), '3.1', 'no record: the package');
eq(builds.running_gen({ ...WAITING, prev_gen: null }, 'boot-1', 98304, KMOD_31), null,
'a module installed by hand before: unknown, the tools are believed');
eq(builds.running_gen(null, null, null, null), null, 'nothing installed');
});
test('caps in a container without AmneziaWG', () => {
let c = awg.caps();
eq(c.kmod, null, 'no module package');
eq(c.pending, false, 'nothing waits for a reboot');
eq(builds.module_core(), null, 'no module loaded');
});
+80 -1
View File
@@ -1,6 +1,7 @@
// dawnline.core: the model read from the fixture config (real libuci), access
// hours, quotas and the derived person state at an explicit time, address
// allocation, the automatic MTU, and other packages' port forwards.
// allocation, the automatic MTU, a device's own MTU, keep-alive and local
// network, and other packages' port forwards.
import { readfile, writefile, unlink } from 'fs';
import * as core from 'dawnline.core';
@@ -28,6 +29,8 @@ test('load reads the fixture', () => {
eq(m.settings.updates.interval, '7d', 'update policy from the same section');
eq(m.settings.updates.targets, [ 'app' ], 'update targets list');
eq(m.settings.retention.log_connections, '0', 'raw retention values');
let d = m.devices.alice_phone;
eq([ d.mtu, d.keepalive, d.lan_bypass ], [ 0, null, false ], 'a device without link values of its own');
});
test('parse_hours', () => {
@@ -129,6 +132,82 @@ test('tunnel_mtu / device_mtu', () => {
eq(core.device_mtu({ mtu: 0, obf: {} }, { kind: 'phone' }), 1280, 'phone');
eq(core.device_mtu({ mtu: 0, obf: {} }, { kind: 'computer' }), 1380, 'computer');
eq(core.device_mtu({ mtu: 1200 }, { kind: 'tablet' }), 1200, 'a smaller tunnel MTU stays');
eq(core.device_mtu({ mtu: 0, obf: {} }, { kind: 'phone', mtu: 1420 }), 1420, 'the device\'s own, also above 1280 on a phone');
eq(core.device_mtu({ mtu: 1420 }, { kind: 'computer', mtu: 1280 }), 1280, 'the device\'s own below the tunnel\'s');
eq(core.device_mtu({ mtu: 0, obf: {} }, { kind: 'computer', mtu: 9000 }), 1380, 'out of range (a hand edit): the automatic one');
eq(core.device_mtu({ mtu: 0, obf: {} }, { kind: 'phone', mtu: 0 }), 1280, '0: as before');
});
test('device_keepalive', () => {
let srv = { keepalive: 25 };
eq(core.device_keepalive(srv, { keepalive: null }), 25, 'the server\'s');
eq(core.device_keepalive(srv, {}), 25, 'none read');
eq(core.device_keepalive(srv, { keepalive: 0 }), 0, 'off for this device');
eq(core.device_keepalive(srv, { keepalive: 120 }), 120, 'its own');
eq(core.device_keepalive(srv, { keepalive: 700 }), 25, 'out of range: the server\'s');
eq(core.device_keepalive({ keepalive: 0 }, { keepalive: 15 }), 15, 'its own on a server without keep-alive');
});
/** A uci cursor that records what is written: { 'section.option': value or null (deleted) }. */
function recorder() {
let w = {};
return { w, c: { set: (cfg, s, k, v) => { w[`${s}.${k}`] = v; }, delete: (cfg, s, k) => { w[`${s}.${k}`] = null; } } };
}
test('set_device_link', () => {
let mm = { devices: { d: { id: 'd', mtu: 0, keepalive: null, lan_bypass: false } } };
let r = recorder();
eq(core.set_device_link(r.c, mm, 'd', { mtu: '1400', keepalive: '0', lan_bypass: true }), [ 'mtu', 'keepalive', 'lan_bypass' ], 'what changed');
eq(r.w, { 'd.mtu': '1400', 'd.keepalive': '0', 'd.lan_bypass': '1' }, 'written');
r = recorder();
mm.devices.d = { id: 'd', mtu: 1400, keepalive: 0, lan_bypass: true };
eq(core.set_device_link(r.c, mm, 'd', { mtu: '', keepalive: '', lan_bypass: false }), [ 'mtu', 'keepalive', 'lan_bypass' ], 'back');
eq(r.w, { 'd.mtu': null, 'd.keepalive': null, 'd.lan_bypass': null }, 'removed: the server\'s again');
r = recorder();
eq(core.set_device_link(r.c, mm, 'd', { mtu: '1400', keepalive: ' 0 ' }), [], 'the same values change nothing');
eq(r.w, {}, 'nothing written');
eq(core.set_device_link(r.c, mm, 'd', {}), [], 'nothing asked');
throws(() => core.set_device_link(r.c, mm, 'd', { mtu: '1279' }), /^MTU must be 1280-1500\.$/, 'MTU too small');
throws(() => core.set_device_link(r.c, mm, 'd', { mtu: '1501' }), /^MTU must be 1280-1500\.$/, 'MTU too large');
throws(() => core.set_device_link(r.c, mm, 'd', { mtu: '1400.5' }), /^MTU/, 'not a whole number');
throws(() => core.set_device_link(r.c, mm, 'd', { keepalive: '601' }), /^Keep-alive must be 0-600 seconds\.$/, 'keep-alive too long');
throws(() => core.set_device_link(r.c, mm, 'd', { keepalive: '-1' }), /^Keep-alive/, 'negative');
throws(() => core.set_device_link(r.c, mm, 'x', { mtu: '' }), /^Unknown device\.$/, 'unknown device');
});
test('create_device: the local network outside the tunnel', () => {
let mm = core.load();
let r = recorder();
let keys = { public_key: 'a8Z2wq0b8rQx3mN6kYyQ2G3bQm2kq5tY5m7Q0yq3m3c=', preshared_key: '' };
let id = core.create_device(r.c, mm, 'bob', 'Laptop', 'computer', { keys, lan_bypass: true });
eq([ r.w[`${id}.lan_bypass`], mm.devices[id].lan_bypass, mm.devices[id].mtu, mm.devices[id].keepalive ], [ '1', true, 0, null ], 'set');
r = recorder();
id = core.create_device(r.c, mm, 'bob', 'Tablet', 'tablet', { keys: { ...keys, public_key: 'b8Z2wq0b8rQx3mN6kYyQ2G3bQm2kq5tY5m7Q0yq3m3c=' } });
ok(!(`${id}.lan_bypass` in r.w) && !mm.devices[id].lan_bypass, 'off unless asked');
});
test('create_device: not with the server\'s own key', () => {
let mm = core.load();
let keys = { public_key: mm.servers.main.public_key, preshared_key: '' };
throws(() => core.create_device(recorder().c, mm, 'bob', 'Laptop', 'computer', { keys }), /^This key is already in use\.$/,
'it is in every configuration of the server');
mm.devices.alice_phone.public_key = mm.servers.main.public_key;
eq(core.model_errors(mm), [ "Device Phone of Alice: the public key is the server's own." ], 'one set by hand is named');
});
test('model_errors: a device\'s own MTU and keep-alive', () => {
let mm = core.load();
eq(core.model_errors(mm), [], 'the fixture is consistent');
let d = mm.devices.alice_phone;
d.mtu = 1400;
d.keepalive = 0;
eq(core.model_errors(mm), [], 'values of its own in range');
d.mtu = 9000;
d.keepalive = 601;
eq(core.model_errors(mm), [
'Device Phone of Alice: MTU 9000 is not between 1280 and 1500.',
'Device Phone of Alice: keep-alive 601 is not between 0 and 600 seconds.',
], 'named');
});
test('names and codes', () => {
+67
View File
@@ -0,0 +1,67 @@
// 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, ensure_dir } from 'dawnline.util';
import * as core from 'dawnline.core';
import * as awg from 'dawnline.awg';
import * as people from 'dawnline.rpc.people';
const CONFIG = '/etc/config/dawnline';
const ISSUED = `${DATA_DIR}/issued.json`;
const RECONNECT = `${DATA_DIR}/reconnect.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');
});
+23 -4
View File
@@ -1,10 +1,29 @@
#!/bin/sh
# Stand-in for amneziawg-tools in the ucode tests (no kernel module in a
# container): `genkey` prints one fixed key, `show all dump` prints the fixture
# a test has put at /tmp/dawnline-tests/awg-dump (or fails, as the tool does
# when no interface is up). Anything else fails.
# container): `genkey` prints one fixed key, `pubkey` (a key on stdin) the
# fixture server's public key, its pair; `show <ifname> dump` prints that
# interface's lines of the fixture a test has put at /tmp/dawnline-tests/awg-dump
# (written as `awg show all dump` prints them: the ifname first, left out here,
# as the tool does), fails as the tool does for an interface that is not there,
# and fails with the text of /tmp/dawnline-tests/awg-fail-<ifname> when a test
# put one. Every call is appended to /tmp/dawnline-tests/awg-calls. Anything
# else fails.
T=/tmp/dawnline-tests
echo "$*" >> "$T/awg-calls"
case "$1 ${2:-} ${3:-}" in
'genkey ') echo 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=' ;;
'show all dump') cat /tmp/dawnline-tests/awg-dump ;;
'pubkey ') cat >/dev/null; echo 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=' ;;
'show '*' dump')
if [ -e "$T/awg-fail-$2" ]; then
cat "$T/awg-fail-$2" >&2
exit 1
fi
out="$(awk -F '\t' -v i="$2" '$1 == i { sub(/^[^\t]*\t/, ""); print }' "$T/awg-dump" 2>/dev/null)"
if [ -z "$out" ]; then
echo 'Unable to access interface: No such device' >&2
exit 1
fi
printf '%s\n' "$out"
;;
*) echo "awg stand-in: unsupported arguments: $*" >&2; exit 1 ;;
esac
+1 -1
View File
@@ -41,4 +41,4 @@ config device 'alice_phone'
option name 'Phone'
option kind 'phone'
option address '10.9.0.2'
option public_key 'xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg='
option public_key 'AuTb2wZ8C1032Ksn76nFgXzOJgT86OgEVbEE7ClpNy8='
+57
View File
@@ -0,0 +1,57 @@
table inet dawnline {
set home_home { type ipv4_addr; flags interval; auto-merge; elements = { 192.168.1.0/24 } }
set home_work { type ipv4_addr; flags interval; auto-merge; elements = { 192.168.1.0/24 } }
set tun_nets { type ipv4_addr; flags interval; auto-merge; elements = { 10.9.0.0/29, 10.9.1.0/29 } }
set lan_ok { type ipv4_addr; elements = { 10.9.0.2, 10.9.0.3, 10.9.1.3 } }
set lan_all { type ipv4_addr; elements = { 10.9.0.2, 10.9.0.3, 10.9.1.3 } }
set lan_part { type ipv4_addr . ipv4_addr; flags interval; }
set mesh_pairs { type ipv4_addr . ipv4_addr; }
set inet_ok { type ipv4_addr; elements = { 10.9.0.2, 10.9.1.2, 10.9.0.4, 10.9.0.5, 10.9.1.3 } }
set svc_ok { type ipv4_addr . ipv4_addr . inet_service; }
set svc_host { type ipv4_addr . ipv4_addr; }
set dns_real { type ipv4_addr; elements = { 10.9.0.3 } }
chain pre {
type filter hook prerouting priority -160; policy accept;
iifname { "awghome", "awgwork" } jump guard
}
chain guard {
meta nfproto ipv6 drop
ct state related accept
ct status dnat accept
icmp type { echo-request, echo-reply } fib daddr type local accept
fib daddr type local meta l4proto { tcp, udp } th dport 53 accept
fib daddr type local tcp dport { 8443 } accept
fib daddr type local ip saddr @lan_all accept
fib daddr type local ip saddr . ip daddr @lan_part accept
fib daddr type local counter drop
ip daddr 192.168.1.250 meta l4proto { tcp, udp } th dport 53 accept
iifname "awghome" ip daddr @home_home ip daddr != @tun_nets ip saddr @lan_all accept
iifname "awgwork" ip daddr @home_work ip daddr != @tun_nets ip saddr @lan_all accept
ip saddr . ip daddr @lan_part ip daddr != @tun_nets accept
iifname "awghome" ip saddr @lan_ok ip daddr @lan_ok accept
iifname "awgwork" ip saddr . ip daddr @mesh_pairs accept
meta l4proto { tcp, udp } ip saddr . ip daddr . th dport @svc_ok accept
ip saddr . ip daddr @svc_host accept
ip daddr { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10, 169.254.0.0/16, 224.0.0.0/3 } counter drop
ip saddr @inet_ok accept
counter drop
}
chain inbound {
type filter hook forward priority filter - 5; policy accept;
oifname { "awghome", "awgwork" } iifname != { "awghome", "awgwork" } ct state new jump to_device
}
chain to_device {
meta nfproto ipv6 drop
ct status dnat accept
oifname "awghome" ip saddr @home_home ip saddr != @tun_nets ip daddr @lan_all accept
oifname "awgwork" ip saddr @home_work ip saddr != @tun_nets ip daddr @lan_all accept
ip daddr . ip saddr @lan_part ip saddr != @tun_nets accept
counter reject with icmpx admin-prohibited
}
chain dns {
type nat hook prerouting priority dstnat - 5; policy accept;
iifname { "awghome", "awgwork" } ip saddr @dns_real meta l4proto { tcp, udp } th dport 53 dnat ip to 169.254.77.2:53
iifname "awghome" ip daddr 10.9.0.1 meta l4proto { tcp, udp } th dport 53 dnat ip to 192.168.1.250:53
iifname "awgwork" ip daddr 10.9.1.1 meta l4proto { tcp, udp } th dport 53 dnat ip to 192.168.1.1:53
}
}
+109
View File
@@ -0,0 +1,109 @@
// dawnline.health: where a public address points, in words. The name's AAAA
// records are checked against the router's public IPv6 addresses as well as
// its A records against the WAN. The facts take a test's reads instead of
// DNS, the WAN and `ip`.
import * as health from 'dawnline.health';
const HOST = 'vpn.example.com';
const WAN = '203.0.113.7';
// The WAN's own address and the LAN's from the delegated prefix: both reach the router.
const ROUTER6 = [ '2001:db8:1::1', '2001:db8:2::1' ];
function facts(ips, router6, wan) {
return health.endpoint_facts(null, HOST, { ips, wan, router6 });
}
function words(ips, router6, wan) {
return health.endpoint_words(facts(ips, router6, wan), 'UDP 51820');
}
test('own_ipv6: public addresses on any interface', () => {
let links = [
{ ifname: 'wan', addr_info: [ { family: 'inet6', local: '2001:db8:1::1', prefixlen: 128, scope: 'global' } ] },
{ ifname: 'br-lan', addr_info: [
{ family: 'inet6', local: '2001:db8:2::1', prefixlen: 64, scope: 'global' },
{ family: 'inet6', local: 'fd12:3456:789a::1', prefixlen: 60, scope: 'global' },
{ family: 'inet6', local: '2001:db8:2::99', prefixlen: 64, scope: 'global', dadfailed: true },
] },
{ ifname: 'lan2', addr_info: [ { family: 'inet6', local: 'FC00::1', prefixlen: 64, scope: 'global' } ] },
{ ifname: 'lo' },
];
eq(health.own_ipv6(links), ROUTER6, 'the WAN and the LAN prefix; no ULA, no failed duplicate');
eq(health.own_ipv6([ links[1] ]), [ '2001:db8:2::1' ], 'only the LAN has one');
eq(health.own_ipv6([ { ifname: 'br-lan', addr_info: [ links[1].addr_info[1] ] } ]), [], 'only a ULA: none');
eq(health.own_ipv6(null), [], 'nothing read');
});
test('endpoint_facts: AAAA records against the router', () => {
let f = facts([ WAN, '2001:db8:2::1' ], ROUTER6, WAN);
eq([ f.here, f.here6, f.foreign6 ], [ true, true, [] ], 'both records are the router');
eq(facts([ WAN, '2001:DB8:2:0:0::1' ], ROUTER6, WAN).here6, true, 'another spelling of the same address');
f = facts([ WAN, '2001:db8:2::1', '2001:db8:9::5' ], ROUTER6, WAN);
eq([ f.here6, f.foreign6 ], [ false, [ '2001:db8:9::5' ] ], 'one of two is not');
f = facts([ WAN, '2001:db8:9::5' ], [], WAN);
eq([ f.here6, f.foreign6, f.router6 ], [ false, [ '2001:db8:9::5' ], [] ], 'the router has no IPv6: none is');
f = facts([ WAN, '2001:db8:9::5' ], null, WAN);
eq([ f.here6, f.foreign6, f.router6 ], [ false, null, null ], 'unknown: no verdict');
eq(facts([ WAN ], ROUTER6, WAN).here6, false, 'no AAAA');
});
test('endpoint_words: IPv4 and IPv6 both at the router', () => {
eq(words([ WAN, '2001:db8:2::1' ], ROUTER6, WAN),
{ status: 'ok', text: 'vpn.example.com points at this router (203.0.113.7, 2001:db8:2::1).' }, 'A and AAAA');
eq(words([ WAN ], null, WAN), { status: 'ok', text: 'vpn.example.com points at this router (203.0.113.7).' }, 'A only, as before');
eq(words([ WAN, '2001:db8:9::5' ], null, WAN).status, 'ok', 'the router\'s IPv6 unknown: the AAAA gets no verdict');
});
test('endpoint_words: an AAAA record that is not the router', () => {
eq(words([ WAN, '2001:db8:9::5' ], ROUTER6, WAN), { status: 'warn',
text: 'vpn.example.com AAAA → 2001:db8:9::5 is not a public address of this router: devices that prefer IPv6 will fail to connect. Fix or remove this AAAA record.' },
'a stale prefix');
eq(words([ WAN, '2001:db8:9::5', '2001:db8:9::6' ], ROUTER6, WAN).text,
'vpn.example.com AAAA → 2001:db8:9::5, 2001:db8:9::6 are not public addresses of this router: devices that prefer IPv6 will fail to connect. Fix or remove these AAAA records.',
'two of them');
eq(words([ WAN, '2001:db8:2::1', 'fd12:3456:789a::1' ], ROUTER6, WAN).text,
'vpn.example.com AAAA → fd12:3456:789a::1 is not a public address of this router: devices that prefer IPv6 will fail to connect. Fix or remove this AAAA record.',
'a ULA beside the right one');
eq(words([ WAN, '2001:db8:9::5' ], [], WAN), { status: 'warn',
text: 'vpn.example.com AAAA → 2001:db8:9::5, but this router has no public IPv6 address: devices that prefer IPv6 will fail to connect. Remove this AAAA record or set up IPv6 on the router.' },
'the router has no IPv6');
eq(words([ '198.51.100.4', '2001:db8:9::5' ], ROUTER6, WAN), { status: 'warn',
text: 'vpn.example.com points at 198.51.100.4, not this router (WAN 203.0.113.7). Check your DNS / DDNS. ' +
'vpn.example.com AAAA → 2001:db8:9::5 is not a public address of this router: devices that prefer IPv6 will fail to connect. Fix or remove this AAAA record.' },
'both wrong: two sentences, IPv4 first');
eq(words([ '198.51.100.4', '2001:db8:2::1' ], ROUTER6, WAN).text,
'vpn.example.com points at 198.51.100.4, not this router (WAN 203.0.113.7). Check your DNS / DDNS.', 'only the A record wrong: as before');
eq(words([ '198.51.100.4', '2001:db8:9::5' ], ROUTER6, null).text,
'vpn.example.com AAAA → 2001:db8:9::5 is not a public address of this router: devices that prefer IPv6 will fail to connect. Fix or remove this AAAA record.',
'no WAN address: the AAAA alone');
});
test('endpoint_words: IPv6 only', () => {
eq(words([ '2001:db8:2::1' ], ROUTER6, WAN), { status: 'warn',
text: "vpn.example.com → 2001:db8:2::1: IPv6 only, so only devices with IPv6 connect (the router's IPv4 203.0.113.7 has no name)." },
'the v6_only wording stays');
eq(words([ '2001:db8:2::1' ], ROUTER6, '100.64.1.2'),
{ status: 'ok', text: 'vpn.example.com → 2001:db8:2::1: IPv6 only, so only devices with IPv6 connect.' }, 'behind CGNAT, as before');
eq(words([ '2001:db8:9::5' ], ROUTER6, WAN), { status: 'warn',
text: 'vpn.example.com → 2001:db8:9::5: IPv6 only, and not a public address of this router: no device can connect. Check your DNS / DDNS.' },
'not the router');
eq(words([ '2001:db8:9::5', '2001:db8:9::6' ], ROUTER6, WAN).text,
'vpn.example.com → 2001:db8:9::5, 2001:db8:9::6: IPv6 only, and not public addresses of this router: no device can connect. Check your DNS / DDNS.',
'two, neither the router');
eq(words([ '2001:db8:9::5' ], [], '100.64.1.2'), { status: 'warn',
text: 'vpn.example.com → 2001:db8:9::5: IPv6 only, but this router has no public IPv6 address: no device can connect. Check your DNS / DDNS, or set up IPv6 on the router.' },
'the router has no IPv6');
eq(words([ '2001:db8:2::1', '2001:db8:9::5' ], ROUTER6, WAN).text,
'vpn.example.com AAAA → 2001:db8:9::5 is not a public address of this router: devices that prefer IPv6 will fail to connect. Fix or remove this AAAA record.',
'one right, one wrong');
eq(words([ '2001:db8:9::5' ], null, WAN).text,
"vpn.example.com → 2001:db8:9::5: IPv6 only, so only devices with IPv6 connect (the router's IPv4 203.0.113.7 has no name).",
'the router\'s IPv6 unknown: as before');
});
test('common home subnets', () => {
eq(health.common_home([ '192.168.1.0/24', '10.0.1.0/24' ]), [ '192.168.1.0/24' ], 'the out-of-the-box /24 only');
eq(health.common_home([ '192.168.0.0/16' ]), [ '192.168.0.0/16' ], 'a wider network that holds one');
eq(health.common_home([ '10.37.12.0/24', '172.20.0.0/24' ]), [], 'rare ones');
eq(health.common_home(null), [], 'none');
});
+332
View File
@@ -0,0 +1,332 @@
// dawnline.link: what a device's counters say about its link, on synthetic
// sequences of one read a second, run the way the agent's watcher runs them
// (observe, the set-up state at once, then classify and settle when
// something happened or CHECK_EVERY passed); and the pieces on their own.
import * as link from 'dawnline.link';
const T0 = 1800000000;
const A = '203.0.113.7:41821', B = '198.51.100.4:50123';
/*
* `seconds` reads from T0. `at(s)` gives what happened in second s: { drx,
* dtx (bytes in, out), hs (a handshake completed), ep (the endpoint now),
* gone (the peer is not in the tunnel) }. Returns the history, the changes
* of what is shown: [ { s, from, to, since (seconds from T0), ev } ], those of
* the set-up state: [ { s, state } ], and the seconds where the set-up state
* kept by setup() was not what setup_state() gives then (it should never be).
*/
function run(seconds, at, opts) {
opts ??= {};
let ka = opts.ka ?? link.KEEPALIVE, window = opts.window ?? 190;
let h = link.fresh(T0);
let peer = { endpoint: opts.ep ?? A, handshake: opts.hs0 ?? 0, rx: 1000, tx: 1000 };
let changes = [], raws = {}, setups = [], lag = [];
for (let s = 0; s < seconds; s++) {
let t = T0 + s, x = at(s) ?? {};
peer.rx += x.drx ?? 0;
peer.tx += x.dtx ?? 0;
if (x.hs)
peer.handshake = t;
if (x.ep)
peer.endpoint = x.ep;
let on = peer.handshake > 0 && t - peer.handshake < window;
let moved = false;
if (x.gone)
link.gone(h);
else
moved = link.observe(h, peer, t, ka);
if (link.setup(h, t, on, moved))
push(setups, { s, state: h.setup?.state ?? null });
if (link.setup_state(h, t, on).state != (h.setup?.state ?? null))
push(lag, s);
if (!moved && t - h.checked < link.CHECK_EVERY)
continue;
h.checked = t;
link.prune(h, t);
h.raw = link.classify(h, t, on);
if (h.raw)
raws[h.raw] ??= s;
let ch = link.settle(h, h.raw, t, on);
if (ch)
push(changes, { s, from: ch.from, to: ch.to, since: h.since ? h.since - T0 : 0,
ev: link.event_for(ch, { id: 'd_1', person: 'p_1' }, on)?.type ?? null });
}
return { h, changes, raws, setups, lag };
}
// A phone in use: keep-alive 25 s, new keys every ~125 s (the initiation in
// one second, the packet that confirms it in the next), something sent or
// received now and then.
function phone(s, busy) {
let x = {};
if (s % 125 == 3)
x = { drx: 148, dtx: 92 };
else if (s % 125 == 4)
x = { hs: true, drx: 32 };
else if (s % 25 == 0)
x = { drx: 32 };
if (busy && s % 30 < 4)
x = { ...x, drx: (x.drx ?? 0) + 1400, dtx: (x.dtx ?? 0) + 9000 };
return x;
}
test('no state for a phone in use', () => {
let r = run(1800, (s) => phone(s, true));
eq(r.changes, [], 'half an hour of normal use');
eq(r.raws, {}, 'not even for a moment');
});
test('no state for a sleeping phone', () => {
eq(run(1800, (s) => phone(s, false)).changes, [], 'keep-alives and new keys only');
// Then it stops sending at all (deep sleep, out of range): it goes offline, nothing else.
let r = run(1200, (s) => s < 300 ? phone(s, false) : {});
eq(r.changes, [], 'silent after five minutes');
eq(r.raws, {}, 'silence is no failure');
// The same with the disguise's content padding: keep-alives of 42-132 bytes.
eq(run(1800, (s) => s % 25 == 0 ? { drx: 42 + (s % 90) } : phone(s, false), { ka: 132 }).changes, [], 'padded keep-alives');
});
test('no state for a phone that left with traffic still coming', () => {
// Online and busy until 100 s, then gone; the internet keeps sending to it for a while.
let at = (s) => s < 100 ? phone(s, true) : (s % 3 == 0 ? { dtx: 1400 } : {});
eq(run(900, at).changes, [], 'the online window ends it');
eq(run(900, at, { window: 400 }).changes, [], 'a long keep-alive window: no handshake within DROP_HS ends it');
});
test('trying: knocks that never finish connecting', () => {
// Never connected: an initiation every 5 s for 90 s, then a pause, again and again.
let knocking = (s) => (s % 120 < 90 && s % 5 == 0) ? { drx: 148, dtx: 92 } : {};
let r = run(600, knocking);
// The first read is the baseline: the knocks count from 5 s.
eq(r.raws.trying, 15, 'from the third accepted initiation');
eq(r.changes[0], { s: 195, from: null, to: 'trying', since: 15, ev: 'device_failing' }, 'shown once it held 3 minutes');
eq(length(r.changes), 1, 'and kept through the pauses');
// It gets through at 400 s: working again at once.
let r2 = run(600, (s) => s < 400 ? knocking(s) : (s == 400 ? { hs: true, drx: 148 + 1400, dtx: 4000 } : phone(s, true)));
eq(r2.changes[1], { s: 400, from: 'trying', to: null, since: 0, ev: 'device_recovered' }, 'connected: recovered');
// It gives up (the app was turned off): the state goes without a "recovered".
let r3 = run(1200, (s) => s < 300 ? knocking(s) : {});
eq(r3.changes[1].to, null, 'cleared');
eq(r3.changes[1].ev, null, 'nobody saw it work');
// The last knock at 295 s: it ages out of TRY_SPAN by 415 s, and HOLD passes by 595 s.
eq(r3.changes[1].s, 595, 'only after the knocks aged out and HOLD passed');
});
test('trying after a session that ran out', () => {
// Online until 200 s; then its new keys never complete (the answers are lost).
let at = (s) => s < 200 ? phone(s, true) : (s % 5 == 0 ? { drx: 148, dtx: 92 } : {});
let r = run(900, at);
eq(r.changes[0].to, 'trying', 'after the online window');
ok(r.changes[0].s > 129 + 190, 'not while the old session still counted');
});
test('shared: one configuration on two devices', () => {
// Each takes the session from the other every 20 s; the endpoint flips with every packet.
let r = run(600, (s) => ({ hs: s % 20 == 0, drx: 2000, dtx: 6000, ep: s % 2 ? B : A }));
eq(r.raws.shared, 60, 'from the fourth handshake');
eq(r.changes[0], { s: 240, from: null, to: 'shared', since: 60, ev: 'device_failing' }, 'shown once it held');
eq(r.raws.unstable, null, 'never taken for a breaking connection');
// Two devices behind one NAT: one address, two ports.
let r2 = run(600, (s) => ({ hs: s % 20 == 0, drx: 2000, dtx: 6000, ep: s % 2 ? '203.0.113.7:1111' : '203.0.113.7:2222' }));
eq(r2.changes[0]?.to, 'shared', 'told apart by port');
});
test('unstable: connecting over and over from one place', () => {
let r = run(600, (s) => ({ hs: s % 20 == 0, drx: s % 20 < 5 ? 3000 : 0, dtx: s % 20 < 5 ? 9000 : 0 }));
eq(r.raws.unstable, 60, 'from the fourth quick handshake');
eq(r.changes[0], { s: 240, from: null, to: 'unstable', since: 60, ev: 'device_failing' }, 'shown once it held');
// Moving once (wifi to mobile) while it breaks is still the connection, not a second device.
let r2 = run(600, (s) => ({ hs: s % 20 == 0, drx: 3000, dtx: 9000, ep: s < 100 ? A : B }));
eq(r2.changes[0]?.to, 'unstable', 'one move is no alternation');
// It settles down: working again once the quick handshakes left the span.
let r3 = run(1200, (s) => s < 300 ? { hs: s % 20 == 0, drx: 3000, dtx: 9000 } : phone(s, true));
eq(r3.changes[1]?.to, null, 'cleared');
eq(r3.changes[1]?.ev, 'device_recovered', 'online: recovered');
// Normal key renewals never churn, even at RekeyAfterTime's shortest (100 s).
eq(run(1800, (s) => ({ hs: s % 100 == 0, drx: s % 25 == 0 ? 32 : 0 })).changes, [], '3.1 timers');
});
/*
* An old address after renumbering: every packet it sends is dropped after
* decryption (not counted in rx), the router answers with a keepalive every
* ~10 s, the device renews its keys every ~125 s (the first packet under them
* is data, so only the initiation shows in rx).
*/
function renumbered(s) {
if (s % 125 == 3)
return { drx: 148, dtx: 92 };
if (s % 125 == 4)
return { hs: true };
return s % 10 == 7 ? { dtx: 32 } : {};
}
test('dropped: connected, but nothing it sends gets through', () => {
let r = run(900, renumbered, { hs0: T0 - 30 });
// Classified on the router's next answer after DROP_SPAN (187 s).
eq(r.raws.dropped, 187, 'once DROP_SPAN passed without data');
eq(r.changes[0], { s: 367, from: null, to: 'dropped', since: 187, ev: 'device_failing' }, 'shown once it held');
// Imported again at 500 s: data flows, working at once.
let r2 = run(900, (s) => s < 500 ? renumbered(s) : (s == 500 ? { hs: true, drx: 3000, dtx: 9000 } : phone(s, true)), { hs0: T0 - 30 });
eq(r2.changes[1], { s: 500, from: 'dropped', to: null, since: 0, ev: 'device_recovered' }, 'recovered');
// With the disguise's padding the router's answers are bigger; still under DROP_TX.
let r3 = run(900, (s) => { let x = renumbered(s); if (x.dtx == 32) x.dtx = 32 + 1400; return x; }, { hs0: T0 - 30, ka: 132 });
eq(r3.changes[0]?.to, 'dropped', 'padded answers');
// Not before the history covers DROP_SPAN (the agent just started).
eq(run(170, renumbered, { hs0: T0 - 30 }).raws, {}, 'too early to tell');
});
test('counters that restart are a new baseline', () => {
let h = link.fresh(T0);
let peer = { endpoint: A, handshake: T0, rx: 50000, tx: 90000 };
link.observe(h, peer, T0, 32);
peer.rx = 148;
peer.tx = 92;
link.observe(h, peer, T0 + 1, 32);
eq([ h.rx, h.tx, length(h.knocks), h.data ], [ 148, 92, 0, 0 ], 'the peer was added again: no knock, no data');
link.gone(h);
eq(h.rx, null, 'not in the tunnel');
eq(link.observe(h, { ...peer, rx: 5000 }, T0 + 2, 32), false, 'back: a baseline, nothing counted');
eq(h.data, 0, 'no data from the jump');
});
test('knock and bare', () => {
eq([ link.knock(148), link.knock(296), link.knock(444) ], [ true, true, true ], 'one to three initiations');
eq([ link.knock(592), link.knock(180), link.knock(0) ], [ false, false, false ], 'too many, with something else, nothing');
eq([ link.bare(32, 32, false), link.bare(0, 32, false), link.bare(180, 32, true), link.bare(124, 32, true), link.bare(92, 32, true) ],
[ true, true, true, true, true ], 'keepalive, nothing; in a handshake\'s second: initiation + keepalive, response + keepalive, response');
// Plain data is 32 + a multiple of 16: an IPv4 header alone is 64, a TCP ACK 80 or 96.
eq([ link.bare(64, 32, false), link.bare(80, 32, true), link.bare(96, 32, false), link.bare(1480, 32, true), link.bare(5000, 32, false) ],
[ false, false, false, false, false ], 'data');
eq([ link.bare(180, 32, false), link.bare(124, 32, false), link.bare(92, 32, false) ], [ false, false, false ],
'handshake messages only count in the second a handshake completed');
// Padding makes it fuzzy: in a handshake's second anything up to three initiations, a response and a
// padded keepalive; in any other second one padded keepalive, never more.
eq([ link.bare(100, 132, false), link.bare(148 + 132, 132, true), link.bare(3 * 148 + 92 + 132, 132, true), link.bare(3 * 148 + 92 + 133, 132, true) ],
[ true, true, true, false ], 'padded keepalives');
eq([ link.bare(133, 132, false), link.bare(148 + 52, 132, false), link.bare(668, 132, false) ], [ false, false, false ],
'small packets on Maximum: data');
});
test('keepalive_max', () => {
eq(link.keepalive_max(null), 32, 'no server');
eq(link.keepalive_max({ obf: {} }), 32, 'no disguise');
eq(link.keepalive_max({ obf: { content_padding_addition: '10-100' } }), 132, 'content padding');
eq(link.keepalive_max({ obf: { content_padding_addition: '40' } }), 72, 'a fixed padding');
eq(link.keepalive_max({ obf: { content_padding_addition: '10-100', random_trailers: 'on' } }), 132, 'content padding wins over trailers');
eq(link.keepalive_max({ obf: { random_trailers: 'on' } }), 1532, 'random trailers: up to a full packet');
let m = { servers: { s_1: { obf: { content_padding_addition: '10-100' } } }, people: { p_1: { server: 's_1' } },
devices: { d_1: { person: 'p_1' }, d_2: { person: 'p_gone' } } };
eq(link.keepalive_sizes(m), { d_1: 132, d_2: 32 }, 'per device');
});
test('settle holds a state before it shows', () => {
let h = link.fresh(T0);
eq(link.settle(h, 'trying', T0, false), null, 'new: waits');
eq(link.settle(h, 'trying', T0 + link.HOLD - 1, false), null, 'still waits');
eq(link.settle(h, 'trying', T0 + link.HOLD, false), { from: null, to: 'trying' }, 'held: shown');
eq([ h.state, h.since ], [ 'trying', T0 ], 'since it began');
eq(link.settle(h, 'unstable', T0 + 200, true), null, 'another state waits too');
eq(link.settle(h, 'trying', T0 + 210, true), null, 'and is forgotten when the first comes back');
eq(h.pend, null, 'nothing pending');
eq(link.settle(h, null, T0 + 220, true), { from: 'trying', to: null }, 'online and fine: at once');
eq([ h.state, h.since ], [ null, 0 ], 'nothing shown');
eq(link.shown({ d_1: h, d_2: { state: 'shared', since: 5 } }), { d_2: { state: 'shared', since: 5 } }, 'only what shows');
eq(link.event_for({ from: 'shared', to: null }, { id: 'd_2', person: 'p_1' }, true),
{ type: 'device_recovered', person: 'p_1', device: 'd_2', detail: 'shared' }, 'recovered event');
eq(link.event_for({ from: null, to: 'dropped' }, { id: 'd_2', person: 'p_1' }, true),
{ type: 'device_failing', person: 'p_1', device: 'd_2', detail: 'dropped' }, 'failing event');
eq(link.event_for(null, { id: 'd_2' }, true), null, 'no change');
});
// The agent moves the person's revision on every change settle() makes, so a
// state that clears while the device is away (no event) still leaves the page.
test('settle clears a state silently while the device is away', () => {
let h = link.fresh(T0);
link.settle(h, 'trying', T0, false);
link.settle(h, 'trying', T0 + link.HOLD, false);
eq(link.settle(h, null, T0 + 300, false), null, 'it stopped trying: waits');
let ch = link.settle(h, null, T0 + 300 + link.HOLD, false);
eq(ch, { from: 'trying', to: null }, 'then a change: nothing shown');
eq(link.event_for(ch, { id: 'd_1', person: 'p_1' }, false), null, 'without an activity event');
});
/*
* The set-up sheet's states: at once, no HOLD. Each run also checks that the
* state setup() keeps, worked out only when something happened, is what
* setup_state() gives on every read.
*/
test('setup: knocks that never finish connecting', () => {
let knocking = (s) => (s % 120 < 90 && s % 5 == 0) ? { drx: 148, dtx: 92 } : {};
let r = run(300, knocking);
// The first read is the baseline: the knocks count from 5 s.
eq(slice(r.setups, 0, 3), [ { s: 10, state: 'trying' }, { s: 100, state: null }, { s: 125, state: 'trying' } ],
'with the second initiation; gone 15 s after the last one (85 s); back with the next two');
eq(run(130, knocking).h.setup, { state: 'trying', since: T0 + 125 }, 'since it began again');
eq(r.lag, [], 'never behind');
// One initiation that the next second confirms is a connection, not a knock.
let ok1 = run(60, (s) => s == 10 ? { drx: 148, dtx: 92 } : s == 11 ? { hs: true, drx: 32 } : {});
eq(ok1.setups, [], 'one knock, then the handshake: nothing to tell (idle)');
// Knocking again while an older session still counts as online: it is trying now.
let late = run(300, (s) => s < 200 ? phone(s, true) : (s % 5 == 0 ? { drx: 148, dtx: 92 } : {}));
eq(late.setups[length(late.setups) - 1], { s: 205, state: 'trying' }, 'its new keys never complete');
eq(late.lag, [], 'never behind');
});
test('setup: a new device that connects and passes data', () => {
// It knocks at 10 s, the next second its first packets under the new keys carry data.
let at = (s) => s < 10 ? {} : s == 10 ? { drx: 148, dtx: 92 } : s == 11 ? { hs: true, drx: 32 + 1400, dtx: 4000 } : phone(s, true);
let r = run(900, at);
eq(r.setups, [ { s: 11, state: 'flowing' } ], 'flowing with the handshake, and through every new key after');
eq(r.h.setup, { state: 'flowing', since: T0 + 11 }, 'since then');
eq(r.lag, [], 'never behind');
// A first keepalive only, data a few seconds later.
let r2 = run(60, (s) => s == 11 ? { hs: true, drx: 32 } : s == 14 ? { drx: 1400, dtx: 9000 } : {});
eq(r2.setups, [ { s: 14, state: 'flowing' } ], 'with the first data');
// Busy until 300 s, then gone: its session ends 190 s after its last handshake (254 s).
let r3 = run(600, (s) => s < 300 ? phone(s, true) : {});
eq(r3.setups, [ { s: 30, state: 'flowing' }, { s: 444, state: null } ], 'data from 30 s (what came before the handshake does not count); away: nothing');
eq(r3.lag, [], 'never behind');
});
test('setup: idle is not "no data"', () => {
// Connected, keepalives only: the router sends nothing back, nothing to tell.
let r = run(900, (s) => phone(s, false));
eq(r.setups, [], 'a sleeping phone');
eq(r.lag, [], 'never behind');
// The router sends it something now and then, and it answers: data flows.
eq(run(120, (s) => s == 4 ? { hs: true, drx: 32 } : s == 30 ? { dtx: 300, drx: 96 } : {}).setups,
[ { s: 30, state: 'flowing' } ], 'an answer is data');
});
test('setup: connected, but nothing it sends comes through', () => {
// An old address: its first handshake at 4 s, the router's answers to what it drops at 7, 17, 27 s...
let r = run(400, renumbered);
eq(r.setups, [ { s: 19, state: 'nodata' } ], 'SETUP_QUIET after the handshake, with an answer in it');
eq(r.lag, [], 'never behind, through its new keys at 128 s');
// Imported again at 300 s: data flows at once.
let r2 = run(400, (s) => s < 300 ? renumbered(s) : s == 300 ? { hs: true, drx: 3000, dtx: 9000 } : phone(s, true));
eq(r2.setups, [ { s: 19, state: 'nodata' }, { s: 300, state: 'flowing' } ], 'then flowing');
// The router answers only after the quiet span: shown with the answer.
let slow = run(60, (s) => s == 4 ? { hs: true } : s == 25 ? { dtx: 32 } : {});
eq(slow.setups, [ { s: 25, state: 'nodata' } ], 'with the first answer');
eq(slow.lag, [], 'never behind');
});
test('setup: light traffic on Maximum is data', () => {
// Content padding of 10-100: keep-alives of 42-132 bytes. A phone that only sends small packets (a DNS
// query, a SYN, ACKs: 150-600 bytes a second), and an answer now and then in a second it sent nothing.
let at = (s) => s == 3 ? { drx: 148, dtx: 92 } : s == 4 ? { hs: true, drx: 42 } :
s > 4 && s % 3 == 0 ? { drx: 150 + (s % 5) * 100, dtx: 1200 } : s % 7 == 0 ? { dtx: 600 } : {};
let r = run(60, at, { ka: 132 });
eq(r.setups, [ { s: 6, state: 'flowing' } ], 'flowing with its first small packets, never "no data"');
eq(r.lag, [], 'never behind');
// A keep-alive alone in a second is still no data: an idle phone on Maximum stays idle.
eq(run(120, (s) => s == 4 ? { hs: true, drx: 42 } : s % 25 == 0 ? { drx: 42 + (s % 90) } : {}, { ka: 132 }).setups, [],
'padded keep-alives');
});
test('setups', () => {
let h = link.fresh(T0);
eq(link.setups({ d_1: h, d_2: { setup: { state: 'trying', since: 5 } } }), { d_2: { state: 'trying', since: 5 } }, 'only devices with one');
eq(link.setup_state(h, T0, false), { state: null, due: 0 }, 'nothing seen: nothing');
});
+115 -1
View File
@@ -1,6 +1,10 @@
// dawnline.live: event categories and the retention policy, from a settings
// object and from the fixture config (real libuci).
// object and from the fixture config (real libuci); which tunnels are read,
// the counters folded from a read, how long a device counts as online, and
// what of the agent's files a read takes (RUN_DIR, put back after).
import * as live from 'dawnline.live';
import { RUN_DIR } from 'dawnline.util';
import { readfile, writefile, unlink } from 'fs';
test('category_of', () => {
eq(live.category_of('connect'), 'connections', 'connect');
@@ -66,3 +70,113 @@ test('fill_places', () => {
ok(!live.fill_places(ev, { '7.7.7.7': 'X' }, 0), 'nothing to fill: unchanged');
ok(!live.fill_places([], { '1.1.1.1': 'X' }, 0), 'empty log');
});
test('tunnel_ifnames: the servers that run, on interfaces of their own', () => {
let srv = (ifname, more) => ({ enabled: true, private_key: 'k', ifname, subnet: '10.9.0.0/29', ...(more ?? {}) });
let m = { servers: {
a: srv('awga'), off: srv('awgoff', { enabled: false }), keyless: srv('awgk', { private_key: '' }),
taken: srv('lan', { blocked: { code: 'taken', ifname: 'lan' } }), bad: srv('Bad Name'),
} };
eq(live.tunnel_ifnames(m), [ 'awga' ], 'not turned off, without keys, kept down or misnamed');
eq(live.tunnel_ifnames({ servers: {} }), [], 'none');
m.servers.b = srv('awgb');
eq(live.tunnel_ifnames(m, 'b'), [ 'awgb' ], 'one server\'s (a person\'s page)');
eq([ live.tunnel_ifnames(m, 'off'), live.tunnel_ifnames(m, ''), live.tunnel_ifnames(m, 'gone') ], [ [], [], [] ],
'one that does not run, no server, an unknown one: nothing');
});
// What a read that failed, a tunnel that is down and a new link do to the counters.
test('collect: counters per tunnel read', () => {
let m = {
servers: { a: { ifname: 'awga' }, b: { ifname: 'awgb' } },
people: { pa: { server: 'a' }, pb: { server: 'b' } },
devices: { da: { person: 'pa', public_key: 'KA' }, db: { person: 'pb', public_key: 'KB' } },
settings: { retention: {} },
};
let usage = { devices: { da: { raw: [ 40, 10 ], ifindex: 7 }, db: { raw: [ 500, 500 ] } }, people: {} };
let peer = (rx, tx) => ({ KA: { ifname: 'awga', endpoint: '', handshake: 0, rx, tx } });
live.collect(m, usage, { ok: false, reads: { awga: 'read', awgb: 'error' }, ifaces: { awga: { ifindex: 7 } }, peers: peer(100, 50) });
eq(usage.devices.da.total, [ 60, 40 ], 'the difference since the last read');
eq(usage.people.pa.total, [ 60, 40 ], 'their person');
eq(usage.devices.db.raw, [ 500, 500 ], 'a tunnel that could not be read keeps its counters');
live.collect(m, usage, { ok: true, reads: { awga: 'read', awgb: 'down' }, ifaces: { awga: { ifindex: 7 } }, peers: peer(100, 50) });
eq(usage.devices.db.raw, [ 0, 0 ], 'a tunnel that is down starts again from zero');
eq(usage.devices.da.total, [ 60, 40 ], 'nothing new');
// Set up again: a new link whose counters already passed the old ones.
live.collect(m, usage, { ok: true, reads: { awga: 'read' }, ifaces: { awga: { ifindex: 8 } }, peers: peer(150, 80) });
eq(usage.devices.da.total, [ 210, 120 ], 'a new link counts from zero');
eq(usage.devices.da.ifindex, 8, 'the record follows its link');
// A link whose index is unknown changes nothing about the epoch.
live.collect(m, usage, { ok: true, reads: { awga: 'read' }, ifaces: { awga: { ifindex: null } }, peers: peer(160, 90) });
eq([ usage.devices.da.total, usage.devices.da.ifindex ], [ [ 220, 130 ], 8 ], 'counted on');
});
// The window follows the keep-alive the device's configuration carries
// (awg.idle_handshake): 190 s for every default, longer only where the
// handshakes of an idle device are further apart.
test('online_window', () => {
let srv = { keepalive: 25, obf: {} };
eq(live.online_window(srv, {}), 190, 'the default keep-alive');
eq(live.online_window({ keepalive: 25, obf: { header_protection_key: 'k', rekey_after_time: '100-120' } }, {}), 190, 'Maximum');
eq(live.online_window(srv, { keepalive: 0 }), 190, 'keep-alive off: the session alone');
eq(live.online_window(srv, { keepalive: 100 }), 250, 'a handshake every second keep-alive');
eq(live.online_window(srv, { keepalive: 300 }), 330, 'one every keep-alive');
eq(live.online_window({ keepalive: 300, obf: {} }, {}), 330, 'the server\'s keep-alive');
eq(live.online_window(null, {}), 190, 'no server');
let m = { servers: { a: srv }, people: { p: { server: 'a' } }, devices: { d: { person: 'p', keepalive: 300 }, e: { person: 'x' } } };
eq(live.online_windows(m), { d: 330, e: 190 }, 'per device');
eq(live.online_windows(m, 'a'), { d: 330 }, 'one server\'s devices');
});
test('online: without the agent, by the device\'s window', () => {
let peer = { handshake: time() - 300 };
eq(live.online({ presence: null, windows: { d: 330 } }, 'd', peer), true, 'within its window');
eq(live.online({ presence: null }, 'd', peer), false, 'the shortest window');
eq(live.online({ presence: { online: { d: false } }, windows: { d: 330 } }, 'd', peer), false, 'the agent\'s word first');
});
test('collect: online by the device\'s window', () => {
let m = {
servers: { a: { ifname: 'awga', keepalive: 300, obf: {} } },
people: { pa: { server: 'a' } },
devices: { da: { person: 'pa', public_key: 'KA' }, db: { person: 'pa', public_key: 'KB', keepalive: 25 } },
settings: { retention: {} },
};
let hs = time() - 300;
let peers = { KA: { ifname: 'awga', endpoint: '', handshake: hs, rx: 0, tx: 0 }, KB: { ifname: 'awga', endpoint: '', handshake: hs, rx: 0, tx: 0 } };
let v = live.collect(m, { devices: {}, people: {} }, { ok: true, reads: { awga: 'read' }, ifaces: { awga: { ifindex: 1 } }, peers });
eq([ v.da.online, v.db.online ], [ true, false ], 'the server\'s keep-alive of 300 s, and a device\'s own of 25 s');
});
// What the agent's watcher shows of each link (dawnline.link) reaches the
// read models through dump(), only while the agent runs.
test('dump: link and set-up states while the agent runs', () => {
let beat = `${RUN_DIR}/agent.beat`;
let had_beat = readfile(beat), had_link = readfile(live.LINK), had_setup = readfile(live.SETUP);
let shown = { d_1: { state: 'trying', since: 1800000000 } }, setups = { d_1: { state: 'trying', since: 1800000000 } };
writefile(live.LINK, sprintf('%J', shown));
writefile(live.SETUP, sprintf('%J', setups));
writefile(beat, `${time()}`);
let m = { servers: {}, people: {}, devices: {} };
eq(live.dump(m).link, shown, 'the watcher\'s states');
eq(live.dump(m).setup, setups, 'and its set-up states');
writefile(beat, `${time() - 600}`);
eq(live.dump(m).link, {}, 'a stopped agent\'s states are stale');
eq(live.dump(m).setup, null, 'and nobody tells the set-up states');
for (let f in [ [ beat, had_beat ], [ live.LINK, had_link ], [ live.SETUP, had_setup ] ])
f[1] == null ? unlink(f[0]) : writefile(f[0], f[1]);
});
// A link that keeps failing is one line per device (add_event_merged), not one per device and person.
test('add_event_merged: per device', () => {
let path = `${RUN_DIR}/events.json`, had = readfile(path);
writefile(path, '[]');
live.add_event_merged({ type: 'device_failing', person: 'p_x', device: 'd_x1', detail: 'trying' }, 3600);
live.add_event_merged({ type: 'device_failing', person: 'p_x', device: 'd_x1', detail: 'unstable' }, 3600);
live.add_event_merged({ type: 'device_failing', person: 'p_x', device: 'd_x2', detail: 'shared' }, 3600);
let ev = live.load_events();
eq(map(ev, (e) => [ e.device, e.detail ]), [ [ 'd_x1', 'trying, unstable' ], [ 'd_x2', 'shared' ] ], 'merged per device');
eq(live.category_of('device_failing'), 'problems', 'a problem');
eq(live.category_of('device_recovered'), 'problems', 'and so is its end');
had == null ? unlink(path) : writefile(path, had);
});
+52 -1
View File
@@ -1,5 +1,7 @@
// dawnline.loop: the "like a home device" link's errors, stored as codes and
// put into words when read; the netns's MAC and which LAN address it may use.
// put into words when read; the netns's MAC and which LAN address it may use;
// the policy rules for the servers that send their devices this way, and the
// commands that bring the rules the kernel shows to them.
import * as loop from 'dawnline.loop';
import { ip2int, parse_cidr } from 'dawnline.util';
@@ -56,3 +58,52 @@ test('ns_rules', () => {
ok(index(plain, 'flowtable') < 0 && index(plain, 'flow add') < 0, 'plain: no flowtable');
eq(replace(fast, /\n\tflowtable ft \{(\n\t\t[^\n]*)*\n\t\}|\n\t\tct state established meta l4proto \{ tcp, udp \} flow add @ft/g, ''), plain, 'otherwise the same rules');
});
// A plan with one server sending its devices like a home device (plan() makes
// it, from the server's interface, its tunnel and its home networks).
const PLAN = { address: '192.168.1.250', table: 2077,
servers: [ { ifname: 'awghome', subnet: '10.9.0.0/29', direct: [ '10.9.0.0/29', '192.168.1.0/24' ] } ] };
test('rules', () => {
eq(loop.rules(PLAN), [
{ pref: 5205, iif: 'awghome', to: '192.168.1.250/32', table: '2077' },
{ pref: 5210, iif: 'awghome', to: '10.9.0.0/29', table: 'main' },
{ pref: 5210, iif: 'awghome', to: '192.168.1.0/24', table: 'main' },
{ pref: 5290, iif: 'awghome', to: null, table: '2077' },
], 'DNS into the netns, home and the tunnel by main, the rest into the netns');
eq(loop.rules({ servers: [] }), [], 'no server sends anyone');
eq(loop.rules(null), [], 'no plan');
});
// What `ip -j -4 rule show` prints for the rules of PLAN: "src": "all" for a
// rule without a source, a /32 without its length (iproute2 iprule.c).
const HOME_SHOWN = [
{ priority: 5205, src: 'all', iif: 'awghome', dst: '192.168.1.250', table: '2077' },
{ priority: 5210, src: 'all', iif: 'awghome', dst: '10.9.0.0', dstlen: 29, table: 'main' },
{ priority: 5210, src: 'all', iif: 'awghome', dst: '192.168.1.0', dstlen: 24, table: 'main' },
{ priority: 5290, src: 'all', iif: 'awghome', table: '2077' },
];
test('rule_cmds: the rules the kernel shows, against the plan', () => {
eq(loop.rule_cmds(PLAN, HOME_SHOWN), [], 'as wanted: nothing to do (no rule added again, none removed)');
eq(loop.rule_cmds(PLAN, slice(HOME_SHOWN, 0, 3)), [ "ip -4 rule add priority 5290 iif 'awghome' lookup 2077" ], 'one gone: only it comes back');
eq(loop.rule_cmds(PLAN, [ ...HOME_SHOWN, HOME_SHOWN[3] ]), [ "ip -4 rule del priority 5290 iif 'awghome' lookup 2077" ], 'one twice: one of them goes');
eq(loop.rule_cmds(PLAN, []), [
"ip -4 rule add priority 5205 iif 'awghome' to 192.168.1.250/32 lookup 2077",
"ip -4 rule add priority 5210 iif 'awghome' to 10.9.0.0/29 lookup main",
"ip -4 rule add priority 5210 iif 'awghome' to 192.168.1.0/24 lookup main",
"ip -4 rule add priority 5290 iif 'awghome' lookup 2077",
], 'none yet: all of them');
eq(loop.rule_cmds({ servers: [] }, HOME_SHOWN), [
"ip -4 rule del priority 5205 iif 'awghome' to 192.168.1.250 lookup 2077",
"ip -4 rule del priority 5210 iif 'awghome' to 10.9.0.0/29 lookup main",
"ip -4 rule del priority 5210 iif 'awghome' to 192.168.1.0/24 lookup main",
"ip -4 rule del priority 5290 iif 'awghome' lookup 2077",
], 'none wanted: each removed as shown, without "from all"');
eq(loop.rule_cmds({ ...PLAN, servers: [ { ...PLAN.servers[0], direct: [ '10.9.0.0/29', '192.168.2.0/24' ] } ] }, HOME_SHOWN), [
"ip -4 rule add priority 5210 iif 'awghome' to 192.168.2.0/24 lookup main",
"ip -4 rule del priority 5210 iif 'awghome' to 192.168.1.0/24 lookup main",
], 'another home network: the new rule first, then the old one goes');
eq(loop.rule_cmds(PLAN, [ ...HOME_SHOWN, { priority: 5290, src: '10.9.0.2', iif: 'awghome', table: '2077' } ]),
[ "ip -4 rule del priority 5290 from 10.9.0.2 iif 'awghome' lookup 2077" ], 'a rule of ours with a source is not one of them: it goes');
});
+73
View File
@@ -0,0 +1,73 @@
// dawnline.meter: the point between two samples (each server's bytes per
// second), the sample taken from a dump, the two minutes kept, and the file
// the watcher writes and the RPC reads (in RUN_DIR, removed after).
import * as meter from 'dawnline.meter';
import { stat, unlink } from 'fs';
test('point', () => {
let a = {
t: 100.0, ts: 5000, servers: [ 's_1', 's_2' ],
dev: { d_1: [ 1000, 2000, 's_1' ], d_2: [ 500, 500, 's_1' ], d_3: [ 9000, 9000, 's_1' ], d_5: [ 0, 0, 's_2' ] },
};
let b = {
t: 101.0, ts: 5001, servers: [ 's_1', 's_2' ],
// d_2 sent nothing; d_3's peer was added again (counters from zero); d_4 is new; d_5 moved to s_1.
dev: { d_1: [ 3000, 12000, 's_1' ], d_2: [ 500, 500, 's_1' ], d_3: [ 100, 300, 's_1' ], d_4: [ 10, 10, 's_1' ], d_5: [ 50, 50, 's_1' ] },
};
eq(meter.point(a, b), { ts: 5001, servers: { s_1: [ 2000, 10000 ], s_2: [ 0, 0 ] } },
'bytes per second of each server\'s devices together; a server read with nothing moving is 0');
eq(meter.point(a, { ...b, t: 102.0 }).servers.s_1, [ 1000, 5000 ], 'over two seconds');
eq(meter.point(a, { ...b, t: 100.0 }), null, 'no time passed');
eq(meter.point(a, { ...b, t: 110.0 }), null, 'the watcher stalled');
eq(meter.point(a, { ...b, servers: [ 's_2' ], dev: { d_5: [ 50, 50, 's_2' ] } }).servers, { s_2: [ 50, 50 ] }, 'only servers read in the newer sample');
eq(meter.point({ ...a, dev: {} }, b).servers, { s_1: [ 0, 0 ], s_2: [ 0, 0 ] }, 'a first look at every device: nothing yet');
});
test('sample', () => {
let m = {
servers: { s_1: { ifname: 'dawn0' }, s_2: { ifname: 'dawn9' } },
people: { p: { server: 's_1' }, q: { server: 's_2' } },
devices: { d_1: { person: 'p', public_key: 'K1' }, d_2: { person: 'p', public_key: 'K2' }, d_3: { person: 'q', public_key: 'K3' } },
};
let d = { reads: { dawn0: 'read', dawn9: 'error' }, peers: { K1: { rx: 10, tx: 20 }, K3: { rx: 1, tx: 1 } } };
let s = meter.sample(m, d, 5000);
eq([ s.ts, s.servers, s.dev ], [ 5000, [ 's_1' ], { d_1: [ 10, 20, 's_1' ] } ],
'the servers read and their devices in the tunnel; not a tunnel that could not be read');
ok(s.t > 0, 'monotonic time');
});
test('keep', () => {
let pt = (ts) => ({ ts: ts, servers: { s_1: [ ts, 0 ] } });
let ring = [];
for (let ts = 1000; ts < 1000 + meter.POINTS + 5; ts++)
meter.keep(ring, pt(ts));
eq([ length(ring), ring[0][0], ring[length(ring) - 1][0] ], [ meter.POINTS, 1005, 1000 + meter.POINTS + 4 ],
'the last POINTS seconds, newest last');
eq(json(ring[0][1]), pt(1005), 'each point kept as its JSON');
meter.keep(ring, pt(5000));
eq(map(ring, (r) => r[0]), [ 5000 ], 'after a stalled watcher: nothing older than two minutes');
meter.keep(ring, pt(5001));
meter.keep(ring, pt(5002));
meter.keep(ring, pt(5001));
eq(map(ring, (r) => r[0]), [ 5000, 5001 ], 'a clock that went back: its points replace the later ones');
});
test('want, save and read', () => {
let had = stat(meter.WANT) != null;
meter.want();
ok(meter.wanted(time()), 'just asked');
ok(!meter.wanted(time() + meter.WANT_FOR), 'stale after WANT_FOR');
ok(!meter.wanted(time() - meter.WANT_FOR - 1), 'a clock that went back does not keep it');
let t = time();
meter.save([ [ t - 2, `{"ts":${t - 2},"servers":{}}` ], [ t - 1, `{"ts":${t - 1},"servers":{}}` ], [ t, `{"ts":${t},"servers":{"s_1":[1,2]}}` ] ]);
let r = meter.read(0);
eq([ r.ts, length(r.points), r.want, r.keep ], [ t, 3, meter.WANT_FOR, meter.POINTS ], 'everything');
eq(meter.read(t - 1).points, [ { ts: t, servers: { s_1: [ 1, 2 ] } } ], 'only what is newer');
let old = t - meter.WANT_FOR - 1;
meter.save([ [ old, `{"ts":${old},"servers":{}}` ] ]);
eq([ meter.read(0).ts, meter.read(0).points ], [ old, [] ], 'left by an agent that died while someone looked: no points');
meter.stop();
eq([ meter.read(0).ts, meter.read(0).points ], [ 0, [] ], 'nobody looks: nothing');
if (!had)
unlink(meter.WANT);
});
+57
View File
@@ -0,0 +1,57 @@
// dawnline.netifd: drift(), the watchdog's look at a server's interface
// (network.<ifname> against what sync() writes, markers aside), on the
// fixture's server and a section this test puts into /etc/config/network
// the way sync() writes it, and takes out again.
import { readfile, writefile, unlink } from 'fs';
import { cursor } from 'uci';
import { uci_put } from 'dawnline.util';
import * as core from 'dawnline.core';
import * as awg from 'dawnline.awg';
import * as netifd from 'dawnline.netifd';
const NETWORK = '/etc/config/network';
test('drift: the interface as Dawnline set it, and edited outside it', () => {
let had = readfile(NETWORK);
if (had == null)
writefile(NETWORK, '');
let m = core.load();
let srv = m.servers.main;
let c = cursor();
c.load('network');
c.set('network', 'awgmain', 'interface');
for (let k, v in awg.netifd_options(srv))
uci_put(c, 'network', 'awgmain', k, v);
c.set('network', 'awgmain', '_dawnline', 'main');
c.set('network', 'awgmain', '_dawnline_name', srv.name);
c.commit('network');
let edit = (opt, val) => {
uci_put(c, 'network', 'awgmain', opt, val);
c.commit('network');
return netifd.drift(m);
};
let got = { as_set: netifd.drift(m) };
got.renamed = edit('_dawnline_name', 'Renamed in LuCI');
got.edited = edit('mtu', '1420');
got.more = edit('awg_jc', null);
edit('mtu', `${core.tunnel_mtu(srv)}`);
got.restored = edit('awg_jc', srv.obf.jc);
got.disabled = edit('disabled', '1');
edit('disabled', null);
got.foreign = edit('_dawnline', 'someone');
m.servers.main.enabled = false;
got.off = netifd.drift(m);
// Put the router back as the other tests know it.
c.delete('network', 'awgmain');
c.commit('network');
if (had == null)
unlink(NETWORK);
eq(got.as_set, { main: [] }, 'as sync() writes it');
eq(got.renamed, { main: [] }, 'the markers are not compared');
eq(got.edited, { main: [ 'mtu' ] }, 'an option changed by hand');
eq(got.more, { main: [ 'mtu', 'awg_jc' ] }, 'and one removed, by name only');
eq(got.restored, { main: [] }, 'put back');
eq(got.disabled, { main: [ 'disabled' ] }, 'switched off outside Dawnline');
eq(got.foreign, {}, "a section that isn't the server's is not looked at");
eq(got.off, {}, 'a server turned off is not looked at');
});
+49
View File
@@ -0,0 +1,49 @@
// dawnline.nft: the access table rendered for a model with two servers (one
// sending everyone like a home device, one direct) and the router read as a
// fixed context: exactly what 0.13.0 renders (fixtures/nft-table.txt, made by
// that version from this model).
import { readfile } from 'fs';
import * as nft from 'dawnline.nft';
const KEY = 'yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=';
const SNAP = { devices: { 'br-lan': { nets: [ '192.168.1.0/24' ], zone: 'lan', addrs: [ '192.168.1.1/24' ] }, eth1: { nets: [], zone: 'wan' } },
wan: 'eth1', lan: 'br-lan', zones: [ 'lan', 'wan' ] };
// The netns is up (its DNS address, the Home-only resolver inside it) and the LAN's DNS is the router.
const CTX = { dns_addr: '192.168.1.250', resolver: { mode: 'ns', address: '169.254.77.2', port: 53 }, lan_dns: '192.168.1.1', snap: SNAP };
const STATES = { alice: 'active', bob: 'active', carol: 'active', dave: 'active', erin: 'active' };
let golden = readfile(sourcepath(0, true) + '/fixtures/nft-table.txt');
/** Server home sends everyone like a home device, work sends everyone direct. */
function model() {
let srv = (id, ifname, subnet, lan_like, mesh) => ({ id, name: id, ifname, subnet, private_key: KEY, enabled: true, lan_like, mesh,
auto_wan: true, auto_lan: true, lan_devices: [], lan_zone: 'lan', wan_zone: 'wan', obf: {} });
let person = (id, server, access, extra) => ({ id, name: id, server, access, dns_mode: 'device', services: [], home_nets: [],
circle: '', ...(extra ?? {}) });
let dev = (person, address) => ({ person, address, disabled: false });
return {
settings: { portal_enabled: true, portal_port: 8443, portal_host: 'vpn.example.com', portal_alt: [] },
servers: { home: srv('home', 'awghome', '10.9.0.0/29', true, 'all'), work: srv('work', 'awgwork', '10.9.1.0/29', false, 'circles') },
people: {
alice: person('alice', 'home', 'both'), bob: person('bob', 'work', 'internet'),
carol: person('carol', 'home', 'lan', { dns_mode: 'home' }), dave: person('dave', 'home', 'internet'),
erin: person('erin', 'work', 'both'),
},
devices: {
a1: dev('alice', '10.9.0.2'), b1: dev('bob', '10.9.1.2'), c1: dev('carol', '10.9.0.3'),
d1: dev('dave', '10.9.0.4'), d2: dev('dave', '10.9.0.5'), e1: dev('erin', '10.9.1.3'),
},
services: {}, circles: {},
};
}
function render(m, states) {
return nft.render(m, nft.access_sets(m, null, states ?? STATES, SNAP), CTX);
}
test('render: the table as it was', () => {
ok(golden != null, 'the fixture is there');
eq(render(model()), golden, 'line for line');
let m = model();
m.devices.b1.lan_bypass = true;
eq(render(m), golden, 'a device that keeps its own local network out of the tunnel changes nothing here');
});
+71
View File
@@ -0,0 +1,71 @@
// dawnline.pkg: the package a control text or file names (ipk control,
// `apk adbdump`), and when an apk install of package files took: every
// package at its file's version, a rollback to an older one included.
import * as pkg from 'dawnline.pkg';
const DIR = '/tmp/dawnline-tests/pkg';
// AmneziaWG 3.1 as the Components tab installs it, and the 2.0 build before it.
const NEW = [
{ name: 'kmod-amneziawg', version: '6.12.94.3.1.20260906-r1', file: '/tmp/x/kmod.apk' },
{ name: 'amneziawg-tools', version: '3.1.20260812-r1', file: '/tmp/x/tools.apk' },
{ name: 'luci-proto-amneziawg', version: '3.1.0-r1', file: '/tmp/x/proto.apk' },
];
const OLD = { 'kmod-amneziawg': '6.12.94.1.0.20250722-r1', 'amneziawg-tools': '1.0.20250722-r1', 'luci-proto-amneziawg': '2.0.0-r1' };
function at(list) {
let have = {};
for (let w in list)
have[w.name] = w.version;
return have;
}
test('control_info of an ipk control file', () => {
eq(pkg.control_info('Package: amneziawg-tools\nVersion: 1.0.20250722-r1\nDepends: libc\nArchitecture: aarch64_cortex-a53\n', true),
{ name: 'amneziawg-tools', version: '1.0.20250722-r1' }, 'fields');
eq(pkg.control_info('Description: no package here\n', true), { name: null, version: null }, 'nothing said');
});
test('control_info of apk adbdump', () => {
let dump = '#%SCHEMA: 00504B47\ninfo:\n name: kmod-amneziawg\n version: 6.12.94.3.1.20260906-r1\n' +
' description: AmneziaWG kernel module\n arch: aarch64_cortex-a53\n depends: # 2 items\n - kernel=6.12.94\n' +
' - kmod-udptunnel4\npaths: # 2 items\n - name: lib/modules\n - name: lib/modules/6.12.94\n files: # 1 items\n' +
' - name: amneziawg.ko\n';
eq(pkg.control_info(dump, false), { name: 'kmod-amneziawg', version: '6.12.94.3.1.20260906-r1' }, 'the package, not its files');
eq(pkg.control_info('', false), { name: null, version: null }, 'adbdump failed');
eq(pkg.control_info(null, false), { name: null, version: null }, 'no output');
});
test('file_info of an ipk', () => {
system(`rm -rf ${DIR} && mkdir -p ${DIR}`);
ok(system(`cd ${DIR} && printf 'Package: luci-proto-amneziawg\\nVersion: 2.0.0-r1\\n' > control && tar -czf control.tar.gz ./control && tar -czf proto.ipk ./control.tar.gz`) == 0,
'made the ipk');
eq(pkg.file_info(`${DIR}/proto.ipk`), { name: 'luci-proto-amneziawg', version: '2.0.0-r1' }, 'name and version');
eq(pkg.file_version(`${DIR}/proto.ipk`), '2.0.0-r1', 'file_version');
});
test('mismatched: an update took', () => {
eq(pkg.mismatched(NEW, at(NEW)), [], 'every package at its file');
});
test('mismatched: a rollback to an older build took', () => {
let back = map(keys(OLD), (n) => ({ name: n, version: OLD[n], file: `/tmp/x/${n}.apk` }));
eq(pkg.mismatched(back, OLD), [], 'older versions are what the files hold');
});
test('mismatched: apk left a package alone', () => {
let have = { ...at(NEW), 'amneziawg-tools': OLD['amneziawg-tools'] };
eq(pkg.mismatched(NEW, have), [ NEW[1] ], 'the tools kept their old version');
eq(pkg.mismatched(NEW, OLD), NEW, 'nothing changed');
});
test('mismatched: missing or unreadable', () => {
let have = at(NEW);
delete have['luci-proto-amneziawg'];
eq(pkg.mismatched(NEW, have), [ NEW[2] ], 'not installed after the install');
let blind = [ { name: null, version: null, file: '/tmp/x/broken.apk' } ];
eq(pkg.mismatched(blind, {}), blind, 'a file that names no package never counts as installed');
eq(pkg.mismatched([ { name: 'amneziawg-tools', version: null, file: '/tmp/x/t.apk' } ], { 'amneziawg-tools': null }),
[ { name: 'amneziawg-tools', version: null, file: '/tmp/x/t.apk' } ], 'no version on either side');
eq(pkg.mismatched(NEW, null), NEW, 'no installed versions');
});
+32
View File
@@ -18,6 +18,38 @@ test('valid_name', () => {
ok(!util.valid_name('a\tb'), 'control character');
});
test('valid_device_name', () => {
eq(util.DEVICE_NAME_MAX, 20, 'the limit');
ok(util.valid_device_name('9999999999999999999'), '19 characters');
ok(util.valid_device_name('99999999999999999999'), '20 characters');
ok(!util.valid_device_name('999999999999999999999'), '21 characters');
ok(util.valid_device_name('Kitchen iPad'), 'letters and a space');
ok(util.valid_device_name('my-pc_2.home'), 'dash, underscore and dot');
ok(util.valid_device_name('Мой ноутбук'), 'Cyrillic');
ok(util.valid_device_name('ЙЦУКЕНГШЩЗХЪФЫВАПРОЛ'), '20 Cyrillic letters (40 bytes) are 20 characters');
ok(!util.valid_device_name('ЙЦУКЕНГШЩЗХЪФЫВАПРОЛД'), '21 Cyrillic letters');
ok(util.valid_device_name('Ordinateur de Zoé'), 'Latin with an accent');
ok(util.valid_device_name('客厅电视'), 'Chinese');
ok(util.valid_device_name('Ελένη'), 'Greek');
ok(!util.valid_device_name('Phone 📱'), 'emoji');
ok(!util.valid_device_name('Офис™'), 'trade mark sign');
ok(!util.valid_device_name('«Дом»'), 'guillemets');
ok(!util.valid_device_name('a\u200bb'), 'zero-width space');
ok(!util.valid_device_name('a×b'), 'multiplication sign');
// Raw bytes by chr(): a "\xd0" in a literal is the character Ð to some ucode releases.
ok(!util.valid_device_name('a' + chr(0xc0) + chr(0xaf) + 'b'), 'a slash spelled long');
ok(!util.valid_device_name('a' + chr(0xd0)), 'a character cut short');
ok(!util.valid_device_name("Bob's iPhone"), 'apostrophe');
ok(!util.valid_device_name('a;rm -rf /'), 'semicolon and slash');
ok(!util.valid_device_name('$(reboot)'), 'shell');
ok(!util.valid_device_name('a<b'), 'angle bracket');
ok(!util.valid_device_name('a\nb'), 'newline');
ok(!util.valid_device_name('a\u0000b'), 'NUL');
ok(!util.valid_device_name(''), 'empty');
ok(!util.valid_device_name(' '), 'blank');
ok(!util.valid_device_name(null), 'null');
});
test('valid_host', () => {
ok(util.valid_host('vpn.example.com'), 'name');
ok(util.valid_host('router'), 'single label');
+20
View File
@@ -37,3 +37,23 @@ test('month_days', () => {
eq(view.month_days(null)[0], [ 0, 0 ], 'a day without traffic is zero both ways');
eq(view.spark({ days }, 1), [ [ 5, 7 ] ], 'the week the same way, today last');
});
// What the set-up sheet reads off a device: the watcher's state, or without the agent a session that lives.
test('device_view: set-up state', () => {
let m = {
settings: { hostnames: false },
servers: { s_1: { id: 's_1', keepalive: 25, obf: {} } },
people: { p_1: { id: 'p_1', server: 's_1', devices: [ 'd_1' ] } },
devices: { d_1: { id: 'd_1', person: 'p_1', kind: 'phone', public_key: 'K1', private_key: 'x', mtu: 0, keepalive: null } },
_reconnect: {}, _issued: {},
};
let hs = time() - 10;
let peers = { K1: { ifname: 'awga', endpoint: '203.0.113.7:4000', handshake: hs, rx: 100, tx: 100 } };
let usage = { devices: {}, people: {} };
let watched = { peers, presence: { online: { d_1: true } }, windows: {}, link: {}, setup: { d_1: { state: 'nodata', since: hs + 15 } } };
eq(view.device_view(m, m.devices.d_1, usage, watched).setup, { state: 'nodata', since: hs + 15 }, 'the watcher\'s');
eq(view.device_view(m, m.devices.d_1, usage, { ...watched, setup: {} }).setup, null, 'the watcher sees nothing');
let alone = { peers, presence: null, windows: {}, link: {}, setup: null };
eq(view.device_view(m, m.devices.d_1, usage, alone).setup, { state: 'flowing', since: hs }, 'no agent: a live session');
eq(view.device_view(m, m.devices.d_1, usage, { ...alone, peers: {} }).setup, null, 'no agent, not online: nothing');
});