Chromium Code Reviews| Index: net/cert/merkle_tree_leaf_unittest.cc |
| diff --git a/net/cert/merkle_tree_leaf_unittest.cc b/net/cert/merkle_tree_leaf_unittest.cc |
| index ab59237a199a3bed983b1d76483605a92da9de91..f768c1f7b25a64b5108e3a06ee91795691d38853 100644 |
| --- a/net/cert/merkle_tree_leaf_unittest.cc |
| +++ b/net/cert/merkle_tree_leaf_unittest.cc |
| @@ -4,12 +4,16 @@ |
| #include "net/cert/merkle_tree_leaf.h" |
| +#include <string.h> |
| + |
| #include <string> |
| +#include "base/strings/string_number_conversions.h" |
| #include "net/base/test_data_directory.h" |
| #include "net/cert/x509_certificate.h" |
| #include "net/test/cert_test_util.h" |
| #include "net/test/ct_test_util.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace net { |
| @@ -18,6 +22,24 @@ namespace ct { |
| namespace { |
| +MATCHER_P(HexEq, hexStr, "") { |
| + std::vector<uint8_t> bytes; |
| + |
| + if (base::HexStringToBytes(hexStr, &bytes)) { |
|
Eran Messeri
2016/05/05 16:03:26
Return early by flipping the condition of the if s
Rob Percival
2016/05/05 16:26:37
Done.
|
| + if (bytes.size() != arg.size()) { |
| + *result_listener << "expected and actual are different lengths"; |
| + return false; |
| + } |
| + |
| + // Print hex string (easier to read than default GTest representation) |
| + *result_listener << "a.k.a. 0x" << base::HexEncode(arg.data(), arg.size()); |
| + return memcmp(arg.data(), bytes.data(), bytes.size()) == 0; |
| + } |
| + |
| + *result_listener << "expected value was not a valid hex string"; |
| + return false; |
| +} |
| + |
| class MerkleTreeLeafTest : public ::testing::Test { |
| public: |
| void SetUp() override { |
| @@ -77,6 +99,26 @@ TEST_F(MerkleTreeLeafTest, DoesNotCreateForEmbeddedSCTButNotPrecert) { |
| ASSERT_FALSE(GetMerkleTreeLeaf(test_cert_.get(), precert_sct_.get(), &leaf)); |
| } |
| +TEST_F(MerkleTreeLeafTest, HashForX509Cert) { |
| + MerkleTreeLeaf leaf; |
| + ct::GetX509CertTreeLeaf(&leaf); |
| + |
| + std::string hash; |
| + ASSERT_TRUE(leaf.Hash(&hash)); |
| + EXPECT_THAT(hash, HexEq("d306c83ef45ac97bba7a0d99331f23433e5fa97cf3a08ed90b24" |
| + "2f7aec99f2ad")); |
| +} |
| + |
| +TEST_F(MerkleTreeLeafTest, HashForPrecert) { |
| + MerkleTreeLeaf leaf; |
| + ct::GetPrecertTreeLeaf(&leaf); |
| + |
| + std::string hash; |
| + ASSERT_TRUE(leaf.Hash(&hash)); |
| + EXPECT_THAT(hash, HexEq("d6f71fef189695a815b98d02d5b66f624323303172f75ff62f62" |
| + "44c01cde7cd3")); |
| +} |
| + |
| } // namespace |
| } // namespace ct |