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 <memory> | |
| 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/test/ct_test_util.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 namespace net { | |
| 17 | |
| 18 namespace ct { | |
| 19 | |
| 20 namespace { | |
| 21 const char kAnotherLogName[] = "another log"; | |
|
Ryan Sleevi
2016/05/12 19:55:06
This doesn't need to be file-level, does it?
Eran Messeri
2016/05/13 09:04:09
Done.
| |
| 22 const char kPilotSTHAgeHistogram[] = "Net.CertificateTransparency.PilotSTHAge"; | |
| 23 const char kPilotLogID[33] = | |
| 24 "\xa4\xb9\x09\x90\xb4\x18\x58\x14\x87\xbb\x13\xa2\xcc\x67\x70\x0a\x3c\x35" | |
| 25 "\x98\x04\xf9\x1b\xdf\xb8\xe3\x77\xcd\x0e\xc8\x0d\xdc\x10"; | |
|
Ryan Sleevi
2016/05/12 19:55:06
The first two variables don't need to be file-leve
Eran Messeri
2016/05/13 09:04:09
Done.
| |
| 26 } | |
| 27 | |
| 28 class StoringSTHObserver : public net::ct::STHObserver { | |
|
Ryan Sleevi
2016/05/12 19:55:06
Document
Ryan Sleevi
2016/05/12 19:55:06
IWYU: STHObserver
Eran Messeri
2016/05/13 09:04:08
Done.
Eran Messeri
2016/05/13 09:04:09
Done.
| |
| 29 public: | |
| 30 void NewSTHObserved(const net::ct::SignedTreeHead& sth) override { | |
| 31 sths[sth.log_id] = sth; | |
| 32 } | |
| 33 | |
| 34 std::map<std::string, net::ct::SignedTreeHead> sths; | |
|
Ryan Sleevi
2016/05/12 19:55:06
IWYU: map
Eran Messeri
2016/05/13 09:04:09
Done.
| |
| 35 }; | |
| 36 | |
| 37 class STHDistributorTest : public ::testing::Test { | |
| 38 public: | |
| 39 STHDistributorTest() {} | |
| 40 | |
| 41 void SetUp() override { | |
| 42 distributor_.reset(new STHDistributor()); | |
|
Ryan Sleevi
2016/05/12 19:55:06
There's no need to do this in SetUp versus the con
Eran Messeri
2016/05/13 09:04:09
Done.
| |
| 43 ASSERT_TRUE(GetSampleSignedTreeHead(&sample_sth_)); | |
| 44 } | |
| 45 | |
| 46 protected: | |
| 47 std::unique_ptr<STHDistributor> distributor_; | |
| 48 SignedTreeHead sample_sth_; | |
| 49 }; | |
| 50 | |
| 51 TEST_F(STHDistributorTest, NotifiesOfExistingSTHs) { | |
| 52 SignedTreeHead second_sth(sample_sth_); | |
| 53 second_sth.log_id = std::string(kAnotherLogName); | |
|
Ryan Sleevi
2016/05/12 19:55:06
Doesn't need to be a constant, does it?
Eran Messeri
2016/05/13 09:04:08
Done.
| |
| 54 | |
| 55 distributor_->NewSTHObserved(sample_sth_); | |
| 56 distributor_->NewSTHObserved(second_sth); | |
| 57 | |
| 58 StoringSTHObserver observer; | |
| 59 distributor_->RegisterObserver(&observer); | |
| 60 | |
| 61 EXPECT_EQ(2u, observer.sths.size()); | |
| 62 EXPECT_EQ(1u, observer.sths.count(kAnotherLogName)); | |
|
Ryan Sleevi
2016/05/12 19:55:06
Document what you're testing, and why. You should
Eran Messeri
2016/05/13 09:04:09
Done.
| |
| 63 } | |
| 64 | |
| 65 TEST_F(STHDistributorTest, LogsUMAForPilotSTH) { | |
| 66 base::HistogramTester histograms; | |
| 67 histograms.ExpectTotalCount(kPilotSTHAgeHistogram, 0); | |
| 68 sample_sth_.log_id = std::string(kPilotLogID, crypto::kSHA256Length); | |
| 69 | |
| 70 distributor_->NewSTHObserved(sample_sth_); | |
| 71 histograms.ExpectTotalCount(kPilotSTHAgeHistogram, 1); | |
| 72 } | |
| 73 | |
| 74 } // namespace ct | |
| 75 | |
| 76 } // namespace net | |
| OLD | NEW |