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

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

Issue 1035023002: Adding the Finch code for the certificate error reporter experiment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix logic bug and add test for invalid Finch param value Created 5 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h"
9 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
10 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" 18 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
18 #include "chrome/browser/net/certificate_error_reporter.h" 19 #include "chrome/browser/net/certificate_error_reporter.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/safe_browsing/ping_manager.h" 21 #include "chrome/browser/safe_browsing/ping_manager.h"
21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
22 #include "chrome/browser/ssl/ssl_blocking_page.h" 23 #include "chrome/browser/ssl/ssl_blocking_page.h"
23 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_commands.h" 25 #include "chrome/browser/ui/browser_commands.h"
25 #include "chrome/browser/ui/browser_navigator.h" 26 #include "chrome/browser/ui/browser_navigator.h"
26 #include "chrome/browser/ui/browser_tabstrip.h" 27 #include "chrome/browser/ui/browser_tabstrip.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/common/chrome_paths.h" 29 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "chrome/test/base/in_process_browser_test.h" 32 #include "chrome/test/base/in_process_browser_test.h"
32 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
33 #include "components/content_settings/core/browser/host_content_settings_map.h" 34 #include "components/content_settings/core/browser/host_content_settings_map.h"
35 #include "components/variations/variations_associated_data.h"
34 #include "components/web_modal/web_contents_modal_dialog_manager.h" 36 #include "components/web_modal/web_contents_modal_dialog_manager.h"
35 #include "content/public/browser/browser_context.h" 37 #include "content/public/browser/browser_context.h"
36 #include "content/public/browser/interstitial_page.h" 38 #include "content/public/browser/interstitial_page.h"
37 #include "content/public/browser/navigation_controller.h" 39 #include "content/public/browser/navigation_controller.h"
38 #include "content/public/browser/navigation_entry.h" 40 #include "content/public/browser/navigation_entry.h"
39 #include "content/public/browser/notification_service.h" 41 #include "content/public/browser/notification_service.h"
40 #include "content/public/browser/render_frame_host.h" 42 #include "content/public/browser/render_frame_host.h"
41 #include "content/public/browser/render_view_host.h" 43 #include "content/public/browser/render_view_host.h"
42 #include "content/public/browser/render_widget_host_view.h" 44 #include "content/public/browser/render_widget_host_view.h"
43 #include "content/public/browser/web_contents.h" 45 #include "content/public/browser/web_contents.h"
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 468
467 if (expect_report == CertificateReporting::CERT_REPORT_EXPECTED) { 469 if (expect_report == CertificateReporting::CERT_REPORT_EXPECTED) {
468 // Check that the mock reporter received a request to send a report. 470 // Check that the mock reporter received a request to send a report.
469 EXPECT_EQ(https_server_expired_.GetURL("/").host(), 471 EXPECT_EQ(https_server_expired_.GetURL("/").host(),
470 reporter_->latest_hostname_reported()); 472 reporter_->latest_hostname_reported());
471 } else { 473 } else {
472 EXPECT_EQ(std::string(), reporter_->latest_hostname_reported()); 474 EXPECT_EQ(std::string(), reporter_->latest_hostname_reported());
473 } 475 }
474 } 476 }
475 477
478 // Helper function to set the Finch parameter for HTTPS error reporting
479 std::map<std::string, std::string> SetFinchPossiblySendParam(
estark 2015/04/02 19:55:56 As a matter of style, I don't think we're generall
fahl 2015/04/02 21:38:04 Done.
480 const std::string value) {
481 std::map<std::string, std::string> params;
482 params["possibly_send"] = value;
483 return params;
484 }
485
476 net::SpawnedTestServer https_server_; 486 net::SpawnedTestServer https_server_;
477 net::SpawnedTestServer https_server_expired_; 487 net::SpawnedTestServer https_server_expired_;
478 net::SpawnedTestServer https_server_mismatched_; 488 net::SpawnedTestServer https_server_mismatched_;
479 net::SpawnedTestServer wss_server_expired_; 489 net::SpawnedTestServer wss_server_expired_;
480 490
481 private: 491 private:
482 typedef net::SpawnedTestServer::SSLOptions SSLOptions; 492 typedef net::SpawnedTestServer::SSLOptions SSLOptions;
483 CertificateReporting::MockReporter* reporter_; 493 CertificateReporting::MockReporter* reporter_;
484 494
485 DISALLOW_COPY_AND_ASSIGN(SSLUITest); 495 DISALLOW_COPY_AND_ASSIGN(SSLUITest);
(...skipping 25 matching lines...) Expand all
511 521
512 void SetUpCommandLine(base::CommandLine* command_line) override { 522 void SetUpCommandLine(base::CommandLine* command_line) override {
513 // Browser will ignore certificate errors on localhost. 523 // Browser will ignore certificate errors on localhost.
514 command_line->AppendSwitch(switches::kAllowInsecureLocalhost); 524 command_line->AppendSwitch(switches::kAllowInsecureLocalhost);
515 } 525 }
516 }; 526 };
517 527
518 class SSLUITestWithExtendedReporting : public SSLUITest { 528 class SSLUITestWithExtendedReporting : public SSLUITest {
519 public: 529 public:
520 SSLUITestWithExtendedReporting() : SSLUITest() {} 530 SSLUITestWithExtendedReporting() : SSLUITest() {}
521
522 void SetUpCommandLine(base::CommandLine* command_line) override {
523 // Enable a checkbox on SSL interstitials that allows users to opt
524 // in to reporting invalid certificate chains.
525 command_line->AppendSwitch(switches::kEnableInvalidCertCollection);
526 }
527 }; 531 };
528 532
529 // Visits a regular page over http. 533 // Visits a regular page over http.
530 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) { 534 IN_PROC_BROWSER_TEST_F(SSLUITest, TestHTTP) {
531 ASSERT_TRUE(test_server()->Start()); 535 ASSERT_TRUE(test_server()->Start());
532 536
533 ui_test_utils::NavigateToURL(browser(), 537 ui_test_utils::NavigateToURL(browser(),
534 test_server()->GetURL("files/ssl/google.html")); 538 test_server()->GetURL("files/ssl/google.html"));
535 539
536 CheckUnauthenticatedState( 540 CheckUnauthenticatedState(
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 &replacement_path)); 1120 &replacement_path));
1117 1121
1118 // Load a page that displays insecure content. 1122 // Load a page that displays insecure content.
1119 ui_test_utils::NavigateToURL(browser(), 1123 ui_test_utils::NavigateToURL(browser(),
1120 https_server_.GetURL(replacement_path)); 1124 https_server_.GetURL(replacement_path));
1121 1125
1122 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(), 1126 CheckAuthenticatedState(browser()->tab_strip_model()->GetActiveWebContents(),
1123 AuthState::DISPLAYED_INSECURE_CONTENT); 1127 AuthState::DISPLAYED_INSECURE_CONTENT);
1124 } 1128 }
1125 1129
1126 // Test that when the checkbox is checked and the user proceeds through 1130 // User proceeds, checkbox is shown and checked, Finch parameter is set
1127 // the interstitial, the FraudulentCertificateReporter sees a request to 1131 // -> we expect a report.
1128 // send a report. 1132 IN_PROC_BROWSER_TEST_F(
1129 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1133 SSLUITestWithExtendedReporting,
1130 TestBrokenHTTPSProceedWithReporting) { 1134 TestBrokenHTTPSProceedWithShowYesCheckYesParamYesReportYes) {
1135 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
estark 2015/04/02 19:55:56 nit: the "ReportCertificateErrors" and group name
fahl 2015/04/02 21:38:04 Done.
1136 "ShowAndPossiblySend");
1137 variations::AssociateVariationParams("ReportCertificateErrors",
1138 "ShowAndPossiblySend",
1139 SetFinchPossiblySendParam("1.0"));
1131 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1140 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1132 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1141 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1133 CertificateReporting::CERT_REPORT_EXPECTED, 1142 CertificateReporting::CERT_REPORT_EXPECTED,
1134 browser()); 1143 browser());
1135 } 1144 }
1136 1145
1137 // Test that when the checkbox is checked and the user goes back (does 1146 // User goes back, checkbox is shown and checked, Finch parameter is set
1138 // not proceed through the interstitial), the 1147 // -> we expect a report.
1139 // FraudulentCertificateReporter sees a request to send a report. 1148 IN_PROC_BROWSER_TEST_F(
1140 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1149 SSLUITestWithExtendedReporting,
1141 TestBrokenHTTPSGoBackWithReporting) { 1150 TestBrokenHTTPSGoBackWithShowYesCheckYesParamYesReportYes) {
1151 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1152 "ShowAndPossiblySend");
1153 variations::AssociateVariationParams("ReportCertificateErrors",
1154 "ShowAndPossiblySend",
1155 SetFinchPossiblySendParam("1.0"));
1142 TestBrokenHTTPSReporting( 1156 TestBrokenHTTPSReporting(
1143 CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1157 CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1144 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED, 1158 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED,
1145 CertificateReporting::CERT_REPORT_EXPECTED, browser()); 1159 CertificateReporting::CERT_REPORT_EXPECTED, browser());
1146 } 1160 }
1147 1161
1148 // Test that when the checkbox is not checked and the user proceeds 1162 // User proceeds, checkbox is shown but unchecked, Finch parameter is set
1149 // through the interstitial, the FraudulentCertificateReporter does not 1163 // -> we expect no report.
1150 // see a request to send a report. 1164 IN_PROC_BROWSER_TEST_F(
1151 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1165 SSLUITestWithExtendedReporting,
1152 TestBrokenHTTPSProceedWithNoReporting) { 1166 TestBrokenHTTPSProceedWithShowYesCheckNoParamYesReportNo) {
1167 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1168 "ShowAndPossiblySend");
1169 variations::AssociateVariationParams("ReportCertificateErrors",
1170 "ShowAndPossiblySend",
1171 SetFinchPossiblySendParam("1.0"));
1153 TestBrokenHTTPSReporting( 1172 TestBrokenHTTPSReporting(
1154 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN, 1173 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN,
1155 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1174 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1156 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser()); 1175 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser());
1157 } 1176 }
1158 1177
1159 // Test that when the checkbox is not checked and the user does not proceed 1178 // User goes back, checkbox is shown but unchecked, Finch parameter is set
1160 // through the interstitial, the FraudulentCertificateReporter does not 1179 // -> we expect no report.
1161 // see a request to send a report.
1162 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1180 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1163 TestBrokenHTTPSGoBackWithNoReporting) { 1181 TestBrokenHTTPSGoBackShowYesCheckNoParamYesReportNo) {
1182 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1183 "ShowAndPossiblySend");
1184 variations::AssociateVariationParams("ReportCertificateErrors",
1185 "ShowAndPossiblySend",
1186 SetFinchPossiblySendParam("1.0"));
1164 TestBrokenHTTPSReporting( 1187 TestBrokenHTTPSReporting(
1165 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN, 1188 CertificateReporting::EXTENDED_REPORTING_DO_NOT_OPT_IN,
1166 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED, 1189 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED,
1167 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser()); 1190 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser());
1168 } 1191 }
1169 1192
1170 // Test that when the command-line switch for reporting invalid cert 1193 // User proceeds, checkbox is shown and checked, Finch parameter is not
1171 // chains is not enabled, reports don't get sent, even if the opt-in 1194 // set -> we expect no report.
1172 // preference is set. (i.e. if a user enables invalid cert collection in 1195 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1173 // chrome://flags, checks the box on an interstitial, and then disables 1196 TestBrokenHTTPSProceedShowYesCheckYesParamNoReportNo) {
1174 // the flag in chrome://flags, reports shouldn't be sent on the next 1197 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1175 // interstitial). 1198 "ShowAndPossiblySend");
1176 IN_PROC_BROWSER_TEST_F(SSLUITest, TestBrokenHTTPSNoReportingWithoutSwitch) { 1199 variations::AssociateVariationParams("ReportCertificateErrors",
1200 "ShowAndPossiblySend",
1201 SetFinchPossiblySendParam("-1.0"));
1177 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1202 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1178 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1203 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1179 CertificateReporting::CERT_REPORT_NOT_EXPECTED, 1204 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1180 browser()); 1205 browser());
1181 } 1206 }
1182 1207
1183 // Test that reports don't get sent in incognito mode even if the opt-in 1208 // User goes back, checkbox is shown and checked, Finch parameter is not set
1184 // preference is set and the command-line switch is enabled. 1209 // -> we expect no report.
1185 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting, 1210 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1186 TestBrokenHTTPSNoReportingInIncognito) { 1211 TestBrokenHTTPSGoBackShowYesCheckYesParamNoReportNo) {
1212 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1213 "ShowAndPossiblySend");
1214 variations::AssociateVariationParams("ReportCertificateErrors",
1215 "ShowAndPossiblySend",
1216 SetFinchPossiblySendParam("-1.0"));
1217 TestBrokenHTTPSReporting(
1218 CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1219 CertificateReporting::SSL_INTERSTITIAL_DO_NOT_PROCEED,
1220 CertificateReporting::CERT_REPORT_NOT_EXPECTED, browser());
1221 }
1222
1223 // User proceeds, checkbox is not shown but checked -> we expect no report
1224 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1225 TestBrokenHTTPSProceedShowNoCheckYesReportNo) {
1226 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1227 "DontShowAndDontSend");
1228 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1229 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1230 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1231 browser());
1232 }
1233
1234 // Browser is incognito, user proceeds, checkbox is shown and checked, Finch
1235 // parameter is set -> we expect no report
1236 IN_PROC_BROWSER_TEST_F(SSLUITestWithExtendedReporting,
1237 TestBrokenHTTPSInIncognitoReportNo) {
1238 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1239 "ShowAndPossiblySend");
1240 variations::AssociateVariationParams("ReportCertificateErrors",
1241 "ShowAndPossiblySend",
1242 SetFinchPossiblySendParam("1.0"));
1187 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN, 1243 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1188 CertificateReporting::SSL_INTERSTITIAL_PROCEED, 1244 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1189 CertificateReporting::CERT_REPORT_NOT_EXPECTED, 1245 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1190 CreateIncognitoBrowser()); 1246 CreateIncognitoBrowser());
1191 } 1247 }
1192 1248
1249 // User proceeds, checkbox is shown and checked, Finch parameter is invalid
1250 // -> we expect no report.
1251 IN_PROC_BROWSER_TEST_F(
1252 SSLUITestWithExtendedReporting,
1253 TestBrokenHTTPSProceedWithShowYesCheckYesParamInvalidReportNo) {
1254 base::FieldTrialList::CreateFieldTrial("ReportCertificateErrors",
1255 "ShowAndPossiblySend");
1256 variations::AssociateVariationParams("ReportCertificateErrors",
1257 "ShowAndPossiblySend",
1258 SetFinchPossiblySendParam("abcdef"));
1259 TestBrokenHTTPSReporting(CertificateReporting::EXTENDED_REPORTING_OPT_IN,
1260 CertificateReporting::SSL_INTERSTITIAL_PROCEED,
1261 CertificateReporting::CERT_REPORT_NOT_EXPECTED,
1262 browser());
1263 }
1264
1193 // Visits a page that runs insecure content and tries to suppress the insecure 1265 // Visits a page that runs insecure content and tries to suppress the insecure
1194 // content warnings by randomizing location.hash. 1266 // content warnings by randomizing location.hash.
1195 // Based on http://crbug.com/8706 1267 // Based on http://crbug.com/8706
1196 IN_PROC_BROWSER_TEST_F(SSLUITest, 1268 IN_PROC_BROWSER_TEST_F(SSLUITest,
1197 TestRunsInsecuredContentRandomizeHash) { 1269 TestRunsInsecuredContentRandomizeHash) {
1198 ASSERT_TRUE(test_server()->Start()); 1270 ASSERT_TRUE(test_server()->Start());
1199 ASSERT_TRUE(https_server_.Start()); 1271 ASSERT_TRUE(https_server_.Start());
1200 1272
1201 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL( 1273 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL(
1202 "files/ssl/page_runs_insecure_content.html")); 1274 "files/ssl/page_runs_insecure_content.html"));
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
2152 2224
2153 // Visit a page over https that contains a frame with a redirect. 2225 // Visit a page over https that contains a frame with a redirect.
2154 2226
2155 // XMLHttpRequest insecure content in synchronous mode. 2227 // XMLHttpRequest insecure content in synchronous mode.
2156 2228
2157 // XMLHttpRequest insecure content in asynchronous mode. 2229 // XMLHttpRequest insecure content in asynchronous mode.
2158 2230
2159 // XMLHttpRequest over bad ssl in synchronous mode. 2231 // XMLHttpRequest over bad ssl in synchronous mode.
2160 2232
2161 // XMLHttpRequest over OK ssl in synchronous mode. 2233 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698