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 #include "components/certificate_transparency/mock_log_dns_traffic.h" | 5 #include "components/certificate_transparency/mock_log_dns_traffic.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <numeric> | 8 #include <numeric> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/big_endian.h" | 11 #include "base/big_endian.h" |
| 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/sys_byteorder.h" | 13 #include "base/sys_byteorder.h" |
13 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
14 #include "net/dns/dns_client.h" | 15 #include "net/dns/dns_client.h" |
15 #include "net/dns/dns_protocol.h" | 16 #include "net/dns/dns_protocol.h" |
16 #include "net/dns/dns_util.h" | 17 #include "net/dns/dns_util.h" |
17 #include "net/socket/socket_test_util.h" | 18 #include "net/socket/socket_test_util.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace certificate_transparency { | 21 namespace certificate_transparency { |
21 | 22 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 base::StringPiece qname, | 198 base::StringPiece qname, |
198 base::StringPiece leaf_index) { | 199 base::StringPiece leaf_index) { |
199 // Prepend size to leaf_index to create the query answer (rdata) | 200 // Prepend size to leaf_index to create the query answer (rdata) |
200 ASSERT_LE(leaf_index.size(), 0xFFul); // size must fit into a single byte | 201 ASSERT_LE(leaf_index.size(), 0xFFul); // size must fit into a single byte |
201 std::string answer = leaf_index.as_string(); | 202 std::string answer = leaf_index.as_string(); |
202 answer.insert(answer.begin(), static_cast<char>(leaf_index.size())); | 203 answer.insert(answer.begin(), static_cast<char>(leaf_index.size())); |
203 | 204 |
204 ExpectRequestAndResponse(qname, answer); | 205 ExpectRequestAndResponse(qname, answer); |
205 } | 206 } |
206 | 207 |
| 208 void MockLogDnsTraffic::ExpectLeafIndexRequestAndResponse( |
| 209 base::StringPiece qname, |
| 210 uint64_t leaf_index) { |
| 211 ExpectLeafIndexRequestAndResponse(qname, base::Uint64ToString(leaf_index)); |
| 212 } |
| 213 |
207 void MockLogDnsTraffic::ExpectAuditProofRequestAndResponse( | 214 void MockLogDnsTraffic::ExpectAuditProofRequestAndResponse( |
208 base::StringPiece qname, | 215 base::StringPiece qname, |
209 std::vector<std::string>::const_iterator audit_path_start, | 216 std::vector<std::string>::const_iterator audit_path_start, |
210 std::vector<std::string>::const_iterator audit_path_end) { | 217 std::vector<std::string>::const_iterator audit_path_end) { |
211 // Join nodes in the audit path into a single string. | 218 // Join nodes in the audit path into a single string. |
212 std::string proof = | 219 std::string proof = |
213 std::accumulate(audit_path_start, audit_path_end, std::string()); | 220 std::accumulate(audit_path_start, audit_path_end, std::string()); |
214 | 221 |
215 // Prepend size to proof to create the query answer (rdata) | 222 // Prepend size to proof to create the query answer (rdata) |
216 ASSERT_LE(proof.size(), 0xFFul); // size must fit into a single byte | 223 ASSERT_LE(proof.size(), 0xFFul); // size must fit into a single byte |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 } | 268 } |
262 | 269 |
263 void MockLogDnsTraffic::SetDnsTimeout(const base::TimeDelta& timeout) { | 270 void MockLogDnsTraffic::SetDnsTimeout(const base::TimeDelta& timeout) { |
264 net::DnsConfig dns_config; | 271 net::DnsConfig dns_config; |
265 DnsChangeNotifier::GetDnsConfig(&dns_config); | 272 DnsChangeNotifier::GetDnsConfig(&dns_config); |
266 dns_config.timeout = timeout; | 273 dns_config.timeout = timeout; |
267 DnsChangeNotifier::SetDnsConfig(dns_config); | 274 DnsChangeNotifier::SetDnsConfig(dns_config); |
268 } | 275 } |
269 | 276 |
270 } // namespace certificate_transparency | 277 } // namespace certificate_transparency |
OLD | NEW |