Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: components/certificate_transparency/log_dns_client_unittest.cc

Issue 2367523002: Merge LogDnsClient's QueryLeafIndex and QueryAuditProof methods (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/log_dns_client.h" 5 #include "components/certificate_transparency/log_dns_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 23 matching lines...) Expand all
34 using ::testing::AllOf; 34 using ::testing::AllOf;
35 using ::testing::Eq; 35 using ::testing::Eq;
36 using ::testing::IsEmpty; 36 using ::testing::IsEmpty;
37 using ::testing::IsNull; 37 using ::testing::IsNull;
38 using ::testing::Le; 38 using ::testing::Le;
39 using ::testing::Not; 39 using ::testing::Not;
40 using ::testing::NotNull; 40 using ::testing::NotNull;
41 using net::test::IsError; 41 using net::test::IsError;
42 using net::test::IsOk; 42 using net::test::IsOk;
43 43
44 // Sample Merkle leaf hashes.
44 const char* kLeafHashes[] = { 45 const char* kLeafHashes[] = {
45 "\x1f\x25\xe1\xca\xba\x4f\xf9\xb8\x27\x24\x83\x0f\xca\x60\xe4\xc2\xbe\xa8" 46 "\x1f\x25\xe1\xca\xba\x4f\xf9\xb8\x27\x24\x83\x0f\xca\x60\xe4\xc2\xbe\xa8"
46 "\xc3\xa9\x44\x1c\x27\xb0\xb4\x3e\x6a\x96\x94\xc7\xb8\x04", 47 "\xc3\xa9\x44\x1c\x27\xb0\xb4\x3e\x6a\x96\x94\xc7\xb8\x04",
47 "\x2c\x26\xb4\x6b\x68\xff\xc6\x8f\xf9\x9b\x45\x3c\x1d\x30\x41\x34\x13\x42" 48 "\x2c\x26\xb4\x6b\x68\xff\xc6\x8f\xf9\x9b\x45\x3c\x1d\x30\x41\x34\x13\x42"
48 "\x2d\x70\x64\x83\xbf\xa0\xf9\x8a\x5e\x88\x62\x66\xe7\xae", 49 "\x2d\x70\x64\x83\xbf\xa0\xf9\x8a\x5e\x88\x62\x66\xe7\xae",
49 "\xfc\xde\x2b\x2e\xdb\xa5\x6b\xf4\x08\x60\x1f\xb7\x21\xfe\x9b\x5c\x33\x8d" 50 "\xfc\xde\x2b\x2e\xdb\xa5\x6b\xf4\x08\x60\x1f\xb7\x21\xfe\x9b\x5c\x33\x8d"
50 "\x10\xee\x42\x9e\xa0\x4f\xae\x55\x11\xb6\x8f\xbf\x8f\xb9", 51 "\x10\xee\x42\x9e\xa0\x4f\xae\x55\x11\xb6\x8f\xbf\x8f\xb9",
51 }; 52 };
52 53
53 // Assumes log domain is "ct.test" 54 // DNS query names for looking up the leaf index associated with each hash in
54 const char* kBase32LeafHashes[] = { 55 // |kLeafHashes|. Assumes the log domain is "ct.test".
56 const char* kLeafIndexQnames[] = {
55 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", 57 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
56 "FQTLI23I77DI76M3IU6B2MCBGQJUELLQMSB37IHZRJPIQYTG46XA.hash.ct.test.", 58 "FQTLI23I77DI76M3IU6B2MCBGQJUELLQMSB37IHZRJPIQYTG46XA.hash.ct.test.",
57 "7TPCWLW3UVV7ICDAD63SD7U3LQZY2EHOIKPKAT5OKUI3ND57R64Q.hash.ct.test.", 59 "7TPCWLW3UVV7ICDAD63SD7U3LQZY2EHOIKPKAT5OKUI3ND57R64Q.hash.ct.test.",
58 }; 60 };
59 61
60 // Leaf indices and tree sizes for use with above leaf hashes. 62 // Leaf indices and tree sizes for use with |kLeafHashes|.
61 const uint64_t kLeafIndices[] = {0, 1, 2}; 63 const uint64_t kLeafIndices[] = {0, 1, 2};
62 const uint64_t kTreeSizes[] = {100, 10000, 1000000}; 64 const uint64_t kTreeSizes[] = {100, 10000, 1000000};
63 65
64 // Only 7 audit proof nodes can fit into a DNS response, because they are sent 66 // Only 7 audit proof nodes can fit into a DNS response, because they are sent
65 // in a TXT RDATA string, which has a maximum size of 255 bytes, and each node 67 // in a TXT RDATA string, which has a maximum size of 255 bytes, and each node
66 // is a SHA-256 hash (32 bytes), i.e. (255 / 32) == 7. 68 // is a SHA-256 hash (32 bytes), i.e. (255 / 32) == 7.
67 // This means audit proofs consisting of more than 7 nodes require multiple DNS 69 // This means audit proofs consisting of more than 7 nodes require multiple DNS
68 // requests to retrieve. 70 // requests to retrieve.
69 const size_t kMaxProofNodesPerDnsResponse = 7; 71 const size_t kMaxProofNodesPerDnsResponse = 7;
70 72
71 std::vector<std::string> GetSampleAuditProof(size_t length) { 73 std::vector<std::string> GetSampleAuditProof(size_t length) {
72 std::vector<std::string> audit_proof(length); 74 std::vector<std::string> audit_proof(length);
73 // Makes each node of the audit proof different, so that tests are able to 75 // Makes each node of the audit proof different, so that tests are able to
74 // confirm that the audit proof is reconstructed in the correct order. 76 // confirm that the audit proof is reconstructed in the correct order.
75 for (size_t i = 0; i < length; ++i) { 77 for (size_t i = 0; i < length; ++i) {
76 std::string node(crypto::kSHA256Length, '\0'); 78 std::string node(crypto::kSHA256Length, '\0');
77 // Each node is 32 bytes, with each byte having a different value. 79 // Each node is 32 bytes, with each byte having a different value.
78 for (size_t j = 0; j < crypto::kSHA256Length; ++j) { 80 for (size_t j = 0; j < crypto::kSHA256Length; ++j) {
79 node[j] = static_cast<char>((-127 + i + j) % 128); 81 node[j] = static_cast<char>((-127 + i + j) % 128);
80 } 82 }
81 audit_proof[i].assign(std::move(node)); 83 audit_proof[i].assign(std::move(node));
82 } 84 }
83 85
84 return audit_proof; 86 return audit_proof;
85 } 87 }
86 88
87 class MockLeafIndexCallback {
88 public:
89 MockLeafIndexCallback() : called_(false) {}
90
91 bool called() const { return called_; }
92 int net_error() const { return net_error_; }
93 uint64_t leaf_index() const { return leaf_index_; }
94
95 void Run(int net_error, uint64_t leaf_index) {
96 EXPECT_TRUE(!called_) << "Callback invoked more than once";
97 called_ = true;
98 net_error_ = net_error;
99 leaf_index_ = leaf_index;
100 run_loop_.Quit();
101 }
102
103 LogDnsClient::LeafIndexCallback AsCallback() {
104 return base::Bind(&MockLeafIndexCallback::Run, base::Unretained(this));
105 }
106
107 void WaitUntilRun() { run_loop_.Run(); }
108
109 private:
110 bool called_;
111 int net_error_;
112 uint64_t leaf_index_;
113 base::RunLoop run_loop_;
114 };
115
116 class MockAuditProofCallback { 89 class MockAuditProofCallback {
117 public: 90 public:
118 MockAuditProofCallback() : called_(false) {} 91 MockAuditProofCallback() : called_(false) {}
119 92
120 bool called() const { return called_; } 93 bool called() const { return called_; }
121 int net_error() const { return net_error_; } 94 int net_error() const { return net_error_; }
122 const net::ct::MerkleAuditProof* proof() const { return proof_.get(); } 95 const net::ct::MerkleAuditProof* proof() const { return proof_.get(); }
123 96
124 void Run(int net_error, std::unique_ptr<net::ct::MerkleAuditProof> proof) { 97 void Run(int net_error, std::unique_ptr<net::ct::MerkleAuditProof> proof) {
125 EXPECT_TRUE(!called_) << "Callback invoked more than once"; 98 EXPECT_TRUE(!called_) << "Callback invoked more than once";
(...skipping 18 matching lines...) Expand all
144 117
145 class LogDnsClientTest : public ::testing::TestWithParam<net::IoMode> { 118 class LogDnsClientTest : public ::testing::TestWithParam<net::IoMode> {
146 protected: 119 protected:
147 LogDnsClientTest() 120 LogDnsClientTest()
148 : network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) { 121 : network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) {
149 mock_dns_.SetSocketReadMode(GetParam()); 122 mock_dns_.SetSocketReadMode(GetParam());
150 mock_dns_.InitializeDnsConfig(); 123 mock_dns_.InitializeDnsConfig();
151 } 124 }
152 125
153 std::unique_ptr<LogDnsClient> CreateLogDnsClient( 126 std::unique_ptr<LogDnsClient> CreateLogDnsClient(
154 size_t max_concurrent_queries) { 127 size_t kMaxConcurrentQueries) {
155 return base::MakeUnique<LogDnsClient>(mock_dns_.CreateDnsClient(), 128 return base::MakeUnique<LogDnsClient>(
156 net::BoundNetLog(), 129 mock_dns_.CreateDnsClient(), net::BoundNetLog(), kMaxConcurrentQueries);
157 max_concurrent_queries);
158 }
159
160 void QueryLeafIndexAsync(LogDnsClient* log_client,
161 base::StringPiece log_domain,
162 const char leaf_hash[crypto::kSHA256Length],
163 const LogDnsClient::LeafIndexCallback& callback) {
164 log_client->QueryLeafIndex(log_domain, leaf_hash, callback);
165 }
166
167 // Convenience function for calling QueryLeafIndexAsync synchronously.
168 void QueryLeafIndex(base::StringPiece log_domain,
169 const char leaf_hash[crypto::kSHA256Length],
170 MockLeafIndexCallback* callback) {
171 std::unique_ptr<LogDnsClient> log_client = CreateLogDnsClient(0);
172 QueryLeafIndexAsync(log_client.get(), log_domain, leaf_hash,
173 callback->AsCallback());
174 callback->WaitUntilRun();
175 } 130 }
176 131
177 void QueryAuditProofAsync(LogDnsClient* log_client, 132 void QueryAuditProofAsync(LogDnsClient* log_client,
178 base::StringPiece log_domain, 133 base::StringPiece log_domain,
179 uint64_t leaf_index, 134 const char leaf_hash[crypto::kSHA256Length],
180 uint64_t tree_size, 135 uint64_t tree_size,
181 const LogDnsClient::AuditProofCallback& callback) { 136 const LogDnsClient::AuditProofCallback& callback) {
182 log_client->QueryAuditProof(log_domain, leaf_index, tree_size, callback); 137 log_client->QueryAuditProof(log_domain, leaf_hash, tree_size, callback);
183 } 138 }
184 139
185 // Convenience function for calling QueryAuditProofAsync synchronously. 140 // Convenience function for calling QueryAuditProofAsync synchronously.
186 void QueryAuditProof(base::StringPiece log_domain, 141 void QueryAuditProof(base::StringPiece log_domain,
187 uint64_t leaf_index, 142 const char leaf_hash[crypto::kSHA256Length],
188 uint64_t tree_size, 143 uint64_t tree_size,
189 MockAuditProofCallback* callback) { 144 MockAuditProofCallback* callback) {
190 std::unique_ptr<LogDnsClient> log_client = CreateLogDnsClient(0); 145 std::unique_ptr<LogDnsClient> log_client = CreateLogDnsClient(0);
191 QueryAuditProofAsync(log_client.get(), log_domain, leaf_index, tree_size, 146 QueryAuditProofAsync(log_client.get(), log_domain, leaf_hash, tree_size,
192 callback->AsCallback()); 147 callback->AsCallback());
193 callback->WaitUntilRun(); 148 callback->WaitUntilRun();
194 } 149 }
195 150
196 // This will be the NetworkChangeNotifier singleton for the duration of the 151 // This will be the NetworkChangeNotifier singleton for the duration of the
197 // test. It is accessed statically by LogDnsClient. 152 // test. It is accessed statically by LogDnsClient.
198 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; 153 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_;
199 // Queues and handles asynchronous DNS tasks. Indirectly used by LogDnsClient, 154 // Queues and handles asynchronous DNS tasks. Indirectly used by LogDnsClient,
200 // the underlying net::DnsClient, and NetworkChangeNotifier. 155 // the underlying net::DnsClient, and NetworkChangeNotifier.
201 base::MessageLoopForIO message_loop_; 156 base::MessageLoopForIO message_loop_;
202 // Allows mock DNS sockets to be setup. 157 // Allows mock DNS sockets to be setup.
203 MockLogDnsTraffic mock_dns_; 158 MockLogDnsTraffic mock_dns_;
204 }; 159 };
205 160
206 TEST_P(LogDnsClientTest, QueryLeafIndex) { 161 TEST_P(LogDnsClientTest, QueryAuditProofReportsThatLogDomainDoesNotExist) {
207 mock_dns_.ExpectLeafIndexRequestAndResponse(kBase32LeafHashes[0], "123456"); 162 mock_dns_.ExpectRequestAndErrorResponse(kLeafIndexQnames[0],
208
209 MockLeafIndexCallback callback;
210 QueryLeafIndex("ct.test", kLeafHashes[0], &callback);
211 ASSERT_TRUE(callback.called());
212 EXPECT_THAT(callback.net_error(), IsOk());
213 EXPECT_THAT(callback.leaf_index(), Eq(123456u));
214 }
215
216 TEST_P(LogDnsClientTest, QueryLeafIndexReportsThatLogDomainDoesNotExist) {
217 mock_dns_.ExpectRequestAndErrorResponse(kBase32LeafHashes[0],
218 net::dns_protocol::kRcodeNXDOMAIN); 163 net::dns_protocol::kRcodeNXDOMAIN);
219 164
220 MockLeafIndexCallback callback; 165 MockAuditProofCallback callback;
221 QueryLeafIndex("ct.test", kLeafHashes[0], &callback); 166 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
222 ASSERT_TRUE(callback.called()); 167 ASSERT_TRUE(callback.called());
223 EXPECT_THAT(callback.net_error(), IsError(net::ERR_NAME_NOT_RESOLVED)); 168 EXPECT_THAT(callback.net_error(), IsError(net::ERR_NAME_NOT_RESOLVED));
224 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 169 EXPECT_THAT(callback.proof(), IsNull());
225 }
226
227 TEST_P(LogDnsClientTest, QueryLeafIndexReportsServerFailure) {
228 mock_dns_.ExpectRequestAndErrorResponse(kBase32LeafHashes[0],
229 net::dns_protocol::kRcodeSERVFAIL);
230
231 MockLeafIndexCallback callback;
232 QueryLeafIndex("ct.test", kLeafHashes[0], &callback);
233 ASSERT_TRUE(callback.called());
234 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_SERVER_FAILED));
235 EXPECT_THAT(callback.leaf_index(), Eq(0u));
236 }
237
238 TEST_P(LogDnsClientTest, QueryLeafIndexReportsServerRefusal) {
239 mock_dns_.ExpectRequestAndErrorResponse(kBase32LeafHashes[0],
240 net::dns_protocol::kRcodeREFUSED);
241
242 MockLeafIndexCallback callback;
243 QueryLeafIndex("ct.test", kLeafHashes[0], &callback);
244 ASSERT_TRUE(callback.called());
245 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_SERVER_FAILED));
246 EXPECT_THAT(callback.leaf_index(), Eq(0u));
247 } 170 }
248 171
249 TEST_P(LogDnsClientTest, 172 TEST_P(LogDnsClientTest,
250 QueryLeafIndexReportsMalformedResponseIfLeafIndexIsNotNumeric) { 173 QueryAuditProofReportsServerFailuresDuringLeafIndexRequests) {
251 mock_dns_.ExpectLeafIndexRequestAndResponse(kBase32LeafHashes[0], "foo"); 174 mock_dns_.ExpectRequestAndErrorResponse(kLeafIndexQnames[0],
175 net::dns_protocol::kRcodeSERVFAIL);
252 176
253 MockLeafIndexCallback callback; 177 MockAuditProofCallback callback;
254 QueryLeafIndex("ct.test", kLeafHashes[0], &callback); 178 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
255 ASSERT_TRUE(callback.called()); 179 ASSERT_TRUE(callback.called());
256 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE)); 180 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_SERVER_FAILED));
257 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 181 EXPECT_THAT(callback.proof(), IsNull());
258 } 182 }
259 183
260 TEST_P(LogDnsClientTest, 184 TEST_P(LogDnsClientTest,
261 QueryLeafIndexReportsMalformedResponseIfLeafIndexIsFloatingPoint) { 185 QueryAuditProofReportsServerRefusalsDuringLeafIndexRequests) {
262 mock_dns_.ExpectLeafIndexRequestAndResponse(kBase32LeafHashes[0], "123456.0"); 186 mock_dns_.ExpectRequestAndErrorResponse(kLeafIndexQnames[0],
187 net::dns_protocol::kRcodeREFUSED);
263 188
264 MockLeafIndexCallback callback; 189 MockAuditProofCallback callback;
265 QueryLeafIndex("ct.test", kLeafHashes[0], &callback); 190 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
266 ASSERT_TRUE(callback.called()); 191 ASSERT_TRUE(callback.called());
267 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE)); 192 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_SERVER_FAILED));
268 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 193 EXPECT_THAT(callback.proof(), IsNull());
269 } 194 }
270 195
271 TEST_P(LogDnsClientTest, 196 TEST_P(LogDnsClientTest,
272 QueryLeafIndexReportsMalformedResponseIfLeafIndexIsEmpty) { 197 QueryAuditProofReportsMalformedResponseIfLeafIndexIsNotNumeric) {
273 mock_dns_.ExpectLeafIndexRequestAndResponse(kBase32LeafHashes[0], ""); 198 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "foo");
274 199
275 MockLeafIndexCallback callback; 200 MockAuditProofCallback callback;
276 QueryLeafIndex("ct.test", kLeafHashes[0], &callback); 201 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
277 ASSERT_TRUE(callback.called()); 202 ASSERT_TRUE(callback.called());
278 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE)); 203 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE));
279 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 204 EXPECT_THAT(callback.proof(), IsNull());
280 } 205 }
281 206
282 TEST_P(LogDnsClientTest, 207 TEST_P(LogDnsClientTest,
283 QueryLeafIndexReportsMalformedResponseIfLeafIndexHasNonNumericPrefix) { 208 QueryAuditProofReportsMalformedResponseIfLeafIndexIsFloatingPoint) {
284 mock_dns_.ExpectLeafIndexRequestAndResponse(kBase32LeafHashes[0], 209 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456.0");
285 "foo123456");
286 210
287 MockLeafIndexCallback callback; 211 MockAuditProofCallback callback;
288 QueryLeafIndex("ct.test", kLeafHashes[0], &callback); 212 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
289 ASSERT_TRUE(callback.called()); 213 ASSERT_TRUE(callback.called());
290 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE)); 214 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE));
291 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 215 EXPECT_THAT(callback.proof(), IsNull());
292 } 216 }
293 217
294 TEST_P(LogDnsClientTest, 218 TEST_P(LogDnsClientTest,
295 QueryLeafIndexReportsMalformedResponseIfLeafIndexHasNonNumericSuffix) { 219 QueryAuditProofReportsMalformedResponseIfLeafIndexIsEmpty) {
296 mock_dns_.ExpectLeafIndexRequestAndResponse(kBase32LeafHashes[0], 220 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "");
297 "123456foo");
298 221
299 MockLeafIndexCallback callback; 222 MockAuditProofCallback callback;
300 QueryLeafIndex("ct.test", kLeafHashes[0], &callback); 223 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
301 ASSERT_TRUE(callback.called()); 224 ASSERT_TRUE(callback.called());
302 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE)); 225 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE));
303 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 226 EXPECT_THAT(callback.proof(), IsNull());
304 } 227 }
305 228
306 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLogDomainIsEmpty) { 229 TEST_P(LogDnsClientTest,
307 MockLeafIndexCallback callback; 230 QueryAuditProofReportsMalformedResponseIfLeafIndexHasNonNumericPrefix) {
308 QueryLeafIndex("", kLeafHashes[0], &callback); 231 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "foo123456");
232
233 MockAuditProofCallback callback;
234 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
235 ASSERT_TRUE(callback.called());
236 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE));
237 EXPECT_THAT(callback.proof(), IsNull());
238 }
239
240 TEST_P(LogDnsClientTest,
241 QueryAuditProofReportsMalformedResponseIfLeafIndexHasNonNumericSuffix) {
242 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456foo");
243
244 MockAuditProofCallback callback;
245 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
246 ASSERT_TRUE(callback.called());
247 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE));
248 EXPECT_THAT(callback.proof(), IsNull());
249 }
250
251 TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLogDomainIsEmpty) {
252 MockAuditProofCallback callback;
253 QueryAuditProof("", kLeafHashes[0], kTreeSizes[0], &callback);
309 ASSERT_TRUE(callback.called()); 254 ASSERT_TRUE(callback.called());
310 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT)); 255 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT));
311 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 256 EXPECT_THAT(callback.proof(), IsNull());
312 } 257 }
313 258
314 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLogDomainIsNull) { 259 TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLogDomainIsNull) {
315 MockLeafIndexCallback callback; 260 MockAuditProofCallback callback;
316 QueryLeafIndex(nullptr, kLeafHashes[0], &callback); 261 QueryAuditProof(nullptr, kLeafHashes[0], kTreeSizes[0], &callback);
317 ASSERT_TRUE(callback.called()); 262 ASSERT_TRUE(callback.called());
318 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT)); 263 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT));
319 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 264 EXPECT_THAT(callback.proof(), IsNull());
320 } 265 }
321 266
322 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLeafHashIsInvalid) { 267 TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLeafHashIsInvalid) {
323 MockLeafIndexCallback callback; 268 MockAuditProofCallback callback;
324 QueryLeafIndex("ct.test", "foo", &callback); 269 QueryAuditProof("ct.test", "foo", kTreeSizes[0], &callback);
325 ASSERT_TRUE(callback.called()); 270 ASSERT_TRUE(callback.called());
326 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT)); 271 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT));
327 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 272 EXPECT_THAT(callback.proof(), IsNull());
328 } 273 }
329 274
330 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLeafHashIsEmpty) { 275 TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLeafHashIsEmpty) {
331 MockLeafIndexCallback callback; 276 MockAuditProofCallback callback;
332 QueryLeafIndex("ct.test", "", &callback); 277 QueryAuditProof("ct.test", "", kTreeSizes[0], &callback);
333 ASSERT_TRUE(callback.called()); 278 ASSERT_TRUE(callback.called());
334 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT)); 279 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT));
335 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 280 EXPECT_THAT(callback.proof(), IsNull());
336 } 281 }
337 282
338 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLeafHashIsNull) { 283 TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLeafHashIsNull) {
339 MockLeafIndexCallback callback; 284 MockAuditProofCallback callback;
340 QueryLeafIndex("ct.test", nullptr, &callback); 285 QueryAuditProof("ct.test", nullptr, kTreeSizes[0], &callback);
341 ASSERT_TRUE(callback.called()); 286 ASSERT_TRUE(callback.called());
342 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT)); 287 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT));
343 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 288 EXPECT_THAT(callback.proof(), IsNull());
344 } 289 }
345 290
346 TEST_P(LogDnsClientTest, QueryLeafIndexReportsSocketError) { 291 TEST_P(LogDnsClientTest,
347 mock_dns_.ExpectRequestAndSocketError(kBase32LeafHashes[0], 292 QueryAuditProofReportsSocketErrorsDuringLeafIndexRequests) {
293 mock_dns_.ExpectRequestAndSocketError(kLeafIndexQnames[0],
348 net::ERR_CONNECTION_REFUSED); 294 net::ERR_CONNECTION_REFUSED);
349 295
350 MockLeafIndexCallback callback; 296 MockAuditProofCallback callback;
351 QueryLeafIndex("ct.test", kLeafHashes[0], &callback); 297 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
352 ASSERT_TRUE(callback.called()); 298 ASSERT_TRUE(callback.called());
353 EXPECT_THAT(callback.net_error(), IsError(net::ERR_CONNECTION_REFUSED)); 299 EXPECT_THAT(callback.net_error(), IsError(net::ERR_CONNECTION_REFUSED));
354 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 300 EXPECT_THAT(callback.proof(), IsNull());
355 } 301 }
356 302
357 TEST_P(LogDnsClientTest, QueryLeafIndexReportsTimeout) { 303 TEST_P(LogDnsClientTest,
358 mock_dns_.ExpectRequestAndTimeout(kBase32LeafHashes[0]); 304 QueryAuditProofReportsTimeoutsDuringLeafIndexRequests) {
305 mock_dns_.ExpectRequestAndTimeout(kLeafIndexQnames[0]);
359 306
360 MockLeafIndexCallback callback; 307 MockAuditProofCallback callback;
361 QueryLeafIndex("ct.test", kLeafHashes[0], &callback); 308 QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &callback);
362 ASSERT_TRUE(callback.called()); 309 ASSERT_TRUE(callback.called());
363 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_TIMED_OUT)); 310 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_TIMED_OUT));
364 EXPECT_THAT(callback.leaf_index(), Eq(0u)); 311 EXPECT_THAT(callback.proof(), IsNull());
365 } 312 }
366 313
367 TEST_P(LogDnsClientTest, QueryAuditProof) { 314 TEST_P(LogDnsClientTest, QueryAuditProof) {
368 const std::vector<std::string> audit_proof = GetSampleAuditProof(20); 315 const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
369 316
317 // Expect a leaf index query first, to map the leaf hash to a leaf index.
318 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
319
370 // It takes a number of DNS requests to retrieve the entire |audit_proof| 320 // It takes a number of DNS requests to retrieve the entire |audit_proof|
371 // (see |kMaxProofNodesPerDnsResponse|). 321 // (see |kMaxProofNodesPerDnsResponse|).
372 for (size_t nodes_begin = 0; nodes_begin < audit_proof.size(); 322 for (size_t nodes_begin = 0; nodes_begin < audit_proof.size();
373 nodes_begin += kMaxProofNodesPerDnsResponse) { 323 nodes_begin += kMaxProofNodesPerDnsResponse) {
374 const size_t nodes_end = std::min( 324 const size_t nodes_end = std::min(
375 nodes_begin + kMaxProofNodesPerDnsResponse, audit_proof.size()); 325 nodes_begin + kMaxProofNodesPerDnsResponse, audit_proof.size());
376 326
377 mock_dns_.ExpectAuditProofRequestAndResponse( 327 mock_dns_.ExpectAuditProofRequestAndResponse(
378 base::StringPrintf("%zu.123456.999999.tree.ct.test.", nodes_begin), 328 base::StringPrintf("%zu.123456.999999.tree.ct.test.", nodes_begin),
379 audit_proof.begin() + nodes_begin, audit_proof.begin() + nodes_end); 329 audit_proof.begin() + nodes_begin, audit_proof.begin() + nodes_end);
380 } 330 }
381 331
382 MockAuditProofCallback callback; 332 MockAuditProofCallback callback;
383 QueryAuditProof("ct.test", 123456, 999999, &callback); 333 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
384 ASSERT_TRUE(callback.called()); 334 ASSERT_TRUE(callback.called());
385 EXPECT_THAT(callback.net_error(), IsOk()); 335 EXPECT_THAT(callback.net_error(), IsOk());
386 ASSERT_THAT(callback.proof(), NotNull()); 336 ASSERT_THAT(callback.proof(), NotNull());
387 EXPECT_THAT(callback.proof()->leaf_index, Eq(123456u)); 337 EXPECT_THAT(callback.proof()->leaf_index, Eq(123456u));
388 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size. 338 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size.
389 // EXPECT_THAT(callback.proof()->tree_size, Eq(999999)); 339 // EXPECT_THAT(callback.proof()->tree_size, Eq(999999));
390 EXPECT_THAT(callback.proof()->nodes, Eq(audit_proof)); 340 EXPECT_THAT(callback.proof()->nodes, Eq(audit_proof));
391 } 341 }
392 342
393 TEST_P(LogDnsClientTest, QueryAuditProofHandlesResponsesWithShortAuditPaths) { 343 TEST_P(LogDnsClientTest, QueryAuditProofHandlesResponsesWithShortAuditPaths) {
394 const std::vector<std::string> audit_proof = GetSampleAuditProof(20); 344 const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
395 345
346 // Expect a leaf index query first, to map the leaf hash to a leaf index.
347 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
348
396 // Make some of the responses contain fewer proof nodes than they can hold. 349 // Make some of the responses contain fewer proof nodes than they can hold.
397 mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", 350 mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
398 audit_proof.begin(), 351 audit_proof.begin(),
399 audit_proof.begin() + 1); 352 audit_proof.begin() + 1);
400 mock_dns_.ExpectAuditProofRequestAndResponse("1.123456.999999.tree.ct.test.", 353 mock_dns_.ExpectAuditProofRequestAndResponse("1.123456.999999.tree.ct.test.",
401 audit_proof.begin() + 1, 354 audit_proof.begin() + 1,
402 audit_proof.begin() + 3); 355 audit_proof.begin() + 3);
403 mock_dns_.ExpectAuditProofRequestAndResponse("3.123456.999999.tree.ct.test.", 356 mock_dns_.ExpectAuditProofRequestAndResponse("3.123456.999999.tree.ct.test.",
404 audit_proof.begin() + 3, 357 audit_proof.begin() + 3,
405 audit_proof.begin() + 6); 358 audit_proof.begin() + 6);
406 mock_dns_.ExpectAuditProofRequestAndResponse("6.123456.999999.tree.ct.test.", 359 mock_dns_.ExpectAuditProofRequestAndResponse("6.123456.999999.tree.ct.test.",
407 audit_proof.begin() + 6, 360 audit_proof.begin() + 6,
408 audit_proof.begin() + 10); 361 audit_proof.begin() + 10);
409 mock_dns_.ExpectAuditProofRequestAndResponse("10.123456.999999.tree.ct.test.", 362 mock_dns_.ExpectAuditProofRequestAndResponse("10.123456.999999.tree.ct.test.",
410 audit_proof.begin() + 10, 363 audit_proof.begin() + 10,
411 audit_proof.begin() + 13); 364 audit_proof.begin() + 13);
412 mock_dns_.ExpectAuditProofRequestAndResponse("13.123456.999999.tree.ct.test.", 365 mock_dns_.ExpectAuditProofRequestAndResponse("13.123456.999999.tree.ct.test.",
413 audit_proof.begin() + 13, 366 audit_proof.begin() + 13,
414 audit_proof.end()); 367 audit_proof.end());
415 368
416 MockAuditProofCallback callback; 369 MockAuditProofCallback callback;
417 QueryAuditProof("ct.test", 123456, 999999, &callback); 370 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
418 ASSERT_TRUE(callback.called()); 371 ASSERT_TRUE(callback.called());
419 EXPECT_THAT(callback.net_error(), IsOk()); 372 EXPECT_THAT(callback.net_error(), IsOk());
420 ASSERT_THAT(callback.proof(), NotNull()); 373 ASSERT_THAT(callback.proof(), NotNull());
421 EXPECT_THAT(callback.proof()->leaf_index, Eq(123456u)); 374 EXPECT_THAT(callback.proof()->leaf_index, Eq(123456u));
422 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size. 375 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size.
423 // EXPECT_THAT(callback.proof()->tree_size, Eq(999999)); 376 // EXPECT_THAT(callback.proof()->tree_size, Eq(999999));
424 EXPECT_THAT(callback.proof()->nodes, Eq(audit_proof)); 377 EXPECT_THAT(callback.proof()->nodes, Eq(audit_proof));
425 } 378 }
426 379
427 TEST_P(LogDnsClientTest, QueryAuditProofReportsThatLogDomainDoesNotExist) { 380 TEST_P(LogDnsClientTest,
381 QueryAuditProofReportsThatAuditProofQnameDoesNotExist) {
382 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
428 mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", 383 mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
429 net::dns_protocol::kRcodeNXDOMAIN); 384 net::dns_protocol::kRcodeNXDOMAIN);
430 385
431 MockAuditProofCallback callback; 386 MockAuditProofCallback callback;
432 QueryAuditProof("ct.test", 123456, 999999, &callback); 387 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
433 ASSERT_TRUE(callback.called()); 388 ASSERT_TRUE(callback.called());
434 EXPECT_THAT(callback.net_error(), IsError(net::ERR_NAME_NOT_RESOLVED)); 389 EXPECT_THAT(callback.net_error(), IsError(net::ERR_NAME_NOT_RESOLVED));
435 EXPECT_THAT(callback.proof(), IsNull()); 390 EXPECT_THAT(callback.proof(), IsNull());
436 } 391 }
437 392
438 TEST_P(LogDnsClientTest, QueryAuditProofReportsServerFailure) { 393 TEST_P(LogDnsClientTest,
394 QueryAuditProofReportsServerFailureDuringAuditProofRequests) {
395 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
439 mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", 396 mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
440 net::dns_protocol::kRcodeSERVFAIL); 397 net::dns_protocol::kRcodeSERVFAIL);
441 398
442 MockAuditProofCallback callback; 399 MockAuditProofCallback callback;
443 QueryAuditProof("ct.test", 123456, 999999, &callback); 400 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
444 ASSERT_TRUE(callback.called()); 401 ASSERT_TRUE(callback.called());
445 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_SERVER_FAILED)); 402 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_SERVER_FAILED));
446 EXPECT_THAT(callback.proof(), IsNull()); 403 EXPECT_THAT(callback.proof(), IsNull());
447 } 404 }
448 405
449 TEST_P(LogDnsClientTest, QueryAuditProofReportsServerRefusal) { 406 TEST_P(LogDnsClientTest,
407 QueryAuditProofReportsServerRefusalDuringAuditProofRequests) {
408 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
450 mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", 409 mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
451 net::dns_protocol::kRcodeREFUSED); 410 net::dns_protocol::kRcodeREFUSED);
452 411
453 MockAuditProofCallback callback; 412 MockAuditProofCallback callback;
454 QueryAuditProof("ct.test", 123456, 999999, &callback); 413 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
455 ASSERT_TRUE(callback.called()); 414 ASSERT_TRUE(callback.called());
456 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_SERVER_FAILED)); 415 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_SERVER_FAILED));
457 EXPECT_THAT(callback.proof(), IsNull()); 416 EXPECT_THAT(callback.proof(), IsNull());
458 } 417 }
459 418
460 TEST_P(LogDnsClientTest, 419 TEST_P(LogDnsClientTest,
461 QueryAuditProofReportsResponseMalformedIfNodeTooShort) { 420 QueryAuditProofReportsResponseMalformedIfNodeTooShort) {
462 // node is shorter than a SHA-256 hash (31 vs 32 bytes) 421 // node is shorter than a SHA-256 hash (31 vs 32 bytes)
463 const std::vector<std::string> audit_proof(1, std::string(31, 'a')); 422 const std::vector<std::string> audit_proof(1, std::string(31, 'a'));
464 423
424 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
465 mock_dns_.ExpectAuditProofRequestAndResponse( 425 mock_dns_.ExpectAuditProofRequestAndResponse(
466 "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end()); 426 "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end());
467 427
468 MockAuditProofCallback callback; 428 MockAuditProofCallback callback;
469 QueryAuditProof("ct.test", 123456, 999999, &callback); 429 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
470 ASSERT_TRUE(callback.called()); 430 ASSERT_TRUE(callback.called());
471 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE)); 431 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE));
472 EXPECT_THAT(callback.proof(), IsNull()); 432 EXPECT_THAT(callback.proof(), IsNull());
473 } 433 }
474 434
475 TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfNodeTooLong) { 435 TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfNodeTooLong) {
476 // node is longer than a SHA-256 hash (33 vs 32 bytes) 436 // node is longer than a SHA-256 hash (33 vs 32 bytes)
477 const std::vector<std::string> audit_proof(1, std::string(33, 'a')); 437 const std::vector<std::string> audit_proof(1, std::string(33, 'a'));
478 438
439 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
479 mock_dns_.ExpectAuditProofRequestAndResponse( 440 mock_dns_.ExpectAuditProofRequestAndResponse(
480 "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end()); 441 "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end());
481 442
482 MockAuditProofCallback callback; 443 MockAuditProofCallback callback;
483 QueryAuditProof("ct.test", 123456, 999999, &callback); 444 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
484 ASSERT_TRUE(callback.called()); 445 ASSERT_TRUE(callback.called());
485 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE)); 446 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE));
486 EXPECT_THAT(callback.proof(), IsNull()); 447 EXPECT_THAT(callback.proof(), IsNull());
487 } 448 }
488 449
489 TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfEmpty) { 450 TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfEmpty) {
490 const std::vector<std::string> audit_proof; 451 const std::vector<std::string> audit_proof;
491 452
453 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
492 mock_dns_.ExpectAuditProofRequestAndResponse( 454 mock_dns_.ExpectAuditProofRequestAndResponse(
493 "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end()); 455 "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end());
494 456
495 MockAuditProofCallback callback; 457 MockAuditProofCallback callback;
496 QueryAuditProof("ct.test", 123456, 999999, &callback); 458 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
497 ASSERT_TRUE(callback.called()); 459 ASSERT_TRUE(callback.called());
498 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE)); 460 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_MALFORMED_RESPONSE));
499 EXPECT_THAT(callback.proof(), IsNull()); 461 EXPECT_THAT(callback.proof(), IsNull());
500 } 462 }
501 463
502 TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLogDomainIsEmpty) {
503 MockAuditProofCallback callback;
504 QueryAuditProof("", 123456, 999999, &callback);
505 ASSERT_TRUE(callback.called());
506 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT));
507 EXPECT_THAT(callback.proof(), IsNull());
508 }
509
510 TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLogDomainIsNull) {
511 MockAuditProofCallback callback;
512 QueryAuditProof(nullptr, 123456, 999999, &callback);
513 ASSERT_TRUE(callback.called());
514 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT));
515 EXPECT_THAT(callback.proof(), IsNull());
516 }
517
518 TEST_P(LogDnsClientTest, 464 TEST_P(LogDnsClientTest,
519 QueryAuditProofReportsInvalidArgIfLeafIndexEqualToTreeSize) { 465 QueryAuditProofReportsInvalidArgIfLeafIndexEqualToTreeSize) {
466 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
467
520 MockAuditProofCallback callback; 468 MockAuditProofCallback callback;
521 QueryAuditProof("ct.test", 123456, 123456, &callback); 469 QueryAuditProof("ct.test", kLeafHashes[0], 123456, &callback);
522 ASSERT_TRUE(callback.called()); 470 ASSERT_TRUE(callback.called());
523 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT)); 471 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT));
524 EXPECT_THAT(callback.proof(), IsNull()); 472 EXPECT_THAT(callback.proof(), IsNull());
525 } 473 }
526 474
527 TEST_P(LogDnsClientTest, 475 TEST_P(LogDnsClientTest,
528 QueryAuditProofReportsInvalidArgIfLeafIndexGreaterThanTreeSize) { 476 QueryAuditProofReportsInvalidArgIfLeafIndexGreaterThanTreeSize) {
477 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "999999");
478
529 MockAuditProofCallback callback; 479 MockAuditProofCallback callback;
530 QueryAuditProof("ct.test", 999999, 123456, &callback); 480 QueryAuditProof("ct.test", kLeafHashes[0], 123456, &callback);
531 ASSERT_TRUE(callback.called()); 481 ASSERT_TRUE(callback.called());
532 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT)); 482 EXPECT_THAT(callback.net_error(), IsError(net::ERR_INVALID_ARGUMENT));
533 EXPECT_THAT(callback.proof(), IsNull()); 483 EXPECT_THAT(callback.proof(), IsNull());
534 } 484 }
535 485
536 TEST_P(LogDnsClientTest, QueryAuditProofReportsSocketError) { 486 TEST_P(LogDnsClientTest,
487 QueryAuditProofReportsSocketErrorsDuringAuditProofRequests) {
488 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
537 mock_dns_.ExpectRequestAndSocketError("0.123456.999999.tree.ct.test.", 489 mock_dns_.ExpectRequestAndSocketError("0.123456.999999.tree.ct.test.",
538 net::ERR_CONNECTION_REFUSED); 490 net::ERR_CONNECTION_REFUSED);
539 491
540 MockAuditProofCallback callback; 492 MockAuditProofCallback callback;
541 QueryAuditProof("ct.test", 123456, 999999, &callback); 493 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
542 ASSERT_TRUE(callback.called()); 494 ASSERT_TRUE(callback.called());
543 EXPECT_THAT(callback.net_error(), IsError(net::ERR_CONNECTION_REFUSED)); 495 EXPECT_THAT(callback.net_error(), IsError(net::ERR_CONNECTION_REFUSED));
544 EXPECT_THAT(callback.proof(), IsNull()); 496 EXPECT_THAT(callback.proof(), IsNull());
545 } 497 }
546 498
547 TEST_P(LogDnsClientTest, QueryAuditProofReportsTimeout) { 499 TEST_P(LogDnsClientTest,
500 QueryAuditProofReportsTimeoutsDuringAuditProofRequests) {
501 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
548 mock_dns_.ExpectRequestAndTimeout("0.123456.999999.tree.ct.test."); 502 mock_dns_.ExpectRequestAndTimeout("0.123456.999999.tree.ct.test.");
549 503
550 MockAuditProofCallback callback; 504 MockAuditProofCallback callback;
551 QueryAuditProof("ct.test", 123456, 999999, &callback); 505 QueryAuditProof("ct.test", kLeafHashes[0], 999999, &callback);
552 ASSERT_TRUE(callback.called()); 506 ASSERT_TRUE(callback.called());
553 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_TIMED_OUT)); 507 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_TIMED_OUT));
554 EXPECT_THAT(callback.proof(), IsNull()); 508 EXPECT_THAT(callback.proof(), IsNull());
555 } 509 }
556 510
557 TEST_P(LogDnsClientTest, AdoptsLatestDnsConfigIfValid) { 511 TEST_P(LogDnsClientTest, AdoptsLatestDnsConfigIfValid) {
558 std::unique_ptr<net::DnsClient> tmp = mock_dns_.CreateDnsClient(); 512 std::unique_ptr<net::DnsClient> tmp = mock_dns_.CreateDnsClient();
559 net::DnsClient* dns_client = tmp.get(); 513 net::DnsClient* dns_client = tmp.get();
560 LogDnsClient log_client(std::move(tmp), net::BoundNetLog(), 0); 514 LogDnsClient log_client(std::move(tmp), net::BoundNetLog(), 0);
561 515
(...skipping 17 matching lines...) Expand all
579 net::DnsConfig config(*dns_client->GetConfig()); 533 net::DnsConfig config(*dns_client->GetConfig());
580 ASSERT_THAT(config.nameservers, Not(IsEmpty())); 534 ASSERT_THAT(config.nameservers, Not(IsEmpty()));
581 config.nameservers.clear(); // Makes config invalid 535 config.nameservers.clear(); // Makes config invalid
582 mock_dns_.SetDnsConfig(config); 536 mock_dns_.SetDnsConfig(config);
583 537
584 // Let the DNS config change propogate. 538 // Let the DNS config change propogate.
585 base::RunLoop().RunUntilIdle(); 539 base::RunLoop().RunUntilIdle();
586 EXPECT_THAT(dns_client->GetConfig()->nameservers, Not(IsEmpty())); 540 EXPECT_THAT(dns_client->GetConfig()->nameservers, Not(IsEmpty()));
587 } 541 }
588 542
589 TEST_P(LogDnsClientTest, CanPerformLeafIndexQueriesInParallel) { 543 TEST_P(LogDnsClientTest, CanPerformQueriesInParallel) {
590 // Test that leaf index queries can be performed in parallel. 544 // Check that 3 queries can be performed in parallel.
591 constexpr size_t kNumOfParallelQueries = 3;
592 ASSERT_THAT(kNumOfParallelQueries, AllOf(Le(arraysize(kLeafHashes)),
593 Le(arraysize(kBase32LeafHashes))))
594 << "Not enough test data for this many parallel queries";
595
596 std::unique_ptr<LogDnsClient> log_client =
597 CreateLogDnsClient(kNumOfParallelQueries);
598 MockLeafIndexCallback callbacks[kNumOfParallelQueries];
599
600 // Expect multiple queries.
601 for (size_t i = 0; i < kNumOfParallelQueries; ++i) {
602 mock_dns_.ExpectLeafIndexRequestAndResponse(
603 kBase32LeafHashes[i], base::Uint64ToString(kLeafIndices[i]));
604 }
605
606 // Start the queries.
607 for (size_t i = 0; i < kNumOfParallelQueries; ++i) {
608 QueryLeafIndexAsync(log_client.get(), "ct.test", kLeafHashes[i],
609 callbacks[i].AsCallback());
610 }
611
612 // Wait for each query to complete and check its results.
613 for (size_t i = 0; i < kNumOfParallelQueries; ++i) {
614 MockLeafIndexCallback& callback = callbacks[i];
615 callback.WaitUntilRun();
616
617 SCOPED_TRACE(testing::Message() << "callbacks[" << i << "]");
618 ASSERT_TRUE(callback.called());
619 EXPECT_THAT(callback.net_error(), IsOk());
620 EXPECT_THAT(callback.leaf_index(), Eq(kLeafIndices[i]));
621 }
622 }
623
624 TEST_P(LogDnsClientTest, CanPerformAuditProofQueriesInParallel) {
625 // Check that 3 audit proof queries can be performed in parallel.
626 constexpr size_t kNumOfParallelQueries = 3; 545 constexpr size_t kNumOfParallelQueries = 3;
627 ASSERT_THAT(kNumOfParallelQueries, 546 ASSERT_THAT(kNumOfParallelQueries,
628 AllOf(Le(arraysize(kLeafIndices)), Le(arraysize(kTreeSizes)))) 547 AllOf(Le(arraysize(kLeafIndexQnames)),
548 Le(arraysize(kLeafIndices)), Le(arraysize(kTreeSizes))))
629 << "Not enough test data for this many parallel queries"; 549 << "Not enough test data for this many parallel queries";
630 550
631 std::unique_ptr<LogDnsClient> log_client = 551 std::unique_ptr<LogDnsClient> log_client =
632 CreateLogDnsClient(kNumOfParallelQueries); 552 CreateLogDnsClient(kNumOfParallelQueries);
633 MockAuditProofCallback callbacks[kNumOfParallelQueries]; 553 MockAuditProofCallback callbacks[kNumOfParallelQueries];
634 554
635 // Each query should require one more DNS request than the last. 555 // Expect multiple leaf index requests.
636 // This helps to test that parallel queries do not intefere with each other, 556 for (size_t i = 0; i < kNumOfParallelQueries; ++i) {
637 // e.g. one query causing another to end prematurely. 557 mock_dns_.ExpectLeafIndexRequestAndResponse(
558 kLeafIndexQnames[i], base::Uint64ToString(kLeafIndices[i]));
559 }
560
561 // Make each query require one more audit proof request than the last, by
562 // increasing the number of nodes in the audit proof by
563 // kMaxProofNodesPerDnsResponse for each query. This helps to test that
564 // parallel queries do not intefere with each other, e.g. one query causing
565 // another to end prematurely.
638 std::vector<std::string> audit_proofs[kNumOfParallelQueries]; 566 std::vector<std::string> audit_proofs[kNumOfParallelQueries];
639 for (size_t query_i = 0; query_i < kNumOfParallelQueries; ++query_i) { 567 for (size_t query_i = 0; query_i < kNumOfParallelQueries; ++query_i) {
640 const size_t dns_requests_required = query_i + 1; 568 const size_t dns_requests_required = query_i + 1;
641 audit_proofs[query_i] = GetSampleAuditProof(dns_requests_required * 569 audit_proofs[query_i] = GetSampleAuditProof(dns_requests_required *
642 kMaxProofNodesPerDnsResponse); 570 kMaxProofNodesPerDnsResponse);
643 } 571 }
644 // The most DNS requests that are made by any of the above N queries is N. 572 // The most DNS requests that are made by any of the above N queries is N.
645 const size_t kMaxDnsRequestsPerQuery = kNumOfParallelQueries; 573 const size_t kMaxDnsRequestsPerQuery = kNumOfParallelQueries;
646 574
647 // Setup expectations for up to N DNS requests per query performed. 575 // Setup expectations for up to N DNS requests per query performed.
(...skipping 17 matching lines...) Expand all
665 base::StringPrintf("%zu.%" PRIu64 ".%" PRIu64 ".tree.ct.test.", 593 base::StringPrintf("%zu.%" PRIu64 ".%" PRIu64 ".tree.ct.test.",
666 start_node, kLeafIndices[query_i], 594 start_node, kLeafIndices[query_i],
667 kTreeSizes[query_i]), 595 kTreeSizes[query_i]),
668 proof.begin() + start_node, proof.begin() + end_node); 596 proof.begin() + start_node, proof.begin() + end_node);
669 } 597 }
670 } 598 }
671 } 599 }
672 600
673 // Start the queries. 601 // Start the queries.
674 for (size_t i = 0; i < kNumOfParallelQueries; ++i) { 602 for (size_t i = 0; i < kNumOfParallelQueries; ++i) {
675 QueryAuditProofAsync(log_client.get(), "ct.test", kLeafIndices[i], 603 QueryAuditProofAsync(log_client.get(), "ct.test", kLeafHashes[i],
676 kTreeSizes[i], callbacks[i].AsCallback()); 604 kTreeSizes[i], callbacks[i].AsCallback());
677 } 605 }
678 606
679 // Wait for each query to complete and check its results. 607 // Wait for each query to complete and check its results.
680 for (size_t i = 0; i < kNumOfParallelQueries; ++i) { 608 for (size_t i = 0; i < kNumOfParallelQueries; ++i) {
681 MockAuditProofCallback& callback = callbacks[i]; 609 MockAuditProofCallback& callback = callbacks[i];
682 callbacks[i].WaitUntilRun(); 610 callbacks[i].WaitUntilRun();
683 611
684 SCOPED_TRACE(testing::Message() << "callbacks[" << i << "]"); 612 SCOPED_TRACE(testing::Message() << "callbacks[" << i << "]");
685 ASSERT_TRUE(callback.called()); 613 ASSERT_TRUE(callback.called());
686 EXPECT_THAT(callback.net_error(), IsOk()); 614 EXPECT_THAT(callback.net_error(), IsOk());
687 ASSERT_THAT(callback.proof(), NotNull()); 615 ASSERT_THAT(callback.proof(), NotNull());
688 EXPECT_THAT(callback.proof()->leaf_index, Eq(kLeafIndices[i])); 616 EXPECT_THAT(callback.proof()->leaf_index, Eq(kLeafIndices[i]));
689 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size. 617 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size.
690 // EXPECT_THAT(callback.proof()->tree_size, kTreeSizes[i]); 618 // EXPECT_THAT(callback.proof()->tree_size, kTreeSizes[i]);
691 EXPECT_THAT(callback.proof()->nodes, Eq(audit_proofs[i])); 619 EXPECT_THAT(callback.proof()->nodes, Eq(audit_proofs[i]));
692 } 620 }
693 } 621 }
694 622
695 TEST_P(LogDnsClientTest, CanPerformLeafIndexAndAuditProofQueriesInParallel) { 623 TEST_P(LogDnsClientTest, CanBeThrottledToOneQueryAtATime) {
696 // Check that a leaf index and audit proof query can be performed in parallel. 624 // Check that queries can be rate-limited to one at a time.
697 constexpr size_t kNumOfParallelQueries = 2; 625 // The second query, initiated while the first is in progress, should fail.
698 std::unique_ptr<LogDnsClient> log_client =
699 CreateLogDnsClient(kNumOfParallelQueries);
700 MockLeafIndexCallback leaf_index_callback;
701 MockAuditProofCallback audit_proof_callback;
702 const std::vector<std::string> audit_proof = GetSampleAuditProof(20); 626 const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
703 627
704 mock_dns_.ExpectLeafIndexRequestAndResponse(kBase32LeafHashes[0], "123456"); 628 // Expect the first query to send leaf index and audit proof requests, but the
705 629 // second should not due to throttling.
706 // It should require 3 requests to collect the entire audit proof, as there is 630 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], "123456");
707 // only space for 7 nodes per TXT record. One node is 32 bytes long and the
708 // TXT RDATA can have a maximum length of 255 bytes (255 / 32).
709 mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
710 audit_proof.begin(),
711 audit_proof.begin() + 7);
712 mock_dns_.ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.",
713 audit_proof.begin() + 7,
714 audit_proof.begin() + 14);
715 mock_dns_.ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.",
716 audit_proof.begin() + 14,
717 audit_proof.end());
718
719 // Start the queries.
720 QueryLeafIndexAsync(log_client.get(), "ct.test", kLeafHashes[0],
721 leaf_index_callback.AsCallback());
722 QueryAuditProofAsync(log_client.get(), "ct.test", 123456, 999999,
723 audit_proof_callback.AsCallback());
724
725 // Wait for the queries to complete, then check their results.
726 leaf_index_callback.WaitUntilRun();
727 audit_proof_callback.WaitUntilRun();
728
729 ASSERT_TRUE(leaf_index_callback.called());
730 EXPECT_THAT(leaf_index_callback.net_error(), IsOk());
731 EXPECT_THAT(leaf_index_callback.leaf_index(), Eq(123456u));
732
733 ASSERT_TRUE(audit_proof_callback.called());
734 EXPECT_THAT(audit_proof_callback.net_error(), IsOk());
735 ASSERT_THAT(audit_proof_callback.proof(), NotNull());
736 EXPECT_THAT(audit_proof_callback.proof()->leaf_index, Eq(123456u));
737 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size.
738 // EXPECT_THAT(audit_proof_callback.proof()->tree_size, Eq(999999));
739 EXPECT_THAT(audit_proof_callback.proof()->nodes, Eq(audit_proof));
740 }
741
742 TEST_P(LogDnsClientTest, CanBeThrottledToOneLeafIndexQueryAtATime) {
743 // Check that leaf index queries can be rate-limited to one at a time.
744 // The second query, initiated while the first is in progress, should fail.
745 mock_dns_.ExpectLeafIndexRequestAndResponse(kBase32LeafHashes[0], "123456");
746
747 const size_t max_concurrent_queries = 1;
748 std::unique_ptr<LogDnsClient> log_client =
749 CreateLogDnsClient(max_concurrent_queries);
750
751 // Start the queries.
752 MockLeafIndexCallback callback1;
753 QueryLeafIndexAsync(log_client.get(), "ct.test", kLeafHashes[0],
754 callback1.AsCallback());
755 MockLeafIndexCallback callback2;
756 QueryLeafIndexAsync(log_client.get(), "ct.test", kLeafHashes[1],
757 callback2.AsCallback());
758
759 callback1.WaitUntilRun();
760 callback2.WaitUntilRun();
761
762 // Check that the first query succeeded.
763 ASSERT_TRUE(callback1.called());
764 EXPECT_THAT(callback1.net_error(), IsOk());
765 EXPECT_THAT(callback1.leaf_index(), Eq(123456u));
766
767 // Check that the second query failed.
768 ASSERT_TRUE(callback2.called());
769 EXPECT_THAT(callback2.net_error(), IsError(net::ERR_TEMPORARILY_THROTTLED));
770 EXPECT_THAT(callback2.leaf_index(), Eq(0u));
771 }
772
773 TEST_P(LogDnsClientTest, CanBeThrottledToOneAuditProofQueryAtATime) {
774 // Check that audit proof queries can be rate-limited to one at a time.
775 // The second query, initiated while the first is in progress, should fail.
776 const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
777 631
778 // It should require 3 requests to collect the entire audit proof, as there is 632 // It should require 3 requests to collect the entire audit proof, as there is
779 // only space for 7 nodes per TXT record. One node is 32 bytes long and the 633 // only space for 7 nodes per TXT record. One node is 32 bytes long and the
780 // TXT RDATA can have a maximum length of 255 bytes (255 / 32). 634 // TXT RDATA can have a maximum length of 255 bytes (255 / 32).
781 // Rate limiting should not interfere with these requests. 635 // Rate limiting should not interfere with these requests.
782 mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", 636 mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
783 audit_proof.begin(), 637 audit_proof.begin(),
784 audit_proof.begin() + 7); 638 audit_proof.begin() + 7);
785 mock_dns_.ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.", 639 mock_dns_.ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.",
786 audit_proof.begin() + 7, 640 audit_proof.begin() + 7,
787 audit_proof.begin() + 14); 641 audit_proof.begin() + 14);
788 mock_dns_.ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.", 642 mock_dns_.ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.",
789 audit_proof.begin() + 14, 643 audit_proof.begin() + 14,
790 audit_proof.end()); 644 audit_proof.end());
791 645
792 const size_t max_concurrent_queries = 1; 646 const size_t kMaxConcurrentQueries = 1;
793 std::unique_ptr<LogDnsClient> log_client = 647 std::unique_ptr<LogDnsClient> log_client =
794 CreateLogDnsClient(max_concurrent_queries); 648 CreateLogDnsClient(kMaxConcurrentQueries);
795 649
796 // Start the queries. 650 // Start the queries.
797 MockAuditProofCallback callback1; 651 MockAuditProofCallback callback1;
798 QueryAuditProofAsync(log_client.get(), "ct.test", 123456, 999999, 652 QueryAuditProofAsync(log_client.get(), "ct.test", kLeafHashes[0], 999999,
799 callback1.AsCallback()); 653 callback1.AsCallback());
800 MockAuditProofCallback callback2; 654 MockAuditProofCallback callback2;
801 QueryAuditProofAsync(log_client.get(), "ct.test", 123456, 999999, 655 QueryAuditProofAsync(log_client.get(), "ct.test", kLeafHashes[1], 999999,
802 callback2.AsCallback()); 656 callback2.AsCallback());
803 657
804 callback1.WaitUntilRun(); 658 callback1.WaitUntilRun();
805 callback2.WaitUntilRun(); 659 callback2.WaitUntilRun();
806 660
807 // Check that the first query succeeded. 661 // Check that the first query succeeded.
808 ASSERT_TRUE(callback1.called()); 662 ASSERT_TRUE(callback1.called());
809 EXPECT_THAT(callback1.net_error(), IsOk()); 663 EXPECT_THAT(callback1.net_error(), IsOk());
810 ASSERT_THAT(callback1.proof(), NotNull()); 664 ASSERT_THAT(callback1.proof(), NotNull());
811 EXPECT_THAT(callback1.proof()->leaf_index, Eq(123456u)); 665 EXPECT_THAT(callback1.proof()->leaf_index, Eq(123456u));
812 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size. 666 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size.
813 // EXPECT_THAT(callback1.proof()->tree_size, Eq(999999)); 667 // EXPECT_THAT(callback1.proof()->tree_size, Eq(999999));
814 EXPECT_THAT(callback1.proof()->nodes, Eq(audit_proof)); 668 EXPECT_THAT(callback1.proof()->nodes, Eq(audit_proof));
815 669
816 // Check that the second query failed. 670 // Check that the second query failed.
817 ASSERT_TRUE(callback2.called()); 671 ASSERT_TRUE(callback2.called());
818 EXPECT_THAT(callback2.net_error(), IsError(net::ERR_TEMPORARILY_THROTTLED)); 672 EXPECT_THAT(callback2.net_error(), IsError(net::ERR_TEMPORARILY_THROTTLED));
819 EXPECT_THAT(callback2.proof(), IsNull()); 673 EXPECT_THAT(callback2.proof(), IsNull());
820 } 674 }
821 675
822 TEST_P(LogDnsClientTest, ThrottlingAppliesAcrossQueryTypes) {
823 // Check that queries can be rate-limited to one at a time, regardless of the
824 // type of query. The second query, initiated while the first is in progress,
825 // should fail.
826 mock_dns_.ExpectLeafIndexRequestAndResponse(
827 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
828 "123456");
829
830 const size_t max_concurrent_queries = 1;
831 std::unique_ptr<LogDnsClient> log_client =
832 CreateLogDnsClient(max_concurrent_queries);
833
834 // Start the queries.
835 MockLeafIndexCallback leaf_index_callback;
836 QueryLeafIndexAsync(log_client.get(), "ct.test", kLeafHashes[0],
837 leaf_index_callback.AsCallback());
838 MockAuditProofCallback audit_proof_callback;
839 QueryAuditProofAsync(log_client.get(), "ct.test", 123456, 999999,
840 audit_proof_callback.AsCallback());
841
842 leaf_index_callback.WaitUntilRun();
843 audit_proof_callback.WaitUntilRun();
844
845 // Check that the first query succeeded.
846 ASSERT_TRUE(leaf_index_callback.called());
847 EXPECT_THAT(leaf_index_callback.net_error(), IsOk());
848 EXPECT_THAT(leaf_index_callback.leaf_index(), Eq(123456u));
849
850 // Check that the second query failed.
851 ASSERT_TRUE(audit_proof_callback.called());
852 EXPECT_THAT(audit_proof_callback.net_error(),
853 IsError(net::ERR_TEMPORARILY_THROTTLED));
854 EXPECT_THAT(audit_proof_callback.proof(), IsNull());
855 }
856
857 INSTANTIATE_TEST_CASE_P(ReadMode, 676 INSTANTIATE_TEST_CASE_P(ReadMode,
858 LogDnsClientTest, 677 LogDnsClientTest,
859 ::testing::Values(net::IoMode::ASYNC, 678 ::testing::Values(net::IoMode::ASYNC,
860 net::IoMode::SYNCHRONOUS)); 679 net::IoMode::SYNCHRONOUS));
861 680
862 } // namespace 681 } // namespace
863 } // namespace certificate_transparency 682 } // namespace certificate_transparency
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698