Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/location.h" | 9 #include "base/location.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" | 21 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" |
| 22 #include "chrome/browser/net/certificate_error_reporter.h" | 22 #include "chrome/browser/net/certificate_error_reporter.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ssl/cert_logger.pb.h" | 24 #include "chrome/browser/ssl/cert_logger.pb.h" |
| 25 #include "chrome/browser/ssl/cert_report_helper.h" | 25 #include "chrome/browser/ssl/cert_report_helper.h" |
| 26 #include "chrome/browser/ssl/certificate_error_report.h" | 26 #include "chrome/browser/ssl/certificate_error_report.h" |
| 27 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" | 27 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" |
| 28 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" | 28 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 29 #include "chrome/browser/ssl/common_name_mismatch_handler.h" | |
| 29 #include "chrome/browser/ssl/ssl_blocking_page.h" | 30 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 31 #include "chrome/browser/ssl/ssl_error_handler.h" | |
| 30 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_commands.h" | 33 #include "chrome/browser/ui/browser_commands.h" |
| 32 #include "chrome/browser/ui/browser_navigator.h" | 34 #include "chrome/browser/ui/browser_navigator.h" |
| 33 #include "chrome/browser/ui/browser_tabstrip.h" | 35 #include "chrome/browser/ui/browser_tabstrip.h" |
| 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 35 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
| 36 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/test/base/in_process_browser_test.h" | 40 #include "chrome/test/base/in_process_browser_test.h" |
| 39 #include "chrome/test/base/ui_test_utils.h" | 41 #include "chrome/test/base/ui_test_utils.h" |
| 40 #include "components/content_settings/core/browser/host_content_settings_map.h" | 42 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 41 #include "components/variations/variations_associated_data.h" | 43 #include "components/variations/variations_associated_data.h" |
| 42 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 44 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 43 #include "content/public/browser/browser_context.h" | 45 #include "content/public/browser/browser_context.h" |
| 44 #include "content/public/browser/interstitial_page.h" | 46 #include "content/public/browser/interstitial_page.h" |
| 45 #include "content/public/browser/navigation_controller.h" | 47 #include "content/public/browser/navigation_controller.h" |
| 46 #include "content/public/browser/navigation_entry.h" | 48 #include "content/public/browser/navigation_entry.h" |
| 47 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
| 48 #include "content/public/browser/render_frame_host.h" | 50 #include "content/public/browser/render_frame_host.h" |
| 49 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
| 50 #include "content/public/browser/render_widget_host_view.h" | 52 #include "content/public/browser/render_widget_host_view.h" |
| 51 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/browser/web_contents_observer.h" | 54 #include "content/public/browser/web_contents_observer.h" |
| 53 #include "content/public/common/security_style.h" | 55 #include "content/public/common/security_style.h" |
| 54 #include "content/public/common/ssl_status.h" | 56 #include "content/public/common/ssl_status.h" |
| 55 #include "content/public/test/browser_test_utils.h" | 57 #include "content/public/test/browser_test_utils.h" |
| 56 #include "content/public/test/download_test_observer.h" | 58 #include "content/public/test/download_test_observer.h" |
| 59 #include "content/public/test/test_navigation_observer.h" | |
| 57 #include "content/public/test/test_renderer_host.h" | 60 #include "content/public/test/test_renderer_host.h" |
| 58 #include "net/base/host_port_pair.h" | 61 #include "net/base/host_port_pair.h" |
| 59 #include "net/base/net_errors.h" | 62 #include "net/base/net_errors.h" |
| 60 #include "net/base/test_data_directory.h" | 63 #include "net/base/test_data_directory.h" |
| 61 #include "net/cert/cert_status_flags.h" | 64 #include "net/cert/cert_status_flags.h" |
| 62 #include "net/cert/x509_certificate.h" | 65 #include "net/cert/x509_certificate.h" |
| 66 #include "net/dns/mock_host_resolver.h" | |
| 63 #include "net/ssl/ssl_info.h" | 67 #include "net/ssl/ssl_info.h" |
| 64 #include "net/test/spawned_test_server/spawned_test_server.h" | 68 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 69 #include "net/test/test_certificate_data.h" | |
| 65 #include "net/url_request/url_request_context.h" | 70 #include "net/url_request/url_request_context.h" |
| 66 | 71 |
| 67 #if defined(USE_NSS_CERTS) | 72 #if defined(USE_NSS_CERTS) |
| 68 #include "chrome/browser/net/nss_context.h" | 73 #include "chrome/browser/net/nss_context.h" |
| 69 #include "net/base/crypto_module.h" | 74 #include "net/base/crypto_module.h" |
| 70 #include "net/cert/nss_cert_database.h" | 75 #include "net/cert/nss_cert_database.h" |
| 71 #endif // defined(USE_NSS_CERTS) | 76 #endif // defined(USE_NSS_CERTS) |
| 72 | 77 |
| 73 using base::ASCIIToUTF16; | 78 using base::ASCIIToUTF16; |
| 74 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 79 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 SSLOptions(SSLOptions::CERT_OK), | 205 SSLOptions(SSLOptions::CERT_OK), |
| 201 base::FilePath(kDocRoot)), | 206 base::FilePath(kDocRoot)), |
| 202 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, | 207 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, |
| 203 SSLOptions(SSLOptions::CERT_EXPIRED), | 208 SSLOptions(SSLOptions::CERT_EXPIRED), |
| 204 base::FilePath(kDocRoot)), | 209 base::FilePath(kDocRoot)), |
| 205 https_server_mismatched_(net::SpawnedTestServer::TYPE_HTTPS, | 210 https_server_mismatched_(net::SpawnedTestServer::TYPE_HTTPS, |
| 206 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME), | 211 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME), |
| 207 base::FilePath(kDocRoot)), | 212 base::FilePath(kDocRoot)), |
| 208 wss_server_expired_(net::SpawnedTestServer::TYPE_WSS, | 213 wss_server_expired_(net::SpawnedTestServer::TYPE_WSS, |
| 209 SSLOptions(SSLOptions::CERT_EXPIRED), | 214 SSLOptions(SSLOptions::CERT_EXPIRED), |
| 210 net::GetWebSocketTestDataDirectory()) {} | 215 net::GetWebSocketTestDataDirectory()), |
| 216 https_server_example_domain_( | |
| 217 net::SpawnedTestServer::TYPE_HTTPS, | |
| 218 SSLOptions(SSLOptions::CERT_EXAMPLE_DOMAIN), | |
| 219 base::FilePath(kDocRoot)), | |
| 220 https_server_www_example_domain_( | |
| 221 net::SpawnedTestServer::TYPE_HTTPS, | |
| 222 SSLOptions(SSLOptions::CERT_WWW_EXAMPLE_DOMAIN), | |
| 223 base::FilePath(kDocRoot)) {} | |
| 211 | 224 |
| 212 void SetUpCommandLine(base::CommandLine* command_line) override { | 225 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 213 // Browser will both run and display insecure content. | 226 // Browser will both run and display insecure content. |
| 214 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); | 227 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); |
| 215 // Use process-per-site so that navigating to a same-site page in a | 228 // Use process-per-site so that navigating to a same-site page in a |
| 216 // new tab will use the same process. | 229 // new tab will use the same process. |
| 217 command_line->AppendSwitch(switches::kProcessPerSite); | 230 command_line->AppendSwitch(switches::kProcessPerSite); |
| 218 } | 231 } |
| 219 | 232 |
| 220 void CheckAuthenticatedState(WebContents* tab, | 233 void CheckAuthenticatedState(WebContents* tab, |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 GetLatestHostnameReported()); | 432 GetLatestHostnameReported()); |
| 420 } else { | 433 } else { |
| 421 EXPECT_EQ(std::string(), GetLatestHostnameReported()); | 434 EXPECT_EQ(std::string(), GetLatestHostnameReported()); |
| 422 } | 435 } |
| 423 } | 436 } |
| 424 | 437 |
| 425 net::SpawnedTestServer https_server_; | 438 net::SpawnedTestServer https_server_; |
| 426 net::SpawnedTestServer https_server_expired_; | 439 net::SpawnedTestServer https_server_expired_; |
| 427 net::SpawnedTestServer https_server_mismatched_; | 440 net::SpawnedTestServer https_server_mismatched_; |
| 428 net::SpawnedTestServer wss_server_expired_; | 441 net::SpawnedTestServer wss_server_expired_; |
| 442 net::SpawnedTestServer https_server_example_domain_; | |
| 443 net::SpawnedTestServer https_server_www_example_domain_; | |
| 429 | 444 |
| 430 private: | 445 private: |
| 431 typedef net::SpawnedTestServer::SSLOptions SSLOptions; | 446 typedef net::SpawnedTestServer::SSLOptions SSLOptions; |
| 432 | 447 |
| 433 DISALLOW_COPY_AND_ASSIGN(SSLUITest); | 448 DISALLOW_COPY_AND_ASSIGN(SSLUITest); |
| 434 }; | 449 }; |
| 435 | 450 |
| 436 class SSLUITestBlock : public SSLUITest { | 451 class SSLUITestBlock : public SSLUITest { |
| 437 public: | 452 public: |
| 438 SSLUITestBlock() : SSLUITest() {} | 453 SSLUITestBlock() : SSLUITest() {} |
| (...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2217 | 2232 |
| 2218 ProceedThroughInterstitial(tab); | 2233 ProceedThroughInterstitial(tab); |
| 2219 EXPECT_TRUE(state->HasAllowException(https_server_host)); | 2234 EXPECT_TRUE(state->HasAllowException(https_server_host)); |
| 2220 | 2235 |
| 2221 ui_test_utils::NavigateToURL(browser(), | 2236 ui_test_utils::NavigateToURL(browser(), |
| 2222 https_server_.GetURL("files/ssl/google.html")); | 2237 https_server_.GetURL("files/ssl/google.html")); |
| 2223 ASSERT_FALSE(tab->GetInterstitialPage()); | 2238 ASSERT_FALSE(tab->GetInterstitialPage()); |
| 2224 EXPECT_FALSE(state->HasAllowException(https_server_host)); | 2239 EXPECT_FALSE(state->HasAllowException(https_server_host)); |
| 2225 } | 2240 } |
| 2226 | 2241 |
| 2242 // Verifies that invoking the SSL Blocking page with a suggested URL displays | |
| 2243 // the common name mismatch interstitial with a link to suggested URL. | |
| 2244 IN_PROC_BROWSER_TEST_F(SSLUITest, SSLBlockingPageWithSuggestedURL) { | |
| 2245 content::WebContents* contents = | |
| 2246 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2247 net::SSLInfo ssl_info; | |
| 2248 ssl_info.cert = net::X509Certificate::CreateFromBytes( | |
| 2249 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | |
| 2250 // Create a new SSL blocking page for https://example.com with | |
| 2251 // https://www.example.com as the suggested URL. | |
| 2252 SSLBlockingPage* blocking_page = new SSLBlockingPage( | |
| 2253 contents, net::ERR_CERT_COMMON_NAME_INVALID, ssl_info, | |
| 2254 GURL("https://example.com"), 0, base::Time::NowFromSystemTime(), nullptr, | |
| 2255 base::Callback<void(bool)>(), GURL("https://www.example.com")); | |
| 2256 blocking_page->Show(); | |
| 2257 | |
| 2258 WaitForInterstitialAttach(contents); | |
| 2259 | |
| 2260 EXPECT_TRUE( | |
| 2261 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | |
| 2262 // The interstitial should display a link to www.example.com | |
| 2263 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
| 2264 contents->GetInterstitialPage(), "www.example.com")); | |
| 2265 // Verify that the link has the text "suggest-link", the id of the | |
| 2266 // link element displayed. | |
| 2267 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
| 2268 contents->GetInterstitialPage(), "suggest-link")); | |
| 2269 } | |
| 2270 | |
| 2271 // Visit the URL www.example.com on a server that presents a valid certificate | |
| 2272 // for example.com. Verify that the common name mismatch interstitial is | |
| 2273 // displayed with a link to example.com. Click the suggested URL link | |
| 2274 // and make sure the page navigates to a non SSL page. | |
|
meacer
2015/07/30 19:40:21
"non SSL page" isn't correct, suggested url is an
Bhanu Dev
2015/07/31 00:07:16
Done.
| |
| 2275 IN_PROC_BROWSER_TEST_F(SSLUITest, ShouldShowWWWSubdomainMismatchInterstitial) { | |
| 2276 // Starts a server with a valid certificate for "example.com". | |
| 2277 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2278 | |
| 2279 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 2280 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | |
| 2281 | |
| 2282 // The path does not matter. | |
| 2283 GURL https_server_url = | |
| 2284 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2285 GURL::Replacements replacements; | |
| 2286 replacements.SetHostStr("www.example.com"); | |
| 2287 GURL https_server_mismatched_url = | |
| 2288 https_server_url.ReplaceComponents(replacements); | |
| 2289 | |
| 2290 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
| 2291 | |
| 2292 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2293 WaitForInterstitialAttach(contents); | |
| 2294 // An interstitial should be displayed with a | |
| 2295 // |CERT_STATUS_COMMON_NAME_INVALID| error. | |
| 2296 CheckAuthenticationBrokenState(contents, net::CERT_STATUS_COMMON_NAME_INVALID, | |
| 2297 AuthState::SHOWING_INTERSTITIAL); | |
| 2298 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() | |
| 2299 ->GetDelegateForTesting() | |
| 2300 ->GetTypeForTesting()); | |
| 2301 | |
| 2302 content::RenderFrameHost* rfh = | |
| 2303 contents->GetInterstitialPage()->GetMainFrame(); | |
| 2304 EXPECT_TRUE(WaitForRenderFrameReady(rfh)); | |
| 2305 // The interstitial should display a link to www.example.com | |
| 2306 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
| 2307 contents->GetInterstitialPage(), "example.com")); | |
| 2308 // Verify that the link has the text "suggest-link", the id of the | |
| 2309 // link element displayed. | |
| 2310 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
| 2311 contents->GetInterstitialPage(), "suggest-link")); | |
| 2312 | |
| 2313 const char kClickConnectButtonJS[] = | |
|
meacer
2015/07/30 19:40:21
ConnectButton -> OpenSuggestedButton?
Bhanu Dev
2015/07/31 00:07:15
Done.
| |
| 2314 "document.getElementById('suggest-link').click();"; | |
| 2315 | |
|
meacer
2015/07/30 19:40:21
Remove blank line. Just a single blank line before
Bhanu Dev
2015/07/31 00:07:15
Done.
| |
| 2316 content::TestNavigationObserver observer(contents, 1); | |
| 2317 EXPECT_TRUE(content::ExecuteScript(rfh, kClickConnectButtonJS)); | |
| 2318 observer.Wait(); | |
| 2319 | |
| 2320 CheckAuthenticatedState(contents, AuthState::NONE); | |
| 2321 | |
|
meacer
2015/07/30 19:40:21
Remove blank line
Bhanu Dev
2015/07/31 00:07:16
Done.
| |
| 2322 replacements.SetHostStr("example.com"); | |
| 2323 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements); | |
| 2324 // Verify that the current URL is the suggested URL. | |
| 2325 EXPECT_EQ(https_server_new_url.spec(), | |
| 2326 contents->GetLastCommittedURL().spec()); | |
| 2327 } | |
| 2328 | |
| 2329 // Visit the URL example.com on a server that presents a valid certificate | |
| 2330 // for www.example.com. Verify that the common name mismatch interstitial is | |
| 2331 // displayed with a link to www.example.com. | |
| 2332 IN_PROC_BROWSER_TEST_F(SSLUITest, CheckWWWSubdomainMismatchInverse) { | |
| 2333 // Starts a server with a valid certificate for "example.com". | |
| 2334 ASSERT_TRUE(https_server_www_example_domain_.Start()); | |
| 2335 | |
| 2336 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 2337 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | |
| 2338 | |
| 2339 GURL https_server_url = | |
| 2340 https_server_www_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2341 GURL::Replacements replacements; | |
| 2342 replacements.SetHostStr("example.com"); | |
| 2343 GURL https_server_mismatched_url = | |
| 2344 https_server_url.ReplaceComponents(replacements); | |
| 2345 | |
| 2346 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
| 2347 | |
| 2348 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2349 WaitForInterstitialAttach(contents); | |
| 2350 CheckAuthenticationBrokenState(contents, net::CERT_STATUS_COMMON_NAME_INVALID, | |
| 2351 AuthState::SHOWING_INTERSTITIAL); | |
| 2352 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() | |
| 2353 ->GetDelegateForTesting() | |
| 2354 ->GetTypeForTesting()); | |
| 2355 | |
| 2356 EXPECT_TRUE( | |
| 2357 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); | |
| 2358 // The interstitial should display a link to www.example.com | |
| 2359 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
| 2360 contents->GetInterstitialPage(), "www.example.com")); | |
| 2361 // Verify that the link has the text "suggest-link", the id of the | |
| 2362 // link element displayed. | |
| 2363 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( | |
| 2364 contents->GetInterstitialPage(), "suggest-link")); | |
| 2365 } | |
| 2366 | |
| 2367 // This observer waits for the SSLErrorHandler to start an interstitial timer | |
| 2368 // for the given web contents. | |
| 2369 class SSLInterstitialTimerObserver { | |
| 2370 public: | |
| 2371 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents); | |
| 2372 ~SSLInterstitialTimerObserver(); | |
| 2373 | |
| 2374 // Waits until the interstitial delay timer in SSLErrorHandler is started. | |
| 2375 void WaitForTimerStarted(); | |
| 2376 | |
| 2377 private: | |
| 2378 void OnTimerStarted(content::WebContents* web_contents); | |
| 2379 | |
| 2380 const content::WebContents* web_contents_; | |
| 2381 SSLErrorHandler::TimerStartedCallback callback_; | |
| 2382 | |
| 2383 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 2384 | |
| 2385 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); | |
| 2386 }; | |
| 2387 | |
| 2388 SSLInterstitialTimerObserver::SSLInterstitialTimerObserver( | |
| 2389 content::WebContents* web_contents) | |
| 2390 : web_contents_(web_contents), | |
| 2391 message_loop_runner_(new content::MessageLoopRunner) { | |
| 2392 callback_ = base::Bind(&SSLInterstitialTimerObserver::OnTimerStarted, | |
| 2393 base::Unretained(this)); | |
| 2394 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(&callback_); | |
| 2395 } | |
| 2396 | |
| 2397 SSLInterstitialTimerObserver::~SSLInterstitialTimerObserver() { | |
| 2398 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(nullptr); | |
| 2399 } | |
| 2400 | |
| 2401 void SSLInterstitialTimerObserver::WaitForTimerStarted() { | |
| 2402 message_loop_runner_->Run(); | |
| 2403 } | |
| 2404 | |
| 2405 void SSLInterstitialTimerObserver::OnTimerStarted( | |
| 2406 content::WebContents* web_contents) { | |
| 2407 if (web_contents_ == web_contents && message_loop_runner_.get()) | |
| 2408 message_loop_runner_->Quit(); | |
| 2409 } | |
| 2410 | |
| 2411 // Tests this scenario: | |
| 2412 // - |CommonNameMismatchHandler| does not give a callback as it's set into the | |
| 2413 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can | |
| 2414 // arrive. | |
| 2415 // - A cert error triggers an interstitial timer with a very long timeout. | |
| 2416 // - No suggested URL check results arrive, causing the tab to appear as loading | |
| 2417 // indefinitely (also because the timer has a long timeout). | |
| 2418 // - Stopping the page load shouldn't result in any interstitials. | |
| 2419 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialStopNavigationWhileLoading) { | |
| 2420 // Starts a server with a valid certificate for "example.com". | |
| 2421 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2422 | |
| 2423 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 2424 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | |
| 2425 | |
| 2426 GURL https_server_url = | |
| 2427 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2428 GURL::Replacements replacements; | |
| 2429 replacements.SetHostStr("www.example.com"); | |
| 2430 GURL https_server_mismatched_url = | |
| 2431 https_server_url.ReplaceComponents(replacements); | |
| 2432 | |
| 2433 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2434 CommonNameMismatchHandler::set_state_for_testing( | |
| 2435 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
| 2436 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 2437 | |
| 2438 ui_test_utils::NavigateToURLWithDisposition( | |
| 2439 browser(), https_server_mismatched_url, CURRENT_TAB, | |
| 2440 ui_test_utils::BROWSER_TEST_NONE); | |
| 2441 interstitial_timer_observer.WaitForTimerStarted(); | |
| 2442 | |
| 2443 EXPECT_TRUE(contents->IsLoading()); | |
| 2444 content::WindowedNotificationObserver observer( | |
| 2445 content::NOTIFICATION_LOAD_STOP, | |
| 2446 content::NotificationService::AllSources()); | |
| 2447 contents->Stop(); | |
| 2448 observer.Wait(); | |
| 2449 | |
| 2450 SSLErrorHandler* ssl_error_handler = | |
| 2451 SSLErrorHandler::FromWebContents(contents); | |
| 2452 // Make sure that the |SSLErrorHandler| is deleted. | |
| 2453 EXPECT_FALSE(ssl_error_handler); | |
| 2454 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 2455 EXPECT_FALSE(contents->IsLoading()); | |
| 2456 } | |
| 2457 | |
| 2458 // Same as above, but instead of stopping, the loading page is reloaded. The end | |
| 2459 // result is the same. (i.e. page load stops, no interstitials shown) | |
| 2460 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialReloadNavigationWhileLoading) { | |
| 2461 // Starts a server with a valid certificate for "example.com". | |
| 2462 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2463 | |
| 2464 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 2465 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | |
| 2466 | |
| 2467 GURL https_server_url = | |
| 2468 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2469 GURL::Replacements replacements; | |
| 2470 replacements.SetHostStr("www.example.com"); | |
| 2471 GURL https_server_mismatched_url = | |
| 2472 https_server_url.ReplaceComponents(replacements); | |
| 2473 | |
| 2474 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2475 CommonNameMismatchHandler::set_state_for_testing( | |
| 2476 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
| 2477 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 2478 | |
| 2479 ui_test_utils::NavigateToURLWithDisposition( | |
| 2480 browser(), https_server_mismatched_url, CURRENT_TAB, | |
| 2481 ui_test_utils::BROWSER_TEST_NONE); | |
| 2482 interstitial_timer_observer.WaitForTimerStarted(); | |
| 2483 | |
| 2484 EXPECT_TRUE(contents->IsLoading()); | |
| 2485 content::TestNavigationObserver observer(contents, 1); | |
| 2486 chrome::Reload(browser(), CURRENT_TAB); | |
| 2487 observer.Wait(); | |
| 2488 | |
| 2489 SSLErrorHandler* ssl_error_handler = | |
| 2490 SSLErrorHandler::FromWebContents(contents); | |
| 2491 // Make sure that the |SSLErrorHandler| is deleted. | |
| 2492 EXPECT_FALSE(ssl_error_handler); | |
| 2493 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 2494 EXPECT_FALSE(contents->IsLoading()); | |
| 2495 } | |
| 2496 | |
| 2497 // Same as above, but instead of reloading, the page is navigated away. The | |
| 2498 // new page should load, and no interstitials should be shown. | |
| 2499 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNavigateAwayWhileLoading) { | |
| 2500 // Starts a server with a valid certificate for "example.com". | |
| 2501 ASSERT_TRUE(https_server_example_domain_.Start()); | |
| 2502 | |
| 2503 host_resolver()->AddRule("example.com", "127.0.0.1"); | |
| 2504 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | |
| 2505 | |
| 2506 GURL https_server_url = | |
| 2507 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
| 2508 GURL::Replacements replacements; | |
| 2509 replacements.SetHostStr("www.example.com"); | |
| 2510 GURL https_server_mismatched_url = | |
| 2511 https_server_url.ReplaceComponents(replacements); | |
| 2512 | |
| 2513 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2514 CommonNameMismatchHandler::set_state_for_testing( | |
| 2515 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
| 2516 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
| 2517 | |
| 2518 ui_test_utils::NavigateToURLWithDisposition( | |
| 2519 browser(), https_server_mismatched_url, CURRENT_TAB, | |
| 2520 ui_test_utils::BROWSER_TEST_NONE); | |
| 2521 interstitial_timer_observer.WaitForTimerStarted(); | |
| 2522 | |
| 2523 EXPECT_TRUE(contents->IsLoading()); | |
| 2524 content::TestNavigationObserver observer(contents, 1); | |
| 2525 browser()->OpenURL(content::OpenURLParams(GURL("https://google.com"), | |
| 2526 content::Referrer(), CURRENT_TAB, | |
| 2527 ui::PAGE_TRANSITION_TYPED, false)); | |
| 2528 observer.Wait(); | |
| 2529 | |
| 2530 SSLErrorHandler* ssl_error_handler = | |
| 2531 SSLErrorHandler::FromWebContents(contents); | |
| 2532 // Make sure that the |SSLErrorHandler| is deleted. | |
| 2533 EXPECT_FALSE(ssl_error_handler); | |
| 2534 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
| 2535 EXPECT_FALSE(contents->IsLoading()); | |
| 2536 } | |
| 2537 | |
| 2227 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { | 2538 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { |
| 2228 protected: | 2539 protected: |
| 2229 // SecurityInterstitialIDNTest implementation | 2540 // SecurityInterstitialIDNTest implementation |
| 2230 SecurityInterstitialPage* CreateInterstitial( | 2541 SecurityInterstitialPage* CreateInterstitial( |
| 2231 content::WebContents* contents, | 2542 content::WebContents* contents, |
| 2232 const GURL& request_url) const override { | 2543 const GURL& request_url) const override { |
| 2233 net::SSLInfo ssl_info; | 2544 net::SSLInfo ssl_info; |
| 2234 ssl_info.cert = new net::X509Certificate( | 2545 ssl_info.cert = new net::X509Certificate( |
| 2235 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 2546 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
| 2236 return new SSLBlockingPage( | 2547 return new SSLBlockingPage(contents, net::ERR_CERT_CONTAINS_ERRORS, |
| 2237 contents, net::ERR_CERT_CONTAINS_ERRORS, ssl_info, request_url, 0, | 2548 ssl_info, request_url, 0, |
| 2238 base::Time::NowFromSystemTime(), nullptr, base::Callback<void(bool)>()); | 2549 base::Time::NowFromSystemTime(), nullptr, |
| 2550 base::Callback<void(bool)>(), GURL()); | |
| 2239 } | 2551 } |
| 2240 }; | 2552 }; |
| 2241 | 2553 |
| 2242 IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest, SSLBlockingPageDecodesIDN) { | 2554 IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest, SSLBlockingPageDecodesIDN) { |
| 2243 EXPECT_TRUE(VerifyIDNDecoded()); | 2555 EXPECT_TRUE(VerifyIDNDecoded()); |
| 2244 } | 2556 } |
| 2245 | 2557 |
| 2246 // TODO(jcampan): more tests to do below. | 2558 // TODO(jcampan): more tests to do below. |
| 2247 | 2559 |
| 2248 // Visit a page over https that contains a frame with a redirect. | 2560 // Visit a page over https that contains a frame with a redirect. |
| 2249 | 2561 |
| 2250 // XMLHttpRequest insecure content in synchronous mode. | 2562 // XMLHttpRequest insecure content in synchronous mode. |
| 2251 | 2563 |
| 2252 // XMLHttpRequest insecure content in asynchronous mode. | 2564 // XMLHttpRequest insecure content in asynchronous mode. |
| 2253 | 2565 |
| 2254 // XMLHttpRequest over bad ssl in synchronous mode. | 2566 // XMLHttpRequest over bad ssl in synchronous mode. |
| 2255 | 2567 |
| 2256 // XMLHttpRequest over OK ssl in synchronous mode. | 2568 // XMLHttpRequest over OK ssl in synchronous mode. |
| OLD | NEW |