| 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
|
|
|