test: extend networking test coverage (#13914)

* test: extend coverage of virtioproxy networking mode * test: add dns test variations to all networking classes * remove bridged dns variations * pr feedback --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>

Ben Hillis committed Dec 16, 2025 at 14:20 UTC d48d374c8cba41dca6d041f3274c807015001d2e
1 file changed +168
test/windows/NetworkTests.cpp
+168
@@ -175,6 +175,7 @@ class NetworkTests
175 WSL_TEST_CLASS(NetworkTests)
176
177 friend class MirroredTests;
178 + friend class BridgedTests;
179 friend class VirtioProxyTests;
180
181 static std::wstring SockaddrToString(const SOCKADDR_INET* sockAddr)
@@ -790,6 +791,51 @@ class NetworkTests
791 VERIFY_IS_TRUE(!out.empty());
792 }
793
794 + static void VerifyDnsResolutionBasic()
795 + {
796 + // Verify basic DNS resolution using getent
797 + auto [out, _] = LxsstuLaunchWslAndCaptureOutput(L"getent ahosts bing.com", 0);
798 + VERIFY_IS_TRUE(!out.empty());
799 + }
800 +
801 + static void VerifyDnsResolutionDig()
802 + {
803 + if (HostHasInternetConnectivity(AF_INET))
804 + {
805 + // Test A record resolution (IPv4) with both UDP and TCP
806 + VerifyDigDnsResolution(L"dig +short +time=5 A bing.com");
807 + VerifyDigDnsResolution(L"dig +tcp +short +time=5 A bing.com");
808 +
809 + // Test reverse DNS lookup
810 + VerifyDigDnsResolution(L"dig +short +time=5 -x 8.8.8.8");
811 + VerifyDigDnsResolution(L"dig +tcp +short +time=5 -x 8.8.8.8");
812 + }
813 + else
814 + {
815 + LogSkipped("Host does not have IPv4 internet connectivity. Skipping IPv4 DNS tests.");
816 + }
817 +
818 + if (HostHasInternetConnectivity(AF_INET6))
819 + {
820 + // Test AAAA record resolution (IPv6) with both UDP and TCP
821 + VerifyDigDnsResolution(L"dig +short +time=5 AAAA bing.com");
822 + VerifyDigDnsResolution(L"dig +tcp +short +time=5 AAAA bing.com");
823 + }
824 + else
825 + {
826 + LogSkipped("Host does not have IPv6 internet connectivity. Skipping IPv6 DNS tests.");
827 + }
828 + }
829 +
830 + static void VerifyDnsResolutionRecordTypes()
831 + {
832 + // Test various DNS record types
833 + VerifyDigDnsResolution(L"dig +short +time=5 MX bing.com");
834 + VerifyDigDnsResolution(L"dig +short +time=5 NS bing.com");
835 + VerifyDigDnsResolution(L"dig +short +time=5 TXT bing.com");
836 + VerifyDigDnsResolution(L"dig +short +time=5 SOA bing.com");
837 + }
838 +
839 static void VerifyDnsQueries()
840 {
841 // query for A/IPv4 records
@@ -1006,6 +1052,27 @@ class NetworkTests
1052 VERIFY_ARE_EQUAL(expected, out.c_str());
1053 }
1054
1055 + TEST_METHOD(DnsResolutionBasic)
1056 + {
1057 + WSL2_TEST_ONLY();
1058 +
1059 + NetworkTests::VerifyDnsResolutionBasic();
1060 + }
1061 +
1062 + TEST_METHOD(DnsResolutionDig)
1063 + {
1064 + WSL2_TEST_ONLY();
1065 +
1066 + NetworkTests::VerifyDnsResolutionDig();
1067 + }
1068 +
1069 + TEST_METHOD(DnsResolutionRecordTypes)
1070 + {
1071 + WSL2_TEST_ONLY();
1072 +
1073 + NetworkTests::VerifyDnsResolutionRecordTypes();
1074 + }
1075 +
1076 static void ClearHttpProxySettings(bool userScope)
1077 {
1078 auto command = L"Set-WinhttpProxy -SettingScope Machine -Proxy \\\"\\\"";
@@ -4302,6 +4369,36 @@ class MirroredTests
4369
4370 VERIFY_IS_FALSE(Watchdog.IsExpired());
4371 }
4372 +
4373 + TEST_METHOD(DnsResolutionBasic)
4374 + {
4375 + MIRRORED_NETWORKING_TEST_ONLY();
4376 +
4377 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::Mirrored}));
4378 + WaitForMirroredStateInLinux();
4379 +
4380 + NetworkTests::VerifyDnsResolutionBasic();
4381 + }
4382 +
4383 + TEST_METHOD(DnsResolutionDig)
4384 + {
4385 + MIRRORED_NETWORKING_TEST_ONLY();
4386 +
4387 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::Mirrored}));
4388 + WaitForMirroredStateInLinux();
4389 +
4390 + NetworkTests::VerifyDnsResolutionDig();
4391 + }
4392 +
4393 + TEST_METHOD(DnsResolutionRecordTypes)
4394 + {
4395 + MIRRORED_NETWORKING_TEST_ONLY();
4396 +
4397 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::Mirrored}));
4398 + WaitForMirroredStateInLinux();
4399 +
4400 + NetworkTests::VerifyDnsResolutionRecordTypes();
4401 + }
4402 };
4403
4404 class BridgedTests
@@ -4416,6 +4513,8 @@ class VirtioProxyTests
4513 {
4514 VIRTIOPROXY_TEST_ONLY();
4515
4516 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4517 +
4518 // Verify that we have a working connection
4519 NetworkTests::GuestClient(L"tcp-connect:bing.com:80");
4520 }
@@ -4424,6 +4523,8 @@ class VirtioProxyTests
4523 {
4524 VIRTIOPROXY_TEST_ONLY();
4525
4526 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4527 +
4528 if (!NetworkTests::HostHasInternetConnectivity(AF_INET))
4529 {
4530 LogSkipped("Host does not have IPv4 internet connectivity. Skipping...");
@@ -4437,6 +4538,8 @@ class VirtioProxyTests
4538 {
4539 VIRTIOPROXY_TEST_ONLY();
4540
4541 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4542 +
4543 if (!NetworkTests::HostHasInternetConnectivity(AF_INET6))
4544 {
4545 LogSkipped("Host does not have IPv6 internet connectivity. Skipping...");
@@ -4450,6 +4553,8 @@ class VirtioProxyTests
4553 {
4554 VIRTIOPROXY_TEST_ONLY();
4555
4556 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4557 +
4558 const auto state = NetworkTests::GetInterfaceState(L"eth0");
4559 VERIFY_IS_FALSE(state.V4Addresses.empty());
4560 VERIFY_IS_TRUE(state.Gateway.has_value());
@@ -4464,6 +4569,8 @@ class VirtioProxyTests
4569 {
4570 VIRTIOPROXY_TEST_ONLY();
4571
4572 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4573 +
4574 // Make sure the VM doesn't time out
4575 WslKeepAlive keepAlive;
4576
@@ -4491,6 +4598,67 @@ class VirtioProxyTests
4598 VERIFY_IS_TRUE(bound);
4599 }
4600
4601 + TEST_METHOD(LoopbackGuestToHost)
4602 + {
4603 + VIRTIOPROXY_TEST_ONLY();
4604 +
4605 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4606 +
4607 + // Verify guest can connect to host on loopback (TCP only, UDP not supported)
4608 + NetworkTests::VerifyLoopbackGuestToHost(L"127.0.0.1", IPPROTO_TCP);
4609 + NetworkTests::VerifyLoopbackGuestToHost(L"0.0.0.0", IPPROTO_TCP);
4610 + // TODO: enable when v6 loopback is supported
4611 + // NetworkTests::VerifyLoopbackGuestToHost(L"::1", IPPROTO_TCP);
4612 + // NetworkTests::VerifyLoopbackGuestToHost(L"::", IPPROTO_TCP);
4613 + }
4614 +
4615 + TEST_METHOD(UdpBindDoesNotPreventTcpBind)
4616 + {
4617 + VIRTIOPROXY_TEST_ONLY();
4618 +
4619 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4620 +
4621 + auto tcpPort = NetworkTests::BindGuestPort(L"TCP4-LISTEN:1234", true);
4622 + auto udpPort = NetworkTests::BindGuestPort(L"UDP4-LISTEN:1234", true);
4623 + }
4624 +
4625 + TEST_METHOD(HostUdpBindDoesNotPreventGuestTcpBind)
4626 + {
4627 + VIRTIOPROXY_TEST_ONLY();
4628 +
4629 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4630 +
4631 + auto udpPort = NetworkTests::BindHostPort(2345, SOCK_DGRAM, IPPROTO_UDP, true);
4632 + auto tcpPort = NetworkTests::BindGuestPort(L"TCP4-LISTEN:2345", true);
4633 + }
4634 +
4635 + TEST_METHOD(DnsResolutionBasic)
4636 + {
4637 + VIRTIOPROXY_TEST_ONLY();
4638 +
4639 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4640 +
4641 + NetworkTests::VerifyDnsResolutionBasic();
4642 + }
4643 +
4644 + TEST_METHOD(DnsResolutionDig)
4645 + {
4646 + VIRTIOPROXY_TEST_ONLY();
4647 +
4648 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4649 +
4650 + NetworkTests::VerifyDnsResolutionDig();
4651 + }
4652 +
4653 + TEST_METHOD(DnsResolutionRecordTypes)
4654 + {
4655 + VIRTIOPROXY_TEST_ONLY();
4656 +
4657 + m_config->Update(LxssGenerateTestConfig({.networkingMode = wsl::core::NetworkingMode::VirtioProxy}));
4658 +
4659 + NetworkTests::VerifyDnsResolutionRecordTypes();
4660 + }
4661 +
4662 TEST_METHOD(HttpProxySimple)
4663 {
4664 VIRTIOPROXY_TEST_ONLY();