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

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

Issue 1223233002: Common Name Mismatch Handler For WWW Subdomain Mismatch case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 5 years, 4 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/location.h" 9 #include "base/location.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" 22 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
23 #include "chrome/browser/net/certificate_error_reporter.h" 23 #include "chrome/browser/net/certificate_error_reporter.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ssl/cert_logger.pb.h" 25 #include "chrome/browser/ssl/cert_logger.pb.h"
26 #include "chrome/browser/ssl/cert_report_helper.h" 26 #include "chrome/browser/ssl/cert_report_helper.h"
27 #include "chrome/browser/ssl/cert_verifier_browser_test.h" 27 #include "chrome/browser/ssl/cert_verifier_browser_test.h"
28 #include "chrome/browser/ssl/certificate_error_report.h" 28 #include "chrome/browser/ssl/certificate_error_report.h"
29 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" 29 #include "chrome/browser/ssl/certificate_reporting_test_utils.h"
30 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" 30 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
31 #include "chrome/browser/ssl/common_name_mismatch_handler.h"
31 #include "chrome/browser/ssl/ssl_blocking_page.h" 32 #include "chrome/browser/ssl/ssl_blocking_page.h"
33 #include "chrome/browser/ssl/ssl_error_handler.h"
32 #include "chrome/browser/ui/browser.h" 34 #include "chrome/browser/ui/browser.h"
33 #include "chrome/browser/ui/browser_commands.h" 35 #include "chrome/browser/ui/browser_commands.h"
34 #include "chrome/browser/ui/browser_navigator.h" 36 #include "chrome/browser/ui/browser_navigator.h"
35 #include "chrome/browser/ui/browser_tabstrip.h" 37 #include "chrome/browser/ui/browser_tabstrip.h"
36 #include "chrome/browser/ui/tabs/tab_strip_model.h" 38 #include "chrome/browser/ui/tabs/tab_strip_model.h"
37 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
38 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
40 #include "chrome/test/base/in_process_browser_test.h" 42 #include "chrome/test/base/in_process_browser_test.h"
41 #include "chrome/test/base/ui_test_utils.h" 43 #include "chrome/test/base/ui_test_utils.h"
42 #include "components/content_settings/core/browser/host_content_settings_map.h" 44 #include "components/content_settings/core/browser/host_content_settings_map.h"
43 #include "components/security_interstitials/core/metrics_helper.h" 45 #include "components/security_interstitials/core/metrics_helper.h"
44 #include "components/variations/variations_associated_data.h" 46 #include "components/variations/variations_associated_data.h"
45 #include "components/web_modal/web_contents_modal_dialog_manager.h" 47 #include "components/web_modal/web_contents_modal_dialog_manager.h"
46 #include "content/public/browser/browser_context.h" 48 #include "content/public/browser/browser_context.h"
47 #include "content/public/browser/interstitial_page.h" 49 #include "content/public/browser/interstitial_page.h"
48 #include "content/public/browser/navigation_controller.h" 50 #include "content/public/browser/navigation_controller.h"
49 #include "content/public/browser/navigation_entry.h" 51 #include "content/public/browser/navigation_entry.h"
50 #include "content/public/browser/notification_service.h" 52 #include "content/public/browser/notification_service.h"
51 #include "content/public/browser/render_frame_host.h" 53 #include "content/public/browser/render_frame_host.h"
52 #include "content/public/browser/render_view_host.h" 54 #include "content/public/browser/render_view_host.h"
53 #include "content/public/browser/render_widget_host_view.h" 55 #include "content/public/browser/render_widget_host_view.h"
54 #include "content/public/browser/web_contents.h" 56 #include "content/public/browser/web_contents.h"
55 #include "content/public/browser/web_contents_observer.h" 57 #include "content/public/browser/web_contents_observer.h"
56 #include "content/public/common/security_style.h" 58 #include "content/public/common/security_style.h"
57 #include "content/public/common/ssl_status.h" 59 #include "content/public/common/ssl_status.h"
58 #include "content/public/test/browser_test_utils.h" 60 #include "content/public/test/browser_test_utils.h"
59 #include "content/public/test/download_test_observer.h" 61 #include "content/public/test/download_test_observer.h"
62 #include "content/public/test/test_navigation_observer.h"
60 #include "content/public/test/test_renderer_host.h" 63 #include "content/public/test/test_renderer_host.h"
61 #include "net/base/host_port_pair.h" 64 #include "net/base/host_port_pair.h"
62 #include "net/base/net_errors.h" 65 #include "net/base/net_errors.h"
63 #include "net/base/test_data_directory.h" 66 #include "net/base/test_data_directory.h"
64 #include "net/cert/cert_status_flags.h" 67 #include "net/cert/cert_status_flags.h"
65 #include "net/cert/mock_cert_verifier.h" 68 #include "net/cert/mock_cert_verifier.h"
66 #include "net/cert/x509_certificate.h" 69 #include "net/cert/x509_certificate.h"
70 #include "net/dns/mock_host_resolver.h"
67 #include "net/ssl/ssl_info.h" 71 #include "net/ssl/ssl_info.h"
72 #include "net/test/cert_test_util.h"
68 #include "net/test/spawned_test_server/spawned_test_server.h" 73 #include "net/test/spawned_test_server/spawned_test_server.h"
74 #include "net/test/test_certificate_data.h"
69 #include "net/url_request/url_request_context.h" 75 #include "net/url_request/url_request_context.h"
70 76
71 #if defined(USE_NSS_CERTS) 77 #if defined(USE_NSS_CERTS)
72 #include "chrome/browser/net/nss_context.h" 78 #include "chrome/browser/net/nss_context.h"
73 #include "net/base/crypto_module.h" 79 #include "net/base/crypto_module.h"
74 #include "net/cert/nss_cert_database.h" 80 #include "net/cert/nss_cert_database.h"
75 #endif // defined(USE_NSS_CERTS) 81 #endif // defined(USE_NSS_CERTS)
76 82
77 using base::ASCIIToUTF16; 83 using base::ASCIIToUTF16;
78 using chrome_browser_interstitials::SecurityInterstitialIDNTest; 84 using chrome_browser_interstitials::SecurityInterstitialIDNTest;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 content::SecurityStyle expected_security_style, 198 content::SecurityStyle expected_security_style,
193 int expected_authentication_state) { 199 int expected_authentication_state) {
194 ASSERT_FALSE(tab->IsCrashed()); 200 ASSERT_FALSE(tab->IsCrashed());
195 NavigationEntry* entry = tab->GetController().GetActiveEntry(); 201 NavigationEntry* entry = tab->GetController().GetActiveEntry();
196 ASSERT_TRUE(entry); 202 ASSERT_TRUE(entry);
197 CertError::Check(*entry, error); 203 CertError::Check(*entry, error);
198 SecurityStyle::Check(*entry, expected_security_style); 204 SecurityStyle::Check(*entry, expected_security_style);
199 AuthState::Check(*entry, expected_authentication_state); 205 AuthState::Check(*entry, expected_authentication_state);
200 } 206 }
201 207
208 // This observer waits for the SSLErrorHandler to start an interstitial timer
209 // for the given web contents.
210 class SSLInterstitialTimerObserver {
211 public:
212 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents)
213 : web_contents_(web_contents), message_loop_runner_(new base::RunLoop) {
214 callback_ = base::Bind(&SSLInterstitialTimerObserver::OnTimerStarted,
215 base::Unretained(this));
216 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(&callback_);
217 }
218
219 ~SSLInterstitialTimerObserver() {
220 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(nullptr);
221 }
222
223 // Waits until the interstitial delay timer in SSLErrorHandler is started.
224 void WaitForTimerStarted() { message_loop_runner_->Run(); }
225
226 private:
227 void OnTimerStarted(content::WebContents* web_contents) {
228 if (web_contents_ == web_contents)
229 message_loop_runner_->Quit();
230 }
231
232 const content::WebContents* web_contents_;
233 SSLErrorHandler::TimerStartedCallback callback_;
234
235 scoped_ptr<base::RunLoop> message_loop_runner_;
236
237 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver);
238 };
239
202 } // namespace 240 } // namespace
203 241
204 class SSLUITest 242 class SSLUITest
205 : public certificate_reporting_test_utils::CertificateReportingTest { 243 : public certificate_reporting_test_utils::CertificateReportingTest {
206 public: 244 public:
207 SSLUITest() 245 SSLUITest()
208 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, 246 : https_server_(net::SpawnedTestServer::TYPE_HTTPS,
209 SSLOptions(SSLOptions::CERT_OK), 247 SSLOptions(SSLOptions::CERT_OK),
210 base::FilePath(kDocRoot)), 248 base::FilePath(kDocRoot)),
211 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, 249 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS,
(...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after
2260 2298
2261 ProceedThroughInterstitial(tab); 2299 ProceedThroughInterstitial(tab);
2262 EXPECT_TRUE(state->HasAllowException(https_server_host)); 2300 EXPECT_TRUE(state->HasAllowException(https_server_host));
2263 2301
2264 ui_test_utils::NavigateToURL(browser(), 2302 ui_test_utils::NavigateToURL(browser(),
2265 https_server_.GetURL("files/ssl/google.html")); 2303 https_server_.GetURL("files/ssl/google.html"));
2266 ASSERT_FALSE(tab->GetInterstitialPage()); 2304 ASSERT_FALSE(tab->GetInterstitialPage());
2267 EXPECT_FALSE(state->HasAllowException(https_server_host)); 2305 EXPECT_FALSE(state->HasAllowException(https_server_host));
2268 } 2306 }
2269 2307
2308 using CommonNameMismatchBrowserTest = CertVerifierBrowserTest;
2309
2310 // Visit the URL www.mail.example.com on a server that presents a valid
2311 // certificate for mail.example.com. Verify that the page navigates to
2312 // mail.example.com.
2313 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
2314 ShouldShowWWWSubdomainMismatchInterstitial) {
2315 net::SpawnedTestServer https_server_example_domain_(
2316 net::SpawnedTestServer::TYPE_HTTPS,
2317 net::SpawnedTestServer::SSLOptions(
2318 net::SpawnedTestServer::SSLOptions::CERT_OK),
2319 base::FilePath(kDocRoot));
2320 ASSERT_TRUE(https_server_example_domain_.Start());
2321
2322 host_resolver()->AddRule(
2323 "mail.example.com", https_server_example_domain_.host_port_pair().host());
2324 host_resolver()->AddRule(
2325 "www.mail.example.com",
2326 https_server_example_domain_.host_port_pair().host());
2327
2328 scoped_refptr<net::X509Certificate> cert =
2329 https_server_example_domain_.GetCertificate();
2330
2331 // Use the "spdy_pooling.pem" cert which has "mail.example.com"
2332 // as one of its SANs.
2333 net::CertVerifyResult verify_result;
2334 verify_result.verified_cert =
2335 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2336 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
2337
2338 // Request to "www.mail.example.com" should result in
2339 // |net::ERR_CERT_COMMON_NAME_INVALID| error.
2340 mock_cert_verifier()->AddResultForCertAndHost(
2341 cert.get(), "www.mail.example.com", verify_result,
2342 net::ERR_CERT_COMMON_NAME_INVALID);
2343
2344 net::CertVerifyResult verify_result_valid;
2345 verify_result_valid.verified_cert =
2346 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2347 // Request to "www.mail.example.com" should not result in any error.
2348 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com",
2349 verify_result_valid, net::OK);
2350
2351 // Use a complex URL to ensure the path, etc., are preserved. The path itself
2352 // does not matter.
2353 GURL https_server_url =
2354 https_server_example_domain_.GetURL("files/ssl/google.html?a=b#anchor");
2355 GURL::Replacements replacements;
2356 replacements.SetHostStr("www.mail.example.com");
2357 GURL https_server_mismatched_url =
2358 https_server_url.ReplaceComponents(replacements);
2359
2360 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
2361 content::TestNavigationObserver observer(contents, 2);
2362 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url);
2363 observer.Wait();
2364
2365 CheckSecurityState(contents, CertError::NONE,
2366 content::SECURITY_STYLE_AUTHENTICATED, AuthState::NONE);
2367 replacements.SetHostStr("mail.example.com");
2368 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements);
2369 // Verify that the current URL is the suggested URL.
2370 EXPECT_EQ(https_server_new_url.spec(),
2371 contents->GetLastCommittedURL().spec());
2372 }
2373
2374 // Visit the URL example.org on a server that presents a valid certificate
2375 // for www.example.org. Verify that the page redirects to www.example.org.
2376 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
2377 CheckWWWSubdomainMismatchInverse) {
2378 net::SpawnedTestServer https_server_example_domain_(
2379 net::SpawnedTestServer::TYPE_HTTPS,
2380 net::SpawnedTestServer::SSLOptions(
2381 net::SpawnedTestServer::SSLOptions::CERT_OK),
2382 base::FilePath(kDocRoot));
2383 ASSERT_TRUE(https_server_example_domain_.Start());
2384
2385 host_resolver()->AddRule(
2386 "www.example.org", https_server_example_domain_.host_port_pair().host());
2387 host_resolver()->AddRule(
2388 "example.org", https_server_example_domain_.host_port_pair().host());
2389
2390 scoped_refptr<net::X509Certificate> cert =
2391 https_server_example_domain_.GetCertificate();
2392
2393 net::CertVerifyResult verify_result;
2394 verify_result.verified_cert =
2395 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2396 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
2397
2398 mock_cert_verifier()->AddResultForCertAndHost(
2399 cert.get(), "example.org", verify_result,
2400 net::ERR_CERT_COMMON_NAME_INVALID);
2401
2402 net::CertVerifyResult verify_result_valid;
2403 verify_result_valid.verified_cert =
2404 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2405 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "www.example.org",
2406 verify_result_valid, net::OK);
2407
2408 GURL https_server_url =
2409 https_server_example_domain_.GetURL("files/ssl/google.html?a=b");
2410 GURL::Replacements replacements;
2411 replacements.SetHostStr("example.org");
2412 GURL https_server_mismatched_url =
2413 https_server_url.ReplaceComponents(replacements);
2414
2415 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
2416 content::TestNavigationObserver observer(contents, 2);
2417 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url);
2418 observer.Wait();
2419
2420 CheckSecurityState(contents, CertError::NONE,
2421 content::SECURITY_STYLE_AUTHENTICATED, AuthState::NONE);
2422 }
2423
2424 // Tests this scenario:
2425 // - |CommonNameMismatchHandler| does not give a callback as it's set into the
2426 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can
2427 // arrive.
2428 // - A cert error triggers an interstitial timer with a very long timeout.
2429 // - No suggested URL check results arrive, causing the tab to appear as loading
2430 // indefinitely (also because the timer has a long timeout).
2431 // - Stopping the page load shouldn't result in any interstitials.
2432 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
2433 InterstitialStopNavigationWhileLoading) {
2434 net::SpawnedTestServer https_server_example_domain_(
2435 net::SpawnedTestServer::TYPE_HTTPS,
2436 net::SpawnedTestServer::SSLOptions(
2437 net::SpawnedTestServer::SSLOptions::CERT_OK),
2438 base::FilePath(kDocRoot));
2439 ASSERT_TRUE(https_server_example_domain_.Start());
2440
2441 host_resolver()->AddRule(
2442 "mail.example.com", https_server_example_domain_.host_port_pair().host());
2443 host_resolver()->AddRule(
2444 "www.mail.example.com",
2445 https_server_example_domain_.host_port_pair().host());
2446
2447 scoped_refptr<net::X509Certificate> cert =
2448 https_server_example_domain_.GetCertificate();
2449
2450 net::CertVerifyResult verify_result;
2451 verify_result.verified_cert =
2452 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2453 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
2454
2455 mock_cert_verifier()->AddResultForCertAndHost(
2456 cert.get(), "www.mail.example.com", verify_result,
2457 net::ERR_CERT_COMMON_NAME_INVALID);
2458
2459 net::CertVerifyResult verify_result_valid;
2460 verify_result_valid.verified_cert =
2461 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2462 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com",
2463 verify_result_valid, net::OK);
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.mail.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 SSLErrorHandler::SetInterstitialDelayTypeForTest(SSLErrorHandler::LONG);
2476 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
2477
2478 ui_test_utils::NavigateToURLWithDisposition(
2479 browser(), https_server_mismatched_url, CURRENT_TAB,
2480 ui_test_utils::BROWSER_TEST_NONE);
2481 interstitial_timer_observer.WaitForTimerStarted();
2482
2483 EXPECT_TRUE(contents->IsLoading());
2484 content::WindowedNotificationObserver observer(
2485 content::NOTIFICATION_LOAD_STOP,
2486 content::NotificationService::AllSources());
2487 contents->Stop();
2488 observer.Wait();
2489
2490 SSLErrorHandler* ssl_error_handler =
2491 SSLErrorHandler::FromWebContents(contents);
2492 // Make sure that the |SSLErrorHandler| is deleted.
2493 EXPECT_FALSE(ssl_error_handler);
2494 EXPECT_FALSE(contents->ShowingInterstitialPage());
2495 EXPECT_FALSE(contents->IsLoading());
2496 }
2497
2498 // Same as above, but instead of stopping, the loading page is reloaded. The end
2499 // result is the same. (i.e. page load stops, no interstitials shown)
2500 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
2501 InterstitialReloadNavigationWhileLoading) {
2502 net::SpawnedTestServer https_server_example_domain_(
2503 net::SpawnedTestServer::TYPE_HTTPS,
2504 net::SpawnedTestServer::SSLOptions(
2505 net::SpawnedTestServer::SSLOptions::CERT_OK),
2506 base::FilePath(kDocRoot));
2507 ASSERT_TRUE(https_server_example_domain_.Start());
2508
2509 host_resolver()->AddRule(
2510 "mail.example.com", https_server_example_domain_.host_port_pair().host());
2511 host_resolver()->AddRule(
2512 "www.mail.example.com",
2513 https_server_example_domain_.host_port_pair().host());
2514
2515 scoped_refptr<net::X509Certificate> cert =
2516 https_server_example_domain_.GetCertificate();
2517
2518 net::CertVerifyResult verify_result;
2519 verify_result.verified_cert =
2520 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2521 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
2522
2523 mock_cert_verifier()->AddResultForCertAndHost(
2524 cert.get(), "www.mail.example.com", verify_result,
2525 net::ERR_CERT_COMMON_NAME_INVALID);
2526
2527 net::CertVerifyResult verify_result_valid;
2528 verify_result_valid.verified_cert =
2529 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2530 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com",
2531 verify_result_valid, net::OK);
2532
2533 GURL https_server_url =
2534 https_server_example_domain_.GetURL("files/ssl/google.html?a=b");
2535 GURL::Replacements replacements;
2536 replacements.SetHostStr("www.mail.example.com");
2537 GURL https_server_mismatched_url =
2538 https_server_url.ReplaceComponents(replacements);
2539
2540 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
2541 CommonNameMismatchHandler::set_state_for_testing(
2542 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING);
2543 SSLErrorHandler::SetInterstitialDelayTypeForTest(SSLErrorHandler::LONG);
2544 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
2545
2546 ui_test_utils::NavigateToURLWithDisposition(
2547 browser(), https_server_mismatched_url, CURRENT_TAB,
2548 ui_test_utils::BROWSER_TEST_NONE);
2549 interstitial_timer_observer.WaitForTimerStarted();
2550
2551 EXPECT_TRUE(contents->IsLoading());
2552 content::TestNavigationObserver observer(contents, 1);
2553 chrome::Reload(browser(), CURRENT_TAB);
2554 observer.Wait();
2555
2556 SSLErrorHandler* ssl_error_handler =
2557 SSLErrorHandler::FromWebContents(contents);
2558 // Make sure that the |SSLErrorHandler| is deleted.
2559 EXPECT_FALSE(ssl_error_handler);
2560 EXPECT_FALSE(contents->ShowingInterstitialPage());
2561 EXPECT_FALSE(contents->IsLoading());
2562 }
2563
2564 // Same as above, but instead of reloading, the page is navigated away. The
2565 // new page should load, and no interstitials should be shown.
2566 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
2567 InterstitialNavigateAwayWhileLoading) {
2568 net::SpawnedTestServer https_server_example_domain_(
2569 net::SpawnedTestServer::TYPE_HTTPS,
2570 net::SpawnedTestServer::SSLOptions(
2571 net::SpawnedTestServer::SSLOptions::CERT_OK),
2572 base::FilePath(kDocRoot));
2573 ASSERT_TRUE(https_server_example_domain_.Start());
2574
2575 host_resolver()->AddRule(
2576 "mail.example.com", https_server_example_domain_.host_port_pair().host());
2577 host_resolver()->AddRule(
2578 "www.mail.example.com",
2579 https_server_example_domain_.host_port_pair().host());
2580
2581 scoped_refptr<net::X509Certificate> cert =
2582 https_server_example_domain_.GetCertificate();
2583
2584 net::CertVerifyResult verify_result;
2585 verify_result.verified_cert =
2586 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2587 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
2588
2589 mock_cert_verifier()->AddResultForCertAndHost(
2590 cert.get(), "www.mail.example.com", verify_result,
2591 net::ERR_CERT_COMMON_NAME_INVALID);
2592
2593 net::CertVerifyResult verify_result_valid;
2594 verify_result_valid.verified_cert =
2595 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
2596 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com",
2597 verify_result_valid, net::OK);
2598
2599 GURL https_server_url =
2600 https_server_example_domain_.GetURL("files/ssl/google.html?a=b");
2601 GURL::Replacements replacements;
2602 replacements.SetHostStr("www.mail.example.com");
2603 GURL https_server_mismatched_url =
2604 https_server_url.ReplaceComponents(replacements);
2605
2606 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
2607 CommonNameMismatchHandler::set_state_for_testing(
2608 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING);
2609 SSLErrorHandler::SetInterstitialDelayTypeForTest(SSLErrorHandler::LONG);
2610 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
2611
2612 ui_test_utils::NavigateToURLWithDisposition(
2613 browser(), https_server_mismatched_url, CURRENT_TAB,
2614 ui_test_utils::BROWSER_TEST_NONE);
2615 interstitial_timer_observer.WaitForTimerStarted();
2616
2617 EXPECT_TRUE(contents->IsLoading());
2618 content::TestNavigationObserver observer(contents, 1);
2619 browser()->OpenURL(content::OpenURLParams(GURL("https://google.com"),
2620 content::Referrer(), CURRENT_TAB,
2621 ui::PAGE_TRANSITION_TYPED, false));
2622 observer.Wait();
2623
2624 SSLErrorHandler* ssl_error_handler =
2625 SSLErrorHandler::FromWebContents(contents);
2626 // Make sure that the |SSLErrorHandler| is deleted.
2627 EXPECT_FALSE(ssl_error_handler);
2628 EXPECT_FALSE(contents->ShowingInterstitialPage());
2629 EXPECT_FALSE(contents->IsLoading());
2630 }
2631
2270 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { 2632 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest {
2271 protected: 2633 protected:
2272 // SecurityInterstitialIDNTest implementation 2634 // SecurityInterstitialIDNTest implementation
2273 SecurityInterstitialPage* CreateInterstitial( 2635 SecurityInterstitialPage* CreateInterstitial(
2274 content::WebContents* contents, 2636 content::WebContents* contents,
2275 const GURL& request_url) const override { 2637 const GURL& request_url) const override {
2276 net::SSLInfo ssl_info; 2638 net::SSLInfo ssl_info;
2277 ssl_info.cert = new net::X509Certificate( 2639 ssl_info.cert = new net::X509Certificate(
2278 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); 2640 request_url.host(), "CA", base::Time::Max(), base::Time::Max());
2279 return new SSLBlockingPage( 2641 return new SSLBlockingPage(
(...skipping 30 matching lines...) Expand all
2310 2672
2311 // Visit a page over https that contains a frame with a redirect. 2673 // Visit a page over https that contains a frame with a redirect.
2312 2674
2313 // XMLHttpRequest insecure content in synchronous mode. 2675 // XMLHttpRequest insecure content in synchronous mode.
2314 2676
2315 // XMLHttpRequest insecure content in asynchronous mode. 2677 // XMLHttpRequest insecure content in asynchronous mode.
2316 2678
2317 // XMLHttpRequest over bad ssl in synchronous mode. 2679 // XMLHttpRequest over bad ssl in synchronous mode.
2318 2680
2319 // XMLHttpRequest over OK ssl in synchronous mode. 2681 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698