blob: b6ffb73999dcf4e98e3a80a7402361624cc9ad2a [file] [log] [blame]
Garrick Evans5fe2a4f2021-02-03 17:04:48 +09001// Copyright 2021 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "dns-proxy/proxy.h"
6
7#include <fcntl.h>
8#include <sys/stat.h>
9
10#include <memory>
11#include <utility>
Garrick Evans2ca050d2021-02-09 18:21:36 +090012#include <vector>
Garrick Evans5fe2a4f2021-02-03 17:04:48 +090013
14#include <chromeos/patchpanel/net_util.h>
15#include <chromeos/patchpanel/dbus/fake_client.h>
16#include <dbus/mock_bus.h>
17#include <gmock/gmock.h>
18#include <gtest/gtest.h>
19#include <shill/dbus/client/fake_client.h>
20#include <shill/dbus-constants.h>
21#include <shill/dbus-proxy-mocks.h>
22
23namespace dns_proxy {
Jason Jeremy Iman1bb71c22021-01-26 21:49:55 +090024namespace {
25constexpr base::TimeDelta kRequestTimeout = base::TimeDelta::FromSeconds(10000);
Jason Jeremy Iman845f2932021-01-31 16:12:13 +090026constexpr base::TimeDelta kRequestRetryDelay =
27 base::TimeDelta::FromMilliseconds(200);
28constexpr int32_t kRequestMaxRetry = 1;
29
Jason Jeremy Iman1bb71c22021-01-26 21:49:55 +090030} // namespace
Garrick Evans5fe2a4f2021-02-03 17:04:48 +090031using org::chromium::flimflam::ManagerProxyInterface;
32using org::chromium::flimflam::ManagerProxyMock;
33using testing::_;
Garrick Evans09646fe2021-04-27 14:38:41 +090034using testing::DoAll;
Garrick Evansd41fdbf2021-03-03 09:15:48 +090035using testing::IsEmpty;
Garrick Evans5fe2a4f2021-02-03 17:04:48 +090036using testing::Return;
Garrick Evansadde9852021-02-15 20:16:53 +090037using testing::SetArgPointee;
Garrick Evans2ca050d2021-02-09 18:21:36 +090038using testing::StrEq;
Garrick Evans5fe2a4f2021-02-03 17:04:48 +090039
40class FakeShillClient : public shill::FakeClient {
41 public:
42 FakeShillClient(scoped_refptr<dbus::Bus> bus,
43 ManagerProxyInterface* manager_proxy)
44 : shill::FakeClient(bus), manager_proxy_(manager_proxy) {}
45
46 std::unique_ptr<shill::Client::ManagerPropertyAccessor> ManagerProperties(
47 const base::TimeDelta& timeout) const override {
48 return std::make_unique<shill::Client::ManagerPropertyAccessor>(
49 manager_proxy_);
50 }
51
Garrick Evansadde9852021-02-15 20:16:53 +090052 std::unique_ptr<shill::Client::Device> DefaultDevice(
53 bool exclude_vpn) override {
54 return std::move(default_device_);
55 }
56
Garrick Evans5fe2a4f2021-02-03 17:04:48 +090057 bool IsInitialized() const { return init_; }
58
Garrick Evansadde9852021-02-15 20:16:53 +090059 std::unique_ptr<shill::Client::Device> default_device_;
60
Garrick Evans5fe2a4f2021-02-03 17:04:48 +090061 private:
62 ManagerProxyInterface* manager_proxy_;
63};
64
65class FakePatchpanelClient : public patchpanel::FakeClient {
66 public:
67 FakePatchpanelClient() = default;
68 ~FakePatchpanelClient() = default;
69
70 void SetConnectNamespaceResult(
71 int fd, const patchpanel::ConnectNamespaceResponse& resp) {
72 ns_fd_ = fd;
73 ns_resp_ = resp;
74 }
75
76 std::pair<base::ScopedFD, patchpanel::ConnectNamespaceResponse>
77 ConnectNamespace(pid_t pid,
78 const std::string& outbound_ifname,
79 bool forward_user_traffic,
80 bool route_on_vpn,
81 patchpanel::TrafficCounter::Source traffic_source) override {
82 ns_ifname_ = outbound_ifname;
83 ns_rvpn_ = route_on_vpn;
84 ns_ts_ = traffic_source;
85 return {base::ScopedFD(ns_fd_), ns_resp_};
86 }
87
88 std::string ns_ifname_;
89 bool ns_rvpn_;
90 patchpanel::TrafficCounter::Source ns_ts_;
91 int ns_fd_;
92 patchpanel::ConnectNamespaceResponse ns_resp_;
93};
94
Garrick Evans2ca050d2021-02-09 18:21:36 +090095class MockResolver : public Resolver {
96 public:
Jason Jeremy Iman845f2932021-01-31 16:12:13 +090097 MockResolver()
98 : Resolver(kRequestTimeout, kRequestRetryDelay, kRequestMaxRetry) {}
Garrick Evans2ca050d2021-02-09 18:21:36 +090099 ~MockResolver() = default;
100
Jason Jeremy Iman6fd98552021-01-27 04:19:07 +0900101 MOCK_METHOD(bool, ListenUDP, (struct sockaddr*), (override));
102 MOCK_METHOD(bool, ListenTCP, (struct sockaddr*), (override));
Garrick Evans2ca050d2021-02-09 18:21:36 +0900103 MOCK_METHOD(void,
104 SetNameServers,
105 (const std::vector<std::string>&),
106 (override));
107 MOCK_METHOD(void,
108 SetDoHProviders,
109 (const std::vector<std::string>&, bool),
110 (override));
111};
112
113class TestProxy : public Proxy {
114 public:
115 TestProxy(const Options& opts,
116 std::unique_ptr<patchpanel::Client> patchpanel,
117 std::unique_ptr<shill::Client> shill)
118 : Proxy(opts, std::move(patchpanel), std::move(shill)) {}
119
120 std::unique_ptr<Resolver> resolver;
Jason Jeremy Iman845f2932021-01-31 16:12:13 +0900121 std::unique_ptr<Resolver> NewResolver(base::TimeDelta timeout,
122 base::TimeDelta retry_delay,
123 int max_num_retries) override {
Garrick Evans2ca050d2021-02-09 18:21:36 +0900124 return std::move(resolver);
125 }
126};
127
Garrick Evans5fe2a4f2021-02-03 17:04:48 +0900128class ProxyTest : public ::testing::Test {
129 protected:
130 ProxyTest() : mock_bus_(new dbus::MockBus{dbus::Bus::Options{}}) {}
131 ~ProxyTest() { mock_bus_->ShutdownAndBlock(); }
132
133 std::unique_ptr<FakePatchpanelClient> PatchpanelClient() const {
134 return std::make_unique<FakePatchpanelClient>();
135 }
136
137 std::unique_ptr<FakeShillClient> ShillClient() const {
138 return std::make_unique<FakeShillClient>(
139 mock_bus_, reinterpret_cast<ManagerProxyInterface*>(
140 const_cast<ManagerProxyMock*>(&mock_manager_)));
141 }
142
143 int make_fd() const {
144 std::string fn(
145 ::testing::UnitTest::GetInstance()->current_test_info()->name());
146 fn = "/tmp/" + fn;
147 return open(fn.c_str(), O_CREAT, 0600);
148 }
149
150 protected:
151 scoped_refptr<dbus::MockBus> mock_bus_;
152 ManagerProxyMock mock_manager_;
153};
154
155TEST_F(ProxyTest, SystemProxy_OnShutdownClearsAddressPropertyOnShill) {
156 EXPECT_CALL(mock_manager_, SetProperty(shill::kDNSProxyIPv4AddressProperty,
157 brillo::Any(std::string()), _, _))
158 .WillOnce(Return(true));
159 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
160 ShillClient());
161 int unused;
162 proxy.OnShutdown(&unused);
163}
164
165TEST_F(ProxyTest, NonSystemProxy_OnShutdownDoesNotCallShill) {
166 EXPECT_CALL(mock_manager_, SetProperty(_, _, _, _)).Times(0);
167 Proxy proxy(Proxy::Options{.type = Proxy::Type::kDefault}, PatchpanelClient(),
168 ShillClient());
169 int unused;
170 proxy.OnShutdown(&unused);
171}
172
173TEST_F(ProxyTest, SystemProxy_SetShillPropertyWithNoRetriesCrashes) {
174 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
175 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
176 ShillClient());
177 EXPECT_DEATH(proxy.SetShillProperty("10.10.10.10", true, 0), "");
178}
179
180TEST_F(ProxyTest, SystemProxy_SetShillPropertyDoesntCrashIfDieFalse) {
181 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
182 EXPECT_CALL(mock_manager_, SetProperty(_, _, _, _)).Times(0);
183 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
184 ShillClient());
185 proxy.SetShillProperty("10.10.10.10", false, 0);
186}
187
Garrick Evansab03c462021-02-15 20:54:20 +0900188TEST_F(ProxyTest, ShillInitializedWhenReady) {
Garrick Evans5fe2a4f2021-02-03 17:04:48 +0900189 auto shill = ShillClient();
190 auto* shill_ptr = shill.get();
191 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
192 std::move(shill));
Garrick Evansab03c462021-02-15 20:54:20 +0900193 proxy.OnShillReady(true);
Garrick Evans5fe2a4f2021-02-03 17:04:48 +0900194 EXPECT_TRUE(shill_ptr->IsInitialized());
195}
196
197TEST_F(ProxyTest, SystemProxy_ConnectedNamedspace) {
198 auto pp = PatchpanelClient();
199 auto* pp_ptr = pp.get();
200 pp->SetConnectNamespaceResult(make_fd(),
201 patchpanel::ConnectNamespaceResponse());
202 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, std::move(pp),
203 ShillClient());
204 proxy.OnPatchpanelReady(true);
205 EXPECT_TRUE(pp_ptr->ns_ifname_.empty());
206 EXPECT_FALSE(pp_ptr->ns_rvpn_);
207 EXPECT_EQ(pp_ptr->ns_ts_, patchpanel::TrafficCounter::SYSTEM);
208}
209
210TEST_F(ProxyTest, DefaultProxy_ConnectedNamedspace) {
211 auto pp = PatchpanelClient();
212 auto* pp_ptr = pp.get();
213 pp->SetConnectNamespaceResult(make_fd(),
214 patchpanel::ConnectNamespaceResponse());
215 Proxy proxy(Proxy::Options{.type = Proxy::Type::kDefault}, std::move(pp),
216 ShillClient());
217 proxy.OnPatchpanelReady(true);
218 EXPECT_TRUE(pp_ptr->ns_ifname_.empty());
219 EXPECT_TRUE(pp_ptr->ns_rvpn_);
220 EXPECT_EQ(pp_ptr->ns_ts_, patchpanel::TrafficCounter::USER);
221}
222
223TEST_F(ProxyTest, ArcProxy_ConnectedNamedspace) {
224 auto pp = PatchpanelClient();
225 auto* pp_ptr = pp.get();
226 pp->SetConnectNamespaceResult(make_fd(),
227 patchpanel::ConnectNamespaceResponse());
228 Proxy proxy(Proxy::Options{.type = Proxy::Type::kARC, .ifname = "eth0"},
229 std::move(pp), ShillClient());
230 proxy.OnPatchpanelReady(true);
231 EXPECT_EQ(pp_ptr->ns_ifname_, "eth0");
232 EXPECT_FALSE(pp_ptr->ns_rvpn_);
233 EXPECT_EQ(pp_ptr->ns_ts_, patchpanel::TrafficCounter::ARC);
234}
235
236TEST_F(ProxyTest, CrashOnConnectNamespaceFailure) {
Garrick Evans2ca050d2021-02-09 18:21:36 +0900237 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
Garrick Evans5fe2a4f2021-02-03 17:04:48 +0900238 auto pp = PatchpanelClient();
239 pp->SetConnectNamespaceResult(-1 /* invalid fd */,
240 patchpanel::ConnectNamespaceResponse());
241 Proxy proxy(Proxy::Options{.type = Proxy::Type::kARC, .ifname = "eth0"},
242 std::move(pp), ShillClient());
243 EXPECT_DEATH(proxy.OnPatchpanelReady(true), "namespace");
244}
245
246TEST_F(ProxyTest, CrashOnPatchpanelNotReady) {
Garrick Evans2ca050d2021-02-09 18:21:36 +0900247 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
Garrick Evans5fe2a4f2021-02-03 17:04:48 +0900248 Proxy proxy(Proxy::Options{.type = Proxy::Type::kARC, .ifname = "eth0"},
249 PatchpanelClient(), ShillClient());
250 EXPECT_DEATH(proxy.OnPatchpanelReady(false), "patchpanel");
251}
252
253TEST_F(ProxyTest, ShillResetRestoresAddressProperty) {
254 auto pp = PatchpanelClient();
255 patchpanel::ConnectNamespaceResponse resp;
Garrick Evansab03c462021-02-15 20:54:20 +0900256 resp.set_peer_ipv4_address(patchpanel::Ipv4Addr(10, 10, 10, 10));
Garrick Evans5fe2a4f2021-02-03 17:04:48 +0900257 pp->SetConnectNamespaceResult(make_fd(), resp);
258 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, std::move(pp),
259 ShillClient());
260 proxy.OnPatchpanelReady(true);
261 EXPECT_CALL(mock_manager_,
262 SetProperty(shill::kDNSProxyIPv4AddressProperty,
263 brillo::Any(std::string("10.10.10.10")), _, _))
264 .WillOnce(Return(true));
265 proxy.OnShillReset(true);
266}
267
Garrick Evans2ca050d2021-02-09 18:21:36 +0900268TEST_F(ProxyTest, StateClearedIfDefaultServiceDrops) {
269 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
270 ShillClient());
271 proxy.device_ = std::make_unique<shill::Client::Device>();
272 proxy.resolver_ = std::make_unique<MockResolver>();
273 proxy.OnDefaultDeviceChanged(nullptr /* no service */);
274 EXPECT_FALSE(proxy.device_);
275 EXPECT_FALSE(proxy.resolver_);
276}
277
278TEST_F(ProxyTest, ArcProxy_IgnoredIfDefaultServiceDrops) {
279 Proxy proxy(Proxy::Options{.type = Proxy::Type::kARC}, PatchpanelClient(),
280 ShillClient());
281 proxy.device_ = std::make_unique<shill::Client::Device>();
282 proxy.resolver_ = std::make_unique<MockResolver>();
283 proxy.OnDefaultDeviceChanged(nullptr /* no service */);
284 EXPECT_TRUE(proxy.device_);
285 EXPECT_TRUE(proxy.resolver_);
286}
287
288TEST_F(ProxyTest, StateClearedIfDefaultServiceIsNotOnline) {
289 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
290 ShillClient());
291 proxy.device_ = std::make_unique<shill::Client::Device>();
292 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
293 proxy.resolver_ = std::make_unique<MockResolver>();
294 shill::Client::Device dev;
295 dev.state = shill::Client::Device::ConnectionState::kReady;
296 proxy.OnDefaultDeviceChanged(&dev);
297 EXPECT_FALSE(proxy.device_);
298 EXPECT_FALSE(proxy.resolver_);
299}
300
301TEST_F(ProxyTest, NewResolverStartsListeningOnDefaultServiceComesOnline) {
302 TestProxy proxy(Proxy::Options{.type = Proxy::Type::kDefault},
303 PatchpanelClient(), ShillClient());
304 proxy.device_ = std::make_unique<shill::Client::Device>();
305 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
306 auto resolver = std::make_unique<MockResolver>();
307 MockResolver* mock_resolver = resolver.get();
308 proxy.resolver = std::move(resolver);
309 shill::Client::Device dev;
310 dev.state = shill::Client::Device::ConnectionState::kOnline;
Jason Jeremy Iman6fd98552021-01-27 04:19:07 +0900311 EXPECT_CALL(*mock_resolver, ListenUDP(_)).WillOnce(Return(true));
312 EXPECT_CALL(*mock_resolver, ListenTCP(_)).WillOnce(Return(true));
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900313 brillo::VariantDictionary props;
314 EXPECT_CALL(mock_manager_, GetProperties(_, _, _))
315 .WillOnce(DoAll(SetArgPointee<0>(props), Return(true)));
Garrick Evans2ca050d2021-02-09 18:21:36 +0900316 proxy.OnDefaultDeviceChanged(&dev);
317 EXPECT_TRUE(proxy.resolver_);
318}
319
320TEST_F(ProxyTest, CrashOnListenFailure) {
321 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
322 TestProxy proxy(Proxy::Options{.type = Proxy::Type::kSystem},
323 PatchpanelClient(), ShillClient());
324 proxy.device_ = std::make_unique<shill::Client::Device>();
325 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
326 auto resolver = std::make_unique<MockResolver>();
327 MockResolver* mock_resolver = resolver.get();
328 proxy.resolver = std::move(resolver);
329 shill::Client::Device dev;
330 dev.state = shill::Client::Device::ConnectionState::kOnline;
Jason Jeremy Iman6fd98552021-01-27 04:19:07 +0900331 ON_CALL(*mock_resolver, ListenUDP(_)).WillByDefault(Return(false));
332 ON_CALL(*mock_resolver, ListenTCP(_)).WillByDefault(Return(false));
Garrick Evans2ca050d2021-02-09 18:21:36 +0900333 EXPECT_DEATH(proxy.OnDefaultDeviceChanged(&dev), "relay loop");
334}
335
336TEST_F(ProxyTest, NameServersUpdatedOnDefaultServiceComesOnline) {
337 Proxy proxy(Proxy::Options{.type = Proxy::Type::kDefault}, PatchpanelClient(),
338 ShillClient());
339 proxy.device_ = std::make_unique<shill::Client::Device>();
340 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
341 auto resolver = std::make_unique<MockResolver>();
342 MockResolver* mock_resolver = resolver.get();
343 proxy.resolver_ = std::move(resolver);
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900344 proxy.doh_config_.set_resolver(mock_resolver);
Garrick Evans2ca050d2021-02-09 18:21:36 +0900345 shill::Client::Device dev;
346 dev.state = shill::Client::Device::ConnectionState::kOnline;
347 dev.ipconfig.ipv4_dns_addresses = {"a", "b"};
348 dev.ipconfig.ipv6_dns_addresses = {"c", "d"};
349 // Doesn't call listen since the resolver already exists.
Jason Jeremy Iman6fd98552021-01-27 04:19:07 +0900350 EXPECT_CALL(*mock_resolver, ListenUDP(_)).Times(0);
351 EXPECT_CALL(*mock_resolver, ListenTCP(_)).Times(0);
Garrick Evans2ca050d2021-02-09 18:21:36 +0900352 EXPECT_CALL(*mock_resolver,
353 SetNameServers(
354 ElementsAre(StrEq("a"), StrEq("b"), StrEq("c"), StrEq("d"))));
355 proxy.OnDefaultDeviceChanged(&dev);
356}
357
358TEST_F(ProxyTest, SystemProxy_ShillPropertyUpdatedOnDefaultServiceComesOnline) {
359 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
360 ShillClient());
361 proxy.device_ = std::make_unique<shill::Client::Device>();
362 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
363 auto resolver = std::make_unique<MockResolver>();
364 MockResolver* mock_resolver = resolver.get();
365 proxy.resolver_ = std::move(resolver);
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900366 proxy.doh_config_.set_resolver(mock_resolver);
Garrick Evans2ca050d2021-02-09 18:21:36 +0900367 shill::Client::Device dev;
368 dev.state = shill::Client::Device::ConnectionState::kOnline;
369 EXPECT_CALL(*mock_resolver, SetNameServers(_));
370 EXPECT_CALL(mock_manager_,
371 SetProperty(shill::kDNSProxyIPv4AddressProperty, _, _, _))
372 .WillOnce(Return(true));
373 proxy.OnDefaultDeviceChanged(&dev);
374}
375
Garrick Evansadde9852021-02-15 20:16:53 +0900376TEST_F(ProxyTest, SystemProxy_IgnoresVPN) {
377 TestProxy proxy(Proxy::Options{.type = Proxy::Type::kSystem},
378 PatchpanelClient(), ShillClient());
379 auto resolver = std::make_unique<MockResolver>();
380 MockResolver* mock_resolver = resolver.get();
381 ON_CALL(*mock_resolver, ListenUDP(_)).WillByDefault(Return(true));
382 ON_CALL(*mock_resolver, ListenTCP(_)).WillByDefault(Return(true));
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900383 brillo::VariantDictionary props;
384 EXPECT_CALL(mock_manager_, GetProperties(_, _, _))
385 .WillOnce(DoAll(SetArgPointee<0>(props), Return(true)));
Garrick Evansadde9852021-02-15 20:16:53 +0900386 EXPECT_CALL(mock_manager_,
387 SetProperty(shill::kDNSProxyIPv4AddressProperty, _, _, _))
388 .WillOnce(Return(true));
389 proxy.resolver = std::move(resolver);
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900390 proxy.doh_config_.set_resolver(mock_resolver);
Garrick Evansadde9852021-02-15 20:16:53 +0900391 shill::Client::Device dev;
392 dev.type = shill::Client::Device::Type::kWifi;
393 dev.state = shill::Client::Device::ConnectionState::kOnline;
394 proxy.OnDefaultDeviceChanged(&dev);
395 EXPECT_TRUE(proxy.device_);
396 EXPECT_EQ(proxy.device_->type, shill::Client::Device::Type::kWifi);
397 dev.type = shill::Client::Device::Type::kVPN;
398 proxy.OnDefaultDeviceChanged(&dev);
399 EXPECT_TRUE(proxy.device_);
400 EXPECT_EQ(proxy.device_->type, shill::Client::Device::Type::kWifi);
401}
402
403TEST_F(ProxyTest, SystemProxy_GetsPhysicalDeviceOnInitialVPN) {
404 auto shill = ShillClient();
405 auto* shill_ptr = shill.get();
406 TestProxy proxy(Proxy::Options{.type = Proxy::Type::kSystem},
407 PatchpanelClient(), std::move(shill));
408 auto resolver = std::make_unique<MockResolver>();
409 MockResolver* mock_resolver = resolver.get();
410 ON_CALL(*mock_resolver, ListenUDP(_)).WillByDefault(Return(true));
411 ON_CALL(*mock_resolver, ListenTCP(_)).WillByDefault(Return(true));
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900412 brillo::VariantDictionary props;
413 EXPECT_CALL(mock_manager_, GetProperties(_, _, _))
414 .WillOnce(DoAll(SetArgPointee<0>(props), Return(true)));
Garrick Evansadde9852021-02-15 20:16:53 +0900415 EXPECT_CALL(mock_manager_,
416 SetProperty(shill::kDNSProxyIPv4AddressProperty, _, _, _))
417 .WillOnce(Return(true));
418 proxy.resolver = std::move(resolver);
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900419 proxy.doh_config_.set_resolver(mock_resolver);
Garrick Evansadde9852021-02-15 20:16:53 +0900420 shill::Client::Device vpn;
421 vpn.type = shill::Client::Device::Type::kVPN;
422 vpn.state = shill::Client::Device::ConnectionState::kOnline;
423 shill_ptr->default_device_ = std::make_unique<shill::Client::Device>();
424 shill_ptr->default_device_->type = shill::Client::Device::Type::kWifi;
425 shill_ptr->default_device_->state =
426 shill::Client::Device::ConnectionState::kOnline;
427 proxy.OnDefaultDeviceChanged(&vpn);
428 EXPECT_TRUE(proxy.device_);
429 EXPECT_EQ(proxy.device_->type, shill::Client::Device::Type::kWifi);
430}
431
432TEST_F(ProxyTest, DefaultProxy_UsesVPN) {
433 TestProxy proxy(Proxy::Options{.type = Proxy::Type::kDefault},
434 PatchpanelClient(), ShillClient());
435 auto resolver = std::make_unique<MockResolver>();
436 MockResolver* mock_resolver = resolver.get();
437 ON_CALL(*mock_resolver, ListenUDP(_)).WillByDefault(Return(true));
438 ON_CALL(*mock_resolver, ListenTCP(_)).WillByDefault(Return(true));
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900439 brillo::VariantDictionary props;
440 EXPECT_CALL(mock_manager_, GetProperties(_, _, _))
441 .WillOnce(DoAll(SetArgPointee<0>(props), Return(true)));
Garrick Evansadde9852021-02-15 20:16:53 +0900442 proxy.resolver = std::move(resolver);
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900443 proxy.doh_config_.set_resolver(mock_resolver);
Garrick Evansadde9852021-02-15 20:16:53 +0900444 shill::Client::Device dev;
445 dev.type = shill::Client::Device::Type::kWifi;
446 dev.state = shill::Client::Device::ConnectionState::kOnline;
447 proxy.OnDefaultDeviceChanged(&dev);
448 EXPECT_TRUE(proxy.device_);
449 EXPECT_EQ(proxy.device_->type, shill::Client::Device::Type::kWifi);
450 dev.type = shill::Client::Device::Type::kVPN;
451 proxy.OnDefaultDeviceChanged(&dev);
452 EXPECT_TRUE(proxy.device_);
453 EXPECT_EQ(proxy.device_->type, shill::Client::Device::Type::kVPN);
454}
455
Garrick Evans73e8e5e2021-04-27 10:16:26 +0900456TEST_F(ProxyTest, ArcProxy_NameServersUpdatedOnDeviceChangeEvent) {
457 Proxy proxy(Proxy::Options{.type = Proxy::Type::kARC, .ifname = "wlan0"},
458 PatchpanelClient(), ShillClient());
459 auto resolver = std::make_unique<MockResolver>();
460 MockResolver* mock_resolver = resolver.get();
461 proxy.resolver_ = std::move(resolver);
462 proxy.doh_config_.set_resolver(mock_resolver);
463 shill::Client::Device dev;
464 dev.ifname = "wlan0";
465 dev.state = shill::Client::Device::ConnectionState::kOnline;
466 dev.ipconfig.ipv4_dns_addresses = {"a", "b"};
467 dev.ipconfig.ipv6_dns_addresses = {"c", "d"};
468 // Doesn't call listen since the resolver already exists.
469 EXPECT_CALL(*mock_resolver, ListenUDP(_)).Times(0);
470 EXPECT_CALL(*mock_resolver, ListenTCP(_)).Times(0);
471 EXPECT_CALL(*mock_resolver,
472 SetNameServers(
473 ElementsAre(StrEq("a"), StrEq("b"), StrEq("c"), StrEq("d"))));
474 proxy.OnDeviceChanged(&dev);
475
476 // Verify it only applies changes for the correct interface.
477 dev.ifname = "eth0";
478 dev.ipconfig.ipv4_dns_addresses = {"X", "Y", "Z"};
479 EXPECT_CALL(*mock_resolver, SetNameServers(_)).Times(0);
480 proxy.OnDeviceChanged(&dev);
481
482 dev.ifname = "wlan0";
483 dev.ipconfig.ipv4_dns_addresses = {"X", "Y", "Z"};
484 dev.ipconfig.ipv6_dns_addresses.clear();
485 EXPECT_CALL(*mock_resolver,
486 SetNameServers(ElementsAre(StrEq("X"), StrEq("Y"), StrEq("Z"))));
487 proxy.OnDeviceChanged(&dev);
488}
489
490TEST_F(ProxyTest, SystemProxy_NameServersUpdatedOnDeviceChangeEvent) {
Garrick Evansa8c12be2021-02-17 16:06:45 +0900491 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
492 ShillClient());
493 proxy.device_ = std::make_unique<shill::Client::Device>();
494 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
495 auto resolver = std::make_unique<MockResolver>();
496 MockResolver* mock_resolver = resolver.get();
497 proxy.resolver_ = std::move(resolver);
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900498 proxy.doh_config_.set_resolver(mock_resolver);
Garrick Evansa8c12be2021-02-17 16:06:45 +0900499 shill::Client::Device dev;
500 dev.state = shill::Client::Device::ConnectionState::kOnline;
501 dev.ipconfig.ipv4_dns_addresses = {"a", "b"};
502 dev.ipconfig.ipv6_dns_addresses = {"c", "d"};
503 // Doesn't call listen since the resolver already exists.
504 EXPECT_CALL(mock_manager_,
505 SetProperty(shill::kDNSProxyIPv4AddressProperty, _, _, _))
506 .WillOnce(Return(true));
507 EXPECT_CALL(*mock_resolver, ListenUDP(_)).Times(0);
508 EXPECT_CALL(*mock_resolver, ListenTCP(_)).Times(0);
509 EXPECT_CALL(*mock_resolver,
510 SetNameServers(
511 ElementsAre(StrEq("a"), StrEq("b"), StrEq("c"), StrEq("d"))));
512 proxy.OnDefaultDeviceChanged(&dev);
513
514 // Now trigger an ipconfig change.
515 dev.ipconfig.ipv4_dns_addresses = {"X"};
516 EXPECT_CALL(*mock_resolver,
517 SetNameServers(ElementsAre(StrEq("X"), StrEq("c"), StrEq("d"))));
518 proxy.OnDeviceChanged(&dev);
519}
520
521TEST_F(ProxyTest, DeviceChangeEventIgnored) {
522 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
523 ShillClient());
524 proxy.device_ = std::make_unique<shill::Client::Device>();
525 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
526 auto resolver = std::make_unique<MockResolver>();
527 MockResolver* mock_resolver = resolver.get();
528 proxy.resolver_ = std::move(resolver);
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900529 proxy.doh_config_.set_resolver(mock_resolver);
Garrick Evansa8c12be2021-02-17 16:06:45 +0900530 shill::Client::Device dev;
531 dev.ifname = "eth0";
532 dev.state = shill::Client::Device::ConnectionState::kOnline;
533 dev.ipconfig.ipv4_dns_addresses = {"a", "b"};
534 dev.ipconfig.ipv6_dns_addresses = {"c", "d"};
535 // Doesn't call listen since the resolver already exists.
536 EXPECT_CALL(mock_manager_,
537 SetProperty(shill::kDNSProxyIPv4AddressProperty, _, _, _))
538 .WillOnce(Return(true));
539 EXPECT_CALL(*mock_resolver, ListenUDP(_)).Times(0);
540 EXPECT_CALL(*mock_resolver, ListenTCP(_)).Times(0);
541 EXPECT_CALL(*mock_resolver,
542 SetNameServers(
543 ElementsAre(StrEq("a"), StrEq("b"), StrEq("c"), StrEq("d"))));
544 proxy.OnDefaultDeviceChanged(&dev);
545
546 // No change to ipconfig, no call to SetNameServers
547 proxy.OnDeviceChanged(&dev);
548
549 // Different ifname, no call to SetNameServers
550 dev.ifname = "wlan0";
551 proxy.OnDeviceChanged(&dev);
552}
553
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900554TEST_F(ProxyTest, BasicDoHDisable) {
555 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
556 ShillClient());
557 proxy.device_ = std::make_unique<shill::Client::Device>();
558 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
559 auto resolver = std::make_unique<MockResolver>();
560 MockResolver* mock_resolver = resolver.get();
561 proxy.resolver_ = std::move(resolver);
562 proxy.doh_config_.set_resolver(mock_resolver);
563 EXPECT_CALL(*mock_resolver, SetDoHProviders(IsEmpty(), false));
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900564 brillo::VariantDictionary props;
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900565 proxy.OnDoHProvidersChanged(props);
566}
567
568TEST_F(ProxyTest, BasicDoHAlwaysOn) {
569 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
570 ShillClient());
571 proxy.device_ = std::make_unique<shill::Client::Device>();
572 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
573 auto resolver = std::make_unique<MockResolver>();
574 MockResolver* mock_resolver = resolver.get();
575 proxy.resolver_ = std::move(resolver);
576 proxy.doh_config_.set_resolver(mock_resolver);
577 EXPECT_CALL(
578 *mock_resolver,
579 SetDoHProviders(ElementsAre(StrEq("https://dns.google.com")), true));
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900580 brillo::VariantDictionary props;
581 props["https://dns.google.com"] = std::string("");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900582 proxy.OnDoHProvidersChanged(props);
583}
584
585TEST_F(ProxyTest, BasicDoHAutomatic) {
586 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
587 ShillClient());
588 proxy.device_ = std::make_unique<shill::Client::Device>();
589 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
590 auto resolver = std::make_unique<MockResolver>();
591 MockResolver* mock_resolver = resolver.get();
592 proxy.resolver_ = std::move(resolver);
593 proxy.doh_config_.set_resolver(mock_resolver);
594 shill::Client::IPConfig ipconfig;
595 ipconfig.ipv4_dns_addresses = {"8.8.4.4"};
596 proxy.UpdateNameServers(ipconfig);
597
598 EXPECT_CALL(
599 *mock_resolver,
600 SetDoHProviders(ElementsAre(StrEq("https://dns.google.com")), false));
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900601 brillo::VariantDictionary props;
602 props["https://dns.google.com"] = std::string("8.8.8.8, 8.8.4.4");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900603 proxy.OnDoHProvidersChanged(props);
604}
605
Garrick Evans4e1fc312021-05-10 14:47:31 +0900606TEST_F(ProxyTest, RemovesDNSQueryParameterTemplate_AlwaysOn) {
607 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
608 ShillClient());
609 proxy.device_ = std::make_unique<shill::Client::Device>();
610 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
611 auto resolver = std::make_unique<MockResolver>();
612 MockResolver* mock_resolver = resolver.get();
613 proxy.resolver_ = std::move(resolver);
614 proxy.doh_config_.set_resolver(mock_resolver);
615 EXPECT_CALL(
616 *mock_resolver,
617 SetDoHProviders(ElementsAre(StrEq("https://dns.google.com")), true));
618 brillo::VariantDictionary props;
619 props["https://dns.google.com{?dns}"] = std::string("");
620 proxy.OnDoHProvidersChanged(props);
621}
622
623TEST_F(ProxyTest, RemovesDNSQueryParameterTemplate_Automatic) {
624 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
625 ShillClient());
626 proxy.device_ = std::make_unique<shill::Client::Device>();
627 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
628 auto resolver = std::make_unique<MockResolver>();
629 MockResolver* mock_resolver = resolver.get();
630 proxy.resolver_ = std::move(resolver);
631 proxy.doh_config_.set_resolver(mock_resolver);
632 shill::Client::IPConfig ipconfig;
633 ipconfig.ipv4_dns_addresses = {"8.8.4.4"};
634 proxy.UpdateNameServers(ipconfig);
635
636 EXPECT_CALL(
637 *mock_resolver,
638 SetDoHProviders(ElementsAre(StrEq("https://dns.google.com")), false));
639 brillo::VariantDictionary props;
640 props["https://dns.google.com{?dns}"] = std::string("8.8.8.8, 8.8.4.4");
641 proxy.OnDoHProvidersChanged(props);
642}
643
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900644TEST_F(ProxyTest, NewResolverConfiguredWhenSet) {
645 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
646 ShillClient());
647 proxy.device_ = std::make_unique<shill::Client::Device>();
648 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900649 brillo::VariantDictionary props;
650 props["https://dns.google.com"] = std::string("8.8.8.8, 8.8.4.4");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900651 props["https://chrome.cloudflare-dns.com/dns-query"] =
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900652 std::string("1.1.1.1,2606:4700:4700::1111");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900653 proxy.OnDoHProvidersChanged(props);
654 shill::Client::IPConfig ipconfig;
655 ipconfig.ipv4_dns_addresses = {"1.0.0.1", "1.1.1.1"};
656 proxy.UpdateNameServers(ipconfig);
657
658 auto resolver = std::make_unique<MockResolver>();
659 MockResolver* mock_resolver = resolver.get();
660 proxy.resolver_ = std::move(resolver);
661 EXPECT_CALL(*mock_resolver, SetNameServers(UnorderedElementsAre(
662 StrEq("1.1.1.1"), StrEq("1.0.0.1"))));
663 EXPECT_CALL(
664 *mock_resolver,
665 SetDoHProviders(
666 ElementsAre(StrEq("https://chrome.cloudflare-dns.com/dns-query")),
667 false));
668 proxy.doh_config_.set_resolver(mock_resolver);
669}
670
671TEST_F(ProxyTest, DoHModeChangingFixedNameServers) {
672 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
673 ShillClient());
674 proxy.device_ = std::make_unique<shill::Client::Device>();
675 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
676 auto resolver = std::make_unique<MockResolver>();
677 MockResolver* mock_resolver = resolver.get();
678 proxy.resolver_ = std::move(resolver);
679 proxy.doh_config_.set_resolver(mock_resolver);
680
681 // Initially off.
682 EXPECT_CALL(*mock_resolver, SetDoHProviders(IsEmpty(), false));
683 shill::Client::IPConfig ipconfig;
684 ipconfig.ipv4_dns_addresses = {"1.1.1.1", "9.9.9.9"};
685 proxy.UpdateNameServers(ipconfig);
686
687 // Automatic mode - matched cloudflare.
688 EXPECT_CALL(
689 *mock_resolver,
690 SetDoHProviders(
691 ElementsAre(StrEq("https://chrome.cloudflare-dns.com/dns-query")),
692 false));
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900693 brillo::VariantDictionary props;
694 props["https://dns.google.com"] = std::string("8.8.8.8, 8.8.4.4");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900695 props["https://chrome.cloudflare-dns.com/dns-query"] =
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900696 std::string("1.1.1.1,2606:4700:4700::1111");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900697 proxy.OnDoHProvidersChanged(props);
698
699 // Automatic mode - no match.
700 EXPECT_CALL(*mock_resolver, SetDoHProviders(IsEmpty(), false));
701 ipconfig.ipv4_dns_addresses = {"10.10.10.1"};
702 proxy.UpdateNameServers(ipconfig);
703
704 // Automatic mode - matched google.
705 EXPECT_CALL(
706 *mock_resolver,
707 SetDoHProviders(ElementsAre(StrEq("https://dns.google.com")), false));
708 ipconfig.ipv4_dns_addresses = {"8.8.4.4", "10.10.10.1", "8.8.8.8"};
709 proxy.UpdateNameServers(ipconfig);
710
711 // Explicitly turned off.
712 EXPECT_CALL(*mock_resolver, SetDoHProviders(IsEmpty(), false));
713 props.clear();
714 proxy.OnDoHProvidersChanged(props);
715
716 // Still off - even switching ns back.
717 EXPECT_CALL(*mock_resolver, SetDoHProviders(IsEmpty(), false));
718 ipconfig.ipv4_dns_addresses = {"8.8.4.4", "10.10.10.1", "8.8.8.8"};
719 proxy.UpdateNameServers(ipconfig);
720
721 // Always-on mode.
722 EXPECT_CALL(
723 *mock_resolver,
724 SetDoHProviders(ElementsAre(StrEq("https://doh.opendns.com/dns-query")),
725 true));
726 props.clear();
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900727 props["https://doh.opendns.com/dns-query"] = std::string("");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900728 proxy.OnDoHProvidersChanged(props);
729
730 // Back to automatic mode, though no matching ns.
731 EXPECT_CALL(*mock_resolver, SetDoHProviders(IsEmpty(), false));
732 props.clear();
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900733 props["https://doh.opendns.com/dns-query"] = std::string(
734 "208.67.222.222,208.67.220.220,2620:119:35::35, 2620:119:53::53");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900735 proxy.OnDoHProvidersChanged(props);
736
737 // Automatic mode working on ns update.
738 EXPECT_CALL(
739 *mock_resolver,
740 SetDoHProviders(ElementsAre(StrEq("https://doh.opendns.com/dns-query")),
741 false));
742 ipconfig.ipv4_dns_addresses = {"8.8.8.8", "2620:119:35::35"};
743 proxy.UpdateNameServers(ipconfig);
744}
745
746TEST_F(ProxyTest, MultipleDoHProvidersForAlwaysOnMode) {
747 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
748 ShillClient());
749 proxy.device_ = std::make_unique<shill::Client::Device>();
750 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
751 auto resolver = std::make_unique<MockResolver>();
752 MockResolver* mock_resolver = resolver.get();
753 proxy.resolver_ = std::move(resolver);
754 proxy.doh_config_.set_resolver(mock_resolver);
755 EXPECT_CALL(
756 *mock_resolver,
757 SetDoHProviders(UnorderedElementsAre(StrEq("https://dns.google.com"),
758 StrEq("https://doh.opendns.com")),
759 true));
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900760 brillo::VariantDictionary props;
761 props["https://dns.google.com"] = std::string("");
762 props["https://doh.opendns.com"] = std::string("");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900763 proxy.OnDoHProvidersChanged(props);
764}
765
766TEST_F(ProxyTest, MultipleDoHProvidersForAutomaticMode) {
767 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
768 ShillClient());
769 proxy.device_ = std::make_unique<shill::Client::Device>();
770 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
771 auto resolver = std::make_unique<MockResolver>();
772 MockResolver* mock_resolver = resolver.get();
773 proxy.resolver_ = std::move(resolver);
774 proxy.doh_config_.set_resolver(mock_resolver);
775 shill::Client::IPConfig ipconfig;
776 ipconfig.ipv4_dns_addresses = {"1.1.1.1", "10.10.10.10"};
777 proxy.UpdateNameServers(ipconfig);
778
779 EXPECT_CALL(
780 *mock_resolver,
781 SetDoHProviders(
782 ElementsAre(StrEq("https://chrome.cloudflare-dns.com/dns-query")),
783 false));
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900784 brillo::VariantDictionary props;
785 props["https://dns.google.com"] = std::string("8.8.8.8, 8.8.4.4");
786 props["https://dns.quad9.net/dns-query"] = std::string("9.9.9.9,2620:fe::9");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900787 props["https://chrome.cloudflare-dns.com/dns-query"] =
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900788 std::string("1.1.1.1,2606:4700:4700::1111");
789 props["https://doh.opendns.com/dns-query"] = std::string(
790 "208.67.222.222,208.67.220.220,2620:119:35::35, 2620:119:53::53");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900791 proxy.OnDoHProvidersChanged(props);
792
793 EXPECT_CALL(*mock_resolver,
794 SetDoHProviders(UnorderedElementsAre(
795 StrEq("https://dns.google.com"),
796 StrEq("https://doh.opendns.com/dns-query"),
797 StrEq("https://dns.quad9.net/dns-query")),
798 false));
799 ipconfig.ipv4_dns_addresses = {"8.8.8.8", "10.10.10.10"};
800 ipconfig.ipv6_dns_addresses = {"2620:fe::9", "2620:119:53::53"};
801 proxy.UpdateNameServers(ipconfig);
802}
803
804TEST_F(ProxyTest, DoHBadAlwaysOnConfigSetsAutomaticMode) {
805 Proxy proxy(Proxy::Options{.type = Proxy::Type::kSystem}, PatchpanelClient(),
806 ShillClient());
807 proxy.device_ = std::make_unique<shill::Client::Device>();
808 proxy.device_->state = shill::Client::Device::ConnectionState::kOnline;
809 auto resolver = std::make_unique<MockResolver>();
810 MockResolver* mock_resolver = resolver.get();
811 proxy.resolver_ = std::move(resolver);
812 proxy.doh_config_.set_resolver(mock_resolver);
813 shill::Client::IPConfig ipconfig;
814 ipconfig.ipv4_dns_addresses = {"1.1.1.1", "10.10.10.10"};
815 proxy.UpdateNameServers(ipconfig);
816
817 EXPECT_CALL(
818 *mock_resolver,
819 SetDoHProviders(
820 ElementsAre(StrEq("https://chrome.cloudflare-dns.com/dns-query")),
821 false));
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900822 brillo::VariantDictionary props;
823 props["https://dns.opendns.com"] = std::string("");
824 props["https://dns.google.com"] = std::string("8.8.8.8, 8.8.4.4");
825 props["https://dns.quad9.net/dns-query"] = std::string("9.9.9.9,2620:fe::9");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900826 props["https://chrome.cloudflare-dns.com/dns-query"] =
Garrick Evans9e5cd1e2021-03-11 22:07:44 +0900827 std::string("1.1.1.1,2606:4700:4700::1111");
828 props["https://doh.opendns.com/dns-query"] = std::string(
829 "208.67.222.222,208.67.220.220,2620:119:35::35, 2620:119:53::53");
Garrick Evansd41fdbf2021-03-03 09:15:48 +0900830 proxy.OnDoHProvidersChanged(props);
831
832 EXPECT_CALL(*mock_resolver,
833 SetDoHProviders(UnorderedElementsAre(
834 StrEq("https://dns.google.com"),
835 StrEq("https://doh.opendns.com/dns-query"),
836 StrEq("https://dns.quad9.net/dns-query")),
837 false));
838 ipconfig.ipv4_dns_addresses = {"8.8.8.8", "10.10.10.10"};
839 ipconfig.ipv6_dns_addresses = {"2620:fe::9", "2620:119:53::53"};
840 proxy.UpdateNameServers(ipconfig);
841}
842
Garrick Evans5fe2a4f2021-02-03 17:04:48 +0900843} // namespace dns_proxy