Index: components/certificate_transparency/log_dns_client_unittest.cc |
diff --git a/components/certificate_transparency/log_dns_client_unittest.cc b/components/certificate_transparency/log_dns_client_unittest.cc |
index 7d25bafeab85024731de54683dbcb5c48b44498a..64223ef51757768878acef01f6fd8431449782c9 100644 |
--- a/components/certificate_transparency/log_dns_client_unittest.cc |
+++ b/components/certificate_transparency/log_dns_client_unittest.cc |
@@ -4,27 +4,22 @@ |
#include "components/certificate_transparency/log_dns_client.h" |
-#include <algorithm> |
-#include <numeric> |
+#include <memory> |
+#include <string> |
#include <utility> |
#include <vector> |
-#include "base/big_endian.h" |
-#include "base/macros.h" |
#include "base/message_loop/message_loop.h" |
#include "base/run_loop.h" |
-#include "base/sys_byteorder.h" |
-#include "base/test/test_timeouts.h" |
+#include "components/certificate_transparency/mock_log_dns_traffic.h" |
#include "crypto/sha2.h" |
#include "net/base/net_errors.h" |
#include "net/cert/merkle_audit_proof.h" |
-#include "net/cert/merkle_tree_leaf.h" |
#include "net/cert/signed_certificate_timestamp.h" |
#include "net/dns/dns_client.h" |
#include "net/dns/dns_config_service.h" |
#include "net/dns/dns_protocol.h" |
#include "net/log/net_log.h" |
-#include "net/socket/socket_test_util.h" |
#include "net/test/gtest_util.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -43,89 +38,6 @@ constexpr char kLeafHash[] = |
"\x1f\x25\xe1\xca\xba\x4f\xf9\xb8\x27\x24\x83\x0f\xca\x60\xe4\xc2\xbe\xa8" |
"\xc3\xa9\x44\x1c\x27\xb0\xb4\x3e\x6a\x96\x94\xc7\xb8\x04"; |
-// Necessary to expose SetDnsConfig for testing. |
-class DnsChangeNotifier : public net::NetworkChangeNotifier { |
- public: |
- static void SetInitialDnsConfig(const net::DnsConfig& config) { |
- net::NetworkChangeNotifier::SetInitialDnsConfig(config); |
- } |
- |
- static void SetDnsConfig(const net::DnsConfig& config) { |
- net::NetworkChangeNotifier::SetDnsConfig(config); |
- } |
-}; |
- |
-// Always return min, to simplify testing. |
-// This should result in the DNS query ID always being 0. |
-int FakeRandInt(int min, int max) { |
- return min; |
-} |
- |
-std::vector<char> CreateDnsTxtRequest(base::StringPiece qname) { |
- std::string encoded_qname; |
- EXPECT_TRUE(net::DNSDomainFromDot(qname, &encoded_qname)); |
- |
- const size_t query_section_size = encoded_qname.size() + 4; |
- |
- std::vector<char> request(sizeof(net::dns_protocol::Header) + |
- query_section_size); |
- base::BigEndianWriter writer(request.data(), request.size()); |
- |
- // Header |
- net::dns_protocol::Header header = {}; |
- header.flags = base::HostToNet16(net::dns_protocol::kFlagRD); |
- header.qdcount = base::HostToNet16(1); |
- EXPECT_TRUE(writer.WriteBytes(&header, sizeof(header))); |
- // Query section |
- EXPECT_TRUE(writer.WriteBytes(encoded_qname.data(), encoded_qname.size())); |
- EXPECT_TRUE(writer.WriteU16(net::dns_protocol::kTypeTXT)); |
- EXPECT_TRUE(writer.WriteU16(net::dns_protocol::kClassIN)); |
- EXPECT_EQ(0, writer.remaining()); |
- |
- return request; |
-} |
- |
-std::vector<char> CreateDnsTxtResponse(const std::vector<char>& request, |
- base::StringPiece answer) { |
- const size_t answers_section_size = 12 + answer.size(); |
- constexpr uint32_t ttl = 86400; // seconds |
- |
- std::vector<char> response(request.size() + answers_section_size); |
- std::copy(request.begin(), request.end(), response.begin()); |
- // Modify the header |
- net::dns_protocol::Header* header = |
- reinterpret_cast<net::dns_protocol::Header*>(response.data()); |
- header->ancount = base::HostToNet16(1); |
- header->flags |= base::HostToNet16(net::dns_protocol::kFlagResponse); |
- |
- // Write the answer section |
- base::BigEndianWriter writer(response.data() + request.size(), |
- response.size() - request.size()); |
- EXPECT_TRUE(writer.WriteU8(0xc0)); // qname is a pointer |
- EXPECT_TRUE(writer.WriteU8( |
- sizeof(*header))); // address of qname (start of query section) |
- EXPECT_TRUE(writer.WriteU16(net::dns_protocol::kTypeTXT)); |
- EXPECT_TRUE(writer.WriteU16(net::dns_protocol::kClassIN)); |
- EXPECT_TRUE(writer.WriteU32(ttl)); |
- EXPECT_TRUE(writer.WriteU16(answer.size())); |
- EXPECT_TRUE(writer.WriteBytes(answer.data(), answer.size())); |
- EXPECT_EQ(0, writer.remaining()); |
- |
- return response; |
-} |
- |
-std::vector<char> CreateDnsErrorResponse(const std::vector<char>& request, |
- uint8_t rcode) { |
- std::vector<char> response(request); |
- // Modify the header |
- net::dns_protocol::Header* header = |
- reinterpret_cast<net::dns_protocol::Header*>(response.data()); |
- header->ancount = base::HostToNet16(1); |
- header->flags |= base::HostToNet16(net::dns_protocol::kFlagResponse | rcode); |
- |
- return response; |
-} |
- |
std::vector<std::string> GetSampleAuditProof(size_t length) { |
std::vector<std::string> audit_proof(length); |
// Makes each node of the audit proof different, so that tests are able to |
@@ -200,161 +112,18 @@ class MockAuditProofCallback { |
base::RunLoop run_loop_; |
}; |
-// A container for all of the data we need to keep alive for a mock socket. |
-// This is useful because Mock{Read,Write}, SequencedSocketData and |
-// MockClientSocketFactory all do not take ownership of or copy their arguments, |
-// so we have to manage the lifetime of those arguments ourselves. Wrapping all |
-// of that up in a single class simplifies this. |
-class MockSocketData { |
- public: |
- // A socket that expects one write and one read operation. |
- MockSocketData(const std::vector<char>& write, const std::vector<char>& read) |
- : expected_write_payload_(write), |
- expected_read_payload_(read), |
- expected_write_(net::SYNCHRONOUS, |
- expected_write_payload_.data(), |
- expected_write_payload_.size(), |
- 0), |
- expected_reads_{net::MockRead(net::ASYNC, |
- expected_read_payload_.data(), |
- expected_read_payload_.size(), |
- 1), |
- eof_}, |
- socket_data_(expected_reads_, 2, &expected_write_, 1) {} |
- |
- // A socket that expects one write and a read error. |
- MockSocketData(const std::vector<char>& write, int net_error) |
- : expected_write_payload_(write), |
- expected_write_(net::SYNCHRONOUS, |
- expected_write_payload_.data(), |
- expected_write_payload_.size(), |
- 0), |
- expected_reads_{net::MockRead(net::ASYNC, net_error, 1), eof_}, |
- socket_data_(expected_reads_, 2, &expected_write_, 1) {} |
- |
- // A socket that expects one write and no response. |
- explicit MockSocketData(const std::vector<char>& write) |
- : expected_write_payload_(write), |
- expected_write_(net::SYNCHRONOUS, |
- expected_write_payload_.data(), |
- expected_write_payload_.size(), |
- 0), |
- expected_reads_{net::MockRead(net::SYNCHRONOUS, net::ERR_IO_PENDING, 1), |
- eof_}, |
- socket_data_(expected_reads_, 2, &expected_write_, 1) {} |
- |
- void SetWriteMode(net::IoMode mode) { expected_write_.mode = mode; } |
- void SetReadMode(net::IoMode mode) { expected_reads_[0].mode = mode; } |
- |
- void AddToFactory(net::MockClientSocketFactory* socket_factory) { |
- socket_factory->AddSocketDataProvider(&socket_data_); |
- } |
- |
- private: |
- // Prevents read overruns and makes a socket timeout the default behaviour. |
- static const net::MockRead eof_; |
- |
- const std::vector<char> expected_write_payload_; |
- const std::vector<char> expected_read_payload_; |
- // Encapsulates the data that is expected to be written to a socket. |
- net::MockWrite expected_write_; |
- // Encapsulates the data/error that should be returned when reading from a |
- // socket. The expected response is followed by |eof_|, to catch further, |
- // unexpected read attempts. |
- net::MockRead expected_reads_[2]; |
- net::SequencedSocketData socket_data_; |
- |
- DISALLOW_COPY_AND_ASSIGN(MockSocketData); |
-}; |
- |
-const net::MockRead MockSocketData::eof_(net::SYNCHRONOUS, |
- net::ERR_IO_PENDING, |
- 2); |
- |
class LogDnsClientTest : public ::testing::TestWithParam<net::IoMode> { |
protected: |
- LogDnsClientTest() : |
- network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) { |
- net::DnsConfig dns_config; |
- // Use an invalid nameserver address. This prevents the tests accidentally |
- // sending real DNS queries. The mock sockets don't care that the address |
- // is invalid. |
- dns_config.nameservers.push_back(net::IPEndPoint()); |
- // Don't attempt retransmissions - just fail. |
- dns_config.attempts = 1; |
- // This ensures timeouts are long enough for memory tests. |
- dns_config.timeout = TestTimeouts::action_timeout(); |
- // Simplify testing - don't require random numbers for the source port. |
- // This means our FakeRandInt function should only be called to get query |
- // IDs. |
- dns_config.randomize_ports = false; |
- |
- DnsChangeNotifier::SetInitialDnsConfig(dns_config); |
- } |
- |
- void ExpectRequestAndErrorResponse(base::StringPiece qname, uint8_t rcode) { |
- std::vector<char> request = CreateDnsTxtRequest(qname); |
- std::vector<char> response = CreateDnsErrorResponse(request, rcode); |
- |
- mock_socket_data_.emplace_back(new MockSocketData(request, response)); |
- mock_socket_data_.back()->SetReadMode(GetParam()); |
- mock_socket_data_.back()->AddToFactory(&socket_factory_); |
- } |
- |
- void ExpectRequestAndSocketError(base::StringPiece qname, int net_error) { |
- std::vector<char> request = CreateDnsTxtRequest(qname); |
- |
- mock_socket_data_.emplace_back(new MockSocketData(request, net_error)); |
- mock_socket_data_.back()->SetReadMode(GetParam()); |
- mock_socket_data_.back()->AddToFactory(&socket_factory_); |
- } |
- |
- void ExpectRequestAndTimeout(base::StringPiece qname) { |
- std::vector<char> request = CreateDnsTxtRequest(qname); |
- |
- mock_socket_data_.emplace_back(new MockSocketData(request)); |
- mock_socket_data_.back()->SetReadMode(GetParam()); |
- mock_socket_data_.back()->AddToFactory(&socket_factory_); |
- |
- // Speed up timeout tests. |
- net::DnsConfig dns_config; |
- DnsChangeNotifier::GetDnsConfig(&dns_config); |
- dns_config.timeout = TestTimeouts::tiny_timeout(); |
- DnsChangeNotifier::SetDnsConfig(dns_config); |
- } |
- |
- void 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); |
- } |
- |
- void 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); |
+ LogDnsClientTest() |
+ : network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) { |
+ mock_dns_.SetSocketReadMode(GetParam()); |
+ mock_dns_.InitializeDnsConfig(); |
} |
void QueryLeafIndex(base::StringPiece log_domain, |
base::StringPiece leaf_hash, |
MockLeafIndexCallback* callback) { |
- std::unique_ptr<net::DnsClient> dns_client = CreateDnsClient(); |
- LogDnsClient log_client(std::move(dns_client), net::BoundNetLog()); |
- net::NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); |
- |
+ LogDnsClient log_client(mock_dns_.CreateDnsClient(), net::BoundNetLog()); |
log_client.QueryLeafIndex(log_domain, leaf_hash, callback->AsCallback()); |
callback->WaitUntilRun(); |
} |
@@ -363,47 +132,24 @@ class LogDnsClientTest : public ::testing::TestWithParam<net::IoMode> { |
uint64_t leaf_index, |
uint64_t tree_size, |
MockAuditProofCallback* callback) { |
- std::unique_ptr<net::DnsClient> dns_client = CreateDnsClient(); |
- LogDnsClient log_client(std::move(dns_client), net::BoundNetLog()); |
- net::NetworkChangeNotifier::NotifyObserversOfInitialDNSConfigReadForTests(); |
- |
+ LogDnsClient log_client(mock_dns_.CreateDnsClient(), net::BoundNetLog()); |
log_client.QueryAuditProof(log_domain, leaf_index, tree_size, |
callback->AsCallback()); |
callback->WaitUntilRun(); |
} |
- std::unique_ptr<net::DnsClient> CreateDnsClient() { |
- return net::DnsClient::CreateClientForTesting(nullptr, &socket_factory_, |
- base::Bind(&FakeRandInt)); |
- } |
- |
- private: |
- |
- void ExpectRequestAndResponse(base::StringPiece qname, |
- base::StringPiece answer) { |
- std::vector<char> request = CreateDnsTxtRequest(qname); |
- std::vector<char> response = CreateDnsTxtResponse(request, answer); |
- |
- mock_socket_data_.emplace_back(new MockSocketData(request, response)); |
- mock_socket_data_.back()->SetReadMode(GetParam()); |
- mock_socket_data_.back()->AddToFactory(&socket_factory_); |
- } |
- |
// This will be the NetworkChangeNotifier singleton for the duration of the |
// test. It is accessed statically by LogDnsClient. |
std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
// Queues and handles asynchronous DNS tasks. Indirectly used by LogDnsClient, |
// the underlying net::DnsClient, and NetworkChangeNotifier. |
base::MessageLoopForIO message_loop_; |
- // One MockSocketData for each socket that is created. This corresponds to one |
- // for each DNS request sent. |
- std::vector<std::unique_ptr<MockSocketData>> mock_socket_data_; |
- // Provides as many mock sockets as there are entries in |mock_socket_data_|. |
- net::MockClientSocketFactory socket_factory_; |
+ // Allows mock DNS sockets to be setup. |
+ MockLogDnsTraffic mock_dns_; |
}; |
TEST_P(LogDnsClientTest, QueryLeafIndex) { |
- ExpectLeafIndexRequestAndResponse( |
+ mock_dns_.ExpectLeafIndexRequestAndResponse( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", |
"123456"); |
@@ -415,7 +161,7 @@ TEST_P(LogDnsClientTest, QueryLeafIndex) { |
} |
TEST_P(LogDnsClientTest, QueryLeafIndexReportsThatLogDomainDoesNotExist) { |
- ExpectRequestAndErrorResponse( |
+ mock_dns_.ExpectRequestAndErrorResponse( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", |
net::dns_protocol::kRcodeNXDOMAIN); |
@@ -427,7 +173,7 @@ TEST_P(LogDnsClientTest, QueryLeafIndexReportsThatLogDomainDoesNotExist) { |
} |
TEST_P(LogDnsClientTest, QueryLeafIndexReportsServerFailure) { |
- ExpectRequestAndErrorResponse( |
+ mock_dns_.ExpectRequestAndErrorResponse( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", |
net::dns_protocol::kRcodeSERVFAIL); |
@@ -439,7 +185,7 @@ TEST_P(LogDnsClientTest, QueryLeafIndexReportsServerFailure) { |
} |
TEST_P(LogDnsClientTest, QueryLeafIndexReportsServerRefusal) { |
- ExpectRequestAndErrorResponse( |
+ mock_dns_.ExpectRequestAndErrorResponse( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", |
net::dns_protocol::kRcodeREFUSED); |
@@ -452,7 +198,7 @@ TEST_P(LogDnsClientTest, QueryLeafIndexReportsServerRefusal) { |
TEST_P(LogDnsClientTest, |
QueryLeafIndexReportsMalformedResponseIfLeafIndexIsNotNumeric) { |
- ExpectLeafIndexRequestAndResponse( |
+ mock_dns_.ExpectLeafIndexRequestAndResponse( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", |
"foo"); |
@@ -465,7 +211,7 @@ TEST_P(LogDnsClientTest, |
TEST_P(LogDnsClientTest, |
QueryLeafIndexReportsMalformedResponseIfLeafIndexIsFloatingPoint) { |
- ExpectLeafIndexRequestAndResponse( |
+ mock_dns_.ExpectLeafIndexRequestAndResponse( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", |
"123456.0"); |
@@ -478,7 +224,7 @@ TEST_P(LogDnsClientTest, |
TEST_P(LogDnsClientTest, |
QueryLeafIndexReportsMalformedResponseIfLeafIndexIsEmpty) { |
- ExpectLeafIndexRequestAndResponse( |
+ mock_dns_.ExpectLeafIndexRequestAndResponse( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", ""); |
MockLeafIndexCallback callback; |
@@ -490,7 +236,7 @@ TEST_P(LogDnsClientTest, |
TEST_P(LogDnsClientTest, |
QueryLeafIndexReportsMalformedResponseIfLeafIndexHasNonNumericPrefix) { |
- ExpectLeafIndexRequestAndResponse( |
+ mock_dns_.ExpectLeafIndexRequestAndResponse( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", |
"foo123456"); |
@@ -503,7 +249,7 @@ TEST_P(LogDnsClientTest, |
TEST_P(LogDnsClientTest, |
QueryLeafIndexReportsMalformedResponseIfLeafIndexHasNonNumericSuffix) { |
- ExpectLeafIndexRequestAndResponse( |
+ mock_dns_.ExpectLeafIndexRequestAndResponse( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", |
"123456foo"); |
@@ -555,7 +301,7 @@ TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLeafHashIsNull) { |
} |
TEST_P(LogDnsClientTest, QueryLeafIndexReportsSocketError) { |
- ExpectRequestAndSocketError( |
+ mock_dns_.ExpectRequestAndSocketError( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", |
net::ERR_CONNECTION_REFUSED); |
@@ -567,7 +313,7 @@ TEST_P(LogDnsClientTest, QueryLeafIndexReportsSocketError) { |
} |
TEST_P(LogDnsClientTest, QueryLeafIndexReportsTimeout) { |
- ExpectRequestAndTimeout( |
+ mock_dns_.ExpectRequestAndTimeout( |
"D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test."); |
MockLeafIndexCallback callback; |
@@ -582,15 +328,15 @@ TEST_P(LogDnsClientTest, QueryAuditProof) { |
// It should require 3 queries to collect the entire audit proof, as there is |
// only space for 7 nodes per UDP packet. |
- ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", |
- audit_proof.begin(), |
- audit_proof.begin() + 7); |
- ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.", |
- audit_proof.begin() + 7, |
- audit_proof.begin() + 14); |
- ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.", |
- audit_proof.begin() + 14, |
- audit_proof.end()); |
+ mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", |
+ audit_proof.begin(), |
+ audit_proof.begin() + 7); |
+ mock_dns_.ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.", |
+ audit_proof.begin() + 7, |
+ audit_proof.begin() + 14); |
+ mock_dns_.ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.", |
+ audit_proof.begin() + 14, |
+ audit_proof.end()); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -606,24 +352,24 @@ TEST_P(LogDnsClientTest, QueryAuditProofHandlesResponsesWithShortAuditPaths) { |
const std::vector<std::string> audit_proof = GetSampleAuditProof(20); |
// Make some of the responses contain fewer proof nodes than they can hold. |
- ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", |
- audit_proof.begin(), |
- audit_proof.begin() + 1); |
- ExpectAuditProofRequestAndResponse("1.123456.999999.tree.ct.test.", |
- audit_proof.begin() + 1, |
- audit_proof.begin() + 3); |
- ExpectAuditProofRequestAndResponse("3.123456.999999.tree.ct.test.", |
- audit_proof.begin() + 3, |
- audit_proof.begin() + 6); |
- ExpectAuditProofRequestAndResponse("6.123456.999999.tree.ct.test.", |
- audit_proof.begin() + 6, |
- audit_proof.begin() + 10); |
- ExpectAuditProofRequestAndResponse("10.123456.999999.tree.ct.test.", |
- audit_proof.begin() + 10, |
- audit_proof.begin() + 13); |
- ExpectAuditProofRequestAndResponse("13.123456.999999.tree.ct.test.", |
- audit_proof.begin() + 13, |
- audit_proof.end()); |
+ mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", |
+ audit_proof.begin(), |
+ audit_proof.begin() + 1); |
+ mock_dns_.ExpectAuditProofRequestAndResponse("1.123456.999999.tree.ct.test.", |
+ audit_proof.begin() + 1, |
+ audit_proof.begin() + 3); |
+ mock_dns_.ExpectAuditProofRequestAndResponse("3.123456.999999.tree.ct.test.", |
+ audit_proof.begin() + 3, |
+ audit_proof.begin() + 6); |
+ mock_dns_.ExpectAuditProofRequestAndResponse("6.123456.999999.tree.ct.test.", |
+ audit_proof.begin() + 6, |
+ audit_proof.begin() + 10); |
+ mock_dns_.ExpectAuditProofRequestAndResponse("10.123456.999999.tree.ct.test.", |
+ audit_proof.begin() + 10, |
+ audit_proof.begin() + 13); |
+ mock_dns_.ExpectAuditProofRequestAndResponse("13.123456.999999.tree.ct.test.", |
+ audit_proof.begin() + 13, |
+ audit_proof.end()); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -636,8 +382,8 @@ TEST_P(LogDnsClientTest, QueryAuditProofHandlesResponsesWithShortAuditPaths) { |
} |
TEST_P(LogDnsClientTest, QueryAuditProofReportsThatLogDomainDoesNotExist) { |
- ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", |
- net::dns_protocol::kRcodeNXDOMAIN); |
+ mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", |
+ net::dns_protocol::kRcodeNXDOMAIN); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -647,8 +393,8 @@ TEST_P(LogDnsClientTest, QueryAuditProofReportsThatLogDomainDoesNotExist) { |
} |
TEST_P(LogDnsClientTest, QueryAuditProofReportsServerFailure) { |
- ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", |
- net::dns_protocol::kRcodeSERVFAIL); |
+ mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", |
+ net::dns_protocol::kRcodeSERVFAIL); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -658,8 +404,8 @@ TEST_P(LogDnsClientTest, QueryAuditProofReportsServerFailure) { |
} |
TEST_P(LogDnsClientTest, QueryAuditProofReportsServerRefusal) { |
- ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", |
- net::dns_protocol::kRcodeREFUSED); |
+ mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", |
+ net::dns_protocol::kRcodeREFUSED); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -673,8 +419,8 @@ TEST_P(LogDnsClientTest, |
// node is shorter than a SHA-256 hash (31 vs 32 bytes) |
const std::vector<std::string> audit_proof(1, std::string(31, 'a')); |
- ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", |
- audit_proof.begin(), audit_proof.end()); |
+ mock_dns_.ExpectAuditProofRequestAndResponse( |
+ "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end()); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -687,8 +433,8 @@ TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfNodeTooLong) { |
// node is longer than a SHA-256 hash (33 vs 32 bytes) |
const std::vector<std::string> audit_proof(1, std::string(33, 'a')); |
- ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", |
- audit_proof.begin(), audit_proof.end()); |
+ mock_dns_.ExpectAuditProofRequestAndResponse( |
+ "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end()); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -700,8 +446,8 @@ TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfNodeTooLong) { |
TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfEmpty) { |
const std::vector<std::string> audit_proof; |
- ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", |
- audit_proof.begin(), audit_proof.end()); |
+ mock_dns_.ExpectAuditProofRequestAndResponse( |
+ "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end()); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -745,8 +491,8 @@ TEST_P(LogDnsClientTest, |
} |
TEST_P(LogDnsClientTest, QueryAuditProofReportsSocketError) { |
- ExpectRequestAndSocketError("0.123456.999999.tree.ct.test.", |
- net::ERR_CONNECTION_REFUSED); |
+ mock_dns_.ExpectRequestAndSocketError("0.123456.999999.tree.ct.test.", |
+ net::ERR_CONNECTION_REFUSED); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -756,7 +502,7 @@ TEST_P(LogDnsClientTest, QueryAuditProofReportsSocketError) { |
} |
TEST_P(LogDnsClientTest, QueryAuditProofReportsTimeout) { |
- ExpectRequestAndTimeout("0.123456.999999.tree.ct.test."); |
+ mock_dns_.ExpectRequestAndTimeout("0.123456.999999.tree.ct.test."); |
MockAuditProofCallback callback; |
QueryAuditProof("ct.test", 123456, 999999, &callback); |
@@ -766,7 +512,7 @@ TEST_P(LogDnsClientTest, QueryAuditProofReportsTimeout) { |
} |
TEST_P(LogDnsClientTest, AdoptsLatestDnsConfigIfValid) { |
- std::unique_ptr<net::DnsClient> tmp = CreateDnsClient(); |
+ std::unique_ptr<net::DnsClient> tmp = mock_dns_.CreateDnsClient(); |
net::DnsClient* dns_client = tmp.get(); |
LogDnsClient log_client(std::move(tmp), net::BoundNetLog()); |
@@ -774,7 +520,7 @@ TEST_P(LogDnsClientTest, AdoptsLatestDnsConfigIfValid) { |
net::DnsConfig config(*dns_client->GetConfig()); |
ASSERT_NE(123, config.attempts); |
config.attempts = 123; |
- DnsChangeNotifier::SetDnsConfig(config); |
+ mock_dns_.SetDnsConfig(config); |
// Let the DNS config change propogate. |
base::RunLoop().RunUntilIdle(); |
@@ -782,7 +528,7 @@ TEST_P(LogDnsClientTest, AdoptsLatestDnsConfigIfValid) { |
} |
TEST_P(LogDnsClientTest, IgnoresLatestDnsConfigIfInvalid) { |
- std::unique_ptr<net::DnsClient> tmp = CreateDnsClient(); |
+ std::unique_ptr<net::DnsClient> tmp = mock_dns_.CreateDnsClient(); |
net::DnsClient* dns_client = tmp.get(); |
LogDnsClient log_client(std::move(tmp), net::BoundNetLog()); |
@@ -790,7 +536,7 @@ TEST_P(LogDnsClientTest, IgnoresLatestDnsConfigIfInvalid) { |
net::DnsConfig config(*dns_client->GetConfig()); |
ASSERT_THAT(config.nameservers, Not(IsEmpty())); |
config.nameservers.clear(); // Makes config invalid |
- DnsChangeNotifier::SetDnsConfig(config); |
+ mock_dns_.SetDnsConfig(config); |
// Let the DNS config change propogate. |
base::RunLoop().RunUntilIdle(); |