(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func TestDNSTrampleRecovery(t *testing.T) { |
| 22 | t.Cleanup(HookWatchFile.SetForTest(watchFile)) |
| 23 | synctest.Test(t, func(t *testing.T) { |
| 24 | tmp := t.TempDir() |
| 25 | if err := os.MkdirAll(filepath.Join(tmp, "etc"), 0700); err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | const resolvPath = "/etc/resolv.conf" |
| 29 | fs := directFS{prefix: tmp} |
| 30 | readFile := func(t *testing.T, path string) string { |
| 31 | t.Helper() |
| 32 | b, err := fs.ReadFile(path) |
| 33 | if err != nil { |
| 34 | t.Errorf("Reading DNS config: %v", err) |
| 35 | } |
| 36 | return string(b) |
| 37 | } |
| 38 | |
| 39 | bus := eventbustest.NewBus(t) |
| 40 | eventbustest.LogAllEvents(t, bus) |
| 41 | m := newDirectManagerOnFS(t.Logf, nil, bus, fs) |
| 42 | defer m.Close() |
| 43 | |
| 44 | if err := m.SetDNS(OSConfig{ |
| 45 | Nameservers: []netip.Addr{netip.MustParseAddr("8.8.8.8"), netip.MustParseAddr("8.8.4.4")}, |
| 46 | SearchDomains: []dnsname.FQDN{"ts.net.", "ts-dns.test."}, |
| 47 | MatchDomains: []dnsname.FQDN{"ignored."}, |
| 48 | }); err != nil { |
| 49 | t.Fatal(err) |
| 50 | } |
| 51 | |
| 52 | const want = `# resolv.conf(5) file generated by tailscale |
| 53 | # For more info, see https://tailscale.com/s/resolvconf-overwrite |
| 54 | # DO NOT EDIT THIS FILE BY HAND -- CHANGES WILL BE OVERWRITTEN |
| 55 | |
| 56 | nameserver 8.8.8.8 |
| 57 | nameserver 8.8.4.4 |
| 58 | search ts.net ts-dns.test |
| 59 | ` |
| 60 | if got := readFile(t, resolvPath); got != want { |
| 61 | t.Fatalf("resolv.conf:\n%s, want:\n%s", got, want) |
| 62 | } |
| 63 | |
| 64 | tw := eventbustest.NewWatcher(t, bus) |
| 65 | |
| 66 | const trample = "Hvem er det som tramper på min bro?" |
| 67 | if err := fs.WriteFile(resolvPath, []byte(trample), 0644); err != nil { |
| 68 | t.Fatal(err) |
| 69 | } |
| 70 | synctest.Wait() |
| 71 | |
| 72 | if err := eventbustest.Expect(tw, eventbustest.Type[TrampleDNS]()); err != nil { |
| 73 | t.Errorf("did not see trample event: %s", err) |
| 74 | } |
| 75 | }) |
| 76 | } |
| 77 | |
| 78 | // watchFile is a test implementation of the file watcher that uses a timer |
nothing calls this directly
no test coverage detected
searching dependent graphs…