From 691ad760d33c762ddfdc2f6dfb3d00f12775e9f6 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 24 Nov 2026 21:34:42 +0100 Subject: [PATCH] systemd-resolved: test that a changed list replaces the old one on the link (issue 960) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R2's acceptance criteria name this case directly: the file's list changes while the default-route link stays the same, and the guard gives the new names to that same link without moving them first. Builds: design 08 sign-in-page §7, §9 --- .../cmd/resolver-tools/guard_test.go | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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) {