| Index: components/certificate_transparency/mock_log_dns_traffic.cc
|
| diff --git a/components/certificate_transparency/mock_log_dns_traffic.cc b/components/certificate_transparency/mock_log_dns_traffic.cc
|
| index 47922c05b2a9bdb0aa519bcb0891365720f109ae..22599950dd70a1df0a034adf0d6e230f73dd162b 100644
|
| --- a/components/certificate_transparency/mock_log_dns_traffic.cc
|
| +++ b/components/certificate_transparency/mock_log_dns_traffic.cc
|
| @@ -7,10 +7,12 @@
|
| #include <algorithm>
|
| #include <numeric>
|
| #include <vector>
|
|
|
| #include "base/big_endian.h"
|
| +#include "base/numerics/safe_conversions.h"
|
| +#include "base/strings/string_number_conversions.h"
|
| #include "base/sys_byteorder.h"
|
| #include "base/test/test_timeouts.h"
|
| #include "net/dns/dns_client.h"
|
| #include "net/dns/dns_protocol.h"
|
| #include "net/dns/dns_util.h"
|
| @@ -191,34 +193,39 @@ void MockLogDnsTraffic::ExpectRequestAndTimeout(base::StringPiece qname) {
|
|
|
| // Speed up timeout tests.
|
| SetDnsTimeout(TestTimeouts::tiny_timeout());
|
| }
|
|
|
| +void MockLogDnsTraffic::ExpectRequestAndResponse(
|
| + base::StringPiece qname,
|
| + const std::vector<base::StringPiece>& txt_strings) {
|
| + std::string answer;
|
| + for (base::StringPiece str : txt_strings) {
|
| + // The size of the string must precede it. The size must fit into 1 byte.
|
| + answer.insert(answer.end(), base::checked_cast<uint8_t>(str.size()));
|
| + str.AppendToString(&answer);
|
| + }
|
| +
|
| + std::vector<char> request = CreateDnsTxtRequest(qname);
|
| + EmplaceMockSocketData(request, CreateDnsTxtResponse(request, answer));
|
| +}
|
| +
|
| void MockLogDnsTraffic::ExpectLeafIndexRequestAndResponse(
|
| base::StringPiece qname,
|
| - base::StringPiece leaf_index) {
|
| - // Prepend size to leaf_index to create the query answer (rdata)
|
| - ASSERT_LE(leaf_index.size(), 0xFFul); // size must fit into a single byte
|
| - std::string answer = leaf_index.as_string();
|
| - answer.insert(answer.begin(), static_cast<char>(leaf_index.size()));
|
| -
|
| - ExpectRequestAndResponse(qname, answer);
|
| + uint64_t leaf_index) {
|
| + ExpectRequestAndResponse(qname, { base::Uint64ToString(leaf_index) });
|
| }
|
|
|
| void MockLogDnsTraffic::ExpectAuditProofRequestAndResponse(
|
| base::StringPiece qname,
|
| std::vector<std::string>::const_iterator audit_path_start,
|
| std::vector<std::string>::const_iterator audit_path_end) {
|
| // Join nodes in the audit path into a single string.
|
| std::string proof =
|
| std::accumulate(audit_path_start, audit_path_end, std::string());
|
|
|
| - // Prepend size to proof to create the query answer (rdata)
|
| - ASSERT_LE(proof.size(), 0xFFul); // size must fit into a single byte
|
| - proof.insert(proof.begin(), static_cast<char>(proof.size()));
|
| -
|
| - ExpectRequestAndResponse(qname, proof);
|
| + ExpectRequestAndResponse(qname, { proof });
|
| }
|
|
|
| void MockLogDnsTraffic::InitializeDnsConfig() {
|
| net::DnsConfig dns_config;
|
| // Use an invalid nameserver address. This prevents the tests accidentally
|
| @@ -244,16 +251,10 @@ void MockLogDnsTraffic::SetDnsConfig(const net::DnsConfig& config) {
|
| std::unique_ptr<net::DnsClient> MockLogDnsTraffic::CreateDnsClient() {
|
| return net::DnsClient::CreateClientForTesting(nullptr, &socket_factory_,
|
| base::Bind(&FakeRandInt));
|
| }
|
|
|
| -void MockLogDnsTraffic::ExpectRequestAndResponse(base::StringPiece qname,
|
| - base::StringPiece answer) {
|
| - std::vector<char> request = CreateDnsTxtRequest(qname);
|
| - EmplaceMockSocketData(request, CreateDnsTxtResponse(request, answer));
|
| -}
|
| -
|
| template <typename... Args>
|
| void MockLogDnsTraffic::EmplaceMockSocketData(Args&&... args) {
|
| mock_socket_data_.emplace_back(
|
| new MockSocketData(std::forward<Args>(args)...));
|
| mock_socket_data_.back()->SetReadMode(socket_read_mode_);
|
|
|