Chromium Code Reviews| Index: chrome/browser/net/chrome_certificate_reporter_unittest.cc |
| diff --git a/chrome/browser/net/chrome_certificate_reporter_unittest.cc b/chrome/browser/net/chrome_certificate_reporter_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fcd4de85d778d303f295779925187430ae69890d |
| --- /dev/null |
| +++ b/chrome/browser/net/chrome_certificate_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/chrome_certificate_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 ChromeCertificateReporter { |
| + public: |
| + explicit TestReporter(net::URLRequestContext* request_context) |
| + : ChromeCertificateReporter(request_context, "") {} |
| + static void BuildReport(const std::string& hostname, |
| + const net::SSLInfo& ssl_info, |
| + CertLoggerRequest& out_request) { |
| + ChromeCertificateReporter::BuildReport(hostname, ssl_info, out_request); |
| + } |
| +}; |
| + |
| +// Test that a built report has the correct data. |
| +TEST(ChromeCertificateReporterTest, 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"); |
| +} |
| + |
|
estark
2015/03/04 17:33:49
I want to add another test here that tests that th
Ryan Sleevi
2015/03/06 19:32:31
Testing the data is as expected is testing the imp
|
| +} // namespace chrome_browser_net |