Skip to content

Commit

Permalink
Remove DNS.Resolvers from IPNS config if DOH is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
cypt4 authored and husobee committed Aug 25, 2022
1 parent 8317878 commit 83c8e08
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/services/ipfs/ipfs_service_utils.cc
Expand Up @@ -59,6 +59,8 @@ bool UpdateConfigJSON(const std::string& source,
base::Value::Dict dns_resolvers;
dns_resolvers.Set(".", *config->doh_server_url);
dict->SetByDottedPath("DNS.Resolvers", std::move(dns_resolvers));
} else {
dict->RemoveByDottedPath("DNS.Resolvers");
}

base::Value::List list;
Expand Down
43 changes: 43 additions & 0 deletions components/services/ipfs/ipfs_service_utils_unittest.cc
Expand Up @@ -65,6 +65,49 @@ TEST_F(IPFSServiceUtils, UpdateConfigJSONTest) {
EXPECT_EQ(updated, "");
}

TEST_F(IPFSServiceUtils, DNSResolversRemove) {
std::string updated;
{
std::string json = R"({})";

auto config = ipfs::mojom::IpfsConfig::New(
base::FilePath(), base::FilePath(), base::FilePath(), "GatewayPort",
"APIPort", "SwarmPort", "StorageSize",
"https://cloudflare.com/dns-query");

std::string expect =
"{\"Addresses\":{\"API\":\"/ip4/127.0.0.1/tcp/APIPort\","
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\",\"Swarm\":"
"[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip6/::/tcp/SwarmPort\""
"]},\"DNS\":{\"Resolvers\":{\".\":\"https://cloudflare.com/"
"dns-query\"}},"
"\"Datastore\":{\"GCPeriod\":\"1h\",\"StorageMax\":"
"\"StorageSize\"},\"Swarm\":{\"ConnMgr\":{\"GracePeriod\":\"20s\","
"\"HighWater\":40,\"LowWater\":20}}}";

EXPECT_TRUE(UpdateConfigJSON(json, config.get(), &updated));
EXPECT_EQ(updated, expect);
}

std::string json = updated;

auto config = ipfs::mojom::IpfsConfig::New(
base::FilePath(), base::FilePath(), base::FilePath(), "GatewayPort",
"APIPort", "SwarmPort", "StorageSize", absl::nullopt);

std::string expect =
"{\"Addresses\":{\"API\":\"/ip4/127.0.0.1/tcp/APIPort\","
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\",\"Swarm\":"
"[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip6/::/tcp/SwarmPort\""
"]},"
"\"Datastore\":{\"GCPeriod\":\"1h\",\"StorageMax\":"
"\"StorageSize\"},\"Swarm\":{\"ConnMgr\":{\"GracePeriod\":\"20s\","
"\"HighWater\":40,\"LowWater\":20}}}";

EXPECT_TRUE(UpdateConfigJSON(json, config.get(), &updated));
ASSERT_EQ(updated, expect);
}

TEST_F(IPFSServiceUtils, DNSResolversUpdate) {
std::string json = R"({})";
std::string updated;
Expand Down

0 comments on commit 83c8e08

Please sign in to comment.