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

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

Issue 2066553002: Certificate Transparency DNS log client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mock_dns_responses
Patch Set: Test with both async and sync socket reads Created 4 years, 5 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
« no previous file with comments | « components/certificate_transparency/log_dns_client.cc ('k') | components/components_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/certificate_transparency/log_dns_client.h"
6
7 #include <algorithm>
8 #include <numeric>
9 #include <utility>
10 #include <vector>
11
12 #include "base/big_endian.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/run_loop.h"
16 #include "base/sys_byteorder.h"
17 #include "base/test/simple_test_clock.h"
18 #include "base/test/test_timeouts.h"
19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "crypto/sha2.h"
21 #include "net/base/net_errors.h"
22 #include "net/cert/merkle_audit_proof.h"
23 #include "net/cert/merkle_tree_leaf.h"
24 #include "net/cert/signed_certificate_timestamp.h"
25 #include "net/dns/dns_client.h"
26 #include "net/dns/dns_config_service.h"
27 #include "net/dns/dns_protocol.h"
28 #include "net/log/net_log.h"
29 #include "net/socket/socket_test_util.h"
30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h"
32
33 namespace certificate_transparency {
34 namespace {
35
36 using ::testing::AllOf;
37 using ::testing::DeleteArg;
38 using ::testing::IsNull;
39 using ::testing::Not;
40 using ::testing::Pointee;
41 using ::testing::Field;
42 using ::testing::SizeIs;
43
44 constexpr char kLeafHash[] =
45 "\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
48 MATCHER(IsNetOk, "") {
49 if (arg <= net::OK)
50 *result_listener << net::ErrorToString(arg);
51 return arg == net::OK;
52 }
53
54 MATCHER_P(IsNetError, expected, "") {
55 if (arg <= net::OK)
56 *result_listener << net::ErrorToString(arg);
57 return arg == expected;
58 }
59
60 // Always return min, to simplify testing.
61 // This should result in the DNS query ID always being 0.
62 int FakeRandInt(int min, int max) {
63 return min;
64 }
65
66 std::vector<char> CreateDnsTxtRequest(base::StringPiece qname) {
67 std::string encoded_qname;
68 EXPECT_TRUE(net::DNSDomainFromDot(qname, &encoded_qname));
69
70 const size_t query_section_size = encoded_qname.size() + 4;
71
72 std::vector<char> request(sizeof(net::dns_protocol::Header) +
73 query_section_size);
74 base::BigEndianWriter writer(request.data(), request.size());
75
76 // Header
77 net::dns_protocol::Header header = {};
78 header.flags = base::HostToNet16(net::dns_protocol::kFlagRD);
79 header.qdcount = base::HostToNet16(1);
80 EXPECT_TRUE(writer.WriteBytes(&header, sizeof(header)));
81 // Query section
82 EXPECT_TRUE(writer.WriteBytes(encoded_qname.data(), encoded_qname.size()));
83 EXPECT_TRUE(writer.WriteU16(net::dns_protocol::kTypeTXT));
84 EXPECT_TRUE(writer.WriteU16(net::dns_protocol::kClassIN));
85 EXPECT_EQ(0, writer.remaining());
86
87 return request;
88 }
89
90 std::vector<char> CreateDnsTxtResponse(const std::vector<char>& request,
91 base::StringPiece answer) {
92 const size_t answers_section_size = 12 + answer.size();
93 constexpr uint32_t ttl = 86400; // seconds
94
95 std::vector<char> response(request.size() + answers_section_size);
96 std::copy(request.begin(), request.end(), response.begin());
97 // Modify the header
98 net::dns_protocol::Header* header =
99 reinterpret_cast<net::dns_protocol::Header*>(response.data());
100 header->ancount = base::HostToNet16(1);
101 header->flags |= base::HostToNet16(net::dns_protocol::kFlagResponse);
102
103 // Write the answer section
104 base::BigEndianWriter writer(response.data() + request.size(),
105 response.size() - request.size());
106 EXPECT_TRUE(writer.WriteU8(0xc0)); // qname is a pointer
107 EXPECT_TRUE(writer.WriteU8(
108 sizeof(*header))); // address of qname (start of query section)
109 EXPECT_TRUE(writer.WriteU16(net::dns_protocol::kTypeTXT));
110 EXPECT_TRUE(writer.WriteU16(net::dns_protocol::kClassIN));
111 EXPECT_TRUE(writer.WriteU32(ttl));
112 EXPECT_TRUE(writer.WriteU16(answer.size()));
113 EXPECT_TRUE(writer.WriteBytes(answer.data(), answer.size()));
114 EXPECT_EQ(0, writer.remaining());
115
116 return response;
117 }
118
119 std::vector<char> CreateDnsErrorResponse(const std::vector<char>& request,
120 uint8_t rcode) {
121 std::vector<char> response(request);
122 // Modify the header
123 net::dns_protocol::Header* header =
124 reinterpret_cast<net::dns_protocol::Header*>(response.data());
125 header->ancount = base::HostToNet16(1);
126 header->flags |= base::HostToNet16(net::dns_protocol::kFlagResponse | rcode);
127
128 return response;
129 }
130
131 std::vector<std::string> GetSampleAuditProof(size_t length) {
132 std::vector<std::string> audit_proof(length);
133 // Makes each node of the audit proof different, so that tests are able to
134 // confirm that the audit proof is reconstructed in the correct order.
135 for (size_t i = 0; i < length; ++i) {
136 std::string node(crypto::kSHA256Length, '\0');
137 // Each node is 32 bytes, with each byte having a different value.
138 for (size_t j = 0; j < crypto::kSHA256Length; ++j) {
139 node[j] = static_cast<char>((-127 + i + j) % 128);
140 }
141 audit_proof[i].assign(std::move(node));
142 }
143
144 return audit_proof;
145 }
146
147 class MockLeafIndexCallback {
148 public:
149 MOCK_METHOD2(Run, void(int net_error, uint64_t leaf_index));
150 };
151
152 class MockAuditProofCallback {
153 public:
154 MOCK_METHOD2(Run_, void(int net_error, net::ct::MerkleAuditProof* proof));
155
156 // This proxy function is required because Chromium's GMock is not built with
157 // C++11 support (required for handling std::unique_ptr parameters).
158 // Remove it once this is rectified.
159 void Run(int net_error, std::unique_ptr<net::ct::MerkleAuditProof> proof) {
160 Run_(net_error, proof.release());
161 }
162 };
163
164 // A container for all of the data we need to keep alive for a mock socket.
165 // This is useful because Mock{Read,Write}, SequencedSocketData and
166 // MockClientSocketFactory all do not take ownership of or copy their arguments,
167 // so we have to manage the lifetime of those arguments ourselves. Wrapping all
168 // of that up in a single class simplifies this.
169 class MockSocketData {
170 public:
171 // A socket that expects one write and one read operation.
172 MockSocketData(const std::vector<char>& write, const std::vector<char>& read)
173 : expected_write_payload_(write),
174 expected_read_payload_(read),
175 expected_write_(net::SYNCHRONOUS,
176 expected_write_payload_.data(),
177 expected_write_payload_.size(),
178 0),
179 expected_read_(net::ASYNC,
180 expected_read_payload_.data(),
181 expected_read_payload_.size(),
182 1),
183 socket_data_(&expected_read_, 1, &expected_write_, 1) {}
184
185 void SetWriteMode(net::IoMode mode) { expected_write_.mode = mode; }
186 void SetReadMode(net::IoMode mode) { expected_read_.mode = mode; }
187
188 void AddToFactory(net::MockClientSocketFactory* socket_factory) {
189 socket_factory->AddSocketDataProvider(&socket_data_);
190 }
191
192 private:
193 const std::vector<char> expected_write_payload_;
194 const std::vector<char> expected_read_payload_;
195 net::MockWrite expected_write_;
196 net::MockRead expected_read_;
197 net::SequencedSocketData socket_data_;
198
199 DISALLOW_COPY_AND_ASSIGN(MockSocketData);
200 };
201
202 class LogDnsClientTest : public ::testing::TestWithParam<net::IoMode> {
203 protected:
204 LogDnsClientTest()
205 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
206
207 std::unique_ptr<net::DnsClient> CreateDnsClient() {
208 net::DnsConfig config;
209 // Use an invalid nameserver address. This prevents the tests accidentally
210 // sending real DNS queries. The mock sockets don't care that the address
211 // is invalid.
212 config.nameservers.push_back(net::IPEndPoint());
213 // Don't attempt retransmissions - just fail.
214 config.attempts = 1;
215 // This ensures timeouts are long enough for memory tests.
216 config.timeout = TestTimeouts::action_timeout();
217 // Simplify testing - don't require random numbers for the source port.
218 // This means our FakeRandInt function should only be called to get query
219 // IDs.
220 config.randomize_ports = false;
221
222 std::unique_ptr<net::DnsClient> client =
223 net::DnsClient::CreateClientForTesting(
224 net_log_.net_log(), &socket_factory_, base::Bind(&FakeRandInt));
225 client->SetConfig(config);
226 return client;
227 }
228
229 void ExpectRequestAndResponse(base::StringPiece qname,
230 base::StringPiece answer) {
231 std::vector<char> request = CreateDnsTxtRequest(qname);
232 std::vector<char> response = CreateDnsTxtResponse(request, answer);
233
234 mock_socket_data_.emplace_back(new MockSocketData(request, response));
235 mock_socket_data_.back()->SetReadMode(GetParam());
236 mock_socket_data_.back()->AddToFactory(&socket_factory_);
237 }
238
239 void ExpectRequestAndErrorResponse(base::StringPiece qname, uint8_t rcode) {
240 std::vector<char> request = CreateDnsTxtRequest(qname);
241 std::vector<char> response = CreateDnsErrorResponse(request, rcode);
242
243 mock_socket_data_.emplace_back(new MockSocketData(request, response));
244 mock_socket_data_.back()->SetReadMode(GetParam());
245 mock_socket_data_.back()->AddToFactory(&socket_factory_);
246 }
247
248 void ExpectLeafIndexRequestAndResponse(base::StringPiece qname,
249 base::StringPiece leaf_index) {
250 // Prepend size to leaf_index to create the query answer (rdata)
251 ASSERT_LE(leaf_index.size(), 0xFFul); // size must fit into a single byte
252 std::string answer = leaf_index.as_string();
253 answer.insert(answer.begin(), static_cast<char>(leaf_index.size()));
254
255 ExpectRequestAndResponse(qname, answer);
256 }
257
258 void ExpectAuditProofRequestAndResponse(
259 base::StringPiece qname,
260 std::vector<std::string>::const_iterator audit_path_start,
261 std::vector<std::string>::const_iterator audit_path_end) {
262 // Join nodes in the audit path into a single string.
263 std::string proof =
264 std::accumulate(audit_path_start, audit_path_end, std::string());
265
266 // Prepend size to proof to create the query answer (rdata)
267 ASSERT_LE(proof.size(), 0xFFul); // size must fit into a single byte
268 proof.insert(proof.begin(), static_cast<char>(proof.size()));
269
270 ExpectRequestAndResponse(qname, proof);
271 }
272
273 void QueryLeafIndex(base::StringPiece log_domain,
274 base::StringPiece leaf_hash,
275 MockLeafIndexCallback* callback) {
276 std::unique_ptr<net::DnsClient> dns_client = CreateDnsClient();
277 LogDnsClient log_client(std::move(dns_client), net_log_, &clock_);
278
279 LogDnsClient::LeafIndexCallback callback_func =
280 base::Bind(&MockLeafIndexCallback::Run, base::Unretained(callback));
281
282 log_client.QueryLeafIndex(log_domain, leaf_hash, callback_func);
283 base::RunLoop().RunUntilIdle();
284 }
285
286 void QueryAuditProof(base::StringPiece log_domain,
287 uint64_t leaf_index,
288 uint64_t tree_size,
289 MockAuditProofCallback* callback) {
290 std::unique_ptr<net::DnsClient> dns_client = CreateDnsClient();
291 LogDnsClient log_client(std::move(dns_client), net_log_, &clock_);
292
293 LogDnsClient::AuditProofCallback callback_func =
294 base::Bind(&MockAuditProofCallback::Run, base::Unretained(callback));
295
296 log_client.QueryAuditProof(log_domain, leaf_index, tree_size,
297 callback_func);
298 base::RunLoop().RunUntilIdle();
299 }
300
301 content::TestBrowserThreadBundle thread_bundle_;
302 net::BoundNetLog net_log_;
mmenke 2016/06/27 19:30:32 Can remove this entirely - just inline net::BoundN
Rob Percival 2016/06/28 21:44:54 Done.
303 base::SimpleTestClock clock_;
304 std::vector<std::unique_ptr<MockSocketData>> mock_socket_data_;
305 net::MockClientSocketFactory socket_factory_;
306 };
307
308 TEST_P(LogDnsClientTest, QueryLeafIndex) {
309 ExpectLeafIndexRequestAndResponse(
310 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
311 "123456");
312
313 MockLeafIndexCallback callback;
314 EXPECT_CALL(callback, Run(IsNetOk(), 123456));
315
316 QueryLeafIndex("ct.test", kLeafHash, &callback);
317 }
318
319 TEST_P(LogDnsClientTest, QueryLeafIndexReportsThatLogDomainDoesNotExist) {
320 ExpectRequestAndErrorResponse(
321 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
322 net::dns_protocol::kRcodeNXDOMAIN);
323
324 MockLeafIndexCallback callback;
325 EXPECT_CALL(callback, Run(IsNetError(net::ERR_NAME_NOT_RESOLVED), 0));
326
327 QueryLeafIndex("ct.test", kLeafHash, &callback);
328 }
329
330 TEST_P(LogDnsClientTest, QueryLeafIndexReportsServerFailure) {
331 ExpectRequestAndErrorResponse(
332 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
333 net::dns_protocol::kRcodeSERVFAIL);
334
335 MockLeafIndexCallback callback;
336 EXPECT_CALL(callback, Run(IsNetError(net::ERR_DNS_SERVER_FAILED), 0));
337
338 QueryLeafIndex("ct.test", kLeafHash, &callback);
339 }
340
341 TEST_P(LogDnsClientTest, QueryLeafIndexReportsServerRefusal) {
342 ExpectRequestAndErrorResponse(
343 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
344 net::dns_protocol::kRcodeREFUSED);
345
346 MockLeafIndexCallback callback;
347 EXPECT_CALL(callback, Run(IsNetError(net::ERR_DNS_SERVER_FAILED), 0));
348
349 QueryLeafIndex("ct.test", kLeafHash, &callback);
350 }
351
352 TEST_P(LogDnsClientTest,
353 QueryLeafIndexReportsMalformedResponseIfLeafIndexIsNotNumeric) {
354 ExpectLeafIndexRequestAndResponse(
355 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
356 "foo");
357
358 MockLeafIndexCallback callback;
359 EXPECT_CALL(callback, Run(IsNetError(net::ERR_DNS_MALFORMED_RESPONSE), 0));
360
361 QueryLeafIndex("ct.test", kLeafHash, &callback);
362 }
363
364 TEST_P(LogDnsClientTest,
365 QueryLeafIndexReportsMalformedResponseIfLeafIndexIsFloatingPoint) {
366 ExpectLeafIndexRequestAndResponse(
367 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
368 "123456.0");
369
370 MockLeafIndexCallback callback;
371 EXPECT_CALL(callback, Run(IsNetError(net::ERR_DNS_MALFORMED_RESPONSE), 0));
372
373 QueryLeafIndex("ct.test", kLeafHash, &callback);
374 }
375
376 TEST_P(LogDnsClientTest,
377 QueryLeafIndexReportsMalformedResponseIfLeafIndexIsEmpty) {
378 ExpectLeafIndexRequestAndResponse(
379 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", "");
380
381 MockLeafIndexCallback callback;
382 EXPECT_CALL(callback, Run(IsNetError(net::ERR_DNS_MALFORMED_RESPONSE), 0));
383
384 QueryLeafIndex("ct.test", kLeafHash, &callback);
385 }
386
387 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLogDomainIsEmpty) {
388 MockLeafIndexCallback callback;
389 EXPECT_CALL(callback, Run(IsNetError(net::ERR_INVALID_ARGUMENT), 0));
390
391 QueryLeafIndex("", kLeafHash, &callback);
392 }
393
394 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLogDomainIsNull) {
395 MockLeafIndexCallback callback;
396 EXPECT_CALL(callback, Run(IsNetError(net::ERR_INVALID_ARGUMENT), 0));
397
398 QueryLeafIndex(nullptr, kLeafHash, &callback);
399 }
400
401 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLeafHashIsInvalid) {
402 MockLeafIndexCallback callback;
403 EXPECT_CALL(callback, Run(IsNetError(net::ERR_INVALID_ARGUMENT), 0));
404
405 QueryLeafIndex("ct.test", "foo", &callback);
406 }
407
408 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLeafHashIsEmpty) {
409 MockLeafIndexCallback callback;
410 EXPECT_CALL(callback, Run(IsNetError(net::ERR_INVALID_ARGUMENT), 0));
411
412 QueryLeafIndex("ct.test", "", &callback);
413 }
414
415 TEST_P(LogDnsClientTest, QueryLeafIndexReportsInvalidArgIfLeafHashIsNull) {
416 MockLeafIndexCallback callback;
417 EXPECT_CALL(callback, Run(IsNetError(net::ERR_INVALID_ARGUMENT), 0));
418
419 QueryLeafIndex("ct.test", nullptr, &callback);
420 }
421
422 TEST_P(LogDnsClientTest, QueryAuditProof) {
423 const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
424
425 // It should require 3 queries to collect the entire audit proof, as there is
426 // only space for 7 nodes per UDP packet.
427 ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
428 audit_proof.begin(),
429 audit_proof.begin() + 7);
430 ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.",
431 audit_proof.begin() + 7,
432 audit_proof.begin() + 14);
433 ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.",
434 audit_proof.begin() + 14,
435 audit_proof.end());
436
437 MockAuditProofCallback callback;
438 EXPECT_CALL(callback,
439 Run_(IsNetOk(),
440 Pointee(AllOf(
441 Field(&net::ct::MerkleAuditProof::nodes, audit_proof),
442 Field(&net::ct::MerkleAuditProof::leaf_index, 123456)))))
443 .WillOnce(DeleteArg<1>());
444
445 QueryAuditProof("ct.test", 123456, 999999, &callback);
446 }
447
448 TEST_P(LogDnsClientTest,
449 QueryAuditProofHandlesResponsesWithEmptyAndShortAuditPaths) {
450 const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
451
452 // Make some of the responses empty or contain fewer audit proof nodes than
453 // they can hold.
454 ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
455 audit_proof.begin(), audit_proof.begin());
456 ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
457 audit_proof.begin(),
458 audit_proof.begin() + 1);
459 ExpectAuditProofRequestAndResponse("1.123456.999999.tree.ct.test.",
460 audit_proof.begin() + 1,
461 audit_proof.begin() + 3);
462 ExpectAuditProofRequestAndResponse("3.123456.999999.tree.ct.test.",
463 audit_proof.begin() + 3,
464 audit_proof.begin() + 6);
465 ExpectAuditProofRequestAndResponse("6.123456.999999.tree.ct.test.",
466 audit_proof.begin() + 6,
467 audit_proof.begin() + 10);
468 ExpectAuditProofRequestAndResponse("10.123456.999999.tree.ct.test.",
469 audit_proof.begin() + 10,
470 audit_proof.begin() + 13);
471 ExpectAuditProofRequestAndResponse("13.123456.999999.tree.ct.test.",
472 audit_proof.begin() + 13,
473 audit_proof.end());
474
475 MockAuditProofCallback callback;
476 EXPECT_CALL(callback,
477 Run_(IsNetOk(),
478 Pointee(AllOf(
479 Field(&net::ct::MerkleAuditProof::nodes, audit_proof),
480 Field(&net::ct::MerkleAuditProof::leaf_index, 123456)))))
481 .WillOnce(DeleteArg<1>());
482
483 QueryAuditProof("ct.test", 123456, 999999, &callback);
484 }
485
486 TEST_P(LogDnsClientTest, QueryAuditProofReportsThatLogDomainDoesNotExist) {
487 ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
488 net::dns_protocol::kRcodeNXDOMAIN);
489
490 MockAuditProofCallback callback;
491 EXPECT_CALL(callback, Run_(IsNetError(net::ERR_NAME_NOT_RESOLVED), nullptr));
492
493 QueryAuditProof("ct.test", 123456, 999999, &callback);
494 }
495
496 TEST_P(LogDnsClientTest, QueryAuditProofReportsServerFailure) {
497 ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
498 net::dns_protocol::kRcodeSERVFAIL);
499
500 MockAuditProofCallback callback;
501 EXPECT_CALL(callback, Run_(IsNetError(net::ERR_DNS_SERVER_FAILED), nullptr));
502
503 QueryAuditProof("ct.test", 123456, 999999, &callback);
504 }
505
506 TEST_P(LogDnsClientTest, QueryAuditProofReportsServerRefusal) {
507 ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
508 net::dns_protocol::kRcodeREFUSED);
509
510 MockAuditProofCallback callback;
511 EXPECT_CALL(callback, Run_(IsNetError(net::ERR_DNS_SERVER_FAILED), nullptr));
512
513 QueryAuditProof("ct.test", 123456, 999999, &callback);
514 }
515
516 TEST_P(LogDnsClientTest,
517 QueryAuditProofReportsResponseMalformedIfNodeTooShort) {
518 // node is shorter than a SHA-256 hash (31 vs 32 bytes)
519 const std::vector<std::string> audit_proof(1, std::string(31, 'a'));
520
521 ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
522 audit_proof.begin(), audit_proof.end());
523
524 MockAuditProofCallback callback;
525 EXPECT_CALL(callback,
526 Run_(IsNetError(net::ERR_DNS_MALFORMED_RESPONSE), nullptr));
527
528 QueryAuditProof("ct.test", 123456, 999999, &callback);
529 }
530
531 TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfNodeTooLong) {
532 // node is longer than a SHA-256 hash (33 vs 32 bytes)
533 const std::vector<std::string> audit_proof(1, std::string(33, 'a'));
534
535 ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
536 audit_proof.begin(), audit_proof.end());
537
538 MockAuditProofCallback callback;
539 EXPECT_CALL(callback,
540 Run_(IsNetError(net::ERR_DNS_MALFORMED_RESPONSE), nullptr));
541
542 QueryAuditProof("ct.test", 123456, 999999, &callback);
543 }
544
545 TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLogDomainIsEmpty) {
546 MockAuditProofCallback callback;
547 EXPECT_CALL(callback, Run_(IsNetError(net::ERR_INVALID_ARGUMENT), nullptr));
548
549 QueryAuditProof("", 123456, 999999, &callback);
550 }
551
552 TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLogDomainIsNull) {
553 MockAuditProofCallback callback;
554 EXPECT_CALL(callback, Run_(IsNetError(net::ERR_INVALID_ARGUMENT), nullptr));
555
556 QueryAuditProof(nullptr, 123456, 999999, &callback);
557 }
558
559 TEST_P(LogDnsClientTest,
560 QueryAuditProofReportInvalidArgIfLeafIndexEqualToTreeSize) {
561 MockAuditProofCallback callback;
562 EXPECT_CALL(callback, Run_(IsNetError(net::ERR_INVALID_ARGUMENT), nullptr));
563
564 QueryAuditProof("ct.test", 123456, 123456, &callback);
565 }
566
567 TEST_P(LogDnsClientTest,
568 QueryAuditProofReportInvalidArgIfLeafIndexGreaterThanTreeSize) {
569 MockAuditProofCallback callback;
570 EXPECT_CALL(callback, Run_(IsNetError(net::ERR_INVALID_ARGUMENT), nullptr));
571
572 QueryAuditProof("ct.test", 999999, 123456, &callback);
573 }
574
575 INSTANTIATE_TEST_CASE_P(ReadMode,
576 LogDnsClientTest,
577 ::testing::Values(net::IoMode::ASYNC,
578 net::IoMode::SYNCHRONOUS));
579
580 } // namespace
581 } // namespace certificate_transparency
OLDNEW
« no previous file with comments | « components/certificate_transparency/log_dns_client.cc ('k') | components/components_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698