Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/cert/sth_distributor.h" | |
| 6 | |
| 7 #include <map> | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/test/histogram_tester.h" | |
| 11 #include "crypto/sha2.h" | |
| 12 #include "net/cert/signed_tree_head.h" | |
| 13 #include "net/cert/sth_observer.h" | |
| 14 #include "net/test/ct_test_util.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 namespace ct { | |
| 20 | |
| 21 // An STHObserver implementation that simply stores all | |
| 22 // observed STHs, keyed by log ID. | |
| 23 class StoringSTHObserver : public net::ct::STHObserver { | |
|
Ryan Sleevi
2016/05/16 19:19:02
These helper classes should be in an unnamed names
Eran Messeri
2016/05/17 09:51:03
Done. As you referred to multiple helper classes,
Ryan Sleevi
2016/05/17 16:52:51
Right, both this and the STHDistributorTest. The i
| |
| 24 public: | |
| 25 void NewSTHObserved(const net::ct::SignedTreeHead& sth) override { | |
| 26 sths[sth.log_id] = sth; | |
| 27 } | |
| 28 | |
| 29 std::map<std::string, net::ct::SignedTreeHead> sths; | |
|
Ryan Sleevi
2016/05/16 19:19:02
You're in net::ct:: - remove all the net::ct:: her
Eran Messeri
2016/05/17 09:51:03
Done.
| |
| 30 }; | |
| 31 | |
| 32 class STHDistributorTest : public ::testing::Test { | |
| 33 public: | |
| 34 STHDistributorTest() {} | |
| 35 | |
| 36 void SetUp() override { | |
| 37 ASSERT_TRUE(GetSampleSignedTreeHead(&sample_sth_)); | |
| 38 sample_sth_.log_id = GetTestPublicKeyId(); | |
| 39 } | |
| 40 | |
| 41 protected: | |
| 42 STHDistributor distributor_; | |
| 43 SignedTreeHead sample_sth_; | |
| 44 }; | |
| 45 | |
| 46 TEST_F(STHDistributorTest, NotifiesOfExistingSTHs) { | |
| 47 const std::string other_log = "another log"; | |
| 48 SignedTreeHead second_sth(sample_sth_); | |
| 49 second_sth.log_id = other_log; | |
| 50 | |
| 51 distributor_.NewSTHObserved(sample_sth_); | |
| 52 distributor_.NewSTHObserved(second_sth); | |
| 53 | |
| 54 StoringSTHObserver observer; | |
| 55 distributor_.RegisterObserver(&observer); | |
| 56 | |
| 57 // Check that two STHs from different logs received prior to observer | |
| 58 // registration were reported to the observer once registered. | |
| 59 EXPECT_EQ(2u, observer.sths.size()); | |
| 60 EXPECT_EQ(1u, observer.sths.count(other_log)); | |
| 61 } | |
| 62 | |
| 63 TEST_F(STHDistributorTest, LogsUMAForPilotSTH) { | |
| 64 const char kPilotSTHAgeHistogram[] = | |
| 65 "Net.CertificateTransparency.PilotSTHAge"; | |
| 66 base::HistogramTester histograms; | |
| 67 histograms.ExpectTotalCount(kPilotSTHAgeHistogram, 0); | |
| 68 | |
| 69 const char kPilotLogID[33] = | |
| 70 "\xa4\xb9\x09\x90\xb4\x18\x58\x14\x87\xbb\x13\xa2\xcc\x67\x70\x0a\x3c\x35" | |
| 71 "\x98\x04\xf9\x1b\xdf\xb8\xe3\x77\xcd\x0e\xc8\x0d\xdc\x10"; | |
|
Ryan Sleevi
2016/05/16 19:19:01
uint8_t for the new code?
Eran Messeri
2016/05/17 09:51:03
Done.
| |
| 72 sample_sth_.log_id = std::string(kPilotLogID, crypto::kSHA256Length); | |
| 73 | |
| 74 distributor_.NewSTHObserved(sample_sth_); | |
| 75 histograms.ExpectTotalCount(kPilotSTHAgeHistogram, 1); | |
| 76 } | |
| 77 | |
| 78 TEST_F(STHDistributorTest, UpdatesObservedSTHData) { | |
| 79 distributor_.NewSTHObserved(sample_sth_); | |
| 80 sample_sth_.tree_size = 23u; | |
| 81 distributor_.NewSTHObserved(sample_sth_); | |
| 82 | |
| 83 StoringSTHObserver observer; | |
| 84 distributor_.RegisterObserver(&observer); | |
| 85 EXPECT_EQ(1u, observer.sths.size()); | |
| 86 EXPECT_EQ(23u, observer.sths[GetTestPublicKeyId()].tree_size); | |
| 87 } | |
| 88 | |
| 89 } // namespace ct | |
| 90 | |
| 91 } // namespace net | |
| OLD | NEW |