fix(networkmanager): read a WireGuard profile's search domains once, not once per family

pull/18/head
reionwong 2 weeks ago
parent 6f779ae2f9
commit ac688d792e

@ -143,6 +143,28 @@ TEST_F(VpnUtilsTest, WireGuardByHand)
EXPECT_FALSE(vpn::wireGuardSettings(badAddress, {}, &error));
}
TEST_F(VpnUtilsTest, WireGuardSearchDomainsSurviveSaves)
{
std::string error;
vpn::WireGuardForm form;
form.privateKey = "yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=";
form.addresses = "10.0.0.2/24, fd00::2/64";
form.dns = "10.0.0.1, fd00::1, corp.example";
form.peers = {{.publicKey = "xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg="}};
auto profile = vpn::wireGuardSettings(form, {}, &error);
ASSERT_TRUE(profile) << error;
EXPECT_EQ(toStringList(value(profile->at("ipv6"), "dns-search")), std::vector<std::string>{"corp.example"});
for (int save = 0; save < 2; ++save) {
const vpn::WireGuardForm back = vpn::wireGuardForm(*profile);
EXPECT_EQ(back.dns, "10.0.0.1, corp.example, fd00::1");
profile = vpn::wireGuardSettings(back, *profile, &error);
ASSERT_TRUE(profile) << error;
EXPECT_EQ(toStringList(value(profile->at("ipv4"), "dns-search")), std::vector<std::string>{"corp.example"});
EXPECT_EQ(toStringList(value(profile->at("ipv6"), "dns-search")), std::vector<std::string>{"corp.example"});
}
}
TEST_F(VpnUtilsTest, Failures)
{
// NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED and _NO_SECRETS say nothing.

@ -604,8 +604,9 @@ WireGuardForm wireGuardForm(const Settings& settings)
dns.push_back(inet::formatIpv6Bytes(bytes));
}
}
// Both families carry the same search domains.
for (const std::string& domain : toStringList(value(ip, "dns-search"))) {
if (domain != "~")
if (domain != "~" && std::find(dns.begin(), dns.end(), domain) == dns.end())
dns.push_back(domain);
}
}

Loading…
Cancel
Save