OLD | NEW |
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 <numeric> | 8 #include <numeric> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 IsError(net::ERR_IO_PENDING)); | 706 IsError(net::ERR_IO_PENDING)); |
707 | 707 |
708 // Check that the third query succeeded. | 708 // Check that the third query succeeded. |
709 EXPECT_THAT(callback3.WaitForResult(), IsOk()); | 709 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
710 EXPECT_THAT(proof3.leaf_index, Eq(666u)); | 710 EXPECT_THAT(proof3.leaf_index, Eq(666u)); |
711 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size. | 711 // TODO(robpercival): Enable this once MerkleAuditProof has tree_size. |
712 // EXPECT_THAT(proof3.tree_size, Eq(999999)); | 712 // EXPECT_THAT(proof3.tree_size, Eq(999999)); |
713 EXPECT_THAT(proof3.nodes, Eq(audit_proof)); | 713 EXPECT_THAT(proof3.nodes, Eq(audit_proof)); |
714 } | 714 } |
715 | 715 |
| 716 TEST_P(LogDnsClientTest, NotifiesWhenNoLongerThrottled) { |
| 717 const std::vector<std::string> audit_proof = GetSampleAuditProof(20); |
| 718 |
| 719 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456); |
| 720 mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.", |
| 721 audit_proof.begin(), |
| 722 audit_proof.begin() + 7); |
| 723 mock_dns_.ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.", |
| 724 audit_proof.begin() + 7, |
| 725 audit_proof.begin() + 14); |
| 726 mock_dns_.ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.", |
| 727 audit_proof.begin() + 14, |
| 728 audit_proof.end()); |
| 729 |
| 730 const size_t kMaxConcurrentQueries = 1; |
| 731 std::unique_ptr<LogDnsClient> log_client = |
| 732 CreateLogDnsClient(kMaxConcurrentQueries); |
| 733 |
| 734 // Start a query. |
| 735 net::ct::MerkleAuditProof proof1; |
| 736 net::TestCompletionCallback proof_callback1; |
| 737 ASSERT_THAT(log_client->QueryAuditProof("ct.test", kLeafHashes[0], 999999, |
| 738 &proof1, proof_callback1.callback()), |
| 739 IsError(net::ERR_IO_PENDING)); |
| 740 |
| 741 net::TestClosure not_throttled_callback; |
| 742 log_client->NotifyWhenNotThrottled(not_throttled_callback.closure()); |
| 743 |
| 744 ASSERT_THAT(proof_callback1.WaitForResult(), IsOk()); |
| 745 not_throttled_callback.WaitForResult(); |
| 746 |
| 747 // Start another query to check |not_throttled_callback| doesn't fire again. |
| 748 mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[1], 666); |
| 749 mock_dns_.ExpectAuditProofRequestAndResponse("0.666.999999.tree.ct.test.", |
| 750 audit_proof.begin(), |
| 751 audit_proof.begin() + 7); |
| 752 mock_dns_.ExpectAuditProofRequestAndResponse("7.666.999999.tree.ct.test.", |
| 753 audit_proof.begin() + 7, |
| 754 audit_proof.begin() + 14); |
| 755 mock_dns_.ExpectAuditProofRequestAndResponse("14.666.999999.tree.ct.test.", |
| 756 audit_proof.begin() + 14, |
| 757 audit_proof.end()); |
| 758 |
| 759 net::ct::MerkleAuditProof proof2; |
| 760 net::TestCompletionCallback proof_callback2; |
| 761 ASSERT_THAT(log_client->QueryAuditProof("ct.test", kLeafHashes[1], 999999, |
| 762 &proof2, proof_callback2.callback()), |
| 763 IsError(net::ERR_IO_PENDING)); |
| 764 |
| 765 // Give the query a chance to run. |
| 766 ASSERT_THAT(proof_callback2.WaitForResult(), IsOk()); |
| 767 // Give |not_throttled_callback| a chance to run - it shouldn't though. |
| 768 base::RunLoop().RunUntilIdle(); |
| 769 ASSERT_FALSE(not_throttled_callback.have_result()); |
| 770 } |
| 771 |
716 INSTANTIATE_TEST_CASE_P(ReadMode, | 772 INSTANTIATE_TEST_CASE_P(ReadMode, |
717 LogDnsClientTest, | 773 LogDnsClientTest, |
718 ::testing::Values(net::IoMode::ASYNC, | 774 ::testing::Values(net::IoMode::ASYNC, |
719 net::IoMode::SYNCHRONOUS)); | 775 net::IoMode::SYNCHRONOUS)); |
720 | 776 |
721 } // namespace certificate_transparency | 777 } // namespace certificate_transparency |
OLD | NEW |