| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ssl/ssl_error_handler.h" | 5 #include "chrome/browser/ssl/ssl_error_handler.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/histogram_tester.h" | 12 #include "base/test/histogram_tester.h" |
| 13 #include "base/test/scoped_feature_list.h" |
| 13 #include "base/test/simple_test_clock.h" | 14 #include "base/test/simple_test_clock.h" |
| 14 #include "base/test/simple_test_tick_clock.h" | 15 #include "base/test/simple_test_tick_clock.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "chrome/browser/captive_portal/captive_portal_service.h" | 17 #include "chrome/browser/captive_portal/captive_portal_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ssl/common_name_mismatch_handler.h" | 19 #include "chrome/browser/ssl/common_name_mismatch_handler.h" |
| 20 #include "chrome/browser/ssl/ssl_error_assistant.pb.h" |
| 19 #include "chrome/common/features.h" | 21 #include "chrome/common/features.h" |
| 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/captive_portal/captive_portal_testing_utils.h" | 24 #include "components/captive_portal/captive_portal_testing_utils.h" |
| 23 #include "components/network_time/network_time_test_utils.h" | 25 #include "components/network_time/network_time_test_utils.h" |
| 24 #include "components/network_time/network_time_tracker.h" | 26 #include "components/network_time/network_time_tracker.h" |
| 25 #include "components/prefs/testing_pref_service.h" | 27 #include "components/prefs/testing_pref_service.h" |
| 26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 28 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
| 29 #include "net/cert/cert_status_flags.h" | 31 #include "net/cert/cert_status_flags.h" |
| 30 #include "net/cert/x509_certificate.h" | 32 #include "net/cert/x509_certificate.h" |
| 31 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 32 #include "net/ssl/ssl_info.h" | 34 #include "net/ssl/ssl_info.h" |
| 33 #include "net/test/cert_test_util.h" | 35 #include "net/test/cert_test_util.h" |
| 34 #include "net/test/embedded_test_server/embedded_test_server.h" | 36 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 35 #include "net/test/embedded_test_server/http_response.h" | 37 #include "net/test/embedded_test_server/http_response.h" |
| 36 #include "net/test/test_certificate_data.h" | 38 #include "net/test/test_certificate_data.h" |
| 37 #include "net/test/test_data_directory.h" | 39 #include "net/test/test_data_directory.h" |
| 38 #include "net/url_request/url_request_test_util.h" | 40 #include "net/url_request/url_request_test_util.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 const char kCertDateErrorHistogram[] = | 45 const char kCertDateErrorHistogram[] = |
| 44 "interstitial.ssl_error_handler.cert_date_error_delay"; | 46 "interstitial.ssl_error_handler.cert_date_error_delay"; |
| 45 | 47 |
| 48 const net::SHA256HashValue kCertPublicKeyHashValue = {{0x01, 0x02}}; |
| 49 |
| 46 // Runs |quit_closure| on the UI thread once a URL request has been | 50 // Runs |quit_closure| on the UI thread once a URL request has been |
| 47 // seen. Returns a request that hangs. | 51 // seen. Returns a request that hangs. |
| 48 std::unique_ptr<net::test_server::HttpResponse> WaitForRequest( | 52 std::unique_ptr<net::test_server::HttpResponse> WaitForRequest( |
| 49 const base::Closure& quit_closure, | 53 const base::Closure& quit_closure, |
| 50 const net::test_server::HttpRequest& request) { | 54 const net::test_server::HttpRequest& request) { |
| 51 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 55 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 52 quit_closure); | 56 quit_closure); |
| 53 return base::MakeUnique<net::test_server::HungResponse>(); | 57 return base::MakeUnique<net::test_server::HungResponse>(); |
| 54 } | 58 } |
| 55 | 59 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 bool captive_portal_interstitial_shown_; | 184 bool captive_portal_interstitial_shown_; |
| 181 bool redirected_to_suggested_url_; | 185 bool redirected_to_suggested_url_; |
| 182 bool is_overridable_error_; | 186 bool is_overridable_error_; |
| 183 CommonNameMismatchHandler::CheckUrlCallback suggested_url_callback_; | 187 CommonNameMismatchHandler::CheckUrlCallback suggested_url_callback_; |
| 184 | 188 |
| 185 DISALLOW_COPY_AND_ASSIGN(TestSSLErrorHandlerDelegate); | 189 DISALLOW_COPY_AND_ASSIGN(TestSSLErrorHandlerDelegate); |
| 186 }; | 190 }; |
| 187 | 191 |
| 188 } // namespace | 192 } // namespace |
| 189 | 193 |
| 190 class SSLErrorHandlerNameMismatchTest : public ChromeRenderViewHostTestHarness { | 194 template <net::CertStatus cert_status> |
| 195 class SSLErrorHandlerCertStatusTestBase |
| 196 : public ChromeRenderViewHostTestHarness { |
| 191 public: | 197 public: |
| 192 SSLErrorHandlerNameMismatchTest() : field_trial_list_(nullptr) {} | 198 SSLErrorHandlerCertStatusTestBase() : field_trial_list_(nullptr) {} |
| 193 | 199 |
| 194 void SetUp() override { | 200 void SetUp() override { |
| 195 ChromeRenderViewHostTestHarness::SetUp(); | 201 ChromeRenderViewHostTestHarness::SetUp(); |
| 202 SSLErrorHandler::ResetConfigForTesting(); |
| 196 SSLErrorHandler::SetInterstitialDelayForTesting(base::TimeDelta()); | 203 SSLErrorHandler::SetInterstitialDelayForTesting(base::TimeDelta()); |
| 197 ssl_info_.cert = | 204 ssl_info_.cert = |
| 198 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | 205 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); |
| 199 ssl_info_.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | 206 ssl_info_.cert_status = cert_status; |
| 207 ssl_info_.public_key_hashes.push_back( |
| 208 net::HashValue(kCertPublicKeyHashValue)); |
| 200 | 209 |
| 201 delegate_ = | 210 delegate_ = |
| 202 new TestSSLErrorHandlerDelegate(profile(), web_contents(), ssl_info_); | 211 new TestSSLErrorHandlerDelegate(profile(), web_contents(), ssl_info_); |
| 203 error_handler_.reset(new TestSSLErrorHandler( | 212 error_handler_.reset(new TestSSLErrorHandler( |
| 204 std::unique_ptr<SSLErrorHandler::Delegate>(delegate_), web_contents(), | 213 std::unique_ptr<SSLErrorHandler::Delegate>(delegate_), web_contents(), |
| 205 profile(), net::MapCertStatusToNetError(ssl_info_.cert_status), | 214 profile(), net::MapCertStatusToNetError(ssl_info_.cert_status), |
| 206 ssl_info_, | 215 ssl_info_, |
| 207 GURL(), // request_url | 216 GURL(), // request_url |
| 208 base::Callback<void(content::CertificateRequestResultType)>())); | 217 base::Callback<void(content::CertificateRequestResultType)>())); |
| 209 | 218 |
| 210 // Enable finch experiment for captive portal interstitials. | 219 // Enable finch experiment for captive portal interstitials. |
| 211 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 220 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 212 "CaptivePortalInterstitial", "Enabled")); | 221 "CaptivePortalInterstitial", "Enabled")); |
| 213 // Enable finch experiment for SSL common name mismatch handling. | 222 // Enable finch experiment for SSL common name mismatch handling. |
| 214 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 223 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 215 "SSLCommonNameMismatchHandling", "Enabled")); | 224 "SSLCommonNameMismatchHandling", "Enabled")); |
| 216 } | 225 } |
| 217 | 226 |
| 218 void TearDown() override { | 227 void TearDown() override { |
| 219 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); | 228 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); |
| 220 error_handler_.reset(nullptr); | 229 error_handler_.reset(nullptr); |
| 230 SSLErrorHandler::ResetConfigForTesting(); |
| 221 ChromeRenderViewHostTestHarness::TearDown(); | 231 ChromeRenderViewHostTestHarness::TearDown(); |
| 222 } | 232 } |
| 223 | 233 |
| 224 TestSSLErrorHandler* error_handler() { return error_handler_.get(); } | 234 TestSSLErrorHandler* error_handler() { return error_handler_.get(); } |
| 225 TestSSLErrorHandlerDelegate* delegate() { return delegate_; } | 235 TestSSLErrorHandlerDelegate* delegate() { return delegate_; } |
| 226 | 236 |
| 237 const net::SSLInfo& ssl_info() { return ssl_info_; } |
| 238 |
| 227 private: | 239 private: |
| 228 net::SSLInfo ssl_info_; | 240 net::SSLInfo ssl_info_; |
| 229 std::unique_ptr<TestSSLErrorHandler> error_handler_; | 241 std::unique_ptr<TestSSLErrorHandler> error_handler_; |
| 230 TestSSLErrorHandlerDelegate* delegate_; | 242 TestSSLErrorHandlerDelegate* delegate_; |
| 231 base::FieldTrialList field_trial_list_; | 243 base::FieldTrialList field_trial_list_; |
| 232 | 244 |
| 233 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandlerNameMismatchTest); | 245 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandlerCertStatusTestBase); |
| 234 }; | 246 }; |
| 235 | 247 |
| 248 using SSLErrorHandlerNameMismatchTest = |
| 249 SSLErrorHandlerCertStatusTestBase<net::CERT_STATUS_COMMON_NAME_INVALID>; |
| 250 using SSLErrorHandlerAuthorityInvalidTest = |
| 251 SSLErrorHandlerCertStatusTestBase<net::CERT_STATUS_AUTHORITY_INVALID>; |
| 252 |
| 236 class SSLErrorHandlerDateInvalidTest : public ChromeRenderViewHostTestHarness { | 253 class SSLErrorHandlerDateInvalidTest : public ChromeRenderViewHostTestHarness { |
| 237 public: | 254 public: |
| 238 SSLErrorHandlerDateInvalidTest() | 255 SSLErrorHandlerDateInvalidTest() |
| 239 : field_trial_test_(new network_time::FieldTrialTest()), | 256 : field_trial_test_(new network_time::FieldTrialTest()), |
| 240 clock_(new base::SimpleTestClock), | 257 clock_(new base::SimpleTestClock), |
| 241 tick_clock_(new base::SimpleTestTickClock), | 258 tick_clock_(new base::SimpleTestTickClock), |
| 242 test_server_(new net::EmbeddedTestServer) { | 259 test_server_(new net::EmbeddedTestServer) { |
| 243 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); | 260 SetThreadBundleOptions(content::TestBrowserThreadBundle::REAL_IO_THREAD); |
| 244 network_time::NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); | 261 network_time::NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); |
| 245 } | 262 } |
| 246 | 263 |
| 247 void SetUp() override { | 264 void SetUp() override { |
| 248 ChromeRenderViewHostTestHarness::SetUp(); | 265 ChromeRenderViewHostTestHarness::SetUp(); |
| 266 SSLErrorHandler::ResetConfigForTesting(); |
| 249 | 267 |
| 250 field_trial_test()->SetNetworkQueriesWithVariationsService( | 268 field_trial_test()->SetNetworkQueriesWithVariationsService( |
| 251 false, 0.0, | 269 false, 0.0, |
| 252 network_time::NetworkTimeTracker::FETCHES_IN_BACKGROUND_ONLY); | 270 network_time::NetworkTimeTracker::FETCHES_IN_BACKGROUND_ONLY); |
| 253 tracker_.reset(new network_time::NetworkTimeTracker( | 271 tracker_.reset(new network_time::NetworkTimeTracker( |
| 254 std::unique_ptr<base::Clock>(clock_), | 272 std::unique_ptr<base::Clock>(clock_), |
| 255 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_, | 273 std::unique_ptr<base::TickClock>(tick_clock_), &pref_service_, |
| 256 new net::TestURLRequestContextGetter( | 274 new net::TestURLRequestContextGetter( |
| 257 content::BrowserThread::GetTaskRunnerForThread( | 275 content::BrowserThread::GetTaskRunnerForThread( |
| 258 content::BrowserThread::IO)))); | 276 content::BrowserThread::IO)))); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 279 // Fix flakiness in case system time is off and triggers a bad clock | 297 // Fix flakiness in case system time is off and triggers a bad clock |
| 280 // interstitial. https://crbug.com/666821#c50 | 298 // interstitial. https://crbug.com/666821#c50 |
| 281 ssl_errors::SetBuildTimeForTesting(base::Time::Now()); | 299 ssl_errors::SetBuildTimeForTesting(base::Time::Now()); |
| 282 } | 300 } |
| 283 | 301 |
| 284 void TearDown() override { | 302 void TearDown() override { |
| 285 if (error_handler()) { | 303 if (error_handler()) { |
| 286 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); | 304 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); |
| 287 error_handler_.reset(nullptr); | 305 error_handler_.reset(nullptr); |
| 288 } | 306 } |
| 307 SSLErrorHandler::ResetConfigForTesting(); |
| 289 ChromeRenderViewHostTestHarness::TearDown(); | 308 ChromeRenderViewHostTestHarness::TearDown(); |
| 290 } | 309 } |
| 291 | 310 |
| 292 TestSSLErrorHandler* error_handler() { return error_handler_.get(); } | 311 TestSSLErrorHandler* error_handler() { return error_handler_.get(); } |
| 293 TestSSLErrorHandlerDelegate* delegate() { return delegate_; } | 312 TestSSLErrorHandlerDelegate* delegate() { return delegate_; } |
| 294 | 313 |
| 295 network_time::FieldTrialTest* field_trial_test() { | 314 network_time::FieldTrialTest* field_trial_test() { |
| 296 return field_trial_test_.get(); | 315 return field_trial_test_.get(); |
| 297 } | 316 } |
| 298 | 317 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 // Check that the histogram for the delay was recorded. | 691 // Check that the histogram for the delay was recorded. |
| 673 histograms.ExpectTotalCount(kCertDateErrorHistogram, 1); | 692 histograms.ExpectTotalCount(kCertDateErrorHistogram, 1); |
| 674 | 693 |
| 675 // Clear the error handler to test that, when the request completes, | 694 // Clear the error handler to test that, when the request completes, |
| 676 // it doesn't try to call a callback on a deleted SSLErrorHandler. | 695 // it doesn't try to call a callback on a deleted SSLErrorHandler. |
| 677 ClearErrorHandler(); | 696 ClearErrorHandler(); |
| 678 | 697 |
| 679 // Shut down the server to cancel the pending request. | 698 // Shut down the server to cancel the pending request. |
| 680 ASSERT_TRUE(test_server()->ShutdownAndWaitUntilComplete()); | 699 ASSERT_TRUE(test_server()->ShutdownAndWaitUntilComplete()); |
| 681 } | 700 } |
| 701 |
| 702 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 703 |
| 704 // Tests that a certificate marked as a known captive portal certificate causes |
| 705 // the captive portal interstitial to be shown. |
| 706 TEST_F(SSLErrorHandlerNameMismatchTest, CaptivePortalCertificateList_Enabled) { |
| 707 base::test::ScopedFeatureList scoped_feature_list; |
| 708 scoped_feature_list.InitFromCommandLine( |
| 709 "CaptivePortalCertificateList" /* enabled */, "" /* disabled */); |
| 710 |
| 711 base::HistogramTester histograms; |
| 712 |
| 713 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); |
| 714 EXPECT_EQ(1u, ssl_info().public_key_hashes.size()); |
| 715 |
| 716 chrome_browser_ssl::SSLErrorAssistantConfig config_proto; |
| 717 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 718 "sha256/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 719 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 720 ssl_info().public_key_hashes[0].ToString()); |
| 721 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 722 "sha256/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); |
| 723 SSLErrorHandler::SetErrorAssistantProtoForTesting(config_proto); |
| 724 |
| 725 error_handler()->StartHandlingError(); |
| 726 |
| 727 // Timer shouldn't start for a known captive portal certificate. |
| 728 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); |
| 729 EXPECT_FALSE(delegate()->captive_portal_checked()); |
| 730 EXPECT_FALSE(delegate()->ssl_interstitial_shown()); |
| 731 EXPECT_TRUE(delegate()->captive_portal_interstitial_shown()); |
| 732 EXPECT_FALSE(delegate()->suggested_url_checked()); |
| 733 |
| 734 // A buggy SSL error handler might have incorrectly started the timer. Run to |
| 735 // completion to ensure the timer is expired. |
| 736 base::RunLoop().RunUntilIdle(); |
| 737 |
| 738 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); |
| 739 EXPECT_FALSE(delegate()->captive_portal_checked()); |
| 740 EXPECT_FALSE(delegate()->ssl_interstitial_shown()); |
| 741 EXPECT_TRUE(delegate()->captive_portal_interstitial_shown()); |
| 742 EXPECT_FALSE(delegate()->suggested_url_checked()); |
| 743 |
| 744 // Check that the histogram for the captive portal cert was recorded. |
| 745 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 3); |
| 746 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 747 SSLErrorHandler::HANDLE_ALL, 1); |
| 748 histograms.ExpectBucketCount( |
| 749 SSLErrorHandler::GetHistogramNameForTesting(), |
| 750 SSLErrorHandler::SHOW_CAPTIVE_PORTAL_INTERSTITIAL_OVERRIDABLE, 1); |
| 751 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 752 SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 1); |
| 753 } |
| 754 |
| 755 // Tests that a certificate marked as a known captive portal certificate does |
| 756 // not cause the captive portal interstitial to be shown, if the feature is |
| 757 // disabled. |
| 758 TEST_F(SSLErrorHandlerNameMismatchTest, CaptivePortalCertificateList_Disabled) { |
| 759 base::test::ScopedFeatureList scoped_feature_list; |
| 760 scoped_feature_list.InitFromCommandLine( |
| 761 "" /* enabled */, "CaptivePortalCertificateList" /* disabled */); |
| 762 |
| 763 base::HistogramTester histograms; |
| 764 |
| 765 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); |
| 766 EXPECT_EQ(1u, ssl_info().public_key_hashes.size()); |
| 767 |
| 768 chrome_browser_ssl::SSLErrorAssistantConfig config_proto; |
| 769 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 770 "sha256/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 771 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 772 ssl_info().public_key_hashes[0].ToString()); |
| 773 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 774 "sha256/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); |
| 775 SSLErrorHandler::SetErrorAssistantProtoForTesting(config_proto); |
| 776 |
| 777 error_handler()->StartHandlingError(); |
| 778 |
| 779 // Timer shouldn't start for a known captive portal certificate. |
| 780 EXPECT_TRUE(error_handler()->IsTimerRunningForTesting()); |
| 781 EXPECT_TRUE(delegate()->captive_portal_checked()); |
| 782 EXPECT_FALSE(delegate()->ssl_interstitial_shown()); |
| 783 EXPECT_FALSE(delegate()->captive_portal_interstitial_shown()); |
| 784 EXPECT_FALSE(delegate()->suggested_url_checked()); |
| 785 |
| 786 // A buggy SSL error handler might have incorrectly started the timer. Run to |
| 787 // completion to ensure the timer is expired. |
| 788 base::RunLoop().RunUntilIdle(); |
| 789 |
| 790 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); |
| 791 EXPECT_TRUE(delegate()->captive_portal_checked()); |
| 792 EXPECT_TRUE(delegate()->ssl_interstitial_shown()); |
| 793 EXPECT_FALSE(delegate()->captive_portal_interstitial_shown()); |
| 794 EXPECT_FALSE(delegate()->suggested_url_checked()); |
| 795 |
| 796 // Check that the histogram for the captive portal cert was recorded. |
| 797 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 2); |
| 798 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 799 SSLErrorHandler::HANDLE_ALL, 1); |
| 800 histograms.ExpectBucketCount( |
| 801 SSLErrorHandler::GetHistogramNameForTesting(), |
| 802 SSLErrorHandler::SHOW_SSL_INTERSTITIAL_OVERRIDABLE, 1); |
| 803 } |
| 804 |
| 805 // Tests that an error other than name mismatch does not cause a captive portal |
| 806 // interstitial to be shown, even if the certificate is marked as a known |
| 807 // captive portal certificate. |
| 808 TEST_F(SSLErrorHandlerAuthorityInvalidTest, |
| 809 CaptivePortalCertificateList_ShouldShowGenericInterstitial) { |
| 810 base::test::ScopedFeatureList scoped_feature_list; |
| 811 scoped_feature_list.InitFromCommandLine( |
| 812 "CaptivePortalCertificateList" /* enabled */, "" /* disabled */); |
| 813 |
| 814 base::HistogramTester histograms; |
| 815 |
| 816 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); |
| 817 EXPECT_EQ(1u, ssl_info().public_key_hashes.size()); |
| 818 |
| 819 chrome_browser_ssl::SSLErrorAssistantConfig config_proto; |
| 820 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 821 "sha256/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 822 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 823 ssl_info().public_key_hashes[0].ToString()); |
| 824 config_proto.add_captive_portal_cert()->set_sha256_hash( |
| 825 "sha256/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); |
| 826 SSLErrorHandler::SetErrorAssistantProtoForTesting(config_proto); |
| 827 |
| 828 error_handler()->StartHandlingError(); |
| 829 |
| 830 // Timer should start for captive portal detection. |
| 831 EXPECT_TRUE(error_handler()->IsTimerRunningForTesting()); |
| 832 EXPECT_TRUE(delegate()->captive_portal_checked()); |
| 833 EXPECT_FALSE(delegate()->ssl_interstitial_shown()); |
| 834 EXPECT_FALSE(delegate()->captive_portal_interstitial_shown()); |
| 835 EXPECT_FALSE(delegate()->suggested_url_checked()); |
| 836 |
| 837 base::RunLoop().RunUntilIdle(); |
| 838 |
| 839 EXPECT_FALSE(error_handler()->IsTimerRunningForTesting()); |
| 840 EXPECT_TRUE(delegate()->captive_portal_checked()); |
| 841 EXPECT_TRUE(delegate()->ssl_interstitial_shown()); |
| 842 EXPECT_FALSE(delegate()->captive_portal_interstitial_shown()); |
| 843 EXPECT_FALSE(delegate()->suggested_url_checked()); |
| 844 |
| 845 // Check that the histogram for the captive portal cert was recorded. |
| 846 histograms.ExpectTotalCount(SSLErrorHandler::GetHistogramNameForTesting(), 2); |
| 847 histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(), |
| 848 SSLErrorHandler::HANDLE_ALL, 1); |
| 849 histograms.ExpectBucketCount( |
| 850 SSLErrorHandler::GetHistogramNameForTesting(), |
| 851 SSLErrorHandler::SHOW_SSL_INTERSTITIAL_OVERRIDABLE, 1); |
| 852 } |
| 853 |
| 854 #endif // BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| OLD | NEW |