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

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

Issue 2449193002: Attempt an on-demand time fetch when encountering a date invalid error (Closed)
Patch Set: Check that network time query state is as expected before triggering response Created 4 years, 1 month 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 <utility> 5 #include <utility>
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/test/histogram_tester.h" 20 #include "base/test/histogram_tester.h"
21 #include "base/test/simple_test_clock.h" 21 #include "base/test/simple_test_clock.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/time/default_clock.h"
24 #include "base/time/default_tick_clock.h"
23 #include "base/time/time.h" 25 #include "base/time/time.h"
24 #include "build/build_config.h" 26 #include "build/build_config.h"
25 #include "chrome/app/chrome_command_ids.h" 27 #include "chrome/app/chrome_command_ids.h"
26 #include "chrome/browser/browser_process.h" 28 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
28 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 30 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
29 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" 31 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
30 #include "chrome/browser/profiles/profile.h" 32 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ssl/bad_clock_blocking_page.h" 33 #include "chrome/browser/ssl/bad_clock_blocking_page.h"
32 #include "chrome/browser/ssl/cert_report_helper.h" 34 #include "chrome/browser/ssl/cert_report_helper.h"
(...skipping 10 matching lines...) Expand all
43 #include "chrome/browser/ui/browser_navigator.h" 45 #include "chrome/browser/ui/browser_navigator.h"
44 #include "chrome/browser/ui/browser_navigator_params.h" 46 #include "chrome/browser/ui/browser_navigator_params.h"
45 #include "chrome/browser/ui/browser_tabstrip.h" 47 #include "chrome/browser/ui/browser_tabstrip.h"
46 #include "chrome/browser/ui/tabs/tab_strip_model.h" 48 #include "chrome/browser/ui/tabs/tab_strip_model.h"
47 #include "chrome/common/chrome_paths.h" 49 #include "chrome/common/chrome_paths.h"
48 #include "chrome/common/chrome_switches.h" 50 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/pref_names.h" 51 #include "chrome/common/pref_names.h"
50 #include "chrome/test/base/in_process_browser_test.h" 52 #include "chrome/test/base/in_process_browser_test.h"
51 #include "chrome/test/base/ui_test_utils.h" 53 #include "chrome/test/base/ui_test_utils.h"
52 #include "components/content_settings/core/browser/host_content_settings_map.h" 54 #include "components/content_settings/core/browser/host_content_settings_map.h"
55 #include "components/network_time/network_time_test_utils.h"
53 #include "components/network_time/network_time_tracker.h" 56 #include "components/network_time/network_time_tracker.h"
54 #include "components/prefs/pref_service.h" 57 #include "components/prefs/testing_pref_service.h"
55 #include "components/security_interstitials/core/controller_client.h" 58 #include "components/security_interstitials/core/controller_client.h"
56 #include "components/security_interstitials/core/metrics_helper.h" 59 #include "components/security_interstitials/core/metrics_helper.h"
57 #include "components/security_state/security_state_model.h" 60 #include "components/security_state/security_state_model.h"
58 #include "components/security_state/switches.h" 61 #include "components/security_state/switches.h"
59 #include "components/ssl_errors/error_classification.h" 62 #include "components/ssl_errors/error_classification.h"
60 #include "components/variations/variations_associated_data.h" 63 #include "components/variations/variations_associated_data.h"
61 #include "components/web_modal/web_contents_modal_dialog_manager.h" 64 #include "components/web_modal/web_contents_modal_dialog_manager.h"
62 #include "content/public/browser/browser_context.h" 65 #include "content/public/browser/browser_context.h"
63 #include "content/public/browser/interstitial_page.h" 66 #include "content/public/browser/interstitial_page.h"
64 #include "content/public/browser/navigation_controller.h" 67 #include "content/public/browser/navigation_controller.h"
65 #include "content/public/browser/navigation_entry.h" 68 #include "content/public/browser/navigation_entry.h"
66 #include "content/public/browser/notification_details.h" 69 #include "content/public/browser/notification_details.h"
67 #include "content/public/browser/notification_service.h" 70 #include "content/public/browser/notification_service.h"
68 #include "content/public/browser/render_frame_host.h" 71 #include "content/public/browser/render_frame_host.h"
69 #include "content/public/browser/render_view_host.h" 72 #include "content/public/browser/render_view_host.h"
70 #include "content/public/browser/render_widget_host_view.h" 73 #include "content/public/browser/render_widget_host_view.h"
71 #include "content/public/browser/restore_type.h" 74 #include "content/public/browser/restore_type.h"
72 #include "content/public/browser/ssl_status.h" 75 #include "content/public/browser/ssl_status.h"
73 #include "content/public/browser/web_contents.h" 76 #include "content/public/browser/web_contents.h"
74 #include "content/public/browser/web_contents_observer.h" 77 #include "content/public/browser/web_contents_observer.h"
75 #include "content/public/common/browser_side_navigation_policy.h" 78 #include "content/public/common/browser_side_navigation_policy.h"
76 #include "content/public/common/content_switches.h" 79 #include "content/public/common/content_switches.h"
77 #include "content/public/common/page_state.h" 80 #include "content/public/common/page_state.h"
78 #include "content/public/test/browser_test_utils.h" 81 #include "content/public/test/browser_test_utils.h"
79 #include "content/public/test/download_test_observer.h" 82 #include "content/public/test/download_test_observer.h"
80 #include "content/public/test/test_navigation_observer.h" 83 #include "content/public/test/test_navigation_observer.h"
81 #include "content/public/test/test_renderer_host.h" 84 #include "content/public/test/test_renderer_host.h"
82 #include "content/public/test/test_utils.h" 85 #include "content/public/test/test_utils.h"
83 #include "net/base/host_port_pair.h" 86 #include "net/base/host_port_pair.h"
87 #include "net/base/io_buffer.h"
84 #include "net/base/net_errors.h" 88 #include "net/base/net_errors.h"
85 #include "net/cert/cert_status_flags.h" 89 #include "net/cert/cert_status_flags.h"
86 #include "net/cert/mock_cert_verifier.h" 90 #include "net/cert/mock_cert_verifier.h"
87 #include "net/cert/x509_certificate.h" 91 #include "net/cert/x509_certificate.h"
88 #include "net/dns/mock_host_resolver.h" 92 #include "net/dns/mock_host_resolver.h"
93 #include "net/http/http_response_headers.h"
89 #include "net/ssl/ssl_info.h" 94 #include "net/ssl/ssl_info.h"
90 #include "net/test/cert_test_util.h" 95 #include "net/test/cert_test_util.h"
91 #include "net/test/embedded_test_server/embedded_test_server.h" 96 #include "net/test/embedded_test_server/embedded_test_server.h"
92 #include "net/test/embedded_test_server/request_handler_util.h" 97 #include "net/test/embedded_test_server/request_handler_util.h"
93 #include "net/test/spawned_test_server/spawned_test_server.h" 98 #include "net/test/spawned_test_server/spawned_test_server.h"
94 #include "net/test/test_certificate_data.h" 99 #include "net/test/test_certificate_data.h"
95 #include "net/test/test_data_directory.h" 100 #include "net/test/test_data_directory.h"
96 #include "net/url_request/url_request_context.h" 101 #include "net/url_request/url_request_context.h"
97 #include "net/url_request/url_request_filter.h" 102 #include "net/url_request/url_request_filter.h"
98 #include "net/url_request/url_request_job.h" 103 #include "net/url_request/url_request_job.h"
(...skipping 2747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 2851
2847 // Grab the SSLStatus from the page and check that it is the same as 2852 // Grab the SSLStatus from the page and check that it is the same as
2848 // on the clock interstitial. 2853 // on the clock interstitial.
2849 entry = tab->GetController().GetActiveEntry(); 2854 entry = tab->GetController().GetActiveEntry();
2850 ASSERT_TRUE(entry); 2855 ASSERT_TRUE(entry);
2851 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL(); 2856 content::SSLStatus after_interstitial_ssl_status = entry->GetSSL();
2852 ASSERT_NO_FATAL_FAILURE( 2857 ASSERT_NO_FATAL_FAILURE(
2853 after_interstitial_ssl_status.Equals(clock_interstitial_ssl_status)); 2858 after_interstitial_ssl_status.Equals(clock_interstitial_ssl_status));
2854 } 2859 }
2855 2860
2861 // A URLRequestJob that serves valid time server responses, but delays
2862 // them until Resume() is called. If Resume() is called before a request
2863 // is made, then the request will not be delayed.
2864 class DelayableNetworkTimeURLRequestJob : public net::URLRequestJob {
2865 public:
2866 DelayableNetworkTimeURLRequestJob(net::URLRequest* request,
2867 net::NetworkDelegate* network_delegate,
2868 bool delayed)
2869 : net::URLRequestJob(request, network_delegate),
2870 delayed_(delayed),
2871 weak_factory_(this) {}
2872
2873 ~DelayableNetworkTimeURLRequestJob() override {}
2874
2875 base::WeakPtr<DelayableNetworkTimeURLRequestJob> GetWeakPtr() {
2876 return weak_factory_.GetWeakPtr();
2877 }
2878
2879 // URLRequestJob:
2880 void Start() override {
2881 started_ = true;
2882 if (delayed_) {
2883 // Do nothing until Resume() is called.
2884 return;
2885 }
2886 Resume();
2887 }
2888
2889 int ReadRawData(net::IOBuffer* buf, int buf_size) override {
2890 int bytes_read =
2891 std::min(static_cast<size_t>(buf_size),
2892 strlen(network_time::kGoodTimeResponseBody) - data_offset_);
2893 memcpy(buf->data(), network_time::kGoodTimeResponseBody + data_offset_,
2894 bytes_read);
2895 data_offset_ += bytes_read;
2896 return bytes_read;
2897 }
2898
2899 int GetResponseCode() const override { return 200; }
2900
2901 void GetResponseInfo(net::HttpResponseInfo* info) override {
2902 std::string headers;
2903 headers.append(
2904 "HTTP/1.1 200 OK\n"
2905 "Content-type: text/plain\n");
2906 headers.append(base::StringPrintf(
2907 "Content-Length: %1d\n",
2908 static_cast<int>(strlen(network_time::kGoodTimeResponseBody))));
2909 info->headers =
2910 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
2911 headers.c_str(), static_cast<int>(headers.length())));
2912 info->headers->AddHeader(
2913 "x-cup-server-proof: " +
2914 std::string(network_time::kGoodTimeResponseServerProofHeader));
2915 }
2916
2917 // Resumes a previously started request that was delayed. If no
2918 // request has been started yet, then when Start() is called it will
2919 // not delay.
2920 void Resume() {
2921 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
2922 DCHECK(delayed_);
2923 if (!started_) {
2924 // If Start() hasn't been called yet, then unset |delayed_| so
2925 // that when Start() is called, the request will begin
2926 // immediately.
2927 delayed_ = false;
2928 return;
2929 }
2930
2931 // Start reading asynchronously as would a normal network request.
2932 base::ThreadTaskRunnerHandle::Get()->PostTask(
2933 FROM_HERE,
2934 base::Bind(&DelayableNetworkTimeURLRequestJob::NotifyHeadersComplete,
2935 weak_factory_.GetWeakPtr()));
2936 }
2937
2938 private:
2939 bool delayed_;
2940 bool started_ = false;
2941 int data_offset_ = 0;
2942 base::WeakPtrFactory<DelayableNetworkTimeURLRequestJob> weak_factory_;
2943
2944 DISALLOW_COPY_AND_ASSIGN(DelayableNetworkTimeURLRequestJob);
2945 };
2946
2947 // A URLRequestInterceptor that intercepts requests to use
2948 // DelayableNetworkTimeURLRequestJobs. Expects only to intercept only a
meacer 2016/11/08 19:39:41 nit: Multiple "only"s
estark 2016/11/08 19:46:34 Done.
2949 // single request in its lifetime.
2950 class DelayedNetworkTimeInterceptor : public net::URLRequestInterceptor {
2951 public:
2952 DelayedNetworkTimeInterceptor() {}
2953 ~DelayedNetworkTimeInterceptor() override {}
2954
2955 // Intercepts |request| to use a DelayableNetworkTimeURLRequestJob. If
2956 // Resume() has been called before MaybeInterceptRequest(), then the
2957 // request will not be delayed.
2958 net::URLRequestJob* MaybeInterceptRequest(
2959 net::URLRequest* request,
2960 net::NetworkDelegate* network_delegate) const override {
2961 // Only support one intercepted request.
2962 EXPECT_FALSE(intercepted_request_);
2963 intercepted_request_ = true;
2964 // If the request has been resumed before this request is created,
2965 // then |delay_requests_| will be false and the request will not delay.
2966 DelayableNetworkTimeURLRequestJob* job =
2967 new DelayableNetworkTimeURLRequestJob(request, network_delegate,
2968 delay_requests_);
2969 if (delay_requests_)
2970 delayed_request_ = job->GetWeakPtr();
2971 return job;
2972 }
2973
2974 void Resume() {
2975 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
2976 if (!delay_requests_)
2977 return;
2978 delay_requests_ = false;
2979 if (delayed_request_)
2980 delayed_request_->Resume();
2981 }
2982
2983 private:
2984 // True if a request has been intercepted. Used to enforce that only
2985 // one request is intercepted in this object's lifetime.
2986 mutable bool intercepted_request_ = false;
2987 // True until Resume() is called. If Resume() is called before a
2988 // request is intercepted, then a request that is intercepted later
2989 // will continue without a delay.
2990 bool delay_requests_ = true;
meacer 2016/11/08 19:39:41 very minor nit: this sounds too much like delayed_
estark 2016/11/08 19:46:34 Done.
2991 // Use a WeakPtr in case the request is cancelled before Resume() is called.
2992 mutable base::WeakPtr<DelayableNetworkTimeURLRequestJob> delayed_request_ =
2993 nullptr;
2994
2995 DISALLOW_COPY_AND_ASSIGN(DelayedNetworkTimeInterceptor);
2996 };
2997
2998 // IO-thread helper methods for SSLNetworkTimeBrowserTest.
2999
3000 void ResumeDelayedNetworkTimeRequest(
3001 DelayedNetworkTimeInterceptor* interceptor) {
3002 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
3003 interceptor->Resume();
3004 }
3005
3006 void SetUpNetworkTimeInterceptorOnIOThread(
3007 DelayedNetworkTimeInterceptor* interceptor,
3008 const GURL& time_server_url) {
3009 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
3010 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor(
3011 time_server_url.scheme(), time_server_url.host(),
3012 std::unique_ptr<DelayedNetworkTimeInterceptor>(interceptor));
3013 }
3014
3015 void CleanUpOnIOThread() {
3016 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
3017 net::URLRequestFilter::GetInstance()->ClearHandlers();
3018 }
3019
3020 // A fixture for testing on-demand network time queries on SSL
3021 // certificate date errors. It can simulate a delayed network time
3022 // request, and it allows the user to configure the experimental
3023 // parameters of the NetworkTimeTracker. Expects only one network time
3024 // request to be issued during the test.
3025 class SSLNetworkTimeBrowserTest : public SSLUITest {
3026 public:
3027 SSLNetworkTimeBrowserTest()
3028 : SSLUITest(),
3029 field_trial_test_(network_time::FieldTrialTest::CreateForBrowserTest()),
3030 interceptor_(nullptr) {}
3031 ~SSLNetworkTimeBrowserTest() override {}
3032
3033 void SetUpOnMainThread() override { SetUpNetworkTimeServer(); }
3034
3035 void TearDownOnMainThread() override {
3036 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
3037 base::Bind(&CleanUpOnIOThread));
3038 }
3039
3040 protected:
3041 network_time::FieldTrialTest* field_trial_test() const {
3042 return field_trial_test_.get();
3043 }
3044
3045 void SetUpNetworkTimeServer() {
3046 field_trial_test()->SetNetworkQueriesWithVariationsService(
3047 true, 0.0, network_time::FieldTrialTest::FETCHES_ON_DEMAND_ONLY);
3048
3049 // Install the URL interceptor that serves delayed network time
3050 // responses.
3051 interceptor_ = new DelayedNetworkTimeInterceptor();
3052 content::BrowserThread::PostTask(
3053 content::BrowserThread::IO, FROM_HERE,
3054 base::Bind(&SetUpNetworkTimeInterceptorOnIOThread,
3055 base::Unretained(interceptor_),
3056 g_browser_process->network_time_tracker()
3057 ->GetTimeServerURLForTesting()));
3058 }
3059
3060 void TriggerTimeResponse() {
3061 content::BrowserThread::PostTask(
3062 content::BrowserThread::IO, FROM_HERE,
3063 base::Bind(&ResumeDelayedNetworkTimeRequest,
3064 base::Unretained(interceptor_)));
3065 }
3066
3067 // Asserts that the first time request to the server is currently pending.
3068 void CheckTimeQueryPending() {
3069 base::Time unused_time;
3070 base::TimeDelta unused_uncertainty;
3071 ASSERT_EQ(network_time::NetworkTimeTracker::NETWORK_TIME_FIRST_SYNC_PENDING,
3072 g_browser_process->network_time_tracker()->GetNetworkTime(
3073 &unused_time, &unused_uncertainty));
3074 }
3075
3076 private:
3077 std::unique_ptr<network_time::FieldTrialTest> field_trial_test_;
3078 DelayedNetworkTimeInterceptor* interceptor_;
3079
3080 DISALLOW_COPY_AND_ASSIGN(SSLNetworkTimeBrowserTest);
3081 };
3082
3083 // Tests that if an on-demand network time fetch returns that the clock
3084 // is okay, a normal SSL interstitial is shown.
3085 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockOk) {
3086 ASSERT_TRUE(https_server_expired_.Start());
3087 // Use a testing clock set to the time that GoodTimeResponseHandler
3088 // returns, to simulate the system clock matching the network time.
3089 base::SimpleTestClock testing_clock;
3090 SSLErrorHandler::SetClockForTest(&testing_clock);
3091 testing_clock.SetNow(
3092 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerJsTime));
3093 // Set the build time to match the testing clock, to ensure that the
3094 // build time heuristic doesn't fire.
3095 ssl_errors::SetBuildTimeForTesting(testing_clock.Now());
3096
3097 // Set a long timeout to ensure that the on-demand time fetch completes.
3098 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3099
3100 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3101 ASSERT_TRUE(contents);
3102 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3103
3104 content::WindowedNotificationObserver observer(
3105 content::NOTIFICATION_LOAD_STOP,
3106 content::NotificationService::AllSources());
3107 ui_test_utils::NavigateToURLWithDisposition(
3108 browser(), https_server_expired_.GetURL("/"),
3109 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3110
3111 // Once |interstitial_timer_observer| has fired, the request has been
3112 // sent. Override the nonce that NetworkTimeTracker expects so that
3113 // when the response comes back, it will validate. The nonce can only
3114 // be overriden for the current in-flight request, so the test must
3115 // call OverrideNonceForTesting() after the request has been sent and
3116 // before the response has been received.
3117 interstitial_timer_observer.WaitForTimerStarted();
3118 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123);
3119 TriggerTimeResponse();
3120
3121 EXPECT_TRUE(contents->IsLoading());
3122 observer.Wait();
3123 content::WaitForInterstitialAttach(contents);
3124
3125 EXPECT_TRUE(contents->ShowingInterstitialPage());
3126 InterstitialPage* interstitial_page = contents->GetInterstitialPage();
3127 ASSERT_TRUE(interstitial_page);
3128 ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
3129 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3130 }
3131
3132 // Tests that if an on-demand network time fetch returns that the clock
3133 // is wrong, a bad clock interstitial is shown.
3134 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, OnDemandFetchClockWrong) {
3135 ASSERT_TRUE(https_server_expired_.Start());
3136 // Use a testing clock set to a time that is different from what
3137 // GoodTimeResponseHandler returns, simulating a system clock that is
3138 // 30 days ahead of the network time.
3139 base::SimpleTestClock testing_clock;
3140 SSLErrorHandler::SetClockForTest(&testing_clock);
3141 testing_clock.SetNow(
3142 base::Time::FromJsTime(network_time::kGoodTimeResponseHandlerJsTime));
3143 testing_clock.Advance(base::TimeDelta::FromDays(30));
3144 // Set the build time to match the testing clock, to ensure that the
3145 // build time heuristic doesn't fire.
3146 ssl_errors::SetBuildTimeForTesting(testing_clock.Now());
3147
3148 // Set a long timeout to ensure that the on-demand time fetch completes.
3149 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3150
3151 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3152 ASSERT_TRUE(contents);
3153 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3154
3155 content::WindowedNotificationObserver observer(
3156 content::NOTIFICATION_LOAD_STOP,
3157 content::NotificationService::AllSources());
3158
3159 ui_test_utils::NavigateToURLWithDisposition(
3160 browser(), https_server_expired_.GetURL("/"),
3161 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3162
3163 // Once |interstitial_timer_observer| has fired, the request has been
3164 // sent. Override the nonce that NetworkTimeTracker expects so that
3165 // when the response comes back, it will validate. The nonce can only
3166 // be overriden for the current in-flight request, so the test must
3167 // call OverrideNonceForTesting() after the request has been sent and
3168 // before the response has been received.
3169 interstitial_timer_observer.WaitForTimerStarted();
3170 g_browser_process->network_time_tracker()->OverrideNonceForTesting(123123123);
3171 TriggerTimeResponse();
3172
3173 EXPECT_TRUE(contents->IsLoading());
3174 observer.Wait();
3175 content::WaitForInterstitialAttach(contents);
3176
3177 EXPECT_TRUE(contents->ShowingInterstitialPage());
3178 InterstitialPage* interstitial_page = contents->GetInterstitialPage();
3179 ASSERT_TRUE(interstitial_page);
3180 ASSERT_EQ(BadClockBlockingPage::kTypeForTesting,
3181 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3182 }
3183
3184 // Tests that if the timeout expires before the network time fetch
3185 // returns, then a normal SSL intersitial is shown.
3186 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest,
3187 TimeoutExpiresBeforeFetchCompletes) {
3188 ASSERT_TRUE(https_server_expired_.Start());
3189 // Set the timer to fire immediately.
3190 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta());
3191
3192 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
3193 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3194 ASSERT_TRUE(contents);
3195 content::WaitForInterstitialAttach(contents);
3196
3197 EXPECT_TRUE(contents->ShowingInterstitialPage());
3198 InterstitialPage* interstitial_page = contents->GetInterstitialPage();
3199 ASSERT_TRUE(interstitial_page);
3200 ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
3201 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3202
3203 // Navigate away, and then trigger the network time response; no crash should
3204 // occur.
3205 ASSERT_TRUE(https_server_.Start());
3206 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/"));
3207 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3208 TriggerTimeResponse();
3209 }
3210
3211 // Tests that if the user stops the page load before either the network
3212 // time fetch completes or the timeout expires, then there is no interstitial.
3213 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, StopBeforeTimeoutExpires) {
3214 ASSERT_TRUE(https_server_expired_.Start());
3215 // Set the timer to a long delay.
3216 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3217
3218 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3219 ASSERT_TRUE(contents);
3220 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3221
3222 ui_test_utils::NavigateToURLWithDisposition(
3223 browser(), https_server_expired_.GetURL("/"),
3224 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3225 interstitial_timer_observer.WaitForTimerStarted();
3226
3227 EXPECT_TRUE(contents->IsLoading());
3228 content::WindowedNotificationObserver observer(
3229 content::NOTIFICATION_LOAD_STOP,
3230 content::NotificationService::AllSources());
3231 contents->Stop();
3232 observer.Wait();
3233
3234 // Make sure that the |SSLErrorHandler| is deleted.
3235 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents));
3236 EXPECT_FALSE(contents->ShowingInterstitialPage());
3237 EXPECT_FALSE(contents->IsLoading());
3238
3239 // Navigate away, and then trigger the network time response; no crash should
3240 // occur.
3241 ASSERT_TRUE(https_server_.Start());
3242 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/title1.html"));
3243 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3244 TriggerTimeResponse();
3245 }
3246
3247 // Tests that if the user reloads the page before either the network
3248 // time fetch completes or the timeout expires, then there is no interstitial.
3249 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest, ReloadBeforeTimeoutExpires) {
3250 ASSERT_TRUE(https_server_expired_.Start());
3251 // Set the timer to a long delay.
3252 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3253
3254 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3255 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3256
3257 ui_test_utils::NavigateToURLWithDisposition(
3258 browser(), https_server_expired_.GetURL("/"),
3259 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3260 interstitial_timer_observer.WaitForTimerStarted();
3261
3262 EXPECT_TRUE(contents->IsLoading());
3263 content::TestNavigationObserver observer(contents, 1);
3264 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
3265 observer.Wait();
3266
3267 // Make sure that the |SSLErrorHandler| is deleted.
3268 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents));
3269 EXPECT_FALSE(contents->ShowingInterstitialPage());
3270 EXPECT_FALSE(contents->IsLoading());
3271
3272 // Navigate away, and then trigger the network time response and wait
3273 // for the response; no crash should occur.
3274 ASSERT_TRUE(https_server_.Start());
3275 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/"));
3276 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3277 TriggerTimeResponse();
3278 }
3279
3280 // Tests that if the user navigates away before either the network time
3281 // fetch completes or the timeout expires, then there is no
3282 // interstitial.
3283 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest,
3284 NavigateAwayBeforeTimeoutExpires) {
3285 ASSERT_TRUE(https_server_expired_.Start());
3286 ASSERT_TRUE(https_server_.Start());
3287 // Set the timer to a long delay.
3288 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta::FromHours(1));
3289
3290 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3291 SSLInterstitialTimerObserver interstitial_timer_observer(contents);
3292
3293 ui_test_utils::NavigateToURLWithDisposition(
3294 browser(), https_server_expired_.GetURL("/"),
3295 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
3296 interstitial_timer_observer.WaitForTimerStarted();
3297
3298 EXPECT_TRUE(contents->IsLoading());
3299 content::TestNavigationObserver observer(contents, 1);
3300 browser()->OpenURL(content::OpenURLParams(
3301 https_server_.GetURL("/"), content::Referrer(),
3302 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
3303 observer.Wait();
3304
3305 // Make sure that the |SSLErrorHandler| is deleted.
3306 EXPECT_FALSE(SSLErrorHandler::FromWebContents(contents));
3307 EXPECT_FALSE(contents->ShowingInterstitialPage());
3308 EXPECT_FALSE(contents->IsLoading());
3309
3310 // Navigate away, and then trigger the network time response and wait
3311 // for the response; no crash should occur.
3312 ui_test_utils::NavigateToURL(browser(), https_server_.GetURL("/"));
3313 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3314 TriggerTimeResponse();
3315 }
3316
3317 // Tests that if the user closes the tab before the network time fetch
3318 // completes, it doesn't cause a crash.
3319 IN_PROC_BROWSER_TEST_F(SSLNetworkTimeBrowserTest,
3320 CloseTabBeforeNetworkFetchCompletes) {
3321 ASSERT_TRUE(https_server_expired_.Start());
3322 // Set the timer to fire immediately.
3323 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta());
3324
3325 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
3326 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
3327 ASSERT_TRUE(contents);
3328 content::WaitForInterstitialAttach(contents);
3329
3330 EXPECT_TRUE(contents->ShowingInterstitialPage());
3331 InterstitialPage* interstitial_page = contents->GetInterstitialPage();
3332 ASSERT_TRUE(interstitial_page);
3333 ASSERT_EQ(SSLBlockingPage::kTypeForTesting,
3334 interstitial_page->GetDelegateForTesting()->GetTypeForTesting());
3335
3336 // Open a second tab, close the first, and then trigger the network time
3337 // response and wait for the response; no crash should occur.
3338 ASSERT_TRUE(https_server_.Start());
3339 AddTabAtIndex(1, https_server_.GetURL("/"), ui::PAGE_TRANSITION_TYPED);
3340 chrome::CloseWebContents(browser(), contents, false);
3341 ASSERT_NO_FATAL_FAILURE(CheckTimeQueryPending());
3342 TriggerTimeResponse();
3343 }
3344
2856 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest { 3345 class CommonNameMismatchBrowserTest : public CertVerifierBrowserTest {
2857 public: 3346 public:
2858 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {} 3347 CommonNameMismatchBrowserTest() : CertVerifierBrowserTest() {}
2859 ~CommonNameMismatchBrowserTest() override {} 3348 ~CommonNameMismatchBrowserTest() override {}
2860 3349
2861 void SetUpCommandLine(base::CommandLine* command_line) override { 3350 void SetUpCommandLine(base::CommandLine* command_line) override {
2862 // Enable finch experiment for SSL common name mismatch handling. 3351 // Enable finch experiment for SSL common name mismatch handling.
2863 command_line->AppendSwitchASCII(switches::kForceFieldTrials, 3352 command_line->AppendSwitchASCII(switches::kForceFieldTrials,
2864 "SSLCommonNameMismatchHandling/Enabled/"); 3353 "SSLCommonNameMismatchHandling/Enabled/");
2865 } 3354 }
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
3410 3899
3411 // Visit a page over https that contains a frame with a redirect. 3900 // Visit a page over https that contains a frame with a redirect.
3412 3901
3413 // XMLHttpRequest insecure content in synchronous mode. 3902 // XMLHttpRequest insecure content in synchronous mode.
3414 3903
3415 // XMLHttpRequest insecure content in asynchronous mode. 3904 // XMLHttpRequest insecure content in asynchronous mode.
3416 3905
3417 // XMLHttpRequest over bad ssl in synchronous mode. 3906 // XMLHttpRequest over bad ssl in synchronous mode.
3418 3907
3419 // XMLHttpRequest over OK ssl in synchronous mode. 3908 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ssl/ssl_error_handler.h » ('j') | components/network_time/network_time_tracker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698