diff --git a/modules/systemd-resolved/cmd/resolver-tools/guard_test.go b/modules/systemd-resolved/cmd/resolver-tools/guard_test.go index 2acfa29aa..c0e637059 100644 --- a/modules/systemd-resolved/cmd/resolver-tools/guard_test.go +++ b/modules/systemd-resolved/cmd/resolver-tools/guard_test.go @@ -337,6 +337,34 @@ func TestUplinkNamesMoveWithTheDefaultRoute(t *testing.T) { } } +// A changed list replaces the old one on the link, the route itself staying put (design 08 sign-in-page §9). +func TestAChangedListReplacesTheOldOneOnTheLink(t *testing.T) { + g, _, f, r := aGuardedMachineWithLinks(t, "wlan0") + f.dns = "Link 2 (wlan0): 192.168.1.1\n" + f.domain = "Link 2 (wlan0): lan\n" + f.ip = "default via 10.0.0.1 dev wlan0 metric 100\n" + if err := os.WriteFile(r.UplinkNamesFile, []byte("check.example\n"), 0o644); err != nil { + t.Fatal(err) + } + g.KeepUplinkNames(context.Background()) + if len(f.changed) != 1 || strings.Join(f.changed[0], " ") != "resolvectl domain wlan0 lan ~check.example" { + t.Fatalf("the first list was given as %v", f.changed) + } + // resolved now holds it; the file's list changes, the link stays the same. + f.domain = "Link 2 (wlan0): lan ~check.example\n" + f.changed = nil + if err := os.WriteFile(r.UplinkNamesFile, []byte("other.example\n"), 0o644); err != nil { + t.Fatal(err) + } + g.KeepUplinkNames(context.Background()) + if len(f.changed) != 1 || strings.Join(f.changed[0], " ") != "resolvectl domain wlan0 lan ~other.example" { + t.Errorf("the changed list was given as %v, want the old name replaced on the same link", f.changed) + } + if g.applied.Link != "wlan0" || strings.Join(g.applied.Names, ",") != "other.example" { + t.Errorf("applied is %+v", g.applied) + } +} + // A guard restarted with an applied file takes the uplink's names off the link it names, never inferring // which (design 08 sign-in-page §8, §9; R-6). func TestARestartedGuardTakesTheUplinkNamesOffTheLinkItNames(t *testing.T) {