Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: net/cert/sth_distributor_unittest.cc

Issue 1968053002: Certificate Transparency: Notify STH Observers of known STHs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test changed not to rely on fixed tree size Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/cert/sth_distributor.cc ('k') | net/net.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 namespace {
22
23 // An STHObserver implementation that simply stores all
24 // observed STHs, keyed by log ID.
25 class StoringSTHObserver : public STHObserver {
26 public:
27 void NewSTHObserved(const SignedTreeHead& sth) override {
28 sths[sth.log_id] = sth;
29 }
30
31 std::map<std::string, SignedTreeHead> sths;
32 };
33
34 class STHDistributorTest : public ::testing::Test {
35 public:
36 STHDistributorTest() {}
37
38 void SetUp() override {
39 ASSERT_TRUE(GetSampleSignedTreeHead(&sample_sth_));
40 sample_sth_.log_id = GetTestPublicKeyId();
41 }
42
43 protected:
44 STHDistributor distributor_;
45 SignedTreeHead sample_sth_;
46 };
47
48 TEST_F(STHDistributorTest, NotifiesOfExistingSTHs) {
Ryan Sleevi 2016/05/17 17:57:17 Test style - I haven't pushed as hard on this with
Eran Messeri 2016/05/17 21:35:07 Done.
49 const std::string other_log = "another log";
50 SignedTreeHead second_sth(sample_sth_);
51 second_sth.log_id = other_log;
52
53 distributor_.NewSTHObserved(sample_sth_);
54 distributor_.NewSTHObserved(second_sth);
55
56 StoringSTHObserver observer;
57 distributor_.RegisterObserver(&observer);
58
59 // Check that two STHs from different logs received prior to observer
60 // registration were reported to the observer once registered.
61 EXPECT_EQ(2u, observer.sths.size());
62 EXPECT_EQ(1u, observer.sths.count(other_log));
63 }
64
65 TEST_F(STHDistributorTest, LogsUMAForPilotSTH) {
Ryan Sleevi 2016/05/17 17:57:17 // Test that histograms are properly recorded for
Eran Messeri 2016/05/17 21:35:07 Done.
66 const char kPilotSTHAgeHistogram[] =
67 "Net.CertificateTransparency.PilotSTHAge";
68 base::HistogramTester histograms;
69 histograms.ExpectTotalCount(kPilotSTHAgeHistogram, 0);
70
71 const uint8_t kPilotLogID[] = {
72 0xa4, 0xb9, 0x09, 0x90, 0xb4, 0x18, 0x58, 0x14, 0x87, 0xbb, 0x13,
73 0xa2, 0xcc, 0x67, 0x70, 0x0a, 0x3c, 0x35, 0x98, 0x04, 0xf9, 0x1b,
74 0xdf, 0xb8, 0xe3, 0x77, 0xcd, 0x0e, 0xc8, 0x0d, 0xdc, 0x10};
75 sample_sth_.log_id = std::string(reinterpret_cast<const char*>(kPilotLogID),
76 crypto::kSHA256Length);
77
78 distributor_.NewSTHObserved(sample_sth_);
79 histograms.ExpectTotalCount(kPilotSTHAgeHistogram, 1);
80 }
81
82 TEST_F(STHDistributorTest, UpdatesObservedSTHData) {
Ryan Sleevi 2016/05/17 17:57:17 Test that... blah
Eran Messeri 2016/05/17 21:35:07 Done.
83 uint64_t orig_tree_size = sample_sth_.tree_size;
84 distributor_.NewSTHObserved(sample_sth_);
85 sample_sth_.tree_size += 1;
86 distributor_.NewSTHObserved(sample_sth_);
87
88 StoringSTHObserver observer;
89 distributor_.RegisterObserver(&observer);
90 EXPECT_EQ(1u, observer.sths.size());
91 EXPECT_EQ(orig_tree_size + 1, observer.sths[GetTestPublicKeyId()].tree_size);
Ryan Sleevi 2016/05/17 17:57:17 This is even less clear than what you originally h
Eran Messeri 2016/05/17 21:35:07 Done - adapted your suggestion, thanks for providi
92 }
93
94 } // namespace
95
96 } // namespace ct
97
98 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/sth_distributor.cc ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698