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" |
(...skipping 10 matching lines...) Expand all Loading... | |
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 content::SecurityStyle expected_security_style, | 193 content::SecurityStyle expected_security_style, |
188 int expected_authentication_state) { | 194 int expected_authentication_state) { |
189 ASSERT_FALSE(tab->IsCrashed()); | 195 ASSERT_FALSE(tab->IsCrashed()); |
190 NavigationEntry* entry = tab->GetController().GetActiveEntry(); | 196 NavigationEntry* entry = tab->GetController().GetActiveEntry(); |
191 ASSERT_TRUE(entry); | 197 ASSERT_TRUE(entry); |
192 CertError::Check(*entry, error); | 198 CertError::Check(*entry, error); |
193 SecurityStyle::Check(*entry, expected_security_style); | 199 SecurityStyle::Check(*entry, expected_security_style); |
194 AuthState::Check(*entry, expected_authentication_state); | 200 AuthState::Check(*entry, expected_authentication_state); |
195 } | 201 } |
196 | 202 |
203 // This observer waits for the SSLErrorHandler to start an interstitial timer | |
204 // for the given web contents. | |
205 class SSLInterstitialTimerObserver { | |
206 public: | |
207 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents); | |
208 ~SSLInterstitialTimerObserver(); | |
209 | |
210 // Waits until the interstitial delay timer in SSLErrorHandler is started. | |
211 void WaitForTimerStarted(); | |
212 | |
213 private: | |
214 void OnTimerStarted(content::WebContents* web_contents); | |
215 | |
216 const content::WebContents* web_contents_; | |
217 SSLErrorHandler::TimerStartedCallback callback_; | |
218 | |
219 scoped_ptr<base::RunLoop> message_loop_runner_; | |
220 | |
221 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); | |
222 }; | |
223 | |
224 SSLInterstitialTimerObserver::SSLInterstitialTimerObserver( | |
225 content::WebContents* web_contents) | |
226 : web_contents_(web_contents), message_loop_runner_(new base::RunLoop) { | |
227 callback_ = base::Bind(&SSLInterstitialTimerObserver::OnTimerStarted, | |
228 base::Unretained(this)); | |
229 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(&callback_); | |
230 } | |
davidben
2015/08/17 18:59:19
Nit: Any reason not to define these inline with th
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
231 | |
232 SSLInterstitialTimerObserver::~SSLInterstitialTimerObserver() { | |
233 SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest(nullptr); | |
234 } | |
235 | |
236 void SSLInterstitialTimerObserver::WaitForTimerStarted() { | |
237 message_loop_runner_->Run(); | |
238 } | |
239 | |
240 void SSLInterstitialTimerObserver::OnTimerStarted( | |
241 content::WebContents* web_contents) { | |
242 if (web_contents_ == web_contents && message_loop_runner_.get()) | |
davidben
2015/08/17 18:59:18
message_loop_runner_.get() is redundant, isn't it?
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
243 message_loop_runner_->Quit(); | |
244 } | |
245 | |
197 } // namespace | 246 } // namespace |
198 | 247 |
199 class SSLUITest | 248 class SSLUITest |
200 : public CertificateReportingTestUtils::CertificateReportingTest { | 249 : public CertificateReportingTestUtils::CertificateReportingTest { |
201 public: | 250 public: |
202 SSLUITest() | 251 SSLUITest() |
203 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, | 252 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, |
204 SSLOptions(SSLOptions::CERT_OK), | 253 SSLOptions(SSLOptions::CERT_OK), |
205 base::FilePath(kDocRoot)), | 254 base::FilePath(kDocRoot)), |
206 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, | 255 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, |
(...skipping 2049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2256 | 2305 |
2257 ProceedThroughInterstitial(tab); | 2306 ProceedThroughInterstitial(tab); |
2258 EXPECT_TRUE(state->HasAllowException(https_server_host)); | 2307 EXPECT_TRUE(state->HasAllowException(https_server_host)); |
2259 | 2308 |
2260 ui_test_utils::NavigateToURL(browser(), | 2309 ui_test_utils::NavigateToURL(browser(), |
2261 https_server_.GetURL("files/ssl/google.html")); | 2310 https_server_.GetURL("files/ssl/google.html")); |
2262 ASSERT_FALSE(tab->GetInterstitialPage()); | 2311 ASSERT_FALSE(tab->GetInterstitialPage()); |
2263 EXPECT_FALSE(state->HasAllowException(https_server_host)); | 2312 EXPECT_FALSE(state->HasAllowException(https_server_host)); |
2264 } | 2313 } |
2265 | 2314 |
2315 typedef CertVerifierBrowserTest CommonNameMismatchBrowserTest; | |
davidben
2015/08/17 18:59:19
Nit: C++11-style is preferred now:
using CommonNa
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
2316 | |
2317 // Visit the URL www.mail.example.com on a server that presents a valid | |
2318 // certificate for mail.example.com. Verify that the page navigates to | |
2319 // mail.example.com. | |
2320 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
2321 ShouldShowWWWSubdomainMismatchInterstitial) { | |
2322 net::SpawnedTestServer https_server_example_domain_( | |
2323 net::SpawnedTestServer::TYPE_HTTPS, | |
2324 net::SpawnedTestServer::SSLOptions( | |
2325 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2326 base::FilePath(kDocRoot)); | |
2327 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2328 | |
2329 host_resolver()->AddRule( | |
2330 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
2331 host_resolver()->AddRule( | |
2332 "www.mail.example.com", | |
2333 https_server_example_domain_.host_port_pair().host()); | |
2334 | |
2335 // The pem file does not matter. | |
davidben
2015/08/17 18:59:18
Nit: pem -> PEM
(Although, with the comment below,
Bhanu Dev
2015/08/18 05:09:10
Done.
| |
2336 scoped_refptr<net::X509Certificate> cert1 = | |
davidben
2015/08/17 18:59:19
Nit: cert1 -> cert? I don't see a cert2.
Bhanu Dev
2015/08/18 05:09:09
Done. Initial implementation used to have cert2. U
| |
2337 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
davidben
2015/08/17 18:59:18
This can now just be https_server_example_domain_.
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
2338 | |
2339 // Use the "spdy_pooling.pem" cert which has "mail.example.com" | |
2340 // as one of its SANs. | |
2341 net::CertVerifyResult verify_result; | |
2342 verify_result.verified_cert = | |
2343 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2344 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2345 | |
2346 // Request to "www.test.example.com" should result in | |
2347 // |net::ERR_CERT_COMMON_NAME_INVALID| error. | |
2348 mock_cert_verifier()->AddResultForCertAndHost( | |
2349 cert1.get(), "www.mail.example.com", verify_result, | |
2350 net::ERR_CERT_COMMON_NAME_INVALID); | |
2351 | |
2352 net::CertVerifyResult verify_result_valid; | |
2353 verify_result_valid.verified_cert = | |
2354 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2355 // Request to "www.test.example.com" should not result in any error. | |
davidben
2015/08/17 18:59:19
www.test.example.com -> mail.example.com?
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
2356 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
2357 verify_result_valid, net::OK); | |
2358 | |
2359 // The path does not matter. | |
davidben
2015/08/17 18:59:18
Nit: I'd maybe write:
// Use a complex URL to e
Bhanu Dev
2015/08/18 05:09:10
Done.
| |
2360 GURL https_server_url = | |
2361 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2362 GURL::Replacements replacements; | |
2363 replacements.SetHostStr("www.mail.example.com"); | |
2364 GURL https_server_mismatched_url = | |
2365 https_server_url.ReplaceComponents(replacements); | |
2366 | |
2367 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2368 content::TestNavigationObserver observer(contents, 2); | |
2369 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
2370 observer.Wait(); | |
2371 | |
2372 CheckSecurityState(contents, CertError::NONE, | |
2373 content::SECURITY_STYLE_AUTHENTICATED, AuthState::NONE); | |
2374 replacements.SetHostStr("mail.example.com"); | |
2375 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements); | |
2376 // Verify that the current URL is the suggested URL. | |
2377 EXPECT_EQ(https_server_new_url.spec(), | |
2378 contents->GetLastCommittedURL().spec()); | |
2379 } | |
2380 | |
2381 // Visit the URL example.org on a server that presents a valid certificate | |
2382 // for www.example.org. Verify that the page redirects to www.example.org. | |
2383 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
2384 CheckWWWSubdomainMismatchInverse) { | |
2385 net::SpawnedTestServer https_server_example_domain_( | |
2386 net::SpawnedTestServer::TYPE_HTTPS, | |
2387 net::SpawnedTestServer::SSLOptions( | |
2388 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2389 base::FilePath(kDocRoot)); | |
2390 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2391 | |
2392 host_resolver()->AddRule( | |
2393 "www.example.org", https_server_example_domain_.host_port_pair().host()); | |
2394 host_resolver()->AddRule( | |
2395 "example.org", https_server_example_domain_.host_port_pair().host()); | |
2396 | |
2397 scoped_refptr<net::X509Certificate> cert1 = | |
2398 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
davidben
2015/08/17 18:59:19
Ditto about GetCertificate and cert1 -> cert
Bhanu Dev
2015/08/18 05:09:10
Done.
| |
2399 | |
2400 net::CertVerifyResult verify_result; | |
2401 verify_result.verified_cert = | |
2402 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2403 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2404 | |
2405 mock_cert_verifier()->AddResultForCertAndHost( | |
2406 cert1.get(), "example.org", verify_result, | |
2407 net::ERR_CERT_COMMON_NAME_INVALID); | |
2408 | |
2409 net::CertVerifyResult verify_result_valid; | |
2410 verify_result_valid.verified_cert = | |
2411 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2412 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "www.example.org", | |
2413 verify_result_valid, net::OK); | |
2414 | |
2415 GURL https_server_url = | |
2416 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2417 GURL::Replacements replacements; | |
2418 replacements.SetHostStr("example.org"); | |
2419 GURL https_server_mismatched_url = | |
2420 https_server_url.ReplaceComponents(replacements); | |
2421 | |
2422 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2423 content::TestNavigationObserver observer(contents, 2); | |
2424 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); | |
2425 observer.Wait(); | |
2426 | |
2427 CheckSecurityState(contents, CertError::NONE, | |
2428 content::SECURITY_STYLE_AUTHENTICATED, AuthState::NONE); | |
2429 } | |
2430 | |
2431 // Tests this scenario: | |
2432 // - |CommonNameMismatchHandler| does not give a callback as it's set into the | |
2433 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can | |
2434 // arrive. | |
2435 // - A cert error triggers an interstitial timer with a very long timeout. | |
2436 // - No suggested URL check results arrive, causing the tab to appear as loading | |
2437 // indefinitely (also because the timer has a long timeout). | |
2438 // - Stopping the page load shouldn't result in any interstitials. | |
2439 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
2440 InterstitialStopNavigationWhileLoading) { | |
2441 net::SpawnedTestServer https_server_example_domain_( | |
2442 net::SpawnedTestServer::TYPE_HTTPS, | |
2443 net::SpawnedTestServer::SSLOptions( | |
2444 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2445 base::FilePath(kDocRoot)); | |
2446 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2447 | |
2448 host_resolver()->AddRule( | |
2449 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
2450 host_resolver()->AddRule( | |
2451 "www.mail.example.com", | |
2452 https_server_example_domain_.host_port_pair().host()); | |
2453 | |
2454 scoped_refptr<net::X509Certificate> cert1 = | |
2455 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
davidben
2015/08/17 18:59:18
Ditto about GetCertificate and cert1 -> cert
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
2456 | |
2457 net::CertVerifyResult verify_result; | |
2458 verify_result.verified_cert = | |
2459 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2460 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2461 | |
2462 mock_cert_verifier()->AddResultForCertAndHost( | |
2463 cert1.get(), "www.mail.example.com", verify_result, | |
2464 net::ERR_CERT_COMMON_NAME_INVALID); | |
2465 | |
2466 net::CertVerifyResult verify_result_valid; | |
2467 verify_result_valid.verified_cert = | |
2468 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2469 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
2470 verify_result_valid, net::OK); | |
2471 | |
2472 GURL https_server_url = | |
2473 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2474 GURL::Replacements replacements; | |
2475 replacements.SetHostStr("www.mail.example.com"); | |
2476 GURL https_server_mismatched_url = | |
2477 https_server_url.ReplaceComponents(replacements); | |
2478 | |
2479 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2480 CommonNameMismatchHandler::set_state_for_testing( | |
2481 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
2482 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
2483 | |
2484 ui_test_utils::NavigateToURLWithDisposition( | |
2485 browser(), https_server_mismatched_url, CURRENT_TAB, | |
2486 ui_test_utils::BROWSER_TEST_NONE); | |
2487 interstitial_timer_observer.WaitForTimerStarted(); | |
davidben
2015/08/17 18:59:19
Since you're mucking about with the timer, this pr
Bhanu Dev
2015/08/18 05:09:10
Done.
| |
2488 | |
2489 EXPECT_TRUE(contents->IsLoading()); | |
2490 content::WindowedNotificationObserver observer( | |
2491 content::NOTIFICATION_LOAD_STOP, | |
2492 content::NotificationService::AllSources()); | |
2493 contents->Stop(); | |
2494 observer.Wait(); | |
2495 | |
2496 SSLErrorHandler* ssl_error_handler = | |
2497 SSLErrorHandler::FromWebContents(contents); | |
2498 // Make sure that the |SSLErrorHandler| is deleted. | |
2499 EXPECT_FALSE(ssl_error_handler); | |
2500 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
2501 EXPECT_FALSE(contents->IsLoading()); | |
2502 } | |
2503 | |
2504 // Same as above, but instead of stopping, the loading page is reloaded. The end | |
2505 // result is the same. (i.e. page load stops, no interstitials shown) | |
2506 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
2507 InterstitialReloadNavigationWhileLoading) { | |
2508 net::SpawnedTestServer https_server_example_domain_( | |
2509 net::SpawnedTestServer::TYPE_HTTPS, | |
2510 net::SpawnedTestServer::SSLOptions( | |
2511 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2512 base::FilePath(kDocRoot)); | |
2513 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2514 | |
2515 host_resolver()->AddRule( | |
2516 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
2517 host_resolver()->AddRule( | |
2518 "www.mail.example.com", | |
2519 https_server_example_domain_.host_port_pair().host()); | |
2520 | |
2521 scoped_refptr<net::X509Certificate> cert1 = | |
2522 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
davidben
2015/08/17 18:59:19
Ditto about GetCertificate and cert1 -> cert
Bhanu Dev
2015/08/18 05:09:10
Done.
| |
2523 | |
2524 net::CertVerifyResult verify_result; | |
2525 verify_result.verified_cert = | |
2526 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2527 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2528 | |
2529 mock_cert_verifier()->AddResultForCertAndHost( | |
2530 cert1.get(), "www.mail.example.com", verify_result, | |
2531 net::ERR_CERT_COMMON_NAME_INVALID); | |
2532 | |
2533 net::CertVerifyResult verify_result_valid; | |
2534 verify_result_valid.verified_cert = | |
2535 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2536 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
2537 verify_result_valid, net::OK); | |
2538 | |
2539 GURL https_server_url = | |
2540 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2541 GURL::Replacements replacements; | |
2542 replacements.SetHostStr("www.mail.example.com"); | |
2543 GURL https_server_mismatched_url = | |
2544 https_server_url.ReplaceComponents(replacements); | |
2545 | |
2546 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2547 CommonNameMismatchHandler::set_state_for_testing( | |
2548 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
2549 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
2550 | |
2551 ui_test_utils::NavigateToURLWithDisposition( | |
2552 browser(), https_server_mismatched_url, CURRENT_TAB, | |
2553 ui_test_utils::BROWSER_TEST_NONE); | |
2554 interstitial_timer_observer.WaitForTimerStarted(); | |
davidben
2015/08/17 18:59:19
Ditto about timer
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
2555 | |
2556 EXPECT_TRUE(contents->IsLoading()); | |
2557 content::TestNavigationObserver observer(contents, 1); | |
2558 chrome::Reload(browser(), CURRENT_TAB); | |
2559 observer.Wait(); | |
2560 | |
2561 SSLErrorHandler* ssl_error_handler = | |
2562 SSLErrorHandler::FromWebContents(contents); | |
2563 // Make sure that the |SSLErrorHandler| is deleted. | |
2564 EXPECT_FALSE(ssl_error_handler); | |
2565 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
2566 EXPECT_FALSE(contents->IsLoading()); | |
2567 } | |
2568 | |
2569 // Same as above, but instead of reloading, the page is navigated away. The | |
2570 // new page should load, and no interstitials should be shown. | |
2571 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, | |
2572 InterstitialNavigateAwayWhileLoading) { | |
2573 net::SpawnedTestServer https_server_example_domain_( | |
2574 net::SpawnedTestServer::TYPE_HTTPS, | |
2575 net::SpawnedTestServer::SSLOptions( | |
2576 net::SpawnedTestServer::SSLOptions::CERT_OK), | |
2577 base::FilePath(kDocRoot)); | |
2578 ASSERT_TRUE(https_server_example_domain_.Start()); | |
2579 | |
2580 host_resolver()->AddRule( | |
2581 "mail.example.com", https_server_example_domain_.host_port_pair().host()); | |
2582 host_resolver()->AddRule( | |
2583 "www.mail.example.com", | |
2584 https_server_example_domain_.host_port_pair().host()); | |
2585 | |
2586 scoped_refptr<net::X509Certificate> cert1 = | |
2587 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
davidben
2015/08/17 18:59:19
Ditto about GetCertificate and cert1 -> cert
Bhanu Dev
2015/08/18 05:09:09
Done.
| |
2588 | |
2589 net::CertVerifyResult verify_result; | |
2590 verify_result.verified_cert = | |
2591 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2592 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
2593 | |
2594 mock_cert_verifier()->AddResultForCertAndHost( | |
2595 cert1.get(), "www.mail.example.com", verify_result, | |
2596 net::ERR_CERT_COMMON_NAME_INVALID); | |
2597 | |
2598 net::CertVerifyResult verify_result_valid; | |
2599 verify_result_valid.verified_cert = | |
2600 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); | |
2601 mock_cert_verifier()->AddResultForCertAndHost(cert1.get(), "mail.example.com", | |
2602 verify_result_valid, net::OK); | |
2603 | |
2604 GURL https_server_url = | |
2605 https_server_example_domain_.GetURL("files/ssl/google.html?a=b"); | |
2606 GURL::Replacements replacements; | |
2607 replacements.SetHostStr("www.mail.example.com"); | |
2608 GURL https_server_mismatched_url = | |
2609 https_server_url.ReplaceComponents(replacements); | |
2610 | |
2611 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
2612 CommonNameMismatchHandler::set_state_for_testing( | |
2613 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); | |
2614 SSLInterstitialTimerObserver interstitial_timer_observer(contents); | |
2615 | |
2616 ui_test_utils::NavigateToURLWithDisposition( | |
2617 browser(), https_server_mismatched_url, CURRENT_TAB, | |
2618 ui_test_utils::BROWSER_TEST_NONE); | |
2619 interstitial_timer_observer.WaitForTimerStarted(); | |
2620 | |
2621 EXPECT_TRUE(contents->IsLoading()); | |
2622 content::TestNavigationObserver observer(contents, 1); | |
2623 browser()->OpenURL(content::OpenURLParams(GURL("https://google.com"), | |
2624 content::Referrer(), CURRENT_TAB, | |
2625 ui::PAGE_TRANSITION_TYPED, false)); | |
2626 observer.Wait(); | |
2627 | |
2628 SSLErrorHandler* ssl_error_handler = | |
2629 SSLErrorHandler::FromWebContents(contents); | |
2630 // Make sure that the |SSLErrorHandler| is deleted. | |
2631 EXPECT_FALSE(ssl_error_handler); | |
2632 EXPECT_FALSE(contents->ShowingInterstitialPage()); | |
2633 EXPECT_FALSE(contents->IsLoading()); | |
2634 } | |
2635 | |
2266 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { | 2636 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { |
2267 protected: | 2637 protected: |
2268 // SecurityInterstitialIDNTest implementation | 2638 // SecurityInterstitialIDNTest implementation |
2269 SecurityInterstitialPage* CreateInterstitial( | 2639 SecurityInterstitialPage* CreateInterstitial( |
2270 content::WebContents* contents, | 2640 content::WebContents* contents, |
2271 const GURL& request_url) const override { | 2641 const GURL& request_url) const override { |
2272 net::SSLInfo ssl_info; | 2642 net::SSLInfo ssl_info; |
2273 ssl_info.cert = new net::X509Certificate( | 2643 ssl_info.cert = new net::X509Certificate( |
2274 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); | 2644 request_url.host(), "CA", base::Time::Max(), base::Time::Max()); |
2275 return new SSLBlockingPage( | 2645 return new SSLBlockingPage( |
(...skipping 30 matching lines...) Expand all Loading... | |
2306 | 2676 |
2307 // Visit a page over https that contains a frame with a redirect. | 2677 // Visit a page over https that contains a frame with a redirect. |
2308 | 2678 |
2309 // XMLHttpRequest insecure content in synchronous mode. | 2679 // XMLHttpRequest insecure content in synchronous mode. |
2310 | 2680 |
2311 // XMLHttpRequest insecure content in asynchronous mode. | 2681 // XMLHttpRequest insecure content in asynchronous mode. |
2312 | 2682 |
2313 // XMLHttpRequest over bad ssl in synchronous mode. | 2683 // XMLHttpRequest over bad ssl in synchronous mode. |
2314 | 2684 |
2315 // XMLHttpRequest over OK ssl in synchronous mode. | 2685 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |