| Index: components/certificate_transparency/log_dns_client_unittest.cc
|
| diff --git a/components/certificate_transparency/log_dns_client_unittest.cc b/components/certificate_transparency/log_dns_client_unittest.cc
|
| index 1db0a3213f0d9d35299ebaf2bc5be47f9d33a08f..819d998ad13d4e867d46b62e853ac3224d3ffb31 100644
|
| --- a/components/certificate_transparency/log_dns_client_unittest.cc
|
| +++ b/components/certificate_transparency/log_dns_client_unittest.cc
|
| @@ -129,98 +129,102 @@ class LogDnsClientTest : public ::testing::TestWithParam<net::IoMode> {
|
| // Allows mock DNS sockets to be setup.
|
| MockLogDnsTraffic mock_dns_;
|
| };
|
|
|
| TEST_P(LogDnsClientTest, QueryAuditProofReportsThatLogDomainDoesNotExist) {
|
| - mock_dns_.ExpectRequestAndErrorResponse(kLeafIndexQnames[0],
|
| - net::dns_protocol::kRcodeNXDOMAIN);
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndErrorResponse(
|
| + kLeafIndexQnames[0], net::dns_protocol::kRcodeNXDOMAIN));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_NAME_NOT_RESOLVED));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsServerFailuresDuringLeafIndexRequests) {
|
| - mock_dns_.ExpectRequestAndErrorResponse(kLeafIndexQnames[0],
|
| - net::dns_protocol::kRcodeSERVFAIL);
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndErrorResponse(
|
| + kLeafIndexQnames[0], net::dns_protocol::kRcodeSERVFAIL));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_SERVER_FAILED));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsServerRefusalsDuringLeafIndexRequests) {
|
| - mock_dns_.ExpectRequestAndErrorResponse(kLeafIndexQnames[0],
|
| - net::dns_protocol::kRcodeREFUSED);
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndErrorResponse(
|
| + kLeafIndexQnames[0], net::dns_protocol::kRcodeREFUSED));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_SERVER_FAILED));
|
| }
|
|
|
| TEST_P(
|
| LogDnsClientTest,
|
| QueryAuditProofReportsMalformedResponseIfLeafIndexResponseContainsNoStrings) {
|
| - mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0],
|
| - std::vector<base::StringPiece>());
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndResponse(
|
| + kLeafIndexQnames[0], std::vector<base::StringPiece>()));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
|
|
| TEST_P(
|
| LogDnsClientTest,
|
| QueryAuditProofReportsMalformedResponseIfLeafIndexResponseContainsMoreThanOneString) {
|
| - mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"123456", "7"});
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"123456", "7"}));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsMalformedResponseIfLeafIndexIsNotNumeric) {
|
| - mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"foo"});
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"foo"}));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsMalformedResponseIfLeafIndexIsFloatingPoint) {
|
| - mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"123456.0"});
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"123456.0"}));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsMalformedResponseIfLeafIndexIsEmpty) {
|
| - mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {""});
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {""}));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsMalformedResponseIfLeafIndexHasNonNumericPrefix) {
|
| - mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"foo123456"});
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"foo123456"}));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsMalformedResponseIfLeafIndexHasNonNumericSuffix) {
|
| - mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"123456foo"});
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectRequestAndResponse(kLeafIndexQnames[0], {"123456foo"}));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
| @@ -243,43 +247,44 @@ TEST_P(LogDnsClientTest, QueryAuditProofReportsInvalidArgIfLeafHashIsEmpty) {
|
| IsError(net::ERR_INVALID_ARGUMENT));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsSocketErrorsDuringLeafIndexRequests) {
|
| - mock_dns_.ExpectRequestAndSocketError(kLeafIndexQnames[0],
|
| - net::ERR_CONNECTION_REFUSED);
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndSocketError(
|
| + kLeafIndexQnames[0], net::ERR_CONNECTION_REFUSED));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_CONNECTION_REFUSED));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsTimeoutsDuringLeafIndexRequests) {
|
| - mock_dns_.ExpectRequestAndTimeout(kLeafIndexQnames[0]);
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndTimeout(kLeafIndexQnames[0]));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], kTreeSizes[0], &proof),
|
| IsError(net::ERR_DNS_TIMED_OUT));
|
| }
|
|
|
| TEST_P(LogDnsClientTest, QueryAuditProof) {
|
| const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
|
|
|
| // Expect a leaf index query first, to map the leaf hash to a leaf index.
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
|
|
| // It takes a number of DNS requests to retrieve the entire |audit_proof|
|
| // (see |kMaxProofNodesPerDnsResponse|).
|
| for (size_t nodes_begin = 0; nodes_begin < audit_proof.size();
|
| nodes_begin += kMaxProofNodesPerDnsResponse) {
|
| const size_t nodes_end = std::min(
|
| nodes_begin + kMaxProofNodesPerDnsResponse, audit_proof.size());
|
|
|
| - mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| base::StringPrintf("%zu.123456.999999.tree.ct.test.", nodes_begin),
|
| - audit_proof.begin() + nodes_begin, audit_proof.begin() + nodes_end);
|
| + audit_proof.begin() + nodes_begin, audit_proof.begin() + nodes_end));
|
| }
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsOk());
|
| @@ -291,31 +296,32 @@ TEST_P(LogDnsClientTest, QueryAuditProof) {
|
|
|
| TEST_P(LogDnsClientTest, QueryAuditProofHandlesResponsesWithShortAuditPaths) {
|
| const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
|
|
|
| // Expect a leaf index query first, to map the leaf hash to a leaf index.
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
|
|
| // Make some of the responses contain fewer proof nodes than they can hold.
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
|
| - audit_proof.begin(),
|
| - audit_proof.begin() + 1);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("1.123456.999999.tree.ct.test.",
|
| - audit_proof.begin() + 1,
|
| - audit_proof.begin() + 3);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("3.123456.999999.tree.ct.test.",
|
| - audit_proof.begin() + 3,
|
| - audit_proof.begin() + 6);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("6.123456.999999.tree.ct.test.",
|
| - audit_proof.begin() + 6,
|
| - audit_proof.begin() + 10);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("10.123456.999999.tree.ct.test.",
|
| - audit_proof.begin() + 10,
|
| - audit_proof.begin() + 13);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("13.123456.999999.tree.ct.test.",
|
| - audit_proof.begin() + 13,
|
| - audit_proof.end());
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "0.123456.999999.tree.ct.test.", audit_proof.begin(),
|
| + audit_proof.begin() + 1));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "1.123456.999999.tree.ct.test.", audit_proof.begin() + 1,
|
| + audit_proof.begin() + 3));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "3.123456.999999.tree.ct.test.", audit_proof.begin() + 3,
|
| + audit_proof.begin() + 6));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "6.123456.999999.tree.ct.test.", audit_proof.begin() + 6,
|
| + audit_proof.begin() + 10));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "10.123456.999999.tree.ct.test.", audit_proof.begin() + 10,
|
| + audit_proof.begin() + 13));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "13.123456.999999.tree.ct.test.", audit_proof.begin() + 13,
|
| + audit_proof.end()));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsOk());
|
| EXPECT_THAT(proof.leaf_index, Eq(123456u));
|
| @@ -324,49 +330,53 @@ TEST_P(LogDnsClientTest, QueryAuditProofHandlesResponsesWithShortAuditPaths) {
|
| EXPECT_THAT(proof.nodes, Eq(audit_proof));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsThatAuditProofQnameDoesNotExist) {
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| - mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
|
| - net::dns_protocol::kRcodeNXDOMAIN);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndErrorResponse(
|
| + "0.123456.999999.tree.ct.test.", net::dns_protocol::kRcodeNXDOMAIN));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_NAME_NOT_RESOLVED));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsServerFailuresDuringAuditProofRequests) {
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| - mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
|
| - net::dns_protocol::kRcodeSERVFAIL);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndErrorResponse(
|
| + "0.123456.999999.tree.ct.test.", net::dns_protocol::kRcodeSERVFAIL));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_DNS_SERVER_FAILED));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsServerRefusalsDuringAuditProofRequests) {
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| - mock_dns_.ExpectRequestAndErrorResponse("0.123456.999999.tree.ct.test.",
|
| - net::dns_protocol::kRcodeREFUSED);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndErrorResponse(
|
| + "0.123456.999999.tree.ct.test.", net::dns_protocol::kRcodeREFUSED));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_DNS_SERVER_FAILED));
|
| }
|
|
|
| TEST_P(
|
| LogDnsClientTest,
|
| QueryAuditProofReportsResponseMalformedIfProofNodesResponseContainsNoStrings) {
|
| // Expect a leaf index query first, to map the leaf hash to a leaf index.
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
|
|
| - mock_dns_.ExpectRequestAndResponse("0.123456.999999.tree.ct.test.",
|
| - std::vector<base::StringPiece>());
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndResponse(
|
| + "0.123456.999999.tree.ct.test.", std::vector<base::StringPiece>()));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
| @@ -382,15 +392,16 @@ TEST_P(
|
| audit_proof.begin(), audit_proof.begin() + 7, std::string());
|
| std::string second_chunk_of_proof = std::accumulate(
|
| audit_proof.begin() + 7, audit_proof.end(), std::string());
|
|
|
| // Expect a leaf index query first, to map the leaf hash to a leaf index.
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
|
|
| - mock_dns_.ExpectRequestAndResponse(
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndResponse(
|
| "0.123456.999999.tree.ct.test.",
|
| - {first_chunk_of_proof, second_chunk_of_proof});
|
| + {first_chunk_of_proof, second_chunk_of_proof}));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
| @@ -398,77 +409,85 @@ TEST_P(
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsResponseMalformedIfNodeTooShort) {
|
| // node is shorter than a SHA-256 hash (31 vs 32 bytes)
|
| const std::vector<std::string> audit_proof(1, std::string(31, 'a'));
|
|
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse(
|
| - "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end());
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end()));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
|
|
| TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfNodeTooLong) {
|
| // node is longer than a SHA-256 hash (33 vs 32 bytes)
|
| const std::vector<std::string> audit_proof(1, std::string(33, 'a'));
|
|
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse(
|
| - "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end());
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end()));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
|
|
| TEST_P(LogDnsClientTest, QueryAuditProofReportsResponseMalformedIfEmpty) {
|
| const std::vector<std::string> audit_proof;
|
|
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse(
|
| - "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end());
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "0.123456.999999.tree.ct.test.", audit_proof.begin(), audit_proof.end()));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_DNS_MALFORMED_RESPONSE));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsInvalidArgIfLeafIndexEqualToTreeSize) {
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 123456, &proof),
|
| IsError(net::ERR_INVALID_ARGUMENT));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsInvalidArgIfLeafIndexGreaterThanTreeSize) {
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 999999);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 999999));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 123456, &proof),
|
| IsError(net::ERR_INVALID_ARGUMENT));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsSocketErrorsDuringAuditProofRequests) {
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| - mock_dns_.ExpectRequestAndSocketError("0.123456.999999.tree.ct.test.",
|
| - net::ERR_CONNECTION_REFUSED);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
| + ASSERT_TRUE(mock_dns_.ExpectRequestAndSocketError(
|
| + "0.123456.999999.tree.ct.test.", net::ERR_CONNECTION_REFUSED));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_CONNECTION_REFUSED));
|
| }
|
|
|
| TEST_P(LogDnsClientTest,
|
| QueryAuditProofReportsTimeoutsDuringAuditProofRequests) {
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| - mock_dns_.ExpectRequestAndTimeout("0.123456.999999.tree.ct.test.");
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectRequestAndTimeout("0.123456.999999.tree.ct.test."));
|
|
|
| net::ct::MerkleAuditProof proof;
|
| ASSERT_THAT(QueryAuditProof("ct.test", kLeafHashes[0], 999999, &proof),
|
| IsError(net::ERR_DNS_TIMED_OUT));
|
| }
|
| @@ -509,22 +528,23 @@ TEST_P(LogDnsClientTest, IgnoresLatestDnsConfigIfInvalid) {
|
| // that the query is not disrupted.
|
| TEST_P(LogDnsClientTest, AdoptsLatestDnsConfigMidQuery) {
|
| const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
|
|
|
| // Expect a leaf index query first, to map the leaf hash to a leaf index.
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
|
|
| // It takes a number of DNS requests to retrieve the entire |audit_proof|
|
| // (see |kMaxProofNodesPerDnsResponse|).
|
| for (size_t nodes_begin = 0; nodes_begin < audit_proof.size();
|
| nodes_begin += kMaxProofNodesPerDnsResponse) {
|
| const size_t nodes_end = std::min(
|
| nodes_begin + kMaxProofNodesPerDnsResponse, audit_proof.size());
|
|
|
| - mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| base::StringPrintf("%zu.123456.999999.tree.ct.test.", nodes_begin),
|
| - audit_proof.begin() + nodes_begin, audit_proof.begin() + nodes_end);
|
| + audit_proof.begin() + nodes_begin, audit_proof.begin() + nodes_end));
|
| }
|
|
|
| std::unique_ptr<net::DnsClient> tmp = mock_dns_.CreateDnsClient();
|
| net::DnsClient* dns_client = tmp.get();
|
| LogDnsClient log_client(std::move(tmp), net::NetLogWithSource(), 0);
|
| @@ -570,12 +590,12 @@ TEST_P(LogDnsClientTest, CanPerformQueriesInParallel) {
|
| CreateLogDnsClient(kNumOfParallelQueries);
|
| net::TestCompletionCallback callbacks[kNumOfParallelQueries];
|
|
|
| // Expect multiple leaf index requests.
|
| for (size_t i = 0; i < kNumOfParallelQueries; ++i) {
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[i],
|
| - kLeafIndices[i]);
|
| + ASSERT_TRUE(mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[i],
|
| + kLeafIndices[i]));
|
| }
|
|
|
| // Make each query require one more audit proof request than the last, by
|
| // increasing the number of nodes in the audit proof by
|
| // kMaxProofNodesPerDnsResponse for each query. This helps to test that
|
| @@ -605,15 +625,15 @@ TEST_P(LogDnsClientTest, CanPerformQueriesInParallel) {
|
| const size_t end_node =
|
| std::min(start_node + kMaxProofNodesPerDnsResponse, proof.size());
|
|
|
| // If there are any nodes left, expect another request and response.
|
| if (start_node < end_node) {
|
| - mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| base::StringPrintf("%zu.%" PRIu64 ".%" PRIu64 ".tree.ct.test.",
|
| start_node, kLeafIndices[query_i],
|
| kTreeSizes[query_i]),
|
| - proof.begin() + start_node, proof.begin() + end_node);
|
| + proof.begin() + start_node, proof.begin() + end_node));
|
| }
|
| }
|
| }
|
|
|
| net::ct::MerkleAuditProof proofs[kNumOfParallelQueries];
|
| @@ -645,25 +665,26 @@ TEST_P(LogDnsClientTest, CanBeThrottledToOneQueryAtATime) {
|
| // The second query, initiated while the first is in progress, should fail.
|
| const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
|
|
|
| // Expect the first query to send leaf index and audit proof requests, but the
|
| // second should not due to throttling.
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
|
|
| // It should require 3 requests to collect the entire audit proof, as there is
|
| // only space for 7 nodes per TXT record. One node is 32 bytes long and the
|
| // TXT RDATA can have a maximum length of 255 bytes (255 / 32).
|
| // Rate limiting should not interfere with these requests.
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
|
| - audit_proof.begin(),
|
| - audit_proof.begin() + 7);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.",
|
| - audit_proof.begin() + 7,
|
| - audit_proof.begin() + 14);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.",
|
| - audit_proof.begin() + 14,
|
| - audit_proof.end());
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "0.123456.999999.tree.ct.test.", audit_proof.begin(),
|
| + audit_proof.begin() + 7));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "7.123456.999999.tree.ct.test.", audit_proof.begin() + 7,
|
| + audit_proof.begin() + 14));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "14.123456.999999.tree.ct.test.", audit_proof.begin() + 14,
|
| + audit_proof.end()));
|
|
|
| const size_t kMaxConcurrentQueries = 1;
|
| std::unique_ptr<LogDnsClient> log_client =
|
| CreateLogDnsClient(kMaxConcurrentQueries);
|
|
|
| @@ -686,20 +707,21 @@ TEST_P(LogDnsClientTest, CanBeThrottledToOneQueryAtATime) {
|
| // TODO(robpercival): Enable this once MerkleAuditProof has tree_size.
|
| // EXPECT_THAT(proof1.tree_size, Eq(999999));
|
| EXPECT_THAT(proof1.nodes, Eq(audit_proof));
|
|
|
| // Try a third query, which should succeed now that the first is finished.
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[2], 666);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("0.666.999999.tree.ct.test.",
|
| - audit_proof.begin(),
|
| - audit_proof.begin() + 7);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("7.666.999999.tree.ct.test.",
|
| - audit_proof.begin() + 7,
|
| - audit_proof.begin() + 14);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("14.666.999999.tree.ct.test.",
|
| - audit_proof.begin() + 14,
|
| - audit_proof.end());
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[2], 666));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "0.666.999999.tree.ct.test.", audit_proof.begin(),
|
| + audit_proof.begin() + 7));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "7.666.999999.tree.ct.test.", audit_proof.begin() + 7,
|
| + audit_proof.begin() + 14));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "14.666.999999.tree.ct.test.", audit_proof.begin() + 14,
|
| + audit_proof.end()));
|
|
|
| net::ct::MerkleAuditProof proof3;
|
| net::TestCompletionCallback callback3;
|
| ASSERT_THAT(log_client->QueryAuditProof("ct.test", kLeafHashes[2], 999999,
|
| &proof3, callback3.callback()),
|
| @@ -714,20 +736,21 @@ TEST_P(LogDnsClientTest, CanBeThrottledToOneQueryAtATime) {
|
| }
|
|
|
| TEST_P(LogDnsClientTest, NotifiesWhenNoLongerThrottled) {
|
| const std::vector<std::string> audit_proof = GetSampleAuditProof(20);
|
|
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("0.123456.999999.tree.ct.test.",
|
| - audit_proof.begin(),
|
| - audit_proof.begin() + 7);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("7.123456.999999.tree.ct.test.",
|
| - audit_proof.begin() + 7,
|
| - audit_proof.begin() + 14);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("14.123456.999999.tree.ct.test.",
|
| - audit_proof.begin() + 14,
|
| - audit_proof.end());
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[0], 123456));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "0.123456.999999.tree.ct.test.", audit_proof.begin(),
|
| + audit_proof.begin() + 7));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "7.123456.999999.tree.ct.test.", audit_proof.begin() + 7,
|
| + audit_proof.begin() + 14));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "14.123456.999999.tree.ct.test.", audit_proof.begin() + 14,
|
| + audit_proof.end()));
|
|
|
| const size_t kMaxConcurrentQueries = 1;
|
| std::unique_ptr<LogDnsClient> log_client =
|
| CreateLogDnsClient(kMaxConcurrentQueries);
|
|
|
| @@ -743,20 +766,21 @@ TEST_P(LogDnsClientTest, NotifiesWhenNoLongerThrottled) {
|
|
|
| ASSERT_THAT(proof_callback1.WaitForResult(), IsOk());
|
| not_throttled_callback.WaitForResult();
|
|
|
| // Start another query to check |not_throttled_callback| doesn't fire again.
|
| - mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[1], 666);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("0.666.999999.tree.ct.test.",
|
| - audit_proof.begin(),
|
| - audit_proof.begin() + 7);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("7.666.999999.tree.ct.test.",
|
| - audit_proof.begin() + 7,
|
| - audit_proof.begin() + 14);
|
| - mock_dns_.ExpectAuditProofRequestAndResponse("14.666.999999.tree.ct.test.",
|
| - audit_proof.begin() + 14,
|
| - audit_proof.end());
|
| + ASSERT_TRUE(
|
| + mock_dns_.ExpectLeafIndexRequestAndResponse(kLeafIndexQnames[1], 666));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "0.666.999999.tree.ct.test.", audit_proof.begin(),
|
| + audit_proof.begin() + 7));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "7.666.999999.tree.ct.test.", audit_proof.begin() + 7,
|
| + audit_proof.begin() + 14));
|
| + ASSERT_TRUE(mock_dns_.ExpectAuditProofRequestAndResponse(
|
| + "14.666.999999.tree.ct.test.", audit_proof.begin() + 14,
|
| + audit_proof.end()));
|
|
|
| net::ct::MerkleAuditProof proof2;
|
| net::TestCompletionCallback proof_callback2;
|
| ASSERT_THAT(log_client->QueryAuditProof("ct.test", kLeafHashes[1], 999999,
|
| &proof2, proof_callback2.callback()),
|
|
|