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

Side by Side Diff: chrome/browser/ssl/certificate_reporting_test_utils.cc

Issue 1211933005: Initial (partial) implementation of HPKP violation reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: style fixes, comments Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" 5 #include "chrome/browser/ssl/certificate_reporting_test_utils.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/safe_browsing/ping_manager.h" 14 #include "chrome/browser/safe_browsing/ping_manager.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
16 #include "chrome/browser/safe_browsing/ui_manager.h" 16 #include "chrome/browser/safe_browsing/ui_manager.h"
17 #include "chrome/browser/ssl/cert_report_helper.h" 17 #include "chrome/browser/ssl/cert_report_helper.h"
18 #include "chrome/browser/ssl/certificate_error_report.h" 18 #include "chrome/browser/ssl/certificate_error_report.h"
19 #include "chrome/browser/ssl/ssl_cert_reporter.h" 19 #include "chrome/browser/ssl/ssl_cert_reporter.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "components/variations/variations_associated_data.h" 22 #include "components/variations/variations_associated_data.h"
23 #include "net/http/certificate_report_sender.h"
23 #include "net/url_request/url_request_context.h" 24 #include "net/url_request/url_request_context.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 #include "url/gurl.h" 26 #include "url/gurl.h"
26 27
27 using chrome_browser_net::CertificateErrorReporter; 28 using chrome_browser_net::CertificateErrorReporter;
28 29
29 namespace { 30 namespace {
30 31
31 void SetMockReporter(SafeBrowsingService* safe_browsing_service, 32 void SetMockReporter(SafeBrowsingService* safe_browsing_service,
32 scoped_ptr<CertificateErrorReporter> reporter) { 33 scoped_ptr<CertificateErrorReporter> reporter) {
33 safe_browsing_service->ping_manager()->SetCertificateErrorReporterForTesting( 34 safe_browsing_service->ping_manager()->SetCertificateErrorReporterForTesting(
34 reporter.Pass()); 35 reporter.Pass());
35 } 36 }
36 37
37 } // namespace 38 } // namespace
38 39
39 namespace CertificateReportingTestUtils { 40 namespace CertificateReportingTestUtils {
40 41
41 // This class is used to test invalid certificate chain reporting when 42 // This class is used to test invalid certificate chain reporting when
42 // the user opts in to do so on the interstitial. It keeps track of the 43 // the user opts in to do so on the interstitial. It keeps track of the
43 // most recent hostname for which a report would have been sent over the 44 // most recent hostname for which a report would have been sent over the
44 // network. 45 // network.
45 class MockReporter : public chrome_browser_net::CertificateErrorReporter { 46 class MockReporter : public chrome_browser_net::CertificateErrorReporter {
46 public: 47 public:
47 MockReporter(net::URLRequestContext* request_context, 48 MockReporter(
48 const GURL& upload_url, 49 net::URLRequestContext* request_context,
49 CookiesPreference cookies_preference); 50 const GURL& upload_url,
51 net::CertificateReportSender::CookiesPreference cookies_preference);
50 52
51 // CertificateErrorReporter implementation 53 // CertificateErrorReporter implementation
52 void SendReport(CertificateErrorReporter::ReportType type, 54 void SendReport(CertificateErrorReporter::ReportType type,
53 const std::string& serialized_report) override; 55 const std::string& serialized_report) override;
54 56
55 // Returns the hostname in the report for the last call to 57 // Returns the hostname in the report for the last call to
56 // |SendReport|. 58 // |SendReport|.
57 const std::string& latest_hostname_reported() { 59 const std::string& latest_hostname_reported() {
58 return latest_hostname_reported_; 60 return latest_hostname_reported_;
59 } 61 }
60 62
61 private: 63 private:
62 std::string latest_hostname_reported_; 64 std::string latest_hostname_reported_;
63 65
64 DISALLOW_COPY_AND_ASSIGN(MockReporter); 66 DISALLOW_COPY_AND_ASSIGN(MockReporter);
65 }; 67 };
66 68
67 MockReporter::MockReporter(net::URLRequestContext* request_context, 69 MockReporter::MockReporter(
68 const GURL& upload_url, 70 net::URLRequestContext* request_context,
69 CookiesPreference cookies_preference) 71 const GURL& upload_url,
72 net::CertificateReportSender::CookiesPreference cookies_preference)
70 : CertificateErrorReporter(request_context, 73 : CertificateErrorReporter(request_context,
71 upload_url, 74 upload_url,
72 cookies_preference) { 75 cookies_preference) {
73 } 76 }
74 77
75 void MockReporter::SendReport(CertificateErrorReporter::ReportType type, 78 void MockReporter::SendReport(CertificateErrorReporter::ReportType type,
76 const std::string& serialized_report) { 79 const std::string& serialized_report) {
77 CertificateErrorReport report; 80 CertificateErrorReport report;
78 ASSERT_TRUE(report.InitializeFromString(serialized_report)); 81 ASSERT_TRUE(report.InitializeFromString(serialized_report));
79 EXPECT_EQ(CertificateErrorReporter::REPORT_TYPE_EXTENDED_REPORTING, type); 82 EXPECT_EQ(CertificateErrorReporter::REPORT_TYPE_EXTENDED_REPORTING, type);
80 latest_hostname_reported_ = report.hostname(); 83 latest_hostname_reported_ = report.hostname();
81 } 84 }
82 85
83 void CertificateReportingTest::SetUpMockReporter() { 86 void CertificateReportingTest::SetUpMockReporter() {
84 // Set up the mock reporter to track the hostnames that reports get 87 // Set up the mock reporter to track the hostnames that reports get
85 // sent for. The request_context argument is null here 88 // sent for. The request_context argument is null here
86 // because the MockReporter doesn't actually use a 89 // because the MockReporter doesn't actually use a
87 // request_context. (In order to pass a real request_context, the 90 // request_context. (In order to pass a real request_context, the
88 // reporter would have to be constructed on the IO thread.) 91 // reporter would have to be constructed on the IO thread.)
89 reporter_ = new MockReporter(nullptr, GURL("http://example.test"), 92 reporter_ =
90 MockReporter::DO_NOT_SEND_COOKIES); 93 new MockReporter(nullptr, GURL("http://example.test"),
94 net::CertificateReportSender::DO_NOT_SEND_COOKIES);
91 95
92 scoped_refptr<SafeBrowsingService> safe_browsing_service = 96 scoped_refptr<SafeBrowsingService> safe_browsing_service =
93 g_browser_process->safe_browsing_service(); 97 g_browser_process->safe_browsing_service();
94 ASSERT_TRUE(safe_browsing_service); 98 ASSERT_TRUE(safe_browsing_service);
95 99
96 content::BrowserThread::PostTask( 100 content::BrowserThread::PostTask(
97 content::BrowserThread::IO, FROM_HERE, 101 content::BrowserThread::IO, FROM_HERE,
98 base::Bind( 102 base::Bind(
99 SetMockReporter, safe_browsing_service, 103 SetMockReporter, safe_browsing_service,
100 base::Passed(scoped_ptr<CertificateErrorReporter>(reporter_)))); 104 base::Passed(scoped_ptr<CertificateErrorReporter>(reporter_))));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 group_name, params); 179 group_name, params);
176 } 180 }
177 } 181 }
178 182
179 // Helper function to set the Finch options in case we have no parameter. 183 // Helper function to set the Finch options in case we have no parameter.
180 void SetCertReportingFinchConfig(const std::string& group_name) { 184 void SetCertReportingFinchConfig(const std::string& group_name) {
181 SetCertReportingFinchConfig(group_name, std::string()); 185 SetCertReportingFinchConfig(group_name, std::string());
182 } 186 }
183 187
184 } // namespace CertificateReportingTestUtils 188 } // namespace CertificateReportingTestUtils
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/ping_manager.cc ('k') | chrome/browser/ssl/chrome_fraudulent_certificate_reporter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698