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

Unified Diff: components/certificate_transparency/single_tree_tracker_unittest.cc

Issue 2153123002: Certificate Transparency: Collect metrics on age of SCT vs STH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renaming enum name Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: components/certificate_transparency/single_tree_tracker_unittest.cc
diff --git a/components/certificate_transparency/single_tree_tracker_unittest.cc b/components/certificate_transparency/single_tree_tracker_unittest.cc
index cbdfe6175b8702c1532a6830790c7d2deba04836..b2e42c8390947b5ff6ab33065b08e81a1fcbe1dd 100644
--- a/components/certificate_transparency/single_tree_tracker_unittest.cc
+++ b/components/certificate_transparency/single_tree_tracker_unittest.cc
@@ -8,6 +8,7 @@
#include <utility>
#include "base/strings/string_piece.h"
+#include "base/test/histogram_tester.h"
#include "net/cert/ct_log_verifier.h"
#include "net/cert/ct_serialization.h"
#include "net/cert/signed_certificate_timestamp.h"
@@ -17,6 +18,7 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace certificate_transparency {
+using internal::kCanCheckForInclusionHistogramName;
Ryan Sleevi 2016/07/20 20:34:00 Newline
Eran Messeri 2016/07/21 17:53:43 Done.
namespace {
@@ -75,6 +77,7 @@ class SingleTreeTrackerTest : public ::testing::Test {
// Test that an SCT is classified as pending for a newer STH if the
// SingleTreeTracker has not seen any STHs so far.
TEST_F(SingleTreeTrackerTest, CorrectlyClassifiesUnobservedSCTNoSTH) {
+ base::HistogramTester histograms;
// First make sure the SCT has not been observed at all.
EXPECT_EQ(
SingleTreeTracker::SCT_NOT_OBSERVED,
@@ -87,11 +90,15 @@ TEST_F(SingleTreeTrackerTest, CorrectlyClassifiesUnobservedSCTNoSTH) {
EXPECT_EQ(
SingleTreeTracker::SCT_PENDING_NEWER_STH,
tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
+
+ // Since there's no valid STH expect nothing was logged to UMA.
Ryan Sleevi 2016/07/20 20:34:00 Grammar: Something feels off on this, most likely
Eran Messeri 2016/07/21 17:53:43 Done.
+ histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 0);
}
// Test that an SCT is classified as pending an inclusion check if the
// SingleTreeTracker has a fresh-enough STH to check inclusion against.
TEST_F(SingleTreeTrackerTest, CorrectlyClassifiesUnobservedSCTWithRecentSTH) {
+ base::HistogramTester histograms;
// Provide an STH to the tree_tracker_.
net::ct::SignedTreeHead sth;
net::ct::GetSampleSignedTreeHead(&sth);
@@ -110,18 +117,25 @@ TEST_F(SingleTreeTrackerTest, CorrectlyClassifiesUnobservedSCTWithRecentSTH) {
EXPECT_EQ(
SingleTreeTracker::SCT_PENDING_INCLUSION_CHECK,
tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
+
+ // Exactly one value should be logged, indicating the SCT
+ // can be checked for inclusion.
Ryan Sleevi 2016/07/20 20:34:00 Similarly, this comment doesn't make sense in the
Eran Messeri 2016/07/21 17:53:43 Expanded the comment to document why it's expected
+ histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1);
+ histograms.ExpectBucketCount(kCanCheckForInclusionHistogramName, true, 1);
}
// Test that the SingleTreeTracker correctly queues verified SCTs for inclusion
// checking such that, upon receiving a fresh STH, it changes the SCT's status
// from pending newer STH to pending inclusion check.
TEST_F(SingleTreeTrackerTest, CorrectlyUpdatesSCTStatusOnNewSTH) {
+ base::HistogramTester histograms;
// Report an observed SCT and make sure it's in the pending newer STH
// state.
tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get());
EXPECT_EQ(
SingleTreeTracker::SCT_PENDING_NEWER_STH,
tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
+ histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 0);
// Provide with a fresh STH
net::ct::SignedTreeHead sth;
@@ -132,6 +146,9 @@ TEST_F(SingleTreeTrackerTest, CorrectlyUpdatesSCTStatusOnNewSTH) {
EXPECT_EQ(
SingleTreeTracker::SCT_PENDING_INCLUSION_CHECK,
tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
+ // Check that no UMA was logged for this case as the histogram is only
+ // supposed to measure the state of newly-observed SCTs, not pending ones.
+ histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 0);
}
// Test that the SingleTreeTracker does not change an SCT's status if an STH
@@ -155,4 +172,22 @@ TEST_F(SingleTreeTrackerTest, DoesNotUpdatesSCTStatusOnOldSTH) {
tree_tracker_->GetLogEntryInclusionStatus(chain_.get(), cert_sct_.get()));
}
+// Test that the SingleTreeTracker correctly logs that an SCT is pending a new
+// STH when it has STH but the observed SCT is newer than that.
Ryan Sleevi 2016/07/20 20:34:00 "than that" is ambiguous. grammatically, this rea
Eran Messeri 2016/07/21 17:53:43 Re-worded the comment a bit, removed 'than that' a
+TEST_F(SingleTreeTrackerTest, LogsUMAForNewSCTAndOldSTH) {
+ base::HistogramTester histograms;
+ // Provide an old STH for the same log.
+ net::ct::SignedTreeHead sth;
+ GetOldSignedTreeHead(&sth);
+ tree_tracker_->NewSTHObserved(sth);
+
+ histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 0);
+ // Notify of an SCT and make sure it's in the 'pending newer STH' state.
+ tree_tracker_->OnSCTVerified(chain_.get(), cert_sct_.get());
Ryan Sleevi 2016/07/20 20:34:00 newline between 184-185 and 186-187
Eran Messeri 2016/07/21 17:53:43 Done.
+ // Exactly one value should be logged, indicating the SCT cannot be checked
+ // for inclusion as the STH is too old.
+ histograms.ExpectTotalCount(kCanCheckForInclusionHistogramName, 1);
+ histograms.ExpectBucketCount(kCanCheckForInclusionHistogramName, false, 1);
+}
+
} // namespace certificate_transparency

Powered by Google App Engine
This is Rietveld 408576698