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

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: BUILD.gn fix 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..d7434b395969c33ef6766ea48f7375b187beef30
--- /dev/null
+++ b/chrome/browser/ssl/certificate_error_report_unittest.cc
@@ -0,0 +1,84 @@
+// 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 <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/ssl/ssl_info.h"
+#include "net/test/cert_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using chrome_browser_ssl::CertLoggerRequest;
+using chrome_browser_ssl::CertificateErrorReport;
+using net::SSLInfo;
+
+namespace {
+
+const char kDummyHostname[] = "dummy.hostname.com";
+const char kDummyFailureLog[] = "dummy failure log";
+const char kTestCertFilename[] = "test_mail_google_com.pem";
+
+SSLInfo GetTestSSLInfo() {
+ SSLInfo info;
+ info.cert =
+ net::ImportCertFromFile(net::GetTestCertsDirectory(), kTestCertFilename);
+ info.is_issued_by_known_root = true;
+ 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;
+}
+
+class CertificateErrorReportTest : public testing::Test {
+ public:
+ CertificateErrorReportTest() {}
+ ~CertificateErrorReportTest() override {}
+};
+
+// 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_F(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));
+}
+
+// Test that a serialized report can be parsed.
+TEST_F(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