| 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> |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void ExpectRequestAndErrorResponse(base::StringPiece qname, uint8_t rcode); | 87 void ExpectRequestAndErrorResponse(base::StringPiece qname, uint8_t rcode); |
| 88 // Expect a CT DNS request for the domain |qname|. | 88 // Expect a CT DNS request for the domain |qname|. |
| 89 // Such a request will trigger a socket error of type |net_error|. | 89 // Such a request will trigger a socket error of type |net_error|. |
| 90 // |net_error| can be any net:Error value. | 90 // |net_error| can be any net:Error value. |
| 91 void ExpectRequestAndSocketError(base::StringPiece qname, int net_error); | 91 void ExpectRequestAndSocketError(base::StringPiece qname, int net_error); |
| 92 // Expect a CT DNS request for the domain |qname|. | 92 // Expect a CT DNS request for the domain |qname|. |
| 93 // Such a request will timeout. | 93 // Such a request will timeout. |
| 94 // This will reduce the DNS timeout to minimize test duration. | 94 // This will reduce the DNS timeout to minimize test duration. |
| 95 void ExpectRequestAndTimeout(base::StringPiece qname); | 95 void ExpectRequestAndTimeout(base::StringPiece qname); |
| 96 // Expect a CT DNS request for the domain |qname|. | 96 // Expect a CT DNS request for the domain |qname|. |
| 97 // Such a request will receive a DNS TXT response containing |txt_strings|. |
| 98 void ExpectRequestAndResponse( |
| 99 base::StringPiece qname, |
| 100 const std::vector<base::StringPiece>& txt_strings); |
| 101 // Expect a CT DNS request for the domain |qname|. |
| 97 // Such a request will receive a DNS response containing |leaf_index|. | 102 // Such a request will receive a DNS response containing |leaf_index|. |
| 98 // A description of such a request and response can be seen here: | 103 // A description of such a request and response can be seen here: |
| 99 // https://github.com/google/certificate-transparency-rfcs/blob/c8844de6bd0b5d
3d16bac79865e6edef533d760b/dns/draft-ct-over-dns.md#hash-query-hashquery | 104 // https://github.com/google/certificate-transparency-rfcs/blob/c8844de6bd0b5d
3d16bac79865e6edef533d760b/dns/draft-ct-over-dns.md#hash-query-hashquery |
| 100 void ExpectLeafIndexRequestAndResponse(base::StringPiece qname, | 105 void ExpectLeafIndexRequestAndResponse(base::StringPiece qname, |
| 101 base::StringPiece leaf_index); | 106 uint64_t leaf_index); |
| 102 // Expect a CT DNS request for the domain |qname|. | 107 // Expect a CT DNS request for the domain |qname|. |
| 103 // Such a request will receive a DNS response containing the inclusion proof | 108 // Such a request will receive a DNS response containing the inclusion proof |
| 104 // nodes between |audit_path_start| and |audit_path_end|. | 109 // nodes between |audit_path_start| and |audit_path_end|. |
| 105 // A description of such a request and response can be seen here: | 110 // A description of such a request and response can be seen here: |
| 106 // https://github.com/google/certificate-transparency-rfcs/blob/c8844de6bd0b5d
3d16bac79865e6edef533d760b/dns/draft-ct-over-dns.md#tree-query-treequery | 111 // https://github.com/google/certificate-transparency-rfcs/blob/c8844de6bd0b5d
3d16bac79865e6edef533d760b/dns/draft-ct-over-dns.md#tree-query-treequery |
| 107 void ExpectAuditProofRequestAndResponse( | 112 void ExpectAuditProofRequestAndResponse( |
| 108 base::StringPiece qname, | 113 base::StringPiece qname, |
| 109 std::vector<std::string>::const_iterator audit_path_start, | 114 std::vector<std::string>::const_iterator audit_path_start, |
| 110 std::vector<std::string>::const_iterator audit_path_end); | 115 std::vector<std::string>::const_iterator audit_path_end); |
| 111 | 116 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 124 // Creates a DNS client that uses mock sockets. | 129 // Creates a DNS client that uses mock sockets. |
| 125 // It is this DNS client that the expectations will be tested against. | 130 // It is this DNS client that the expectations will be tested against. |
| 126 std::unique_ptr<net::DnsClient> CreateDnsClient(); | 131 std::unique_ptr<net::DnsClient> CreateDnsClient(); |
| 127 | 132 |
| 128 // Sets whether mock reads should complete synchronously or asynchronously. | 133 // Sets whether mock reads should complete synchronously or asynchronously. |
| 129 void SetSocketReadMode(net::IoMode read_mode) { | 134 void SetSocketReadMode(net::IoMode read_mode) { |
| 130 socket_read_mode_ = read_mode; | 135 socket_read_mode_ = read_mode; |
| 131 } | 136 } |
| 132 | 137 |
| 133 private: | 138 private: |
| 134 // Expect A CT DNS request for the domain |qname|. | |
| 135 // Such a request will receive a DNS response containing |answer|. | |
| 136 void ExpectRequestAndResponse(base::StringPiece qname, | |
| 137 base::StringPiece answer); | |
| 138 | |
| 139 // Constructs MockSocketData from |args| and adds it to |socket_factory_|. | 139 // Constructs MockSocketData from |args| and adds it to |socket_factory_|. |
| 140 template <typename... Args> | 140 template <typename... Args> |
| 141 void EmplaceMockSocketData(Args&&... args); | 141 void EmplaceMockSocketData(Args&&... args); |
| 142 | 142 |
| 143 // Sets the timeout used for DNS queries. | 143 // Sets the timeout used for DNS queries. |
| 144 // Requires that net::NetworkChangeNotifier is initialized first. | 144 // Requires that net::NetworkChangeNotifier is initialized first. |
| 145 // The new timeout is propogated to NetworkChangeNotifier::DNSObservers | 145 // The new timeout is propogated to NetworkChangeNotifier::DNSObservers |
| 146 // asynchronously. | 146 // asynchronously. |
| 147 void SetDnsTimeout(const base::TimeDelta& timeout); | 147 void SetDnsTimeout(const base::TimeDelta& timeout); |
| 148 | 148 |
| 149 // One MockSocketData for each socket that is created. This corresponds to one | 149 // One MockSocketData for each socket that is created. This corresponds to one |
| 150 // for each DNS request sent. | 150 // for each DNS request sent. |
| 151 std::vector<std::unique_ptr<internal::MockSocketData>> mock_socket_data_; | 151 std::vector<std::unique_ptr<internal::MockSocketData>> mock_socket_data_; |
| 152 // Provides as many mock sockets as there are entries in |mock_socket_data_|. | 152 // Provides as many mock sockets as there are entries in |mock_socket_data_|. |
| 153 net::MockClientSocketFactory socket_factory_; | 153 net::MockClientSocketFactory socket_factory_; |
| 154 // Controls whether mock socket reads are asynchronous. | 154 // Controls whether mock socket reads are asynchronous. |
| 155 net::IoMode socket_read_mode_; | 155 net::IoMode socket_read_mode_; |
| 156 | 156 |
| 157 DISALLOW_COPY_AND_ASSIGN(MockLogDnsTraffic); | 157 DISALLOW_COPY_AND_ASSIGN(MockLogDnsTraffic); |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 } // namespace certificate_transparency | 160 } // namespace certificate_transparency |
| 161 | 161 |
| 162 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_MOCK_LOG_DNS_TRAFFIC_H_ | 162 #endif // COMPONENTS_CERTIFICATE_TRANSPARENCY_MOCK_LOG_DNS_TRAFFIC_H_ |
| OLD | NEW |