From 5a376bb01b76baf28d24a4c84332ada310ff8b39 Mon Sep 17 00:00:00 2001 From: Thomas Hallgren Date: Tue, 28 Nov 2023 00:22:40 +0100 Subject: [PATCH] Add test to verify that DNS search path is restored on quit. This test is windows specific because: - On linux, the DNS search path is attached to the VIF, so when the VIF is gone, our DNS settings are gone with it. - On macOS, there's no DNS search path. Instead, we add domains that correspond to the namespaces. Signed-off-by: Thomas Hallgren --- .../restore_dns_search_windows_test.go | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 integration_test/restore_dns_search_windows_test.go diff --git a/integration_test/restore_dns_search_windows_test.go b/integration_test/restore_dns_search_windows_test.go new file mode 100644 index 0000000000..05a03fd88d --- /dev/null +++ b/integration_test/restore_dns_search_windows_test.go @@ -0,0 +1,40 @@ +package integration_test + +import ( + "os" + "strings" + + "golang.org/x/sys/windows/registry" + + "github.com/telepresenceio/telepresence/v2/integration_test/itest" +) + +func (s *notConnectedSuite) getGlobalSearchList() []string { + const ( + tcpParamKey = `System\CurrentControlSet\Services\Tcpip\Parameters` + searchListKey = `SearchList` + ) + rk, err := registry.OpenKey(registry.LOCAL_MACHINE, tcpParamKey, registry.QUERY_VALUE) + if os.IsNotExist(err) { + err = nil + } + s.Require().NoError(err) + defer rk.Close() + csv, _, err := rk.GetStringValue(searchListKey) + if os.IsNotExist(err) { + err = nil + } + s.Require().NoError(err) + return strings.Split(csv, ",") +} + +func (s *notConnectedSuite) Test_DNSSearchRestored() { + beforeConnect := s.getGlobalSearchList() + ctx := s.Context() + s.TelepresenceConnect(ctx) + afterConnect := s.getGlobalSearchList() + s.Assert().NotEqual(beforeConnect, afterConnect) + itest.TelepresenceQuitOk(ctx) + afterQuit := s.getGlobalSearchList() + s.Assert().Equal(beforeConnect, afterQuit) +}