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..890645d335a3c6b319ec6d785d1bb349a64885f5 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)) { |
| + *result_listener << "expected value was not a valid hex string"; |
| + return false; |
| + } |
| + |
| + 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; |
|
eroman
2016/05/06 23:51:22
technically this is incorrect in the case where th
Rob Percival
2016/05/09 12:36:05
Fixed. Surprisingly, that is only mentioned in the
eroman
2016/05/09 16:44:02
Yeah, the C++ spec defers to the C spec for defini
|
| +} |
| + |
| 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(Hash(leaf, &hash)); |
| + EXPECT_THAT(hash, HexEq("d306c83ef45ac97bba7a0d99331f23433e5fa97cf3a08ed90b24" |
|
eroman
2016/05/06 23:51:22
Where does this data come from?
Are there official
Rob Percival
2016/05/09 12:36:05
I independently generated this, by taking the seri
|
| + "2f7aec99f2ad")); |
| +} |
| + |
| +TEST_F(MerkleTreeLeafTest, HashForPrecert) { |
| + MerkleTreeLeaf leaf; |
| + ct::GetPrecertTreeLeaf(&leaf); |
| + |
| + std::string hash; |
| + ASSERT_TRUE(Hash(leaf, &hash)); |
| + EXPECT_THAT(hash, HexEq("d6f71fef189695a815b98d02d5b66f624323303172f75ff62f62" |
| + "44c01cde7cd3")); |
| +} |
| + |
| } // namespace |
| } // namespace ct |