fix(networkmanager): read the automatic DNS switch from a family that takes name servers

pull/18/head
reionwong 2 weeks ago
parent ac688d792e
commit d8c9244c08

@ -197,8 +197,11 @@ Form form(const Settings& settings)
}
}
// The switch stands for both families; IPv4's decides when they differ.
form.automaticDns = !toBool(value(group(settings, ipv4Setting), "ignore-auto-dns"));
// The switch stands for both families; IPv4's decides when they differ,
// unless IPv4 takes no name servers and so keeps a value nothing writes.
const std::string& dnsFamily =
configurable(form.ipv4Method) || !configurable(form.ipv6Method) ? ipv4Setting : ipv6Setting;
form.automaticDns = !toBool(value(group(settings, dnsFamily), "ignore-auto-dns"));
form.dns = text::join(dnsServers(settings), ", ");
return form;
}

@ -264,6 +264,30 @@ TEST(IpUtils, WritesNameServers)
EXPECT_FALSE(toBool(value(cleared->at("ipv4"), "ignore-auto-dns")));
}
TEST(IpUtils, AutomaticDnsOfAnIpv6OnlyProfile)
{
Settings existing = automaticProfile();
existing["ipv4"] = {{"method", Variant(std::string("disabled"))}};
ip::Form form = ip::form(existing);
EXPECT_TRUE(form.automaticDns);
form.automaticDns = false;
form.dns = "2606:4700::1111";
bool changed = false;
std::string error;
const auto profile = ip::settings(form, existing, &changed, &error);
ASSERT_TRUE(profile) << error;
EXPECT_TRUE(toBool(value(profile->at("ipv6"), "ignore-auto-dns")));
// Read back, the switch is off as saved, and another server keeps it off.
form = ip::form(*profile);
EXPECT_FALSE(form.automaticDns);
form.dns = "2001:4860:4860::8888";
const auto edited = ip::settings(form, *profile, &changed, &error);
ASSERT_TRUE(edited) << error;
EXPECT_TRUE(toBool(value(edited->at("ipv6"), "ignore-auto-dns")));
}
TEST(IpUtils, WritesDnsDataWhereItCameFrom)
{
Settings existing = automaticProfile();

Loading…
Cancel
Save