OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_MOCK_LOG_DNS_TRAFFIC_H_ | 5 #ifndef COMPONENTS_CERTIFICATE_TRANSPARENCY_MOCK_LOG_DNS_TRAFFIC_H_ |
6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_MOCK_LOG_DNS_TRAFFIC_H_ | 6 #define COMPONENTS_CERTIFICATE_TRANSPARENCY_MOCK_LOG_DNS_TRAFFIC_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
| 14 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
16 #include "net/dns/dns_client.h" | 17 #include "net/dns/dns_client.h" |
17 #include "net/dns/dns_config_service.h" | 18 #include "net/dns/dns_config_service.h" |
18 #include "net/socket/socket_test_util.h" | 19 #include "net/socket/socket_test_util.h" |
19 | 20 |
20 namespace certificate_transparency { | 21 namespace certificate_transparency { |
21 | 22 |
22 // Mocks DNS requests and responses for a Certificate Transparency (CT) log. | 23 // Mocks DNS requests and responses for a Certificate Transparency (CT) log. |
23 // This is implemented using mock sockets. Call the CreateDnsClient() method to | 24 // This is implemented using mock sockets. Call the CreateDnsClient() method to |
(...skipping 19 matching lines...) Expand all Loading... |
43 // log_client.QueryAuditProof("ct.test", ..., base::Bind(...)); | 44 // log_client.QueryAuditProof("ct.test", ..., base::Bind(...)); |
44 class MockLogDnsTraffic { | 45 class MockLogDnsTraffic { |
45 public: | 46 public: |
46 MockLogDnsTraffic(); | 47 MockLogDnsTraffic(); |
47 ~MockLogDnsTraffic(); | 48 ~MockLogDnsTraffic(); |
48 | 49 |
49 // Expect a CT DNS request for the domain |qname|. | 50 // Expect a CT DNS request for the domain |qname|. |
50 // Such a request will receive a DNS response indicating that the error | 51 // Such a request will receive a DNS response indicating that the error |
51 // specified by |rcode| occurred. See RFC1035, Section 4.1.1 for |rcode| | 52 // specified by |rcode| occurred. See RFC1035, Section 4.1.1 for |rcode| |
52 // values. | 53 // values. |
53 void ExpectRequestAndErrorResponse(base::StringPiece qname, uint8_t rcode); | 54 // Returns false if any of the arguments are invalid. |
| 55 WARN_UNUSED_RESULT |
| 56 bool ExpectRequestAndErrorResponse(base::StringPiece qname, uint8_t rcode); |
54 | 57 |
55 // Expect a CT DNS request for the domain |qname|. | 58 // Expect a CT DNS request for the domain |qname|. |
56 // Such a request will trigger a socket error of type |error|. | 59 // Such a request will trigger a socket error of type |error|. |
57 void ExpectRequestAndSocketError(base::StringPiece qname, net::Error error); | 60 // Returns false if any of the arguments are invalid. |
| 61 WARN_UNUSED_RESULT |
| 62 bool ExpectRequestAndSocketError(base::StringPiece qname, net::Error error); |
58 | 63 |
59 // Expect a CT DNS request for the domain |qname|. | 64 // Expect a CT DNS request for the domain |qname|. |
60 // Such a request will timeout. | 65 // Such a request will timeout. |
61 // This will reduce the DNS timeout to minimize test duration. | 66 // This will reduce the DNS timeout to minimize test duration. |
62 void ExpectRequestAndTimeout(base::StringPiece qname); | 67 // Returns false if |qname| is invalid. |
| 68 WARN_UNUSED_RESULT |
| 69 bool ExpectRequestAndTimeout(base::StringPiece qname); |
63 | 70 |
64 // Expect a CT DNS request for the domain |qname|. | 71 // Expect a CT DNS request for the domain |qname|. |
65 // Such a request will receive a DNS TXT response containing |txt_strings|. | 72 // Such a request will receive a DNS TXT response containing |txt_strings|. |
66 void ExpectRequestAndResponse( | 73 // Returns false if any of the arguments are invalid. |
67 base::StringPiece qname, | 74 WARN_UNUSED_RESULT |
68 const std::vector<base::StringPiece>& txt_strings); | 75 bool ExpectRequestAndResponse( |
| 76 base::StringPiece qname, |
| 77 const std::vector<base::StringPiece>& txt_strings); |
| 78 |
69 // Expect a CT DNS request for the domain |qname|. | 79 // Expect a CT DNS request for the domain |qname|. |
70 // Such a request will receive a DNS response containing |leaf_index|. | 80 // Such a request will receive a DNS response containing |leaf_index|. |
71 // A description of such a request and response can be seen here: | 81 // A description of such a request and response can be seen here: |
72 // https://github.com/google/certificate-transparency-rfcs/blob/c8844de6bd0b5d
3d16bac79865e6edef533d760b/dns/draft-ct-over-dns.md#hash-query-hashquery | 82 // https://github.com/google/certificate-transparency-rfcs/blob/c8844de6bd0b5d
3d16bac79865e6edef533d760b/dns/draft-ct-over-dns.md#hash-query-hashquery |
73 void ExpectLeafIndexRequestAndResponse(base::StringPiece qname, | 83 // Returns false if any of the arguments are invalid. |
| 84 WARN_UNUSED_RESULT |
| 85 bool ExpectLeafIndexRequestAndResponse(base::StringPiece qname, |
74 uint64_t leaf_index); | 86 uint64_t leaf_index); |
| 87 |
75 // Expect a CT DNS request for the domain |qname|. | 88 // Expect a CT DNS request for the domain |qname|. |
76 // Such a request will receive a DNS response containing the inclusion proof | 89 // Such a request will receive a DNS response containing the inclusion proof |
77 // nodes between |audit_path_start| and |audit_path_end|. | 90 // nodes between |audit_path_start| and |audit_path_end|. |
78 // A description of such a request and response can be seen here: | 91 // A description of such a request and response can be seen here: |
79 // https://github.com/google/certificate-transparency-rfcs/blob/c8844de6bd0b5d
3d16bac79865e6edef533d760b/dns/draft-ct-over-dns.md#tree-query-treequery | 92 // https://github.com/google/certificate-transparency-rfcs/blob/c8844de6bd0b5d
3d16bac79865e6edef533d760b/dns/draft-ct-over-dns.md#tree-query-treequery |
80 void ExpectAuditProofRequestAndResponse( | 93 // Returns false if any of the arguments are invalid. |
| 94 WARN_UNUSED_RESULT |
| 95 bool ExpectAuditProofRequestAndResponse( |
81 base::StringPiece qname, | 96 base::StringPiece qname, |
82 std::vector<std::string>::const_iterator audit_path_start, | 97 std::vector<std::string>::const_iterator audit_path_start, |
83 std::vector<std::string>::const_iterator audit_path_end); | 98 std::vector<std::string>::const_iterator audit_path_end); |
84 | 99 |
85 // Sets the initial DNS config appropriate for testing. | 100 // Sets the initial DNS config appropriate for testing. |
86 // Requires that net::NetworkChangeNotifier is initialized first. | 101 // Requires that net::NetworkChangeNotifier is initialized first. |
87 // The DNS config is propogated to NetworkChangeNotifier::DNSObservers | 102 // The DNS config is propogated to NetworkChangeNotifier::DNSObservers |
88 // asynchronously. | 103 // asynchronously. |
89 void InitializeDnsConfig(); | 104 void InitializeDnsConfig(); |
90 | 105 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 net::MockClientSocketFactory socket_factory_; | 143 net::MockClientSocketFactory socket_factory_; |
129 // Controls whether mock socket reads are asynchronous. | 144 // Controls whether mock socket reads are asynchronous. |
130 net::IoMode socket_read_mode_; | 145 net::IoMode socket_read_mode_; |
131 | 146 |
132 DISALLOW_COPY_AND_ASSIGN(MockLogDnsTraffic); | 147 DISALLOW_COPY_AND_ASSIGN(MockLogDnsTraffic); |
133 }; | 148 }; |
134 | 149 |
135 } // namespace certificate_transparency | 150 } // namespace certificate_transparency |
136 | 151 |
137 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_MOCK_LOG_DNS_TRAFFIC_H_ | 152 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_MOCK_LOG_DNS_TRAFFIC_H_ |
OLD | NEW |