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 suggested URL. |
| 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 kOpenSuggestedLinkJS[] = |
| 2314 "document.getElementById('suggest-link').click();"; |
| 2315 content::TestNavigationObserver observer(contents, 1); |
| 2316 EXPECT_TRUE(content::ExecuteScript(rfh, kClickConnectButtonJS)); |
| 2317 observer.Wait(); |
| 2318 |
| 2319 CheckAuthenticatedState(contents, AuthState::NONE); |
| 2320 replacements.SetHostStr("example.com"); |
| 2321 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements); |
| 2322 // Verify that the current URL is the suggested URL. |
| 2323 EXPECT_EQ(https_server_new_url.spec(), |
| 2324 contents->GetLastCommittedURL().spec()); |
| 2325 } |
| 2326 |
| 2327 // Visit the URL example.com on a server that presents a valid certificate |
| 2328 // for www.example.com. Verify that the common name mismatch interstitial is |
| 2329 // displayed with a link to www.example.com. |
| 2330 IN_PROC_BROWSER_TEST_F(SSLUITest, CheckWWWSubdomainMismatchInverse) { |
| 2331 // Starts a server with a valid certificate for "example.com". |
| 2332 ASSERT_TRUE(https_server_www_example_domain_.Start()); |
| 2333 |
| 2334 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2335 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2336 |
| 2337 GURL https_server_url = |
| 2338 https_server_www_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2339 GURL::Replacements replacements; |
| 2340 replacements.SetHostStr("example.com"); |
| 2341 GURL https_server_mismatched_url = |
| 2342 https_server_url.ReplaceComponents(replacements); |
| 2343 |
| 2344 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); |
| 2345 |
| 2346 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2347 WaitForInterstitialAttach(contents); |
| 2348 CheckAuthenticationBrokenState(contents, net::CERT_STATUS_COMMON_NAME_INVALID, |
| 2349 AuthState::SHOWING_INTERSTITIAL); |
| 2350 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, contents->GetInterstitialPage() |
| 2351 ->GetDelegateForTesting() |
| 2352 ->GetTypeForTesting()); |
| 2353 |
| 2354 EXPECT_TRUE( |
| 2355 WaitForRenderFrameReady(contents->GetInterstitialPage()->GetMainFrame())); |
| 2356 // The interstitial should display a link to www.example.com |
| 2357 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2358 contents->GetInterstitialPage(), "www.example.com")); |
| 2359 // Verify that the link has the text "suggest-link", the id of the |
| 2360 // link element displayed. |
| 2361 EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText( |
| 2362 contents->GetInterstitialPage(), "suggest-link")); |
| 2363 } |
| 2364 |
| 2365 // This observer waits for the SSLErrorHandler to start an interstitial timer |
| 2366 // for the given web contents. |
| 2367 class SSLInterstitialTimerObserver { |
| 2368 public: |
| 2369 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents); |
| 2370 ~SSLInterstitialTimerObserver(); |
| 2371 |
| 2372 // Waits until the interstitial delay timer in SSLErrorHandler is started. |
| 2373 void WaitForTimerStarted(); |
| 2374 |
| 2375 private: |
| 2376 void OnTimerStarted(content::WebContents* web_contents); |
| 2377 |
| 2378 const content::WebContents* web_contents_; |
| 2379 SSLErrorHandler::TimerStartedCallback callback_; |
| 2380 |
| 2381 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 2382 |
| 2383 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); |
| 2384 }; |
| 2385 |
| 2386 SSLInterstitialTimerObserver::SSLInterstitialTimerObserver( |
| 2387 content::WebContents* web_contents) |
| 2388 : web_contents_(web_contents), |
| 2389 message_loop_runner_(new content::MessageLoopRunner) { |
| 2390 callback_ = base::Bind(&SSLInterstitialTimerObserver::OnTimerStarted, |
| 2391 base::Unretained(this)); |
| 2392 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(&callback_); |
| 2393 } |
| 2394 |
| 2395 SSLInterstitialTimerObserver::~SSLInterstitialTimerObserver() { |
| 2396 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(nullptr); |
| 2397 } |
| 2398 |
| 2399 void SSLInterstitialTimerObserver::WaitForTimerStarted() { |
| 2400 message_loop_runner_->Run(); |
| 2401 } |
| 2402 |
| 2403 void SSLInterstitialTimerObserver::OnTimerStarted( |
| 2404 content::WebContents* web_contents) { |
| 2405 if (web_contents_ == web_contents && message_loop_runner_.get()) |
| 2406 message_loop_runner_->Quit(); |
| 2407 } |
| 2408 |
| 2409 // Tests this scenario: |
| 2410 // - |CommonNameMismatchHandler| does not give a callback as it's set into the |
| 2411 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can |
| 2412 // arrive. |
| 2413 // - A cert error triggers an interstitial timer with a very long timeout. |
| 2414 // - No suggested URL check results arrive, causing the tab to appear as loading |
| 2415 // indefinitely (also because the timer has a long timeout). |
| 2416 // - Stopping the page load shouldn't result in any interstitials. |
| 2417 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialStopNavigationWhileLoading) { |
| 2418 // Starts a server with a valid certificate for "example.com". |
| 2419 ASSERT_TRUE(https_server_example_domain_.Start()); |
| 2420 |
| 2421 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2422 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2423 |
| 2424 GURL https_server_url = |
| 2425 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2426 GURL::Replacements replacements; |
| 2427 replacements.SetHostStr("www.example.com"); |
| 2428 GURL https_server_mismatched_url = |
| 2429 https_server_url.ReplaceComponents(replacements); |
| 2430 |
| 2431 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2432 CommonNameMismatchHandler::set_state_for_testing( |
| 2433 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); |
| 2434 SSLInterstitialTimerObserver interstitial_timer_observer(contents); |
| 2435 |
| 2436 ui_test_utils::NavigateToURLWithDisposition( |
| 2437 browser(), https_server_mismatched_url, CURRENT_TAB, |
| 2438 ui_test_utils::BROWSER_TEST_NONE); |
| 2439 interstitial_timer_observer.WaitForTimerStarted(); |
| 2440 |
| 2441 EXPECT_TRUE(contents->IsLoading()); |
| 2442 content::WindowedNotificationObserver observer( |
| 2443 content::NOTIFICATION_LOAD_STOP, |
| 2444 content::NotificationService::AllSources()); |
| 2445 contents->Stop(); |
| 2446 observer.Wait(); |
| 2447 |
| 2448 SSLErrorHandler* ssl_error_handler = |
| 2449 SSLErrorHandler::FromWebContents(contents); |
| 2450 // Make sure that the |SSLErrorHandler| is deleted. |
| 2451 EXPECT_FALSE(ssl_error_handler); |
| 2452 EXPECT_FALSE(contents->ShowingInterstitialPage()); |
| 2453 EXPECT_FALSE(contents->IsLoading()); |
| 2454 } |
| 2455 |
| 2456 // Same as above, but instead of stopping, the loading page is reloaded. The end |
| 2457 // result is the same. (i.e. page load stops, no interstitials shown) |
| 2458 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialReloadNavigationWhileLoading) { |
| 2459 // Starts a server with a valid certificate for "example.com". |
| 2460 ASSERT_TRUE(https_server_example_domain_.Start()); |
| 2461 |
| 2462 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2463 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2464 |
| 2465 GURL https_server_url = |
| 2466 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2467 GURL::Replacements replacements; |
| 2468 replacements.SetHostStr("www.example.com"); |
| 2469 GURL https_server_mismatched_url = |
| 2470 https_server_url.ReplaceComponents(replacements); |
| 2471 |
| 2472 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2473 CommonNameMismatchHandler::set_state_for_testing( |
| 2474 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); |
| 2475 SSLInterstitialTimerObserver interstitial_timer_observer(contents); |
| 2476 |
| 2477 ui_test_utils::NavigateToURLWithDisposition( |
| 2478 browser(), https_server_mismatched_url, CURRENT_TAB, |
| 2479 ui_test_utils::BROWSER_TEST_NONE); |
| 2480 interstitial_timer_observer.WaitForTimerStarted(); |
| 2481 |
| 2482 EXPECT_TRUE(contents->IsLoading()); |
| 2483 content::TestNavigationObserver observer(contents, 1); |
| 2484 chrome::Reload(browser(), CURRENT_TAB); |
| 2485 observer.Wait(); |
| 2486 |
| 2487 SSLErrorHandler* ssl_error_handler = |
| 2488 SSLErrorHandler::FromWebContents(contents); |
| 2489 // Make sure that the |SSLErrorHandler| is deleted. |
| 2490 EXPECT_FALSE(ssl_error_handler); |
| 2491 EXPECT_FALSE(contents->ShowingInterstitialPage()); |
| 2492 EXPECT_FALSE(contents->IsLoading()); |
| 2493 } |
| 2494 |
| 2495 // Same as above, but instead of reloading, the page is navigated away. The |
| 2496 // new page should load, and no interstitials should be shown. |
| 2497 IN_PROC_BROWSER_TEST_F(SSLUITest, InterstitialNavigateAwayWhileLoading) { |
| 2498 // Starts a server with a valid certificate for "example.com". |
| 2499 ASSERT_TRUE(https_server_example_domain_.Start()); |
| 2500 |
| 2501 host_resolver()->AddRule("example.com", "127.0.0.1"); |
| 2502 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 2503 |
| 2504 GURL https_server_url = |
| 2505 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); |
| 2506 GURL::Replacements replacements; |
| 2507 replacements.SetHostStr("www.example.com"); |
| 2508 GURL https_server_mismatched_url = |
| 2509 https_server_url.ReplaceComponents(replacements); |
| 2510 |
| 2511 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2512 CommonNameMismatchHandler::set_state_for_testing( |
| 2513 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); |
| 2514 SSLInterstitialTimerObserver interstitial_timer_observer(contents); |
| 2515 |
| 2516 ui_test_utils::NavigateToURLWithDisposition( |
| 2517 browser(), https_server_mismatched_url, CURRENT_TAB, |
| 2518 ui_test_utils::BROWSER_TEST_NONE); |
| 2519 interstitial_timer_observer.WaitForTimerStarted(); |
| 2520 |
| 2521 EXPECT_TRUE(contents->IsLoading()); |
| 2522 content::TestNavigationObserver observer(contents, 1); |
| 2523 browser()->OpenURL(content::OpenURLParams(GURL("https://google.com"), |
| 2524 content::Referrer(), CURRENT_TAB, |
| 2525 ui::PAGE_TRANSITION_TYPED, false)); |
| 2526 observer.Wait(); |
| 2527 |
| 2528 SSLErrorHandler* ssl_error_handler = |
| 2529 SSLErrorHandler::FromWebContents(contents); |
| 2530 // Make sure that the |SSLErrorHandler| is deleted. |
| 2531 EXPECT_FALSE(ssl_error_handler); |
| 2532 EXPECT_FALSE(contents->ShowingInterstitialPage()); |
| 2533 EXPECT_FALSE(contents->IsLoading()); |
| 2534 } |
| 2535 |
2227 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { | 2536 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { |
2228 protected: | 2537 protected: |
2229 // SecurityInterstitialIDNTest implementation | 2538 // SecurityInterstitialIDNTest implementation |
2230 SecurityInterstitialPage* CreateInterstitial( | 2539 SecurityInterstitialPage* CreateInterstitial( |
2231 content::WebContents* contents, | 2540 content::WebContents* contents, |
2232 const GURL& request_url) const override { | 2541 const GURL& request_url) const override { |
2233 net::SSLInfo ssl_info; | 2542 net::SSLInfo ssl_info; |
2234 ssl_info.cert = new net::X509Certificate( | 2543 ssl_info.cert = new net::X509Certificate( |
2235 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 2544 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
2236 return new SSLBlockingPage( | 2545 return new SSLBlockingPage(contents, net::ERR_CERT_CONTAINS_ERRORS, |
2237 contents, net::ERR_CERT_CONTAINS_ERRORS, ssl_info, request_url, 0, | 2546 ssl_info, request_url, 0, |
2238 base::Time::NowFromSystemTime(), nullptr, base::Callback<void(bool)>()); | 2547 base::Time::NowFromSystemTime(), nullptr, |
| 2548 base::Callback<void(bool)>(), GURL()); |
2239 } | 2549 } |
2240 }; | 2550 }; |
2241 | 2551 |
2242 IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest, SSLBlockingPageDecodesIDN) { | 2552 IN_PROC_BROWSER_TEST_F(SSLBlockingPageIDNTest, SSLBlockingPageDecodesIDN) { |
2243 EXPECT_TRUE(VerifyIDNDecoded()); | 2553 EXPECT_TRUE(VerifyIDNDecoded()); |
2244 } | 2554 } |
2245 | 2555 |
2246 // TODO(jcampan): more tests to do below. | 2556 // TODO(jcampan): more tests to do below. |
2247 | 2557 |
2248 // Visit a page over https that contains a frame with a redirect. | 2558 // Visit a page over https that contains a frame with a redirect. |
2249 | 2559 |
2250 // XMLHttpRequest insecure content in synchronous mode. | 2560 // XMLHttpRequest insecure content in synchronous mode. |
2251 | 2561 |
2252 // XMLHttpRequest insecure content in asynchronous mode. | 2562 // XMLHttpRequest insecure content in asynchronous mode. |
2253 | 2563 |
2254 // XMLHttpRequest over bad ssl in synchronous mode. | 2564 // XMLHttpRequest over bad ssl in synchronous mode. |
2255 | 2565 |
2256 // XMLHttpRequest over OK ssl in synchronous mode. | 2566 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |