| Index: chrome/browser/net/certificate_error_reporter_unittest.cc
|
| diff --git a/chrome/browser/net/certificate_error_reporter_unittest.cc b/chrome/browser/net/certificate_error_reporter_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..904fb32dfc119e75721f7cb5de4e07efcc8765e4
|
| --- /dev/null
|
| +++ b/chrome/browser/net/certificate_error_reporter_unittest.cc
|
| @@ -0,0 +1,61 @@
|
| +// 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/net/certificate_error_reporter.h"
|
| +
|
| +#include "base/files/file_util.h"
|
| +#include "chrome/browser/net/cert_logger.pb.h"
|
| +#include "content/public/test/test_browser_thread.h"
|
| +#include "net/base/test_data_directory.h"
|
| +#include "net/test/cert_test_util.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +using content::BrowserThread;
|
| +using net::SSLInfo;
|
| +
|
| +namespace chrome_browser_net {
|
| +
|
| +const std::string kHostname = "test.mail.google.com";
|
| +
|
| +static SSLInfo GetSSLInfo() {
|
| + SSLInfo info;
|
| + info.cert = net::ImportCertFromFile(net::GetTestCertsDirectory(),
|
| + "test_mail_google_com.pem");
|
| + info.is_issued_by_known_root = true;
|
| + info.pinning_failure_log = "dummy failure log";
|
| + return info;
|
| +}
|
| +
|
| +static std::string GetPEMEncodedChain() {
|
| + base::FilePath cert_path =
|
| + net::GetTestCertsDirectory().AppendASCII("test_mail_google_com.pem");
|
| + std::string cert_data;
|
| + EXPECT_TRUE(base::ReadFileToString(cert_path, &cert_data));
|
| + return cert_data;
|
| +}
|
| +
|
| +class TestReporter : public CertificateErrorReporter {
|
| + public:
|
| + explicit TestReporter(net::URLRequestContext* request_context)
|
| + : CertificateErrorReporter(request_context, GURL("http://example.com")) {}
|
| + static void BuildReport(const std::string& hostname,
|
| + const net::SSLInfo& ssl_info,
|
| + CertLoggerRequest& out_request) {
|
| + CertificateErrorReporter::BuildReport(hostname, ssl_info, out_request);
|
| + }
|
| +};
|
| +
|
| +// Test that a built report has the correct data.
|
| +TEST(CertificateErrorReporterTest, ReportIsBuiltCorrectly) {
|
| + SSLInfo info = GetSSLInfo();
|
| + CertLoggerRequest request;
|
| + TestReporter::BuildReport(kHostname, info, request);
|
| +
|
| + EXPECT_EQ(request.hostname(), kHostname);
|
| + EXPECT_EQ(request.cert_chain(), GetPEMEncodedChain());
|
| + EXPECT_EQ(request.pin().size(), 1);
|
| + EXPECT_EQ(request.pin().Get(0), "dummy failure log");
|
| +}
|
| +
|
| +} // namespace chrome_browser_net
|
|
|