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

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

Issue 2865753003: Stop on redirects while checking for www mismatches (Closed)
Patch Set: Adjust comments Created 3 years, 6 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
« no previous file with comments | « chrome/browser/ssl/common_name_mismatch_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility> 5 #include <utility>
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/base_switches.h" 8 #include "base/base_switches.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 #include "net/base/net_errors.h" 97 #include "net/base/net_errors.h"
98 #include "net/cert/asn1_util.h" 98 #include "net/cert/asn1_util.h"
99 #include "net/cert/cert_status_flags.h" 99 #include "net/cert/cert_status_flags.h"
100 #include "net/cert/mock_cert_verifier.h" 100 #include "net/cert/mock_cert_verifier.h"
101 #include "net/cert/x509_certificate.h" 101 #include "net/cert/x509_certificate.h"
102 #include "net/dns/mock_host_resolver.h" 102 #include "net/dns/mock_host_resolver.h"
103 #include "net/http/http_response_headers.h" 103 #include "net/http/http_response_headers.h"
104 #include "net/ssl/ssl_info.h" 104 #include "net/ssl/ssl_info.h"
105 #include "net/test/cert_test_util.h" 105 #include "net/test/cert_test_util.h"
106 #include "net/test/embedded_test_server/embedded_test_server.h" 106 #include "net/test/embedded_test_server/embedded_test_server.h"
107 #include "net/test/embedded_test_server/http_request.h"
107 #include "net/test/embedded_test_server/request_handler_util.h" 108 #include "net/test/embedded_test_server/request_handler_util.h"
108 #include "net/test/spawned_test_server/spawned_test_server.h" 109 #include "net/test/spawned_test_server/spawned_test_server.h"
109 #include "net/test/test_certificate_data.h" 110 #include "net/test/test_certificate_data.h"
110 #include "net/test/test_data_directory.h" 111 #include "net/test/test_data_directory.h"
111 #include "net/url_request/url_request_context.h" 112 #include "net/url_request/url_request_context.h"
112 #include "net/url_request/url_request_filter.h" 113 #include "net/url_request/url_request_filter.h"
113 #include "net/url_request/url_request_job.h" 114 #include "net/url_request/url_request_job.h"
114 #include "net/url_request/url_request_test_util.h" 115 #include "net/url_request/url_request_test_util.h"
115 116
116 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) 117 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION)
(...skipping 3449 matching lines...) Expand 10 before | Expand all | Expand 10 after
3566 3567
3567 // Open a second tab, close the first, and then trigger the network time 3568 // Open a second tab, close the first, and then trigger the network time
3568 // response and wait for the response; no crash should occur. 3569 // response and wait for the response; no crash should occur.
3569 ASSERT_TRUE(https_server_.Start()); 3570 ASSERT_TRUE(https_server_.Start());
3570 AddTabAtIndex(1, https_server_.GetURL("/"), ui::PAGE_TRANSITION_TYPED); 3571 AddTabAtIndex(1, https_server_.GetURL("/"), ui::PAGE_TRANSITION_TYPED);
3571 chrome::CloseWebContents(browser(), contents, false); 3572 chrome::CloseWebContents(browser(), contents, false);
3572 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending()); 3573 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3573 TriggerTimeResponse(); 3574 TriggerTimeResponse();
3574 } 3575 }
3575 3576
3577 // Fails with a CHECK for all requests over HTTP except for favicons. This is to
3578 // ensure that name mismatch redirect feature's suggest URL ping stops on
3579 // redirects and never hits an HTTP URL.
3580 class HttpNameMismatchPingInterceptor : public net::URLRequestInterceptor {
3581 public:
3582 HttpNameMismatchPingInterceptor() {}
3583 ~HttpNameMismatchPingInterceptor() override {}
3584
3585 net::URLRequestJob* MaybeInterceptRequest(
3586 net::URLRequest* request,
3587 net::NetworkDelegate* delegate) const override {
3588 if (request->url().path() == "/favicon.ico") {
3589 // Ignore favicon requests.
elawrence 2017/06/03 18:45:11 As someone new to this code, it would be nice if t
meacer 2017/06/05 21:57:59 Done.
3590 return nullptr;
3591 }
3592
3593 CHECK(request->url().SchemeIsCryptographic())
elawrence 2017/06/03 18:45:11 Can this check ever pass? Below, AddHostnameInterc
meacer 2017/06/05 21:57:59 No, it can never pass. Converted to CHECK(false).
3594 << "Name mismatch pings must never be over HTTP. This request was for "
3595 << request->url();
3596 return nullptr;
3597 }
3598
3599 private:
3600 DISALLOW_COPY_AND_ASSIGN(HttpNameMismatchPingInterceptor);
3601 };
3602
3576 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { 3603 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest {
3577 public: 3604 public:
3578 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} 3605 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {
3579 ~CommonNameMismatchBrowserTest() override {} 3606 // Add interceptors for HTTP versions of example.org and www.example.org.
3607 // These are the hostnames used in the tests, and we never want them to be
3608 // contacted over HTTP.
3609 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor(
3610 "http", "example.org",
3611 std::unique_ptr<HttpNameMismatchPingInterceptor>(
3612 new HttpNameMismatchPingInterceptor()));
3613 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor(
3614 "http", "www.example.org",
3615 std::unique_ptr<HttpNameMismatchPingInterceptor>(
3616 new HttpNameMismatchPingInterceptor()));
3617 }
3618 ~CommonNameMismatchBrowserTest() override {
3619 net::URLRequestFilter::GetInstance()->ClearHandlers();
3620 }
3580 3621
3581 void SetUpCommandLine(base::CommandLine* command_line) override { 3622 void SetUpCommandLine(base::CommandLine* command_line) override {
3582 // Enable finch experiment for SSL common name mismatch handling. 3623 // Enable finch experiment for SSL common name mismatch handling.
3583 command_line->AppendSwitchASCII(switches::kForceFieldTrials, 3624 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
3584 "SSLCommonNameMismatchHandling/Enabled/"); 3625 "SSLCommonNameMismatchHandling/Enabled/");
3585 } 3626 }
3586 3627
3587 void SetUpOnMainThread() override { 3628 void SetUpOnMainThread() override {
3588 CertVerifierBrowserTest::SetUpOnMainThread(); 3629 CertVerifierBrowserTest::SetUpOnMainThread();
3589 host_resolver()->AddRule("*", "127.0.0.1"); 3630 host_resolver()->AddRule("*", "127.0.0.1");
3590 } 3631 }
3591 }; 3632 };
3592 3633
3593 // Visit the URL www.mail.example.com on a server that presents a valid 3634 // Visit the URL www.mail.example.com on a server that presents a valid
3594 // certificate for mail.example.com. Verify that the page navigates to 3635 // certificate for mail.example.com. Verify that the page navigates to
3595 // mail.example.com. 3636 // mail.example.com.
3596 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, 3637 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
3597 ShouldShowWWWSubdomainMismatchInterstitial) { 3638 ShouldShowWWWSubdomainMismatchInterstitial) {
3598 net::EmbeddedTestServer https_server_example_domain_( 3639 net::EmbeddedTestServer https_server_example_domain(
3599 net::EmbeddedTestServer::TYPE_HTTPS); 3640 net::EmbeddedTestServer::TYPE_HTTPS);
3600 https_server_example_domain_.ServeFilesFromSourceDirectory( 3641 https_server_example_domain.ServeFilesFromSourceDirectory(
3601 base::FilePath(kDocRoot)); 3642 base::FilePath(kDocRoot));
3602 ASSERT_TRUE(https_server_example_domain_.Start()); 3643 ASSERT_TRUE(https_server_example_domain.Start());
3603 3644
3604 scoped_refptr<net::X509Certificate> cert = 3645 scoped_refptr<net::X509Certificate> cert =
3605 https_server_example_domain_.GetCertificate(); 3646 https_server_example_domain.GetCertificate();
3606 3647
3607 // Use the "spdy_pooling.pem" cert which has "mail.example.com" 3648 // Use the "spdy_pooling.pem" cert which has "mail.example.com"
3608 // as one of its SANs. 3649 // as one of its SANs.
3609 net::CertVerifyResult verify_result; 3650 net::CertVerifyResult verify_result;
3610 verify_result.verified_cert = 3651 verify_result.verified_cert =
3611 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3652 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3612 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; 3653 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
3613 3654
3614 // Request to "www.mail.example.com" should result in 3655 // Request to "www.mail.example.com" should result in
3615 // |net::ERR_CERT_COMMON_NAME_INVALID| error. 3656 // |net::ERR_CERT_COMMON_NAME_INVALID| error.
3616 mock_cert_verifier()->AddResultForCertAndHost( 3657 mock_cert_verifier()->AddResultForCertAndHost(
3617 cert.get(), "www.mail.example.com", verify_result, 3658 cert.get(), "www.mail.example.com", verify_result,
3618 net::ERR_CERT_COMMON_NAME_INVALID); 3659 net::ERR_CERT_COMMON_NAME_INVALID);
3619 3660
3620 net::CertVerifyResult verify_result_valid; 3661 net::CertVerifyResult verify_result_valid;
3621 verify_result_valid.verified_cert = 3662 verify_result_valid.verified_cert =
3622 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3663 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3623 // Request to "www.mail.example.com" should not result in any error. 3664 // Request to "www.mail.example.com" should not result in any error.
3624 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com", 3665 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com",
3625 verify_result_valid, net::OK); 3666 verify_result_valid, net::OK);
3626 3667
3627 // Use a complex URL to ensure the path, etc., are preserved. The path itself 3668 // Use a complex URL to ensure the path, etc., are preserved. The path itself
3628 // does not matter. 3669 // does not matter.
3629 GURL https_server_url = 3670 const GURL https_server_url =
3630 https_server_example_domain_.GetURL("/ssl/google.html?a=b#anchor"); 3671 https_server_example_domain.GetURL("/ssl/google.html?a=b#anchor");
3631 GURL::Replacements replacements; 3672 GURL::Replacements replacements;
3632 replacements.SetHostStr("www.mail.example.com"); 3673 replacements.SetHostStr("www.mail.example.com");
3633 GURL https_server_mismatched_url = 3674 const GURL https_server_mismatched_url =
3634 https_server_url.ReplaceComponents(replacements); 3675 https_server_url.ReplaceComponents(replacements);
3635 3676
3636 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 3677 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3637 content::TestNavigationObserver observer( 3678 content::TestNavigationObserver observer(
3638 contents, 3679 contents,
3639 // With PlzNavigate, the renderer only sees one navigation (i.e. not the 3680 // With PlzNavigate, the renderer only sees one navigation (i.e. not the
3640 // redirect, since that happens in the browser). 3681 // redirect, since that happens in the browser).
3641 content::IsBrowserSideNavigationEnabled() ? 1 : 2); 3682 content::IsBrowserSideNavigationEnabled() ? 1 : 2);
3642 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); 3683 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url);
3643 observer.Wait(); 3684 observer.Wait();
3644 3685
3645 CheckSecurityState(contents, CertError::NONE, security_state::SECURE, 3686 CheckSecurityState(contents, CertError::NONE, security_state::SECURE,
3646 AuthState::NONE); 3687 AuthState::NONE);
3647 replacements.SetHostStr("mail.example.com"); 3688 replacements.SetHostStr("mail.example.com");
3648 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements); 3689 GURL https_server_new_url = https_server_url.ReplaceComponents(replacements);
3649 // Verify that the current URL is the suggested URL. 3690 // Verify that the current URL is the suggested URL.
3650 EXPECT_EQ(https_server_new_url.spec(), 3691 EXPECT_EQ(https_server_new_url.spec(),
3651 contents->GetLastCommittedURL().spec()); 3692 contents->GetLastCommittedURL().spec());
3652 } 3693 }
3653 3694
3654 // Visit the URL example.org on a server that presents a valid certificate 3695 // Visit the URL example.org on a server that presents a valid certificate
3655 // for www.example.org. Verify that the page redirects to www.example.org. 3696 // for www.example.org. Verify that the page redirects to www.example.org.
3656 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, 3697 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
3657 CheckWWWSubdomainMismatchInverse) { 3698 CheckWWWSubdomainMismatchInverse) {
3658 net::EmbeddedTestServer https_server_example_domain_( 3699 net::EmbeddedTestServer https_server_example_domain(
3659 net::EmbeddedTestServer::TYPE_HTTPS); 3700 net::EmbeddedTestServer::TYPE_HTTPS);
3660 https_server_example_domain_.ServeFilesFromSourceDirectory( 3701 https_server_example_domain.ServeFilesFromSourceDirectory(
3661 base::FilePath(kDocRoot)); 3702 base::FilePath(kDocRoot));
3662 ASSERT_TRUE(https_server_example_domain_.Start()); 3703 ASSERT_TRUE(https_server_example_domain.Start());
3663 3704
3664 scoped_refptr<net::X509Certificate> cert = 3705 scoped_refptr<net::X509Certificate> cert =
3665 https_server_example_domain_.GetCertificate(); 3706 https_server_example_domain.GetCertificate();
3666 3707
3667 net::CertVerifyResult verify_result; 3708 net::CertVerifyResult verify_result;
3668 verify_result.verified_cert = 3709 verify_result.verified_cert =
3669 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3710 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3670 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; 3711 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
3671 3712
3672 mock_cert_verifier()->AddResultForCertAndHost( 3713 mock_cert_verifier()->AddResultForCertAndHost(
3673 cert.get(), "example.org", verify_result, 3714 cert.get(), "example.org", verify_result,
3674 net::ERR_CERT_COMMON_NAME_INVALID); 3715 net::ERR_CERT_COMMON_NAME_INVALID);
3675 3716
3676 net::CertVerifyResult verify_result_valid; 3717 net::CertVerifyResult verify_result_valid;
3677 verify_result_valid.verified_cert = 3718 verify_result_valid.verified_cert =
3678 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3719 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3679 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "www.example.org", 3720 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "www.example.org",
3680 verify_result_valid, net::OK); 3721 verify_result_valid, net::OK);
3681 3722
3682 GURL https_server_url = 3723 const GURL https_server_url =
3683 https_server_example_domain_.GetURL("/ssl/google.html?a=b"); 3724 https_server_example_domain.GetURL("/ssl/google.html?a=b");
3684 GURL::Replacements replacements; 3725 GURL::Replacements replacements;
3685 replacements.SetHostStr("example.org"); 3726 replacements.SetHostStr("example.org");
3686 GURL https_server_mismatched_url = 3727 const GURL https_server_mismatched_url =
3687 https_server_url.ReplaceComponents(replacements); 3728 https_server_url.ReplaceComponents(replacements);
3688 3729
3689 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 3730 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3690 content::TestNavigationObserver observer( 3731 content::TestNavigationObserver observer(
3691 contents, 3732 contents,
3692 // With PlzNavigate, the renderer only sees one navigation (i.e. not the 3733 // With PlzNavigate, the renderer only sees one navigation (i.e. not the
3693 // redirect, since that happens in the browser). 3734 // redirect, since that happens in the browser).
3694 content::IsBrowserSideNavigationEnabled() ? 1 : 2); 3735 content::IsBrowserSideNavigationEnabled() ? 1 : 2);
3695 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url); 3736 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url);
3696 observer.Wait(); 3737 observer.Wait();
3697 3738
3698 CheckSecurityState(contents, CertError::NONE, security_state::SECURE, 3739 CheckSecurityState(contents, CertError::NONE, security_state::SECURE,
3699 AuthState::NONE); 3740 AuthState::NONE);
3700 } 3741 }
3701 3742
3743 namespace {
3744 // Redirects incoming request to http://example.org.
3745 std::unique_ptr<net::test_server::HttpResponse> HTTPSToHTTPRedirectHandler(
3746 const net::EmbeddedTestServer* test_server,
3747 const net::test_server::HttpRequest& request) {
3748 GURL::Replacements replacements;
3749 replacements.SetHostStr("example.org");
3750 replacements.SetSchemeStr("http");
3751 const GURL redirect_url =
3752 test_server->base_url().ReplaceComponents(replacements);
3753
3754 std::unique_ptr<net::test_server::BasicHttpResponse> http_response(
3755 new net::test_server::BasicHttpResponse);
3756 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
3757 http_response->AddCustomHeader("Location", redirect_url.spec());
3758 return std::move(http_response);
3759 }
3760 } // namespace
3761
3762 // Common name mismatch handling feature should ignore redirects when pinging
3763 // the suggested hostname. Visit the URL example.org on a server that presents a
3764 // valid certificate for www.example.org. In this case, www.example.org
3765 // redirects to http://example.org, and the SSL error should not be redirected
3766 // to this URL.
3767 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
3768 WWWSubdomainMismatch_StopOnRedirects) {
3769 net::EmbeddedTestServer https_server_example_domain(
3770 net::EmbeddedTestServer::TYPE_HTTPS);
3771
3772 // Redirect all URLs to http://example.org. Since this test will trigger only
3773 // one request to check the suggested URL, redirecting all requests is OK.
3774 // We would normally use content::SetupCrossSiteRedirector here, but that
3775 // function does not support https to http redirects.
3776 // This must be done before ServeFilesFromSourceDirectory(), otherwise the
3777 // test server will serve files instead of redirecting requests to them.
3778 https_server_example_domain.RegisterRequestHandler(
3779 base::Bind(&HTTPSToHTTPRedirectHandler, &https_server_example_domain));
3780
3781 https_server_example_domain.ServeFilesFromSourceDirectory(
3782 base::FilePath(kDocRoot));
3783
3784 ASSERT_TRUE(https_server_example_domain.Start());
3785
3786 scoped_refptr<net::X509Certificate> cert =
3787 https_server_example_domain.GetCertificate();
3788
3789 net::CertVerifyResult verify_result;
3790 verify_result.verified_cert =
3791 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3792 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
3793
3794 mock_cert_verifier()->AddResultForCertAndHost(
3795 cert.get(), "example.org", verify_result,
3796 net::ERR_CERT_COMMON_NAME_INVALID);
3797
3798 net::CertVerifyResult verify_result_valid;
3799 verify_result_valid.verified_cert =
3800 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3801 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "www.example.org",
3802 verify_result_valid, net::OK);
3803
3804 // The user will visit https://example.org:port/ssl/blank.html.
3805 GURL::Replacements replacements;
3806 replacements.SetHostStr("example.org");
3807 const GURL https_server_mismatched_url =
3808 https_server_example_domain.GetURL("/ssl/blank.html")
3809 .ReplaceComponents(replacements);
3810
3811 // Should simply show an interstitial, because the suggested URL
3812 // (https://www.example.org) redirected to http://example.org.
3813 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3814 ui_test_utils::NavigateToURL(browser(), https_server_mismatched_url);
3815 WaitForInterstitialAttach(contents);
3816
3817 CheckSecurityState(contents, net::CERT_STATUS_COMMON_NAME_INVALID,
3818 security_state::DANGEROUS,
3819 AuthState::SHOWING_INTERSTITIAL);
3820 }
3821
3702 // Tests this scenario: 3822 // Tests this scenario:
3703 // - |CommonNameMismatchHandler| does not give a callback as it's set into the 3823 // - |CommonNameMismatchHandler| does not give a callback as it's set into the
3704 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can 3824 // state |IGNORE_REQUESTS_FOR_TESTING|. So no suggested URL check result can
3705 // arrive. 3825 // arrive.
3706 // - A cert error triggers an interstitial timer with a very long timeout. 3826 // - A cert error triggers an interstitial timer with a very long timeout.
3707 // - No suggested URL check results arrive, causing the tab to appear as loading 3827 // - No suggested URL check results arrive, causing the tab to appear as loading
3708 // indefinitely (also because the timer has a long timeout). 3828 // indefinitely (also because the timer has a long timeout).
3709 // - Stopping the page load shouldn't result in any interstitials. 3829 // - Stopping the page load shouldn't result in any interstitials.
3710 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, 3830 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
3711 InterstitialStopNavigationWhileLoading) { 3831 InterstitialStopNavigationWhileLoading) {
3712 net::EmbeddedTestServer https_server_example_domain_( 3832 net::EmbeddedTestServer https_server_example_domain(
3713 net::EmbeddedTestServer::TYPE_HTTPS); 3833 net::EmbeddedTestServer::TYPE_HTTPS);
3714 https_server_example_domain_.ServeFilesFromSourceDirectory( 3834 https_server_example_domain.ServeFilesFromSourceDirectory(
3715 base::FilePath(kDocRoot)); 3835 base::FilePath(kDocRoot));
3716 ASSERT_TRUE(https_server_example_domain_.Start()); 3836 ASSERT_TRUE(https_server_example_domain.Start());
3717 3837
3718 scoped_refptr<net::X509Certificate> cert = 3838 scoped_refptr<net::X509Certificate> cert =
3719 https_server_example_domain_.GetCertificate(); 3839 https_server_example_domain.GetCertificate();
3720 3840
3721 net::CertVerifyResult verify_result; 3841 net::CertVerifyResult verify_result;
3722 verify_result.verified_cert = 3842 verify_result.verified_cert =
3723 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3843 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3724 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; 3844 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
3725 3845
3726 mock_cert_verifier()->AddResultForCertAndHost( 3846 mock_cert_verifier()->AddResultForCertAndHost(
3727 cert.get(), "www.mail.example.com", verify_result, 3847 cert.get(), "www.mail.example.com", verify_result,
3728 net::ERR_CERT_COMMON_NAME_INVALID); 3848 net::ERR_CERT_COMMON_NAME_INVALID);
3729 3849
3730 net::CertVerifyResult verify_result_valid; 3850 net::CertVerifyResult verify_result_valid;
3731 verify_result_valid.verified_cert = 3851 verify_result_valid.verified_cert =
3732 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3852 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3733 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com", 3853 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com",
3734 verify_result_valid, net::OK); 3854 verify_result_valid, net::OK);
3735 3855
3736 GURL https_server_url = 3856 const GURL https_server_url =
3737 https_server_example_domain_.GetURL("/ssl/google.html?a=b"); 3857 https_server_example_domain.GetURL("/ssl/google.html?a=b");
3738 GURL::Replacements replacements; 3858 GURL::Replacements replacements;
3739 replacements.SetHostStr("www.mail.example.com"); 3859 replacements.SetHostStr("www.mail.example.com");
3740 GURL https_server_mismatched_url = 3860 const GURL https_server_mismatched_url =
3741 https_server_url.ReplaceComponents(replacements); 3861 https_server_url.ReplaceComponents(replacements);
3742 3862
3743 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 3863 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3744 CommonNameMismatchHandler::set_state_for_testing( 3864 CommonNameMismatchHandler::set_state_for_testing(
3745 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); 3865 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING);
3746 // Set delay long enough so that the page appears loading. 3866 // Set delay long enough so that the page appears loading.
3747 SSLErrorHandler::SetInterstitialDelayForTesting( 3867 SSLErrorHandler::SetInterstitialDelayForTesting(
3748 base::TimeDelta::FromHours(1)); 3868 base::TimeDelta::FromHours(1));
3749 SSLInterstitialTimerObserver interstitial_timer_observer(contents); 3869 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3750 3870
(...skipping 14 matching lines...) Expand all
3765 // Make sure that the |SSLErrorHandler| is deleted. 3885 // Make sure that the |SSLErrorHandler| is deleted.
3766 EXPECT_FALSE(ssl_error_handler); 3886 EXPECT_FALSE(ssl_error_handler);
3767 EXPECT_FALSE(contents->ShowingInterstitialPage()); 3887 EXPECT_FALSE(contents->ShowingInterstitialPage());
3768 EXPECT_FALSE(contents->IsLoading()); 3888 EXPECT_FALSE(contents->IsLoading());
3769 } 3889 }
3770 3890
3771 // Same as above, but instead of stopping, the loading page is reloaded. The end 3891 // Same as above, but instead of stopping, the loading page is reloaded. The end
3772 // result is the same. (i.e. page load stops, no interstitials shown) 3892 // result is the same. (i.e. page load stops, no interstitials shown)
3773 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, 3893 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
3774 InterstitialReloadNavigationWhileLoading) { 3894 InterstitialReloadNavigationWhileLoading) {
3775 net::EmbeddedTestServer https_server_example_domain_( 3895 net::EmbeddedTestServer https_server_example_domain(
3776 net::EmbeddedTestServer::TYPE_HTTPS); 3896 net::EmbeddedTestServer::TYPE_HTTPS);
3777 https_server_example_domain_.ServeFilesFromSourceDirectory( 3897 https_server_example_domain.ServeFilesFromSourceDirectory(
3778 base::FilePath(kDocRoot)); 3898 base::FilePath(kDocRoot));
3779 ASSERT_TRUE(https_server_example_domain_.Start()); 3899 ASSERT_TRUE(https_server_example_domain.Start());
3780 3900
3781 scoped_refptr<net::X509Certificate> cert = 3901 scoped_refptr<net::X509Certificate> cert =
3782 https_server_example_domain_.GetCertificate(); 3902 https_server_example_domain.GetCertificate();
3783 3903
3784 net::CertVerifyResult verify_result; 3904 net::CertVerifyResult verify_result;
3785 verify_result.verified_cert = 3905 verify_result.verified_cert =
3786 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3906 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3787 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; 3907 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
3788 3908
3789 mock_cert_verifier()->AddResultForCertAndHost( 3909 mock_cert_verifier()->AddResultForCertAndHost(
3790 cert.get(), "www.mail.example.com", verify_result, 3910 cert.get(), "www.mail.example.com", verify_result,
3791 net::ERR_CERT_COMMON_NAME_INVALID); 3911 net::ERR_CERT_COMMON_NAME_INVALID);
3792 3912
3793 net::CertVerifyResult verify_result_valid; 3913 net::CertVerifyResult verify_result_valid;
3794 verify_result_valid.verified_cert = 3914 verify_result_valid.verified_cert =
3795 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3915 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3796 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com", 3916 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com",
3797 verify_result_valid, net::OK); 3917 verify_result_valid, net::OK);
3798 3918
3799 GURL https_server_url = 3919 const GURL https_server_url =
3800 https_server_example_domain_.GetURL("/ssl/google.html?a=b"); 3920 https_server_example_domain.GetURL("/ssl/google.html?a=b");
3801 GURL::Replacements replacements; 3921 GURL::Replacements replacements;
3802 replacements.SetHostStr("www.mail.example.com"); 3922 replacements.SetHostStr("www.mail.example.com");
3803 GURL https_server_mismatched_url = 3923 const GURL https_server_mismatched_url =
3804 https_server_url.ReplaceComponents(replacements); 3924 https_server_url.ReplaceComponents(replacements);
3805 3925
3806 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 3926 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3807 CommonNameMismatchHandler::set_state_for_testing( 3927 CommonNameMismatchHandler::set_state_for_testing(
3808 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); 3928 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING);
3809 // Set delay long enough so that the page appears loading. 3929 // Set delay long enough so that the page appears loading.
3810 SSLErrorHandler::SetInterstitialDelayForTesting( 3930 SSLErrorHandler::SetInterstitialDelayForTesting(
3811 base::TimeDelta::FromHours(1)); 3931 base::TimeDelta::FromHours(1));
3812 SSLInterstitialTimerObserver interstitial_timer_observer(contents); 3932 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3813 3933
(...skipping 12 matching lines...) Expand all
3826 // Make sure that the |SSLErrorHandler| is deleted. 3946 // Make sure that the |SSLErrorHandler| is deleted.
3827 EXPECT_FALSE(ssl_error_handler); 3947 EXPECT_FALSE(ssl_error_handler);
3828 EXPECT_FALSE(contents->ShowingInterstitialPage()); 3948 EXPECT_FALSE(contents->ShowingInterstitialPage());
3829 EXPECT_FALSE(contents->IsLoading()); 3949 EXPECT_FALSE(contents->IsLoading());
3830 } 3950 }
3831 3951
3832 // Same as above, but instead of reloading, the page is navigated away. The 3952 // Same as above, but instead of reloading, the page is navigated away. The
3833 // new page should load, and no interstitials should be shown. 3953 // new page should load, and no interstitials should be shown.
3834 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest, 3954 IN_PROC_BROWSER_TEST_F(CommonNameMismatchBrowserTest,
3835 InterstitialNavigateAwayWhileLoading) { 3955 InterstitialNavigateAwayWhileLoading) {
3836 net::EmbeddedTestServer https_server_example_domain_( 3956 net::EmbeddedTestServer https_server_example_domain(
3837 net::EmbeddedTestServer::TYPE_HTTPS); 3957 net::EmbeddedTestServer::TYPE_HTTPS);
3838 https_server_example_domain_.ServeFilesFromSourceDirectory( 3958 https_server_example_domain.ServeFilesFromSourceDirectory(
3839 base::FilePath(kDocRoot)); 3959 base::FilePath(kDocRoot));
3840 ASSERT_TRUE(https_server_example_domain_.Start()); 3960 ASSERT_TRUE(https_server_example_domain.Start());
3841 3961
3842 scoped_refptr<net::X509Certificate> cert = 3962 scoped_refptr<net::X509Certificate> cert =
3843 https_server_example_domain_.GetCertificate(); 3963 https_server_example_domain.GetCertificate();
3844 3964
3845 net::CertVerifyResult verify_result; 3965 net::CertVerifyResult verify_result;
3846 verify_result.verified_cert = 3966 verify_result.verified_cert =
3847 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3967 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3848 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; 3968 verify_result.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
3849 3969
3850 mock_cert_verifier()->AddResultForCertAndHost( 3970 mock_cert_verifier()->AddResultForCertAndHost(
3851 cert.get(), "www.mail.example.com", verify_result, 3971 cert.get(), "www.mail.example.com", verify_result,
3852 net::ERR_CERT_COMMON_NAME_INVALID); 3972 net::ERR_CERT_COMMON_NAME_INVALID);
3853 3973
3854 net::CertVerifyResult verify_result_valid; 3974 net::CertVerifyResult verify_result_valid;
3855 verify_result_valid.verified_cert = 3975 verify_result_valid.verified_cert =
3856 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem"); 3976 net::ImportCertFromFile(net::GetTestCertsDirectory(), "spdy_pooling.pem");
3857 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com", 3977 mock_cert_verifier()->AddResultForCertAndHost(cert.get(), "mail.example.com",
3858 verify_result_valid, net::OK); 3978 verify_result_valid, net::OK);
3859 3979
3860 GURL https_server_url = 3980 const GURL https_server_url =
3861 https_server_example_domain_.GetURL("/ssl/google.html?a=b"); 3981 https_server_example_domain.GetURL("/ssl/google.html?a=b");
3862 GURL::Replacements replacements; 3982 GURL::Replacements replacements;
3863 replacements.SetHostStr("www.mail.example.com"); 3983 replacements.SetHostStr("www.mail.example.com");
3864 GURL https_server_mismatched_url = 3984 const GURL https_server_mismatched_url =
3865 https_server_url.ReplaceComponents(replacements); 3985 https_server_url.ReplaceComponents(replacements);
3866 3986
3867 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 3987 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3868 CommonNameMismatchHandler::set_state_for_testing( 3988 CommonNameMismatchHandler::set_state_for_testing(
3869 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING); 3989 CommonNameMismatchHandler::IGNORE_REQUESTS_FOR_TESTING);
3870 // Set delay long enough so that the page appears loading. 3990 // Set delay long enough so that the page appears loading.
3871 SSLErrorHandler::SetInterstitialDelayForTesting( 3991 SSLErrorHandler::SetInterstitialDelayForTesting(
3872 base::TimeDelta::FromHours(1)); 3992 base::TimeDelta::FromHours(1));
3873 SSLInterstitialTimerObserver interstitial_timer_observer(contents); 3993 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3874 3994
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
4605 4725
4606 // Visit a page over https that contains a frame with a redirect. 4726 // Visit a page over https that contains a frame with a redirect.
4607 4727
4608 // XMLHttpRequest insecure content in synchronous mode. 4728 // XMLHttpRequest insecure content in synchronous mode.
4609 4729
4610 // XMLHttpRequest insecure content in asynchronous mode. 4730 // XMLHttpRequest insecure content in asynchronous mode.
4611 4731
4612 // XMLHttpRequest over bad ssl in synchronous mode. 4732 // XMLHttpRequest over bad ssl in synchronous mode.
4613 4733
4614 // XMLHttpRequest over OK ssl in synchronous mode. 4734 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « chrome/browser/ssl/common_name_mismatch_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698