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

Unified Diff: chrome/browser/ssl/certificate_error_report_unittest.cc

Issue 1117173004: Split cert reporter class into report building/serializing and sending (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move //c/b/ssl classes into global namespace Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/certificate_error_report_unittest.cc
diff --git a/chrome/browser/ssl/certificate_error_report_unittest.cc b/chrome/browser/ssl/certificate_error_report_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ff9b1ba679452169c0ed0c5ea65f069304cff305
--- /dev/null
+++ b/chrome/browser/ssl/certificate_error_report_unittest.cc
@@ -0,0 +1,97 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ssl/certificate_error_report.h"
+
+#include <set>
+#include <string>
+
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/path_service.h"
+#include "chrome/browser/ssl/cert_logger.pb.h"
+#include "chrome/common/chrome_paths.h"
+#include "net/base/test_data_directory.h"
+#include "net/cert/cert_status_flags.h"
+#include "net/ssl/ssl_info.h"
+#include "net/test/cert_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using net::SSLInfo;
+
+namespace {
+
+const char kDummyHostname[] = "dummy.hostname.com";
+const char kDummyFailureLog[] = "dummy failure log";
+const char kTestCertFilename[] = "test_mail_google_com.pem";
+
+const net::CertStatus kCertStatus =
+ net::CERT_STATUS_COMMON_NAME_INVALID | net::CERT_STATUS_REVOKED;
+const size_t kNumCertErrors = 2;
+
+const CertLoggerRequest::CertError kFirstReportedCertError =
+ CertLoggerRequest::ERR_CERT_COMMON_NAME_INVALID;
+const CertLoggerRequest::CertError kSecondReportedCertError =
+ CertLoggerRequest::ERR_CERT_REVOKED;
+
+SSLInfo GetTestSSLInfo() {
+ SSLInfo info;
+ info.cert =
+ net::ImportCertFromFile(net::GetTestCertsDirectory(), kTestCertFilename);
+ info.is_issued_by_known_root = true;
+ info.cert_status = kCertStatus;
+ info.pinning_failure_log = kDummyFailureLog;
+ return info;
+}
+
+std::string GetPEMEncodedChain() {
+ base::FilePath cert_path =
+ net::GetTestCertsDirectory().AppendASCII(kTestCertFilename);
+ std::string cert_data;
+ EXPECT_TRUE(base::ReadFileToString(cert_path, &cert_data));
+ return cert_data;
+}
+
+// Test that a serialized CertificateErrorReport can be deserialized as
+// a CertLoggerRequest protobuf (which is the format that the receiving
+// server expects it in) with the right data in it.
+TEST(CertificateErrorReportTest, SerializedReportAsProtobuf) {
+ SSLInfo ssl_info = GetTestSSLInfo();
+
+ std::string serialized_report;
+ CertificateErrorReport report(kDummyHostname, ssl_info);
+ report.Serialize(&serialized_report);
+
+ CertLoggerRequest deserialized_report;
+ ASSERT_TRUE(deserialized_report.ParseFromString(serialized_report));
+ EXPECT_EQ(kDummyHostname, deserialized_report.hostname());
+ EXPECT_EQ(GetPEMEncodedChain(), deserialized_report.cert_chain());
+ EXPECT_EQ(1, deserialized_report.pin().size());
+ EXPECT_EQ(kDummyFailureLog, deserialized_report.pin().Get(0));
+
+ std::set<CertLoggerRequest::CertError> reported_errors;
+ reported_errors.insert(static_cast<CertLoggerRequest::CertError>(
+ deserialized_report.cert_error().Get(0)));
+ reported_errors.insert(static_cast<CertLoggerRequest::CertError>(
+ deserialized_report.cert_error().Get(1)));
+ EXPECT_EQ(kNumCertErrors, reported_errors.size());
+ EXPECT_EQ(1u, reported_errors.count(kFirstReportedCertError));
+ EXPECT_EQ(1u, reported_errors.count(kSecondReportedCertError));
+}
+
+// Test that a serialized report can be parsed.
+TEST(CertificateErrorReportTest, ParseSerializedReport) {
+ SSLInfo ssl_info = GetTestSSLInfo();
+
+ std::string serialized_report;
+ CertificateErrorReport report(kDummyHostname, ssl_info);
+ EXPECT_EQ(kDummyHostname, report.hostname());
+ report.Serialize(&serialized_report);
+
+ CertificateErrorReport parsed;
+ ASSERT_TRUE(parsed.InitializeFromString(serialized_report));
+ EXPECT_EQ(report.hostname(), parsed.hostname());
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698