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

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

Issue 2331923003: Allow LogDnsClient queries to be rate-limited (Closed)
Patch Set: Set LogDnsClient max_concurrent_queries via constructor param Created 4 years, 3 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>
11 11
12 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "components/certificate_transparency/mock_log_dns_traffic.h" 15 #include "components/certificate_transparency/mock_log_dns_traffic.h"
15 #include "crypto/sha2.h" 16 #include "crypto/sha2.h"
16 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
17 #include "net/cert/merkle_audit_proof.h" 18 #include "net/cert/merkle_audit_proof.h"
18 #include "net/cert/signed_certificate_timestamp.h" 19 #include "net/cert/signed_certificate_timestamp.h"
19 #include "net/dns/dns_client.h" 20 #include "net/dns/dns_client.h"
20 #include "net/dns/dns_config_service.h" 21 #include "net/dns/dns_config_service.h"
21 #include "net/dns/dns_protocol.h" 22 #include "net/dns/dns_protocol.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 }; 114 };
114 115
115 class LogDnsClientTest : public ::testing::TestWithParam<net::IoMode> { 116 class LogDnsClientTest : public ::testing::TestWithParam<net::IoMode> {
116 protected: 117 protected:
117 LogDnsClientTest() 118 LogDnsClientTest()
118 : network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) { 119 : network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) {
119 mock_dns_.SetSocketReadMode(GetParam()); 120 mock_dns_.SetSocketReadMode(GetParam());
120 mock_dns_.InitializeDnsConfig(); 121 mock_dns_.InitializeDnsConfig();
121 } 122 }
122 123
124 std::unique_ptr<LogDnsClient> CreateLogDnsClient(
125 size_t max_concurrent_queries = 0 /* unlimited */) {
Ryan Sleevi 2016/09/12 18:12:44 https://google.github.io/styleguide/cppguide.html#
Rob Percival 2016/09/13 14:06:31 That's why I didn't set a default value for the co
126 return base::MakeUnique<LogDnsClient>(mock_dns_.CreateDnsClient(),
127 net::BoundNetLog(),
128 max_concurrent_queries);
129 }
130
131 void QueryLeafIndexAsync(LogDnsClient* log_client,
132 base::StringPiece log_domain,
133 base::StringPiece leaf_hash,
134 const LogDnsClient::LeafIndexCallback& callback) {
135 log_client->QueryLeafIndex(log_domain, leaf_hash, callback);
136 }
137
138 // Convenience function for calling QueryLeafIndexAsync synchronously.
123 void QueryLeafIndex(base::StringPiece log_domain, 139 void QueryLeafIndex(base::StringPiece log_domain,
124 base::StringPiece leaf_hash, 140 base::StringPiece leaf_hash,
125 MockLeafIndexCallback* callback) { 141 MockLeafIndexCallback* callback) {
126 LogDnsClient log_client(mock_dns_.CreateDnsClient(), net::BoundNetLog()); 142 auto log_client = CreateLogDnsClient();
Ryan Sleevi 2016/09/12 18:12:43 There's been a variety of threads on this particul
Rob Percival 2016/09/13 14:06:31 Done.
127 log_client.QueryLeafIndex(log_domain, leaf_hash, callback->AsCallback()); 143 QueryLeafIndexAsync(log_client.get(), log_domain, leaf_hash,
144 callback->AsCallback());
128 callback->WaitUntilRun(); 145 callback->WaitUntilRun();
129 } 146 }
130 147
148 void QueryAuditProofAsync(LogDnsClient* log_client,
149 base::StringPiece log_domain,
150 uint64_t leaf_index,
151 uint64_t tree_size,
152 const LogDnsClient::AuditProofCallback& callback) {
153 log_client->QueryAuditProof(log_domain, leaf_index, tree_size, callback);
154 }
155
156 // Convenience function for calling QueryAuditProofAsync synchronously.
131 void QueryAuditProof(base::StringPiece log_domain, 157 void QueryAuditProof(base::StringPiece log_domain,
132 uint64_t leaf_index, 158 uint64_t leaf_index,
133 uint64_t tree_size, 159 uint64_t tree_size,
134 MockAuditProofCallback* callback) { 160 MockAuditProofCallback* callback) {
135 LogDnsClient log_client(mock_dns_.CreateDnsClient(), net::BoundNetLog()); 161 auto log_client = CreateLogDnsClient();
Ryan Sleevi 2016/09/12 18:12:44 see above
Rob Percival 2016/09/13 14:06:31 Done.
136 log_client.QueryAuditProof(log_domain, leaf_index, tree_size, 162 QueryAuditProofAsync(log_client.get(), log_domain, leaf_index, tree_size,
137 callback->AsCallback()); 163 callback->AsCallback());
138 callback->WaitUntilRun(); 164 callback->WaitUntilRun();
139 } 165 }
140 166
141 // This will be the NetworkChangeNotifier singleton for the duration of the 167 // This will be the NetworkChangeNotifier singleton for the duration of the
142 // test. It is accessed statically by LogDnsClient. 168 // test. It is accessed statically by LogDnsClient.
143 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; 169 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_;
144 // Queues and handles asynchronous DNS tasks. Indirectly used by LogDnsClient, 170 // Queues and handles asynchronous DNS tasks. Indirectly used by LogDnsClient,
145 // the underlying net::DnsClient, and NetworkChangeNotifier. 171 // the underlying net::DnsClient, and NetworkChangeNotifier.
146 base::MessageLoopForIO message_loop_; 172 base::MessageLoopForIO message_loop_;
147 // Allows mock DNS sockets to be setup. 173 // Allows mock DNS sockets to be setup.
148 MockLogDnsTraffic mock_dns_; 174 MockLogDnsTraffic mock_dns_;
149 }; 175 };
150 176
151 TEST_P(LogDnsClientTest, QueryLeafIndex) { 177 TEST_P(LogDnsClientTest, QueryLeafIndex) {
152 mock_dns_.ExpectLeafIndexRequestAndResponse( 178 mock_dns_.ExpectLeafIndexRequestAndResponse(
153 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", 179 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
154 "123456"); 180 "123456");
155 181
156 MockLeafIndexCallback callback; 182 MockLeafIndexCallback callback;
157 QueryLeafIndex("ct.test", kLeafHash, &callback); 183 QueryLeafIndex("ct.test", kLeafHash, &callback);
158 ASSERT_TRUE(callback.called()); 184 ASSERT_TRUE(callback.called());
159 EXPECT_THAT(callback.net_error(), IsOk()); 185 EXPECT_THAT(callback.net_error(), IsOk());
160 EXPECT_THAT(callback.leaf_index(), 123456); 186 EXPECT_THAT(callback.leaf_index(), 123456);
Ryan Sleevi 2016/09/12 18:12:43 This is a really odd usage of GMock. There's alrea
Rob Percival 2016/09/13 14:06:31 This is actually the recommended usage, according
mmenke 2016/09/13 14:31:29 The fact that they're reversed seems extremely con
161 } 187 }
162 188
163 TEST_P(LogDnsClientTest, QueryLeafIndexReportsThatLogDomainDoesNotExist) { 189 TEST_P(LogDnsClientTest, QueryLeafIndexReportsThatLogDomainDoesNotExist) {
164 mock_dns_.ExpectRequestAndErrorResponse( 190 mock_dns_.ExpectRequestAndErrorResponse(
165 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.", 191 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
166 net::dns_protocol::kRcodeNXDOMAIN); 192 net::dns_protocol::kRcodeNXDOMAIN);
167 193
168 MockLeafIndexCallback callback; 194 MockLeafIndexCallback callback;
169 QueryLeafIndex("ct.test", kLeafHash, &callback); 195 QueryLeafIndex("ct.test", kLeafHash, &callback);
170 ASSERT_TRUE(callback.called()); 196 ASSERT_TRUE(callback.called());
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 mock_dns_.ExpectAuditProofRequestAndResponse("13.123456.999999.tree.ct.test.", 396 mock_dns_.ExpectAuditProofRequestAndResponse("13.123456.999999.tree.ct.test.",
371 audit_proof.begin() + 13, 397 audit_proof.begin() + 13,
372 audit_proof.end()); 398 audit_proof.end());
373 399
374 MockAuditProofCallback callback; 400 MockAuditProofCallback callback;
375 QueryAuditProof("ct.test", 123456, 999999, &callback); 401 QueryAuditProof("ct.test", 123456, 999999, &callback);
376 ASSERT_TRUE(callback.called()); 402 ASSERT_TRUE(callback.called());
377 EXPECT_THAT(callback.net_error(), IsOk()); 403 EXPECT_THAT(callback.net_error(), IsOk());
378 ASSERT_THAT(callback.proof(), NotNull()); 404 ASSERT_THAT(callback.proof(), NotNull());
379 EXPECT_THAT(callback.proof()->leaf_index, 123456); 405 EXPECT_THAT(callback.proof()->leaf_index, 123456);
380 // EXPECT_THAT(callback.proof()->tree_size, 999999); 406 // EXPECT_THAT(callback.proof()->tree_size, 999999);
Ryan Sleevi 2016/09/12 18:12:43 Dead code?
Rob Percival 2016/09/13 14:06:31 Future code - it's pending the addition of a tree_
381 EXPECT_THAT(callback.proof()->nodes, audit_proof); 407 EXPECT_THAT(callback.proof()->nodes, audit_proof);
382 } 408 }
383 409
384 TEST_P(LogDnsClientTest, QueryAuditProofReportsThatLogDomainDoesNotExist) { 410 TEST_P(LogDnsClientTest, QueryAuditProofReportsThatLogDomainDoesNotExist) {
385 mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.", 411 mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
386 net::dns_protocol::kRcodeNXDOMAIN); 412 net::dns_protocol::kRcodeNXDOMAIN);
387 413
388 MockAuditProofCallback callback; 414 MockAuditProofCallback callback;
389 QueryAuditProof("ct.test", 123456, 999999, &callback); 415 QueryAuditProof("ct.test", 123456, 999999, &callback);
390 ASSERT_TRUE(callback.called()); 416 ASSERT_TRUE(callback.called());
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 MockAuditProofCallback callback; 533 MockAuditProofCallback callback;
508 QueryAuditProof("ct.test", 123456, 999999, &callback); 534 QueryAuditProof("ct.test", 123456, 999999, &callback);
509 ASSERT_TRUE(callback.called()); 535 ASSERT_TRUE(callback.called());
510 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_TIMED_OUT)); 536 EXPECT_THAT(callback.net_error(), IsError(net::ERR_DNS_TIMED_OUT));
511 EXPECT_THAT(callback.proof(), IsNull()); 537 EXPECT_THAT(callback.proof(), IsNull());
512 } 538 }
513 539
514 TEST_P(LogDnsClientTest, AdoptsLatestDnsConfigIfValid) { 540 TEST_P(LogDnsClientTest, AdoptsLatestDnsConfigIfValid) {
515 std::unique_ptr<net::DnsClient> tmp = mock_dns_.CreateDnsClient(); 541 std::unique_ptr<net::DnsClient> tmp = mock_dns_.CreateDnsClient();
516 net::DnsClient* dns_client = tmp.get(); 542 net::DnsClient* dns_client = tmp.get();
517 LogDnsClient log_client(std::move(tmp), net::BoundNetLog()); 543 LogDnsClient log_client(std::move(tmp), net::BoundNetLog(), 0);
518 544
519 // Get the current DNS config, modify it and broadcast the update. 545 // Get the current DNS config, modify it and broadcast the update.
520 net::DnsConfig config(*dns_client->GetConfig()); 546 net::DnsConfig config(*dns_client->GetConfig());
521 ASSERT_NE(123, config.attempts); 547 ASSERT_NE(123, config.attempts);
522 config.attempts = 123; 548 config.attempts = 123;
523 mock_dns_.SetDnsConfig(config); 549 mock_dns_.SetDnsConfig(config);
524 550
525 // Let the DNS config change propogate. 551 // Let the DNS config change propogate.
526 base::RunLoop().RunUntilIdle(); 552 base::RunLoop().RunUntilIdle();
527 EXPECT_EQ(123, dns_client->GetConfig()->attempts); 553 EXPECT_EQ(123, dns_client->GetConfig()->attempts);
528 } 554 }
529 555
530 TEST_P(LogDnsClientTest, IgnoresLatestDnsConfigIfInvalid) { 556 TEST_P(LogDnsClientTest, IgnoresLatestDnsConfigIfInvalid) {
531 std::unique_ptr<net::DnsClient> tmp = mock_dns_.CreateDnsClient(); 557 std::unique_ptr<net::DnsClient> tmp = mock_dns_.CreateDnsClient();
532 net::DnsClient* dns_client = tmp.get(); 558 net::DnsClient* dns_client = tmp.get();
533 LogDnsClient log_client(std::move(tmp), net::BoundNetLog()); 559 LogDnsClient log_client(std::move(tmp), net::BoundNetLog(), 0);
534 560
535 // Get the current DNS config, modify it and broadcast the update. 561 // Get the current DNS config, modify it and broadcast the update.
536 net::DnsConfig config(*dns_client->GetConfig()); 562 net::DnsConfig config(*dns_client->GetConfig());
537 ASSERT_THAT(config.nameservers, Not(IsEmpty())); 563 ASSERT_THAT(config.nameservers, Not(IsEmpty()));
538 config.nameservers.clear(); // Makes config invalid 564 config.nameservers.clear(); // Makes config invalid
539 mock_dns_.SetDnsConfig(config); 565 mock_dns_.SetDnsConfig(config);
540 566
541 // Let the DNS config change propogate. 567 // Let the DNS config change propogate.
542 base::RunLoop().RunUntilIdle(); 568 base::RunLoop().RunUntilIdle();
543 EXPECT_THAT(dns_client->GetConfig()->nameservers, Not(IsEmpty())); 569 EXPECT_THAT(dns_client->GetConfig()->nameservers, Not(IsEmpty()));
544 } 570 }
545 571
572 TEST_P(LogDnsClientTest, CanPerformLeafIndexQueriesInParallel) {
573 constexpr size_t num_of_parallel_queries = 3;
574 auto log_client = CreateLogDnsClient(num_of_parallel_queries);
575 MockLeafIndexCallback callbacks[num_of_parallel_queries];
576
577 for (size_t i = 0; i < num_of_parallel_queries; ++i) {
578 mock_dns_.ExpectLeafIndexRequestAndResponse(
579 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
580 "123456");
581 }
582
583 for (size_t i = 0; i < num_of_parallel_queries; ++i) {
584 QueryLeafIndexAsync(log_client.get(), "ct.test", kLeafHash,
585 callbacks[i].AsCallback());
586 }
587
588 for (size_t i = 0; i < num_of_parallel_queries; ++i) {
Ryan Sleevi 2016/09/12 18:12:44 More inline documentation about the tests and what
Rob Percival 2016/09/13 14:06:31 Done.
589 MockLeafIndexCallback& callback = callbacks[i];
590 callback.WaitUntilRun();
591
592 SCOPED_TRACE(i);
593 EXPECT_TRUE(callback.called());
594 if (callback.called()) {
595 EXPECT_THAT(callback.net_error(), IsOk());
596 EXPECT_THAT(callback.leaf_index(), 123456);
597 }
598 }
599 }
600
601 TEST_P(LogDnsClientTest, CanPerformAuditProofQueriesInParallel) {
602 constexpr size_t num_of_parallel_queries = 3;
603 auto log_client = CreateLogDnsClient(num_of_parallel_queries);
604 MockAuditProofCallback callbacks[num_of_parallel_queries];
605 const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
606
607 // It should require 3 queries to collect the entire audit proof, as there is
608 // only space for 7 nodes per UDP packet. Expect each of these queries to
Ryan Sleevi 2016/09/12 18:12:44 What is the source of this magic value (7 nodes pe
Rob Percival 2016/09/13 14:06:31 I've now clarified this. That should have said TXT
609 // occur once for each call to QueryAuditProof.
610
611 for (size_t i = 0; i < num_of_parallel_queries; ++i) {
612 mock_dns_.ExpectAuditProofRequestAndResponse(
613 "0.123456.999999.tree.ct.test.", audit_proof.begin(),
614 audit_proof.begin() + 7);
615 }
616
617 for (size_t i = 0; i < num_of_parallel_queries; ++i) {
618 mock_dns_.ExpectAuditProofRequestAndResponse(
619 "7.123456.999999.tree.ct.test.", audit_proof.begin() + 7,
620 audit_proof.begin() + 14);
621 }
622
623 for (size_t i = 0; i < num_of_parallel_queries; ++i) {
624 mock_dns_.ExpectAuditProofRequestAndResponse(
625 "14.123456.999999.tree.ct.test.", audit_proof.begin() + 14,
626 audit_proof.end());
627 }
628
629 // Begin the queries.
630 for (size_t i = 0; i < num_of_parallel_queries; ++i) {
631 QueryAuditProofAsync(log_client.get(), "ct.test", 123456, 999999,
632 callbacks[i].AsCallback());
633 }
634
635 // Check that they were all successful.
636 for (size_t i = 0; i < num_of_parallel_queries; ++i) {
637 MockAuditProofCallback& callback = callbacks[i];
638 callbacks[i].WaitUntilRun();
639
640 SCOPED_TRACE(i);
641 EXPECT_TRUE(callback.called());
642 if (callback.called()) {
643 EXPECT_THAT(callback.net_error(), IsOk());
644 EXPECT_THAT(callback.proof(), NotNull());
645 if (callback.proof() != nullptr) {
646 EXPECT_THAT(callback.proof()->leaf_index, 123456);
647 // EXPECT_THAT(callback.proof()->tree_size, 999999);
648 EXPECT_THAT(callback.proof()->nodes, audit_proof);
649 }
650 }
651 }
652 }
653
654 TEST_P(LogDnsClientTest, CanPerformLeafIndexAndAuditProofQueriesInParallel) {
655 constexpr size_t num_of_parallel_queries = 2;
656 auto log_client = CreateLogDnsClient(num_of_parallel_queries);
657 MockLeafIndexCallback leaf_index_callback;
658 MockAuditProofCallback audit_proof_callback;
659 const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
660
661 mock_dns_.ExpectLeafIndexRequestAndResponse(
662 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
663 "123456");
664
665 // It should require 3 queries to collect the entire audit proof, as there is
666 // only space for 7 nodes per UDP packet.
667 mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
668 audit_proof.begin(),
669 audit_proof.begin() + 7);
670 mock_dns_.ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.",
671 audit_proof.begin() + 7,
672 audit_proof.begin() + 14);
673 mock_dns_.ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.",
674 audit_proof.begin() + 14,
675 audit_proof.end());
676
677 QueryLeafIndexAsync(log_client.get(), "ct.test", kLeafHash,
678 leaf_index_callback.AsCallback());
679 QueryAuditProofAsync(log_client.get(), "ct.test", 123456, 999999,
680 audit_proof_callback.AsCallback());
681
682 leaf_index_callback.WaitUntilRun();
683 audit_proof_callback.WaitUntilRun();
684
685 EXPECT_TRUE(leaf_index_callback.called());
686 if (leaf_index_callback.called()) {
687 EXPECT_THAT(leaf_index_callback.net_error(), IsOk());
688 EXPECT_THAT(leaf_index_callback.leaf_index(), 123456);
689 }
690
691 EXPECT_TRUE(audit_proof_callback.called());
692 if (audit_proof_callback.called()) {
693 EXPECT_THAT(audit_proof_callback.net_error(), IsOk());
694 EXPECT_THAT(audit_proof_callback.proof(), NotNull());
695 if (audit_proof_callback.proof() != nullptr) {
696 EXPECT_THAT(audit_proof_callback.proof()->leaf_index, 123456);
697 // EXPECT_THAT(audit_proof_callback.proof()->tree_size, 999999);
698 EXPECT_THAT(audit_proof_callback.proof()->nodes, audit_proof);
699 }
700 }
701 }
702
703 TEST_P(LogDnsClientTest, CanBeThrottledToOneLeafIndexQueryAtATime) {
704 mock_dns_.ExpectLeafIndexRequestAndResponse(
705 "D4S6DSV2J743QJZEQMH4UYHEYK7KRQ5JIQOCPMFUHZVJNFGHXACA.hash.ct.test.",
706 "123456");
707
708 const size_t max_concurrent_queries = 1;
709 auto log_client = CreateLogDnsClient(max_concurrent_queries);
710
711 MockLeafIndexCallback callback1;
712 QueryLeafIndexAsync(log_client.get(), "ct.test", kLeafHash,
713 callback1.AsCallback());
714 MockLeafIndexCallback callback2;
715 QueryLeafIndexAsync(log_client.get(), "ct.test", kLeafHash,
716 callback2.AsCallback());
717
718 callback1.WaitUntilRun();
719 callback2.WaitUntilRun();
720
721 EXPECT_TRUE(callback1.called());
722 if (callback1.called()) {
723 EXPECT_THAT(callback1.net_error(), IsOk());
724 EXPECT_THAT(callback1.leaf_index(), 123456);
725 }
726
727 EXPECT_TRUE(callback2.called());
728 if (callback2.called()) {
729 EXPECT_THAT(callback2.net_error(), IsError(net::ERR_TEMPORARILY_THROTTLED));
730 EXPECT_THAT(callback2.leaf_index(), 0);
731 }
732 }
733
734 TEST_P(LogDnsClientTest, CanBeThrottledToOneAuditProofQueryAtATime) {
735 const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
736
737 // It should require 3 queries to collect the entire audit proof, as there is
738 // only space for 7 nodes per UDP packet.
739 mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
740 audit_proof.begin(),
741 audit_proof.begin() + 7);
742 mock_dns_.ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.",
743 audit_proof.begin() + 7,
744 audit_proof.begin() + 14);
745 mock_dns_.ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.",
746 audit_proof.begin() + 14,
747 audit_proof.end());
748
749 const size_t max_concurrent_queries = 1;
750 auto log_client = CreateLogDnsClient(max_concurrent_queries);
751
752 MockAuditProofCallback callback1;
753 QueryAuditProofAsync(log_client.get(), "ct.test", 123456, 999999,
754 callback1.AsCallback());
755 MockAuditProofCallback callback2;
756 QueryAuditProofAsync(log_client.get(), "ct.test", 123456, 999999,
757 callback2.AsCallback());
758
759 callback1.WaitUntilRun();
760 callback2.WaitUntilRun();
761
762 EXPECT_TRUE(callback1.called());
763 if (callback1.called()) {
764 EXPECT_THAT(callback1.net_error(), IsOk());
765 EXPECT_THAT(callback1.proof(), NotNull());
766 if (callback1.proof() != nullptr) {
767 EXPECT_THAT(callback1.proof()->leaf_index, 123456);
768 // EXPECT_THAT(callback1.proof()->tree_size, 999999);
769 EXPECT_THAT(callback1.proof()->nodes, audit_proof);
770 }
771 }
772
773 EXPECT_TRUE(callback2.called());
774 if (callback2.called()) {
775 EXPECT_THAT(callback2.net_error(), IsError(net::ERR_TEMPORARILY_THROTTLED));
776 EXPECT_THAT(callback2.proof(), IsNull());
777 }
778 }
779
546 INSTANTIATE_TEST_CASE_P(ReadMode, 780 INSTANTIATE_TEST_CASE_P(ReadMode,
547 LogDnsClientTest, 781 LogDnsClientTest,
548 ::testing::Values(net::IoMode::ASYNC, 782 ::testing::Values(net::IoMode::ASYNC,
549 net::IoMode::SYNCHRONOUS)); 783 net::IoMode::SYNCHRONOUS));
550 784
551 } // namespace 785 } // namespace
552 } // namespace certificate_transparency 786 } // namespace certificate_transparency
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698