OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This test creates a fake safebrowsing service, where we can inject known- | 5 // This test creates a fake safebrowsing service, where we can inject known- |
6 // threat urls. It then uses a real browser to go to these urls, and sends | 6 // threat urls. It then uses a real browser to go to these urls, and sends |
7 // "goback" or "proceed" commands and verifies they work. | 7 // "goback" or "proceed" commands and verifies they work. |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/test/histogram_tester.h" | 16 #include "base/test/histogram_tester.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" | 20 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" |
21 #include "chrome/browser/net/url_request_mock_util.h" | 21 #include "chrome/browser/net/url_request_mock_util.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/safe_browsing/local_database_manager.h" | 23 #include "chrome/browser/safe_browsing/local_database_manager.h" |
24 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 24 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
25 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | 25 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
26 #include "chrome/browser/safe_browsing/threat_details.h" | 26 #include "chrome/browser/safe_browsing/threat_details.h" |
27 #include "chrome/browser/safe_browsing/ui_manager.h" | 27 #include "chrome/browser/safe_browsing/ui_manager.h" |
28 #include "chrome/browser/ssl/cert_verifier_browser_test.h" | |
29 #include "chrome/browser/ssl/chrome_security_state_model_client.h" | |
28 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_tabstrip.h" | 31 #include "chrome/browser/ui/browser_tabstrip.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
31 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
33 #include "chrome/test/base/in_process_browser_test.h" | 35 #include "chrome/test/base/in_process_browser_test.h" |
34 #include "chrome/test/base/ui_test_utils.h" | 36 #include "chrome/test/base/ui_test_utils.h" |
35 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
36 #include "components/safe_browsing_db/database_manager.h" | 38 #include "components/safe_browsing_db/database_manager.h" |
37 #include "components/safe_browsing_db/test_database_manager.h" | 39 #include "components/safe_browsing_db/test_database_manager.h" |
38 #include "components/safe_browsing_db/util.h" | 40 #include "components/safe_browsing_db/util.h" |
39 #include "components/security_interstitials/core/controller_client.h" | 41 #include "components/security_interstitials/core/controller_client.h" |
40 #include "components/security_interstitials/core/metrics_helper.h" | 42 #include "components/security_interstitials/core/metrics_helper.h" |
41 #include "content/public/browser/interstitial_page.h" | 43 #include "content/public/browser/interstitial_page.h" |
42 #include "content/public/browser/navigation_controller.h" | 44 #include "content/public/browser/navigation_controller.h" |
43 #include "content/public/browser/notification_types.h" | 45 #include "content/public/browser/notification_types.h" |
44 #include "content/public/browser/render_frame_host.h" | 46 #include "content/public/browser/render_frame_host.h" |
45 #include "content/public/browser/render_process_host.h" | 47 #include "content/public/browser/render_process_host.h" |
46 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
47 #include "content/public/test/browser_test_utils.h" | 49 #include "content/public/test/browser_test_utils.h" |
48 #include "content/public/test/test_browser_thread.h" | 50 #include "content/public/test/test_browser_thread.h" |
49 #include "content/public/test/test_utils.h" | 51 #include "content/public/test/test_utils.h" |
52 #include "net/cert/cert_verify_result.h" | |
53 #include "net/cert/mock_cert_verifier.h" | |
54 #include "net/test/embedded_test_server/embedded_test_server.h" | |
50 #include "net/test/url_request/url_request_mock_http_job.h" | 55 #include "net/test/url_request/url_request_mock_http_job.h" |
51 | 56 |
52 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 57 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
53 using content::BrowserThread; | 58 using content::BrowserThread; |
54 using content::InterstitialPage; | 59 using content::InterstitialPage; |
55 using content::NavigationController; | 60 using content::NavigationController; |
56 using content::RenderFrameHost; | 61 using content::RenderFrameHost; |
57 using content::WebContents; | 62 using content::WebContents; |
58 | 63 |
59 namespace safe_browsing { | 64 namespace safe_browsing { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 const GURL& main_frame_url, | 268 const GURL& main_frame_url, |
264 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) | 269 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) |
265 override { | 270 override { |
266 return new TestSafeBrowsingBlockingPage(delegate, web_contents, | 271 return new TestSafeBrowsingBlockingPage(delegate, web_contents, |
267 main_frame_url, unsafe_resources); | 272 main_frame_url, unsafe_resources); |
268 } | 273 } |
269 }; | 274 }; |
270 | 275 |
271 // Tests the safe browsing blocking page in a browser. | 276 // Tests the safe browsing blocking page in a browser. |
272 class SafeBrowsingBlockingPageBrowserTest | 277 class SafeBrowsingBlockingPageBrowserTest |
273 : public InProcessBrowserTest, | 278 : public CertVerifierBrowserTest, |
274 public testing::WithParamInterface<testing::tuple<SBThreatType, bool>> { | 279 public testing::WithParamInterface<testing::tuple<SBThreatType, bool>> { |
275 public: | 280 public: |
276 enum Visibility { | 281 enum Visibility { |
277 VISIBILITY_ERROR = -1, | 282 VISIBILITY_ERROR = -1, |
278 HIDDEN = 0, | 283 HIDDEN = 0, |
279 VISIBLE = 1 | 284 VISIBLE = 1 |
280 }; | 285 }; |
281 | 286 |
282 SafeBrowsingBlockingPageBrowserTest() {} | 287 SafeBrowsingBlockingPageBrowserTest() |
288 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {} | |
283 | 289 |
284 void SetUp() override { | 290 void SetUp() override { |
285 // Test UI manager and test database manager should be set before | 291 // Test UI manager and test database manager should be set before |
286 // InProcessBrowserTest::SetUp(). | 292 // InProcessBrowserTest::SetUp(). |
287 factory_.SetTestUIManager(new FakeSafeBrowsingUIManager()); | 293 factory_.SetTestUIManager(new FakeSafeBrowsingUIManager()); |
288 factory_.SetTestDatabaseManager(new FakeSafeBrowsingDatabaseManager()); | 294 factory_.SetTestDatabaseManager(new FakeSafeBrowsingDatabaseManager()); |
289 SafeBrowsingService::RegisterFactory(&factory_); | 295 SafeBrowsingService::RegisterFactory(&factory_); |
290 SafeBrowsingBlockingPage::RegisterFactory(&blocking_page_factory_); | 296 SafeBrowsingBlockingPage::RegisterFactory(&blocking_page_factory_); |
291 ThreatDetails::RegisterFactory(&details_factory_); | 297 ThreatDetails::RegisterFactory(&details_factory_); |
292 InProcessBrowserTest::SetUp(); | 298 InProcessBrowserTest::SetUp(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 for (auto resource : report.resources()) { | 531 for (auto resource : report.resources()) { |
526 if (actual_resource.parent_id() == resource.id()) { | 532 if (actual_resource.parent_id() == resource.id()) { |
527 EXPECT_EQ(expected_parent, resource.url()); | 533 EXPECT_EQ(expected_parent, resource.url()); |
528 break; | 534 break; |
529 } | 535 } |
530 } | 536 } |
531 EXPECT_EQ(expected_child_size, actual_resource.child_ids_size()); | 537 EXPECT_EQ(expected_child_size, actual_resource.child_ids_size()); |
532 EXPECT_EQ(expected_tag_name, actual_resource.tag_name()); | 538 EXPECT_EQ(expected_tag_name, actual_resource.tag_name()); |
533 } | 539 } |
534 | 540 |
541 void SetUpMockCertVerifierForHttpsServer(net::CertStatus cert_status, | |
542 int net_result) { | |
543 ASSERT_TRUE(https_server_.Start()); | |
544 scoped_refptr<net::X509Certificate> cert(https_server_.GetCertificate()); | |
545 net::CertVerifyResult verify_result; | |
546 verify_result.is_issued_by_known_root = true; | |
547 verify_result.verified_cert = cert; | |
548 verify_result.cert_status = cert_status; | |
549 | |
550 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, | |
551 net_result); | |
552 } | |
553 | |
535 protected: | 554 protected: |
536 TestThreatDetailsFactory details_factory_; | 555 TestThreatDetailsFactory details_factory_; |
537 | 556 |
538 private: | 557 private: |
539 TestSafeBrowsingServiceFactory factory_; | 558 TestSafeBrowsingServiceFactory factory_; |
540 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; | 559 TestSafeBrowsingBlockingPageFactory blocking_page_factory_; |
560 net::EmbeddedTestServer https_server_; | |
541 | 561 |
542 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageBrowserTest); | 562 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageBrowserTest); |
543 }; | 563 }; |
544 | 564 |
545 // TODO(linux_aura) https://crbug.com/163931 | 565 // TODO(linux_aura) https://crbug.com/163931 |
546 // TODO(win_aura) https://crbug.com/154081 | 566 // TODO(win_aura) https://crbug.com/154081 |
547 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 567 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
548 #define MAYBE_RedirectInIFrameCanceled DISABLED_RedirectInIFrameCanceled | 568 #define MAYBE_RedirectInIFrameCanceled DISABLED_RedirectInIFrameCanceled |
549 #else | 569 #else |
550 #define MAYBE_RedirectInIFrameCanceled RedirectInIFrameCanceled | 570 #define MAYBE_RedirectInIFrameCanceled RedirectInIFrameCanceled |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 ui_test_utils::NavigateToURL(browser(), GURL(kUnrelatedUrl)); | 1006 ui_test_utils::NavigateToURL(browser(), GURL(kUnrelatedUrl)); |
987 AssertNoInterstitial(false); | 1007 AssertNoInterstitial(false); |
988 | 1008 |
989 // The non-whitelisted page should now show an interstitial. | 1009 // The non-whitelisted page should now show an interstitial. |
990 ui_test_utils::NavigateToURL(browser(), url); | 1010 ui_test_utils::NavigateToURL(browser(), url); |
991 EXPECT_TRUE(WaitForReady()); | 1011 EXPECT_TRUE(WaitForReady()); |
992 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 1012 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
993 AssertNoInterstitial(true); | 1013 AssertNoInterstitial(true); |
994 } | 1014 } |
995 | 1015 |
1016 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | |
1017 SecurityStatePostInterstitial) { | |
1018 SetupWarningAndNavigate(); | |
1019 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | |
1020 AssertNoInterstitial(true); | |
1021 | |
1022 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
1023 ASSERT_TRUE(tab); | |
1024 ChromeSecurityStateModelClient* model_client = | |
1025 ChromeSecurityStateModelClient::FromWebContents(tab); | |
1026 ASSERT_TRUE(model_client); | |
1027 EXPECT_EQ(security_state::SecurityStateModel::SECURITY_ERROR, | |
1028 model_client->GetSecurityInfo().security_level); | |
1029 } | |
1030 | |
1031 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | |
1032 HTTPSOverridePostInterstitial) { | |
estark
2016/08/24 05:15:39
Either I'm missing something or this test is not t
Jialiu Lin
2016/08/24 06:27:20
This test seems very similar to the previous one,
felt
2016/08/24 19:27:19
All of the existing SB tests, including SecuritySt
felt
2016/08/24 19:27:19
Whoops you're right, I was missing an if-statement
| |
1033 SetUpMockCertVerifierForHttpsServer(0, net::OK); | |
1034 SetupWarningAndNavigate(); | |
1035 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | |
1036 AssertNoInterstitial(true); | |
1037 | |
1038 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
1039 ASSERT_TRUE(tab); | |
1040 ChromeSecurityStateModelClient* model_client = | |
1041 ChromeSecurityStateModelClient::FromWebContents(tab); | |
1042 ASSERT_TRUE(model_client); | |
1043 EXPECT_EQ(security_state::SecurityStateModel::SECURITY_ERROR, | |
1044 model_client->GetSecurityInfo().security_level); | |
1045 } | |
1046 | |
996 INSTANTIATE_TEST_CASE_P( | 1047 INSTANTIATE_TEST_CASE_P( |
997 SafeBrowsingBlockingPageBrowserTestWithThreatTypeAndIsolationSetting, | 1048 SafeBrowsingBlockingPageBrowserTestWithThreatTypeAndIsolationSetting, |
998 SafeBrowsingBlockingPageBrowserTest, | 1049 SafeBrowsingBlockingPageBrowserTest, |
999 testing::Combine( | 1050 testing::Combine( |
1000 testing::Values(SB_THREAT_TYPE_URL_MALWARE, // Threat types | 1051 testing::Values(SB_THREAT_TYPE_URL_MALWARE, // Threat types |
1001 SB_THREAT_TYPE_URL_PHISHING, | 1052 SB_THREAT_TYPE_URL_PHISHING, |
1002 SB_THREAT_TYPE_URL_UNWANTED), | 1053 SB_THREAT_TYPE_URL_UNWANTED), |
1003 testing::Bool())); // If isolate all sites for testing. | 1054 testing::Bool())); // If isolate all sites for testing. |
1004 | 1055 |
1005 // Test that SafeBrowsingBlockingPage properly decodes IDN URLs that are | 1056 // Test that SafeBrowsingBlockingPage properly decodes IDN URLs that are |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1041 | 1092 |
1042 INSTANTIATE_TEST_CASE_P( | 1093 INSTANTIATE_TEST_CASE_P( |
1043 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1094 SafeBrowsingBlockingPageIDNTestWithThreatType, |
1044 SafeBrowsingBlockingPageIDNTest, | 1095 SafeBrowsingBlockingPageIDNTest, |
1045 testing::Combine(testing::Values(false, true), | 1096 testing::Combine(testing::Values(false, true), |
1046 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1097 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1047 SB_THREAT_TYPE_URL_PHISHING, | 1098 SB_THREAT_TYPE_URL_PHISHING, |
1048 SB_THREAT_TYPE_URL_UNWANTED))); | 1099 SB_THREAT_TYPE_URL_UNWANTED))); |
1049 | 1100 |
1050 } // namespace safe_browsing | 1101 } // namespace safe_browsing |
OLD | NEW |