• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_DNS_DNS_TEST_UTIL_H_
6 #define NET_DNS_DNS_TEST_UTIL_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include <memory>
12 #include <set>
13 #include <string>
14 #include <utility>
15 #include <vector>
16 
17 #include "base/containers/span.h"
18 #include "base/memory/raw_ptr.h"
19 #include "base/memory/scoped_refptr.h"
20 #include "base/memory/weak_ptr.h"
21 #include "base/time/time.h"
22 #include "base/values.h"
23 #include "net/base/connection_endpoint_metadata.h"
24 #include "net/base/ip_endpoint.h"
25 #include "net/dns/dns_client.h"
26 #include "net/dns/dns_config.h"
27 #include "net/dns/dns_response.h"
28 #include "net/dns/dns_transaction.h"
29 #include "net/dns/dns_util.h"
30 #include "net/dns/public/dns_over_https_server_config.h"
31 #include "net/dns/public/dns_protocol.h"
32 #include "net/dns/public/secure_dns_mode.h"
33 #include "net/socket/socket_test_util.h"
34 #include "third_party/abseil-cpp/absl/types/optional.h"
35 #include "url/scheme_host_port.h"
36 
37 namespace net {
38 
39 //-----------------------------------------------------------------------------
40 // Query/response set for www.google.com, ID is fixed to 0.
41 static const char kT0HostName[] = "www.google.com";
42 static const uint16_t kT0Qtype = dns_protocol::kTypeA;
43 static const char kT0DnsName[] = {
44   0x03, 'w', 'w', 'w',
45   0x06, 'g', 'o', 'o', 'g', 'l', 'e',
46   0x03, 'c', 'o', 'm',
47   0x00
48 };
49 static const size_t kT0QuerySize = 32;
50 static const uint8_t kT0ResponseDatagram[] = {
51     // response contains one CNAME for www.l.google.com and the following
52     // IP addresses: 74.125.226.{179,180,176,177,178}
53     0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
54     0x03, 0x77, 0x77, 0x77, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03,
55     0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05,
56     0x00, 0x01, 0x00, 0x01, 0x4d, 0x13, 0x00, 0x08, 0x03, 0x77, 0x77, 0x77,
57     0x01, 0x6c, 0xc0, 0x10, 0xc0, 0x2c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
58     0x00, 0xe4, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb3, 0xc0, 0x2c, 0x00, 0x01,
59     0x00, 0x01, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb4,
60     0xc0, 0x2c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x04,
61     0x4a, 0x7d, 0xe2, 0xb0, 0xc0, 0x2c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
62     0x00, 0xe4, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb1, 0xc0, 0x2c, 0x00, 0x01,
63     0x00, 0x01, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb2};
64 static const char* const kT0IpAddresses[] = {
65   "74.125.226.179", "74.125.226.180", "74.125.226.176",
66   "74.125.226.177", "74.125.226.178"
67 };
68 static const char kT0CanonName[] = "www.l.google.com";
69 static const base::TimeDelta kT0Ttl = base::Seconds(0x000000e4);
70 // +1 for the CNAME record.
71 static const unsigned kT0RecordCount = std::size(kT0IpAddresses) + 1;
72 
73 //-----------------------------------------------------------------------------
74 // Query/response set for codereview.chromium.org, ID is fixed to 1.
75 static const char kT1HostName[] = "codereview.chromium.org";
76 static const uint16_t kT1Qtype = dns_protocol::kTypeA;
77 static const char kT1DnsName[] = {
78   0x0a, 'c', 'o', 'd', 'e', 'r', 'e', 'v', 'i', 'e', 'w',
79   0x08, 'c', 'h', 'r', 'o', 'm', 'i', 'u', 'm',
80   0x03, 'o', 'r', 'g',
81   0x00
82 };
83 static const size_t kT1QuerySize = 41;
84 static const uint8_t kT1ResponseDatagram[] = {
85     // response contains one CNAME for ghs.l.google.com and the following
86     // IP address: 64.233.169.121
87     0x00, 0x01, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,
88     0x00, 0x0a, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x65, 0x76, 0x69, 0x65,
89     0x77, 0x08, 0x63, 0x68, 0x72, 0x6f, 0x6d, 0x69, 0x75, 0x6d, 0x03,
90     0x6f, 0x72, 0x67, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, 0x0c, 0x00,
91     0x05, 0x00, 0x01, 0x00, 0x01, 0x41, 0x75, 0x00, 0x12, 0x03, 0x67,
92     0x68, 0x73, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
93     0x03, 0x63, 0x6f, 0x6d, 0x00, 0xc0, 0x35, 0x00, 0x01, 0x00, 0x01,
94     0x00, 0x00, 0x01, 0x0b, 0x00, 0x04, 0x40, 0xe9, 0xa9, 0x79};
95 static const char* const kT1IpAddresses[] = {
96   "64.233.169.121"
97 };
98 static const char kT1CanonName[] = "ghs.l.google.com";
99 static const base::TimeDelta kT1Ttl = base::Seconds(0x0000010b);
100 // +1 for the CNAME record.
101 static const unsigned kT1RecordCount = std::size(kT1IpAddresses) + 1;
102 
103 //-----------------------------------------------------------------------------
104 // Query/response set for www.ccs.neu.edu, ID is fixed to 2.
105 static const char kT2HostName[] = "www.ccs.neu.edu";
106 static const uint16_t kT2Qtype = dns_protocol::kTypeA;
107 static const char kT2DnsName[] = {
108   0x03, 'w', 'w', 'w',
109   0x03, 'c', 'c', 's',
110   0x03, 'n', 'e', 'u',
111   0x03, 'e', 'd', 'u',
112   0x00
113 };
114 static const size_t kT2QuerySize = 33;
115 static const uint8_t kT2ResponseDatagram[] = {
116     // response contains one CNAME for vulcan.ccs.neu.edu and the following
117     // IP address: 129.10.116.81
118     0x00, 0x02, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
119     0x03, 0x77, 0x77, 0x77, 0x03, 0x63, 0x63, 0x73, 0x03, 0x6e, 0x65, 0x75,
120     0x03, 0x65, 0x64, 0x75, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, 0x0c, 0x00,
121     0x05, 0x00, 0x01, 0x00, 0x00, 0x01, 0x2c, 0x00, 0x09, 0x06, 0x76, 0x75,
122     0x6c, 0x63, 0x61, 0x6e, 0xc0, 0x10, 0xc0, 0x2d, 0x00, 0x01, 0x00, 0x01,
123     0x00, 0x00, 0x01, 0x2c, 0x00, 0x04, 0x81, 0x0a, 0x74, 0x51};
124 static const char* const kT2IpAddresses[] = {
125   "129.10.116.81"
126 };
127 static const char kT2CanonName[] = "vulcan.ccs.neu.edu";
128 static const base::TimeDelta kT2Ttl = base::Seconds(0x0000012c);
129 // +1 for the CNAME record.
130 static const unsigned kT2RecordCount = std::size(kT2IpAddresses) + 1;
131 
132 //-----------------------------------------------------------------------------
133 // Query/response set for www.google.az, ID is fixed to 3.
134 static const char kT3HostName[] = "www.google.az";
135 static const uint16_t kT3Qtype = dns_protocol::kTypeA;
136 static const char kT3DnsName[] = {
137   0x03, 'w', 'w', 'w',
138   0x06, 'g', 'o', 'o', 'g', 'l', 'e',
139   0x02, 'a', 'z',
140   0x00
141 };
142 static const size_t kT3QuerySize = 31;
143 static const uint8_t kT3ResponseDatagram[] = {
144     // response contains www.google.com as CNAME for www.google.az and
145     // www.l.google.com as CNAME for www.google.com and the following
146     // IP addresses: 74.125.226.{178,179,180,176,177}
147     // The TTLs on the records are: 0x00015099, 0x00025099, 0x00000415,
148     // 0x00003015, 0x00002015, 0x00000015, 0x00001015.
149     // The last record is an imaginary TXT record for t.google.com.
150     0x00, 0x03, 0x81, 0x80, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
151     0x03, 0x77, 0x77, 0x77, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x02,
152     0x61, 0x7a, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05, 0x00,
153     0x01, 0x00, 0x01, 0x50, 0x99, 0x00, 0x10, 0x03, 0x77, 0x77, 0x77, 0x06,
154     0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0xc0,
155     0x2b, 0x00, 0x05, 0x00, 0x01, 0x00, 0x02, 0x50, 0x99, 0x00, 0x08, 0x03,
156     0x77, 0x77, 0x77, 0x01, 0x6c, 0xc0, 0x2f, 0xc0, 0x47, 0x00, 0x01, 0x00,
157     0x01, 0x00, 0x00, 0x04, 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb2, 0xc0,
158     0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x30, 0x15, 0x00, 0x04, 0x4a,
159     0x7d, 0xe2, 0xb3, 0xc0, 0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x20,
160     0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb4, 0xc0, 0x47, 0x00, 0x01, 0x00,
161     0x01, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x4a, 0x7d, 0xe2, 0xb0, 0xc0,
162     0x47, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10, 0x15, 0x00, 0x04, 0x4a,
163     0x7d, 0xe2, 0xb1, 0x01, 0x74, 0xc0, 0x2f, 0x00, 0x10, 0x00, 0x01, 0x00,
164     0x00, 0x00, 0x01, 0x00, 0x04, 0xde, 0xad, 0xfe, 0xed};
165 static const char* const kT3IpAddresses[] = {
166   "74.125.226.178", "74.125.226.179", "74.125.226.180",
167   "74.125.226.176", "74.125.226.177"
168 };
169 static const char kT3CanonName[] = "www.l.google.com";
170 static const base::TimeDelta kT3Ttl = base::Seconds(0x00000015);
171 // +2 for the CNAME records, +1 for TXT record.
172 static const unsigned kT3RecordCount = std::size(kT3IpAddresses) + 3;
173 
174 //-----------------------------------------------------------------------------
175 // Query/response set for www.gstatic.com, ID is fixed to 0.
176 static const char kT4HostName[] = "www.gstatic.com";
177 static const uint16_t kT4Qtype = dns_protocol::kTypeA;
178 static const char kT4DnsName[] = {0x03, 'w', 'w', 'w', 0x07, 'g',
179                                   's',  't', 'a', 't', 'i',  'c',
180                                   0x03, 'c', 'o', 'm', 0x00};
181 static const size_t kT4QuerySize = 33;
182 static const uint8_t kT4ResponseDatagram[] = {
183     // response contains the following IP addresses: 172.217.6.195.
184     0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
185     0x00, 0x00, 0x03, 0x77, 0x77, 0x77, 0x07, 0x67, 0x73, 0x74,
186     0x61, 0x74, 0x69, 0x63, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00,
187     0x01, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00,
188     0x00, 0x01, 0x2b, 0x00, 0x04, 0xac, 0xd9, 0x06, 0xc3};
189 
190 static const char* const kT4IpAddresses[] = {"172.217.6.195"};
191 static const base::TimeDelta kT4Ttl = base::Seconds(0x0000012b);
192 static const unsigned kT4RecordCount = std::size(kT0IpAddresses);
193 
194 class AddressSorter;
195 class DnsClient;
196 class DnsSession;
197 class IPAddress;
198 class ResolveContext;
199 class URLRequestContext;
200 
201 DnsResourceRecord BuildTestDnsRecord(std::string name,
202                                      uint16_t type,
203                                      std::string rdata,
204                                      base::TimeDelta ttl = base::Days(1));
205 
206 DnsResourceRecord BuildTestCnameRecord(std::string name,
207                                        base::StringPiece canonical_name,
208                                        base::TimeDelta ttl = base::Days(1));
209 
210 DnsResourceRecord BuildTestAddressRecord(std::string name,
211                                          const IPAddress& ip,
212                                          base::TimeDelta ttl = base::Days(1));
213 
214 DnsResourceRecord BuildTestTextRecord(std::string name,
215                                       std::vector<std::string> text_strings,
216                                       base::TimeDelta ttl = base::Days(1));
217 
218 DnsResourceRecord BuildTestHttpsAliasRecord(
219     std::string name,
220     base::StringPiece alias_name,
221     base::TimeDelta ttl = base::Days(1));
222 
223 std::pair<uint16_t, std::string> BuildTestHttpsServiceAlpnParam(
224     const std::vector<std::string>& alpns);
225 
226 std::pair<uint16_t, std::string> BuildTestHttpsServiceEchConfigParam(
227     base::span<const uint8_t> ech_config_list);
228 
229 std::pair<uint16_t, std::string> BuildTestHttpsServiceMandatoryParam(
230     std::vector<uint16_t> param_key_list);
231 
232 std::pair<uint16_t, std::string> BuildTestHttpsServicePortParam(uint16_t port);
233 
234 // `params` is a mapping from service param keys to a string containing the
235 // encoded bytes of a service param value (without the value length prefix which
236 // this method will automatically add).
237 DnsResourceRecord BuildTestHttpsServiceRecord(
238     std::string name,
239     uint16_t priority,
240     base::StringPiece service_name,
241     const std::map<uint16_t, std::string>& params,
242     base::TimeDelta ttl = base::Days(1));
243 
244 DnsResponse BuildTestDnsResponse(
245     std::string name,
246     uint16_t type,
247     const std::vector<DnsResourceRecord>& answers,
248     const std::vector<DnsResourceRecord>& authority = {},
249     const std::vector<DnsResourceRecord>& additional = {},
250     uint8_t rcode = dns_protocol::kRcodeNOERROR);
251 
252 DnsResponse BuildTestDnsAddressResponse(std::string name,
253                                         const IPAddress& ip,
254                                         std::string answer_name = "");
255 DnsResponse BuildTestDnsAddressResponseWithCname(std::string name,
256                                                  const IPAddress& ip,
257                                                  std::string cannonname,
258                                                  std::string answer_name = "");
259 
260 // If |answer_name| is empty, |name| will be used for all answer records, as is
261 // the normal behavior.
262 DnsResponse BuildTestDnsTextResponse(
263     std::string name,
264     std::vector<std::vector<std::string>> text_records,
265     std::string answer_name = "");
266 DnsResponse BuildTestDnsPointerResponse(std::string name,
267                                         std::vector<std::string> pointer_names,
268                                         std::string answer_name = "");
269 
270 struct TestServiceRecord {
271   uint16_t priority;
272   uint16_t weight;
273   uint16_t port;
274   std::string target;
275 };
276 
277 DnsResponse BuildTestDnsServiceResponse(
278     std::string name,
279     std::vector<TestServiceRecord> service_records,
280     std::string answer_name = "");
281 
282 struct MockDnsClientRule {
283   enum class ResultType {
284     // Fail asynchronously with ERR_NAME_NOT_RESOLVED and NXDOMAIN.
285     kNoDomain,
286     // Fail asynchronously with `net_error` or (if nullopt)
287     // ERR_NAME_NOT_RESOLVED and  `response` if not nullopt.
288     kFail,
289     // Fail asynchronously with ERR_DNS_TIMED_OUT.
290     kTimeout,
291     // Simulates a slow transaction that will complete only with a lenient
292     // timeout. Fails asynchronously with ERR_DNS_TIMED_OUT only if the
293     // transaction was created with |fast_timeout|. Otherwise completes
294     // successfully as if the ResultType were |kOk|.
295     kSlow,
296     // Return an empty response.
297     kEmpty,
298     // "Succeed" but with an unparsable response.
299     kMalformed,
300     // Immediately records a test failure if queried. Used to catch unexpected
301     // queries. Alternately, if combined with `MockDnsClientRule::delay`, fails
302     // only if the query is allowed to complete without being cancelled.
303     kUnexpected,
304 
305     // Results in the response in |Result::response| or, if null, results in a
306     // localhost IP response.
307     kOk,
308   };
309 
310   struct Result {
311     explicit Result(ResultType type,
312                     absl::optional<DnsResponse> response = absl::nullopt,
313                     absl::optional<int> net_error = absl::nullopt);
314     explicit Result(DnsResponse response);
315     Result(Result&&);
316     Result& operator=(Result&&);
317     ~Result();
318 
319     ResultType type;
320     absl::optional<DnsResponse> response;
321     absl::optional<int> net_error;
322   };
323 
324   // If |delay| is true, matching transactions will be delayed until triggered
325   // by the consumer. If |context| is non-null, it will only match transactions
326   // with the same context.
327   MockDnsClientRule(const std::string& prefix,
328                     uint16_t qtype,
329                     bool secure,
330                     Result result,
331                     bool delay,
332                     URLRequestContext* context = nullptr);
333   MockDnsClientRule(MockDnsClientRule&& rule);
334 
335   Result result;
336   std::string prefix;
337   uint16_t qtype;
338   bool secure;
339   bool delay;
340   raw_ptr<URLRequestContext> context;
341 };
342 
343 typedef std::vector<MockDnsClientRule> MockDnsClientRuleList;
344 
345 // A DnsTransactionFactory which creates MockTransaction.
346 class MockDnsTransactionFactory : public DnsTransactionFactory {
347  public:
348   explicit MockDnsTransactionFactory(MockDnsClientRuleList rules);
349   ~MockDnsTransactionFactory() override;
350 
351   std::unique_ptr<DnsTransaction> CreateTransaction(
352       std::string hostname,
353       uint16_t qtype,
354       const NetLogWithSource&,
355       bool secure,
356       SecureDnsMode secure_dns_mode,
357       ResolveContext* resolve_context,
358       bool fast_timeout) override;
359 
360   std::unique_ptr<DnsProbeRunner> CreateDohProbeRunner(
361       ResolveContext* resolve_context) override;
362 
363   void AddEDNSOption(std::unique_ptr<OptRecordRdata::Opt> opt) override;
364 
365   SecureDnsMode GetSecureDnsModeForTest() override;
366 
367   void CompleteDelayedTransactions();
368   // If there are any pending transactions of the given type,
369   // completes one and returns true. Otherwise, returns false.
370   [[nodiscard]] bool CompleteOneDelayedTransactionOfType(DnsQueryType type);
371 
doh_probes_running()372   bool doh_probes_running() { return !running_doh_probe_runners_.empty(); }
CompleteDohProbeRuners()373   void CompleteDohProbeRuners() { running_doh_probe_runners_.clear(); }
374 
set_force_doh_server_available(bool available)375   void set_force_doh_server_available(bool available) {
376     force_doh_server_available_ = available;
377   }
378 
379  private:
380   class MockTransaction;
381   class MockDohProbeRunner;
382   using DelayedTransactionList = std::vector<base::WeakPtr<MockTransaction>>;
383 
384   MockDnsClientRuleList rules_;
385   DelayedTransactionList delayed_transactions_;
386 
387   bool force_doh_server_available_ = true;
388   std::set<MockDohProbeRunner*> running_doh_probe_runners_;
389 
390   base::WeakPtrFactory<MockDnsTransactionFactory> weak_ptr_factory_{this};
391 };
392 
393 // MockDnsClient provides MockDnsTransactionFactory.
394 class MockDnsClient : public DnsClient {
395  public:
396   MockDnsClient(DnsConfig config, MockDnsClientRuleList rules);
397   ~MockDnsClient() override;
398 
399   // DnsClient interface:
400   bool CanUseSecureDnsTransactions() const override;
401   bool CanUseInsecureDnsTransactions() const override;
402   bool CanQueryAdditionalTypesViaInsecureDns() const override;
403   void SetInsecureEnabled(bool enabled, bool additional_types_enabled) override;
404   bool FallbackFromSecureTransactionPreferred(
405       ResolveContext* resolve_context) const override;
406   bool FallbackFromInsecureTransactionPreferred() const override;
407   bool SetSystemConfig(absl::optional<DnsConfig> system_config) override;
408   bool SetConfigOverrides(DnsConfigOverrides config_overrides) override;
409   void ReplaceCurrentSession() override;
410   DnsSession* GetCurrentSession() override;
411   const DnsConfig* GetEffectiveConfig() const override;
412   const DnsHosts* GetHosts() const override;
413   DnsTransactionFactory* GetTransactionFactory() override;
414   AddressSorter* GetAddressSorter() override;
415   void IncrementInsecureFallbackFailures() override;
416   void ClearInsecureFallbackFailures() override;
417   base::Value::Dict GetDnsConfigAsValueForNetLog() const override;
418   absl::optional<DnsConfig> GetSystemConfigForTesting() const override;
419   DnsConfigOverrides GetConfigOverridesForTesting() const override;
420   void SetTransactionFactoryForTesting(
421       std::unique_ptr<DnsTransactionFactory> factory) override;
422   absl::optional<std::vector<IPEndPoint>> GetPresetAddrs(
423       const url::SchemeHostPort& endpoint) const override;
424 
425   // Completes all DnsTransactions that were delayed by a rule.
426   void CompleteDelayedTransactions();
427   // If there are any pending transactions of the given type,
428   // completes one and returns true. Otherwise, returns false.
429   [[nodiscard]] bool CompleteOneDelayedTransactionOfType(DnsQueryType type);
430 
set_max_fallback_failures(int max_fallback_failures)431   void set_max_fallback_failures(int max_fallback_failures) {
432     max_fallback_failures_ = max_fallback_failures;
433   }
434 
set_ignore_system_config_changes(bool ignore_system_config_changes)435   void set_ignore_system_config_changes(bool ignore_system_config_changes) {
436     ignore_system_config_changes_ = ignore_system_config_changes;
437   }
438 
set_preset_endpoint(absl::optional<url::SchemeHostPort> endpoint)439   void set_preset_endpoint(absl::optional<url::SchemeHostPort> endpoint) {
440     preset_endpoint_ = std::move(endpoint);
441   }
442 
set_preset_addrs(std::vector<IPEndPoint> preset_addrs)443   void set_preset_addrs(std::vector<IPEndPoint> preset_addrs) {
444     preset_addrs_ = std::move(preset_addrs);
445   }
446 
447   void SetForceDohServerAvailable(bool available);
448 
factory()449   MockDnsTransactionFactory* factory() { return factory_.get(); }
450 
451  private:
452   absl::optional<DnsConfig> BuildEffectiveConfig();
453   scoped_refptr<DnsSession> BuildSession();
454 
455   bool insecure_enabled_ = false;
456   bool additional_types_enabled_ = false;
457   int fallback_failures_ = 0;
458   int max_fallback_failures_ = DnsClient::kMaxInsecureFallbackFailures;
459   bool ignore_system_config_changes_ = false;
460 
461   // If |true|, MockDnsClient will always pretend DoH servers are available and
462   // allow secure transactions no matter what the state is in the transaction
463   // ResolveContext. If |false|, the ResolveContext must contain at least one
464   // available DoH server to allow secure transactions.
465   bool force_doh_server_available_ = true;
466 
467   MockClientSocketFactory socket_factory_;
468   absl::optional<DnsConfig> config_;
469   scoped_refptr<DnsSession> session_;
470   DnsConfigOverrides overrides_;
471   absl::optional<DnsConfig> effective_config_;
472   std::unique_ptr<MockDnsTransactionFactory> factory_;
473   std::unique_ptr<AddressSorter> address_sorter_;
474   absl::optional<url::SchemeHostPort> preset_endpoint_;
475   absl::optional<std::vector<IPEndPoint>> preset_addrs_;
476 };
477 
478 }  // namespace net
479 
480 #endif  // NET_DNS_DNS_TEST_UTIL_H_
481