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 / Backend (Go: vet, tests, a real ubusd and uhttpd) (push) Blocked by required conditions
CI / Package files (push) Blocked by required conditions
- **Backend rewritten in Go.** One daemon, `dawnlined`, replaces the whole ucode backend: the rpcd plugin, the agent, the CLI and the updater. The package no longer depends on ucode. - **Per-architecture builds.** The release carries the backend for arm64, ARMv7, mips, mipsle and amd64; the router fetches its own after the package is installed and checks its sha256. Dawnline does not run on other architectures (older ARM, 32-bit x86, RISC-V). - **Faster on the router.** A firewall sync takes 0.06 s instead of 0.9 s; a full apply takes about 300 ms. The portal is served by the daemon itself, without a CGI process per request. - **Live pages.** The admin and the portal follow a live stream from the router instead of re-fetching the whole state every 30 seconds. - **Admin redesigned in the portal's style.** Three sections (Overview · Log · Settings); a server is a page of its own with People, Places and Settings; a device opens as a dialog over its person. - **Changes wait for «Apply».** Every setting, and a person's access, is staged in one dock before it reaches the router. - **Configuration rollout.** After a change that makes devices fetch their configuration again, the admin shows how many have fetched it and who has not. Every setting shows beforehand (⟳N) how many devices it will touch. - **Waiting for a decision.** Overview and People put first the people who need one (access ended, limit reached, a device that does not connect), each with its one action a tap away. - **Bulk actions on people.** «Select» (or a long press on a card) picks several people to extend by a month, pause or resume at once. - **Undo.** An action done from a card or a request is undone from its toast. - **Update dialogs redesigned.** An update is one view from its question to its result; Dawnline's own update runs in it like every other, and the page reloads itself once the new version answers. Other versions are a list, each with its notes and Install on a page of its own. - **Site to site: networks behind a router.** A router connected as a device can have networks behind it (up to eight, /16 to /30): the server routes them and applies the router's access to them. A network that shares addresses with a tunnel, the router's own networks or another site is refused by name. - **Routers from the portal.** People can add a router and name its networks on their own page; the admin accepts or declines with a reason, or lets them through without asking. - **Check access and Health know the networks behind routers.** - **Usage limits reworked.** A monthly limit no longer follows the calendar. A person's month starts with their first traffic and ends a month later; the next one starts only when they connect again, so time away uses up none of it. Before, everyone's limit reset on the 1st. - Extra data lasts until that person's month ends; «Reset usage» starts the month anew. - A limit is for a month or for the whole term; the admin and the portal show when it resets. - Charts that said «this month» show the last 30 days. - After the update nobody loses what was counted: the month that was running becomes the person's first and ends on the 1st. - **Access by time of day removed.** The Hours limit is gone from the admin, the portal and the backend; saved hours are dropped. - **Expiry simplified.** An end date always stops access, with a heads-up three days before; the per-person choice is gone. - **No false disconnects from sleeping phones.** A phone or a tablet stays online through ten minutes of silence. - **Mobile Safari fixes.** Pressing a control no longer sends the page to its top; tab tracks that do not fit scroll; switches animate after a press.
165 lines
6.4 KiB
Go
165 lines
6.4 KiB
Go
package presence
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/tickcount/luci-app-dawnline/backend/awg"
|
|
"github.com/tickcount/luci-app-dawnline/backend/model"
|
|
"github.com/tickcount/luci-app-dawnline/backend/uci"
|
|
)
|
|
|
|
const (
|
|
keyPhone = "HIgo9xNzJMWLKASShiTqIybxZ0U3wGLiUeJ1PKf8ykw="
|
|
keyLaptop = "TrMvSoP4jYQlY6RIzBgbssQqY3vxI2Pi+y71lOWWXX0="
|
|
keyNew = "u4pL0000000000000000000000000000000000DyRrM="
|
|
)
|
|
|
|
func settings(t *testing.T, phoneKey string) *model.Model {
|
|
c, err := uci.Parse(`
|
|
config server 'home'
|
|
option ifname 'dawn0'
|
|
option subnet '10.77.0.0/24'
|
|
option private_key 'k'
|
|
config person 'anna'
|
|
option server 'home'
|
|
config device 'phone'
|
|
option person 'anna'
|
|
option kind 'phone'
|
|
option public_key '` + phoneKey + `'
|
|
config device 'laptop'
|
|
option person 'anna'
|
|
option kind 'computer'
|
|
option public_key '` + keyLaptop + `'
|
|
`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return model.Load(c, nil)
|
|
}
|
|
|
|
// A look at the tunnel: its link's index, and the peers with their handshake and where they spoke from.
|
|
func look(index int, peers map[string]awg.Peer) awg.Dump {
|
|
d := awg.Dump{OK: true, Reads: map[string]string{"dawn0": awg.Read}, Ifaces: map[string]awg.Iface{"dawn0": {Ifindex: index}}, Peers: peers}
|
|
if index == 0 {
|
|
d.Reads["dawn0"] = awg.Down
|
|
d.Ifaces = map[string]awg.Iface{}
|
|
}
|
|
return d
|
|
}
|
|
|
|
func TestConnectRoamDisconnect(t *testing.T) {
|
|
m := settings(t, keyPhone)
|
|
w := New(nil, nil)
|
|
at := func(now, handshake int64, from string) Seen {
|
|
return w.Look(m, look(7, map[string]awg.Peer{keyLaptop: {Handshake: handshake, Endpoint: from}, keyPhone: {}}), now, nil)
|
|
}
|
|
// never shook hands: nothing
|
|
if s := at(1000, 0, ""); len(s.Events) != 0 || len(s.People) != 0 {
|
|
t.Fatalf("idle: %+v", s)
|
|
}
|
|
s := at(1010, 1005, "203.0.113.7:41821")
|
|
if !reflect.DeepEqual(s.Events, []Event{{Type: Connect, Person: "anna", Device: "laptop", Detail: "203.0.113.7"}}) ||
|
|
!reflect.DeepEqual(s.People, []string{"anna"}) || !reflect.DeepEqual(s.Addresses, []string{"203.0.113.7"}) {
|
|
t.Fatalf("connect: %+v", s)
|
|
}
|
|
// still there, nothing new
|
|
if s := at(1100, 1005, "203.0.113.7:41821"); len(s.Events) != 0 || len(s.People) != 0 {
|
|
t.Fatalf("steady: %+v", s)
|
|
}
|
|
s = at(1120, 1110, "[2001:db8::1]:500")
|
|
if len(s.Events) != 1 || s.Events[0].Type != Roam || s.Events[0].Detail != "203.0.113.7 → 2001:db8::1" || len(s.People) != 1 {
|
|
t.Fatalf("roam: %+v", s)
|
|
}
|
|
// a computer's window is 190 s from its handshake
|
|
if s := at(1110+189, 1110, "[2001:db8::1]:500"); len(s.Events) != 0 {
|
|
t.Fatalf("within its window: %+v", s)
|
|
}
|
|
s = at(1110+190, 1110, "[2001:db8::1]:500")
|
|
if !reflect.DeepEqual(s.Events, []Event{{Type: Disconnect, Person: "anna", Device: "laptop"}}) || w.Online["laptop"] {
|
|
t.Fatalf("disconnect: %+v", s)
|
|
}
|
|
if w.Endpoint["laptop"] != "2001:db8::1" {
|
|
t.Fatalf("the last address is kept: %v", w.Endpoint)
|
|
}
|
|
}
|
|
|
|
// A phone sleeps through its keep-alives: ten minutes, not three.
|
|
func TestPhoneSleeps(t *testing.T) {
|
|
m := settings(t, keyPhone)
|
|
w := New(nil, nil)
|
|
at := func(now int64) Seen {
|
|
return w.Look(m, look(7, map[string]awg.Peer{keyPhone: {Handshake: 1000, Endpoint: "198.51.100.4:9"}}), now, nil)
|
|
}
|
|
at(1001)
|
|
if s := at(1000 + 599); len(s.Events) != 0 || !w.Online["phone"] {
|
|
t.Fatalf("asleep: %+v", s)
|
|
}
|
|
if s := at(1000 + 600); len(s.Events) != 1 || s.Events[0].Type != Disconnect {
|
|
t.Fatalf("gone: %+v", s)
|
|
}
|
|
}
|
|
|
|
// One configuration on two devices: its address goes back and forth, which is no roaming.
|
|
func TestSharedConfigurationDoesNotRoam(t *testing.T) {
|
|
m := settings(t, keyPhone)
|
|
w := New(nil, nil)
|
|
w.Look(m, look(7, map[string]awg.Peer{keyLaptop: {Handshake: 1000, Endpoint: "203.0.113.7:1"}}), 1001, nil)
|
|
s := w.Look(m, look(7, map[string]awg.Peer{keyLaptop: {Handshake: 1010, Endpoint: "198.51.100.4:1"}}), 1011, func(string, *awg.Peer, bool, bool) bool { return true })
|
|
if len(s.Events) != 0 || len(s.People) != 0 {
|
|
t.Fatalf("shared: %+v", s)
|
|
}
|
|
}
|
|
|
|
// The tunnel set up again: its devices are missing for a while and come back without a handshake.
|
|
func TestTunnelSetUpAgain(t *testing.T) {
|
|
m := settings(t, keyPhone)
|
|
w := New(nil, nil)
|
|
w.Look(m, look(7, map[string]awg.Peer{keyLaptop: {Handshake: 1000, Endpoint: "203.0.113.7:1"}}), 1001, nil)
|
|
// a new link, no peers yet, then peers with no handshake: still online within the grace and its window
|
|
if s := w.Look(m, look(8, map[string]awg.Peer{}), 1010, nil); len(s.Events) != 0 || !w.Online["laptop"] {
|
|
t.Fatalf("set up again: %+v", s)
|
|
}
|
|
if s := w.Look(m, look(8, map[string]awg.Peer{keyLaptop: {}}), 1030, nil); len(s.Events) != 0 || !w.Online["laptop"] {
|
|
t.Fatalf("back without a handshake: %+v", s)
|
|
}
|
|
// past the grace, a device that is not in the tunnel is offline at once
|
|
if s := w.Look(m, look(8, map[string]awg.Peer{}), 1010+RestartGrace+1, nil); len(s.Events) != 1 || s.Events[0].Type != Disconnect {
|
|
t.Fatalf("removed: %+v", s)
|
|
}
|
|
}
|
|
|
|
func TestUnreadTunnelSaysNothing(t *testing.T) {
|
|
m := settings(t, keyPhone)
|
|
w := New(nil, nil)
|
|
w.Look(m, look(7, map[string]awg.Peer{keyLaptop: {Handshake: 1000, Endpoint: "203.0.113.7:1"}}), 1001, nil)
|
|
failed := awg.Dump{Reads: map[string]string{"dawn0": awg.Failed}, Ifaces: map[string]awg.Iface{}, Peers: map[string]awg.Peer{}}
|
|
if s := w.Look(m, failed, 5000, nil); len(s.Events) != 0 || !w.Online["laptop"] {
|
|
t.Fatalf("an unread tunnel changed something: %+v", s)
|
|
}
|
|
}
|
|
|
|
// New keys end the old session, whatever its handshake said; a removed device is forgotten.
|
|
func TestNewKeysAndRemoval(t *testing.T) {
|
|
w := New(nil, nil)
|
|
w.Look(settings(t, keyPhone), look(7, map[string]awg.Peer{keyPhone: {Handshake: 1000, Endpoint: "198.51.100.4:9"}}), 1001, nil)
|
|
s := w.Look(settings(t, keyNew), look(7, map[string]awg.Peer{keyNew: {}}), 1002, nil)
|
|
if !reflect.DeepEqual(s.Rekeyed, []string{"phone"}) || len(s.Events) != 1 || s.Events[0].Type != Disconnect {
|
|
t.Fatalf("new keys: %+v", s)
|
|
}
|
|
c, _ := uci.Parse("config server 'home'\n")
|
|
w.Look(model.Load(c, nil), look(7, nil), 1003, nil)
|
|
if len(w.Online) != 0 || len(w.Endpoint) != 0 {
|
|
t.Fatalf("removed devices are kept: %+v %+v", w.Online, w.Endpoint)
|
|
}
|
|
}
|
|
|
|
// What was kept of the last run: a device online then is not a new connect now.
|
|
func TestRestartKeepsWhoWasOnline(t *testing.T) {
|
|
m := settings(t, keyPhone)
|
|
w := New(map[string]bool{"laptop": true}, map[string]string{"laptop": "203.0.113.7"})
|
|
if s := w.Look(m, look(7, map[string]awg.Peer{keyLaptop: {Handshake: 1000, Endpoint: "203.0.113.7:1"}}), 1001, nil); len(s.Events) != 0 {
|
|
t.Fatalf("a restart logged a connect: %+v", s)
|
|
}
|
|
}
|