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 safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
7 // service. | 7 // service. |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 #error This test requires SAFE_BROWSING_DB_LOCAL. | 63 #error This test requires SAFE_BROWSING_DB_LOCAL. |
64 #endif | 64 #endif |
65 | 65 |
66 using content::BrowserThread; | 66 using content::BrowserThread; |
67 using content::InterstitialPage; | 67 using content::InterstitialPage; |
68 using content::WebContents; | 68 using content::WebContents; |
69 using ::testing::_; | 69 using ::testing::_; |
70 using ::testing::Mock; | 70 using ::testing::Mock; |
71 using ::testing::StrictMock; | 71 using ::testing::StrictMock; |
72 | 72 |
73 namespace safe_browsing { | |
74 | |
73 namespace { | 75 namespace { |
74 | 76 |
75 void InvokeFullHashCallback( | 77 void InvokeFullHashCallback( |
76 SafeBrowsingProtocolManager::FullHashCallback callback, | 78 SafeBrowsingProtocolManager::FullHashCallback callback, |
77 const std::vector<SBFullHashResult>& result) { | 79 const std::vector<SBFullHashResult>& result) { |
78 callback.Run(result, base::TimeDelta::FromMinutes(45)); | 80 callback.Run(result, base::TimeDelta::FromMinutes(45)); |
79 } | 81 } |
80 | 82 |
81 class FakeSafeBrowsingService : public SafeBrowsingService { | 83 class FakeSafeBrowsingService : public SafeBrowsingService { |
82 public: | 84 public: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 return true; | 133 return true; |
132 } | 134 } |
133 | 135 |
134 // Called on the IO thread to check if the given URL is safe or not. If we | 136 // Called on the IO thread to check if the given URL is safe or not. If we |
135 // can synchronously determine that the URL is safe, CheckUrl returns true, | 137 // can synchronously determine that the URL is safe, CheckUrl returns true, |
136 // otherwise it returns false. | 138 // otherwise it returns false. |
137 bool ContainsBrowseUrl(const GURL& url, | 139 bool ContainsBrowseUrl(const GURL& url, |
138 std::vector<SBPrefix>* prefix_hits, | 140 std::vector<SBPrefix>* prefix_hits, |
139 std::vector<SBFullHashResult>* cache_hits) override { | 141 std::vector<SBFullHashResult>* cache_hits) override { |
140 cache_hits->clear(); | 142 cache_hits->clear(); |
141 return ContainsUrl(safe_browsing::MALWARE, | 143 return ContainsUrl(MALWARE, |
142 safe_browsing::PHISH, | 144 PHISH, |
143 std::vector<GURL>(1, url), | 145 std::vector<GURL>(1, url), |
144 prefix_hits); | 146 prefix_hits); |
145 } | 147 } |
146 bool ContainsUnwantedSoftwareUrl( | 148 bool ContainsUnwantedSoftwareUrl( |
147 const GURL& url, | 149 const GURL& url, |
148 std::vector<SBPrefix>* prefix_hits, | 150 std::vector<SBPrefix>* prefix_hits, |
149 std::vector<SBFullHashResult>* cache_hits) override { | 151 std::vector<SBFullHashResult>* cache_hits) override { |
150 cache_hits->clear(); | 152 cache_hits->clear(); |
151 return ContainsUrl(safe_browsing::UNWANTEDURL, | 153 return ContainsUrl(UNWANTEDURL, |
152 safe_browsing::UNWANTEDURL, | 154 UNWANTEDURL, |
153 std::vector<GURL>(1, url), | 155 std::vector<GURL>(1, url), |
154 prefix_hits); | 156 prefix_hits); |
155 } | 157 } |
156 bool ContainsDownloadUrlPrefixes( | 158 bool ContainsDownloadUrlPrefixes( |
157 const std::vector<SBPrefix>& prefixes, | 159 const std::vector<SBPrefix>& prefixes, |
158 std::vector<SBPrefix>* prefix_hits) override { | 160 std::vector<SBPrefix>* prefix_hits) override { |
159 bool found = | 161 bool found = |
160 ContainsUrlPrefixes(safe_browsing::BINURL, | 162 ContainsUrlPrefixes(BINURL, |
161 safe_browsing::BINURL, prefixes, prefix_hits); | 163 BINURL, prefixes, prefix_hits); |
162 if (!found) | 164 if (!found) |
163 return false; | 165 return false; |
164 DCHECK_LE(1U, prefix_hits->size()); | 166 DCHECK_LE(1U, prefix_hits->size()); |
165 return true; | 167 return true; |
166 } | 168 } |
167 bool ContainsCsdWhitelistedUrl(const GURL& url) override { return true; } | 169 bool ContainsCsdWhitelistedUrl(const GURL& url) override { return true; } |
168 bool ContainsDownloadWhitelistedString(const std::string& str) override { | 170 bool ContainsDownloadWhitelistedString(const std::string& str) override { |
169 return true; | 171 return true; |
170 } | 172 } |
171 bool ContainsDownloadWhitelistedUrl(const GURL& url) override { return true; } | 173 bool ContainsDownloadWhitelistedUrl(const GURL& url) override { return true; } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 class SafeBrowsingServiceTest : public InProcessBrowserTest { | 419 class SafeBrowsingServiceTest : public InProcessBrowserTest { |
418 public: | 420 public: |
419 SafeBrowsingServiceTest() { | 421 SafeBrowsingServiceTest() { |
420 } | 422 } |
421 | 423 |
422 static void GenUrlFullhashResult(const GURL& url, | 424 static void GenUrlFullhashResult(const GURL& url, |
423 int list_id, | 425 int list_id, |
424 SBFullHashResult* full_hash) { | 426 SBFullHashResult* full_hash) { |
425 std::string host; | 427 std::string host; |
426 std::string path; | 428 std::string path; |
427 safe_browsing::CanonicalizeUrl(url, &host, &path, NULL); | 429 CanonicalizeUrl(url, &host, &path, NULL); |
428 full_hash->hash = safe_browsing::SBFullHashForString(host + path); | 430 full_hash->hash = SBFullHashForString(host + path); |
429 full_hash->list_id = list_id; | 431 full_hash->list_id = list_id; |
430 } | 432 } |
431 | 433 |
432 void SetUp() override { | 434 void SetUp() override { |
433 // InProcessBrowserTest::SetUp() instantiates SafebrowsingService and | 435 // InProcessBrowserTest::SetUp() instantiates SafebrowsingService and |
434 // RegisterFactory has to be called before SafeBrowsingService is created. | 436 // RegisterFactory has to be called before SafeBrowsingService is created. |
435 sb_factory_.reset(new TestSafeBrowsingServiceFactory( | 437 sb_factory_.reset(new TestSafeBrowsingServiceFactory( |
436 "https://definatelynotarealdomain/safebrowsing")); | 438 "https://definatelynotarealdomain/safebrowsing")); |
437 SafeBrowsingService::RegisterFactory(sb_factory_.get()); | 439 SafeBrowsingService::RegisterFactory(sb_factory_.get()); |
438 SafeBrowsingDatabase::RegisterFactory(&db_factory_); | 440 SafeBrowsingDatabase::RegisterFactory(&db_factory_); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 return LocalDatabaseManagerForService(sb_service)->check_timeout_; | 522 return LocalDatabaseManagerForService(sb_service)->check_timeout_; |
521 } | 523 } |
522 | 524 |
523 static void SetCheckTimeout(SafeBrowsingService* sb_service, | 525 static void SetCheckTimeout(SafeBrowsingService* sb_service, |
524 const base::TimeDelta& delay) { | 526 const base::TimeDelta& delay) { |
525 LocalDatabaseManagerForService(sb_service)->check_timeout_ = delay; | 527 LocalDatabaseManagerForService(sb_service)->check_timeout_ = delay; |
526 } | 528 } |
527 | 529 |
528 void CreateCSDService() { | 530 void CreateCSDService() { |
529 #if defined(SAFE_BROWSING_CSD) | 531 #if defined(SAFE_BROWSING_CSD) |
530 safe_browsing::ClientSideDetectionService* csd_service = | 532 ClientSideDetectionService* csd_service = |
531 safe_browsing::ClientSideDetectionService::Create(NULL); | 533 ClientSideDetectionService::Create(NULL); |
532 SafeBrowsingService* sb_service = | 534 SafeBrowsingService* sb_service = |
533 g_browser_process->safe_browsing_service(); | 535 g_browser_process->safe_browsing_service(); |
534 | 536 |
535 // A CSD service should already exist. | 537 // A CSD service should already exist. |
536 EXPECT_TRUE(sb_service->csd_service_); | 538 EXPECT_TRUE(sb_service->csd_service_); |
537 | 539 |
538 sb_service->csd_service_.reset(csd_service); | 540 sb_service->csd_service_.reset(csd_service); |
539 sb_service->RefreshState(); | 541 sb_service->RefreshState(); |
540 #endif | 542 #endif |
541 } | 543 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 }; | 596 }; |
595 | 597 |
596 class SafeBrowsingServiceMetadataTest | 598 class SafeBrowsingServiceMetadataTest |
597 : public SafeBrowsingServiceTest, | 599 : public SafeBrowsingServiceTest, |
598 public ::testing::WithParamInterface<MalwareMetadataTestType> { | 600 public ::testing::WithParamInterface<MalwareMetadataTestType> { |
599 public: | 601 public: |
600 SafeBrowsingServiceMetadataTest() {} | 602 SafeBrowsingServiceMetadataTest() {} |
601 | 603 |
602 void GenUrlFullhashResultWithMetadata(const GURL& url, | 604 void GenUrlFullhashResultWithMetadata(const GURL& url, |
603 SBFullHashResult* full_hash) { | 605 SBFullHashResult* full_hash) { |
604 GenUrlFullhashResult(url, safe_browsing::MALWARE, full_hash); | 606 GenUrlFullhashResult(url, MALWARE, full_hash); |
605 | 607 |
606 safe_browsing::MalwarePatternType proto; | 608 MalwarePatternType proto; |
607 switch (GetParam()) { | 609 switch (GetParam()) { |
608 case METADATA_NONE: | 610 case METADATA_NONE: |
609 full_hash->metadata = std::string(); | 611 full_hash->metadata = std::string(); |
610 break; | 612 break; |
611 case METADATA_LANDING: | 613 case METADATA_LANDING: |
612 proto.set_pattern_type(safe_browsing::MalwarePatternType::LANDING); | 614 proto.set_pattern_type(MalwarePatternType::LANDING); |
613 full_hash->metadata = proto.SerializeAsString(); | 615 full_hash->metadata = proto.SerializeAsString(); |
614 break; | 616 break; |
615 case METADATA_DISTRIBUTION: | 617 case METADATA_DISTRIBUTION: |
616 proto.set_pattern_type(safe_browsing::MalwarePatternType::DISTRIBUTION); | 618 proto.set_pattern_type(MalwarePatternType::DISTRIBUTION); |
617 full_hash->metadata = proto.SerializeAsString(); | 619 full_hash->metadata = proto.SerializeAsString(); |
618 break; | 620 break; |
619 } | 621 } |
620 } | 622 } |
621 | 623 |
622 private: | 624 private: |
623 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest); | 625 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceMetadataTest); |
624 }; | 626 }; |
625 | 627 |
626 namespace { | 628 namespace { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 METADATA_LANDING, | 707 METADATA_LANDING, |
706 METADATA_DISTRIBUTION)); | 708 METADATA_DISTRIBUTION)); |
707 | 709 |
708 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, UnwantedImgIgnored) { | 710 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, UnwantedImgIgnored) { |
709 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | 711 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); |
710 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); | 712 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); |
711 | 713 |
712 // Add the img url as coming from a site serving UwS and then load the parent | 714 // Add the img url as coming from a site serving UwS and then load the parent |
713 // page. | 715 // page. |
714 SBFullHashResult uws_full_hash; | 716 SBFullHashResult uws_full_hash; |
715 GenUrlFullhashResult(img_url, safe_browsing::UNWANTEDURL, | 717 GenUrlFullhashResult(img_url, UNWANTEDURL, |
716 &uws_full_hash); | 718 &uws_full_hash); |
mattm
2015/11/12 00:36:05
formatting
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
717 SetupResponseForUrl(img_url, uws_full_hash); | 719 SetupResponseForUrl(img_url, uws_full_hash); |
718 | 720 |
719 ui_test_utils::NavigateToURL(browser(), main_url); | 721 ui_test_utils::NavigateToURL(browser(), main_url); |
720 | 722 |
721 EXPECT_FALSE(ShowingInterstitialPage()); | 723 EXPECT_FALSE(ShowingInterstitialPage()); |
722 } | 724 } |
723 | 725 |
724 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, DISABLED_MalwareWithWhitelist) { | 726 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, DISABLED_MalwareWithWhitelist) { |
725 GURL url = embedded_test_server()->GetURL(kEmptyPage); | 727 GURL url = embedded_test_server()->GetURL(kEmptyPage); |
726 | 728 |
727 // After adding the url to safebrowsing database and getfullhash result, | 729 // After adding the url to safebrowsing database and getfullhash result, |
728 // we should see the interstitial page. | 730 // we should see the interstitial page. |
729 SBFullHashResult malware_full_hash; | 731 SBFullHashResult malware_full_hash; |
730 GenUrlFullhashResult(url, safe_browsing::MALWARE, &malware_full_hash); | 732 GenUrlFullhashResult(url, MALWARE, &malware_full_hash); |
731 EXPECT_CALL(observer_, | 733 EXPECT_CALL(observer_, |
732 OnSafeBrowsingMatch(IsUnsafeResourceFor(url))).Times(1); | 734 OnSafeBrowsingMatch(IsUnsafeResourceFor(url))).Times(1); |
733 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1) | 735 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1) |
734 .WillOnce(testing::Invoke( | 736 .WillOnce(testing::Invoke( |
735 this, &SafeBrowsingServiceTest::ProceedAndWhitelist)); | 737 this, &SafeBrowsingServiceTest::ProceedAndWhitelist)); |
736 SetupResponseForUrl(url, malware_full_hash); | 738 SetupResponseForUrl(url, malware_full_hash); |
737 | 739 |
738 ui_test_utils::NavigateToURL(browser(), url); | 740 ui_test_utils::NavigateToURL(browser(), url); |
739 // Mock calls OnBlockingPageDone set to proceed, so the interstitial | 741 // Mock calls OnBlockingPageDone set to proceed, so the interstitial |
740 // is removed. | 742 // is removed. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 } | 776 } |
775 | 777 |
776 private: | 778 private: |
777 prerender::PrerenderManager::PrerenderManagerMode old_prerender_mode_; | 779 prerender::PrerenderManager::PrerenderManagerMode old_prerender_mode_; |
778 } set_prefetch_for_test(true); | 780 } set_prefetch_for_test(true); |
779 | 781 |
780 // Even though we have added this uri to the safebrowsing database and | 782 // Even though we have added this uri to the safebrowsing database and |
781 // getfullhash result, we should not see the interstitial page since the | 783 // getfullhash result, we should not see the interstitial page since the |
782 // only malware was a prefetch target. | 784 // only malware was a prefetch target. |
783 SBFullHashResult malware_full_hash; | 785 SBFullHashResult malware_full_hash; |
784 GenUrlFullhashResult(malware_url, safe_browsing::MALWARE, | 786 GenUrlFullhashResult(malware_url, MALWARE, |
785 &malware_full_hash); | 787 &malware_full_hash); |
mattm
2015/11/12 00:36:06
formatting
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
786 SetupResponseForUrl(malware_url, malware_full_hash); | 788 SetupResponseForUrl(malware_url, malware_full_hash); |
787 ui_test_utils::NavigateToURL(browser(), url); | 789 ui_test_utils::NavigateToURL(browser(), url); |
788 EXPECT_FALSE(ShowingInterstitialPage()); | 790 EXPECT_FALSE(ShowingInterstitialPage()); |
789 Mock::VerifyAndClear(&observer_); | 791 Mock::VerifyAndClear(&observer_); |
790 | 792 |
791 // However, when we navigate to the malware page, we should still get | 793 // However, when we navigate to the malware page, we should still get |
792 // the interstitial. | 794 // the interstitial. |
793 EXPECT_CALL(observer_, OnSafeBrowsingMatch(IsUnsafeResourceFor(malware_url))) | 795 EXPECT_CALL(observer_, OnSafeBrowsingMatch(IsUnsafeResourceFor(malware_url))) |
794 .Times(1); | 796 .Times(1); |
795 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(malware_url))) | 797 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(malware_url))) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
889 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); | 891 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); |
890 std::vector<GURL> badbin_urls(1, badbin_url); | 892 std::vector<GURL> badbin_urls(1, badbin_url); |
891 | 893 |
892 scoped_refptr<TestSBClient> client(new TestSBClient); | 894 scoped_refptr<TestSBClient> client(new TestSBClient); |
893 client->CheckDownloadUrl(badbin_urls); | 895 client->CheckDownloadUrl(badbin_urls); |
894 | 896 |
895 // Since badbin_url is not in database, it is considered to be safe. | 897 // Since badbin_url is not in database, it is considered to be safe. |
896 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 898 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
897 | 899 |
898 SBFullHashResult full_hash_result; | 900 SBFullHashResult full_hash_result; |
899 GenUrlFullhashResult(badbin_url, safe_browsing::BINURL, | 901 GenUrlFullhashResult(badbin_url, BINURL, |
900 &full_hash_result); | 902 &full_hash_result); |
mattm
2015/11/12 00:36:06
formatting
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
901 SetupResponseForUrl(badbin_url, full_hash_result); | 903 SetupResponseForUrl(badbin_url, full_hash_result); |
902 | 904 |
903 client->CheckDownloadUrl(badbin_urls); | 905 client->CheckDownloadUrl(badbin_urls); |
904 | 906 |
905 // Now, the badbin_url is not safe since it is added to download database. | 907 // Now, the badbin_url is not safe since it is added to download database. |
906 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); | 908 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); |
907 } | 909 } |
908 | 910 |
909 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckUnwantedSoftwareUrl) { | 911 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckUnwantedSoftwareUrl) { |
910 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); | 912 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); |
911 { | 913 { |
912 scoped_refptr<TestSBClient> client(new TestSBClient); | 914 scoped_refptr<TestSBClient> client(new TestSBClient); |
913 | 915 |
914 // Since bad_url is not in database, it is considered to be | 916 // Since bad_url is not in database, it is considered to be |
915 // safe. | 917 // safe. |
916 client->CheckBrowseUrl(bad_url); | 918 client->CheckBrowseUrl(bad_url); |
917 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 919 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
918 | 920 |
919 SBFullHashResult full_hash_result; | 921 SBFullHashResult full_hash_result; |
920 GenUrlFullhashResult( | 922 GenUrlFullhashResult( |
921 bad_url, safe_browsing::UNWANTEDURL, &full_hash_result); | 923 bad_url, UNWANTEDURL, &full_hash_result); |
mattm
2015/11/12 00:36:05
formatting
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
922 SetupResponseForUrl(bad_url, full_hash_result); | 924 SetupResponseForUrl(bad_url, full_hash_result); |
923 | 925 |
924 // Now, the bad_url is not safe since it is added to download | 926 // Now, the bad_url is not safe since it is added to download |
925 // database. | 927 // database. |
926 client->CheckBrowseUrl(bad_url); | 928 client->CheckBrowseUrl(bad_url); |
927 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); | 929 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); |
928 } | 930 } |
929 | 931 |
930 // The unwantedness should survive across multiple clients. | 932 // The unwantedness should survive across multiple clients. |
931 { | 933 { |
932 scoped_refptr<TestSBClient> client(new TestSBClient); | 934 scoped_refptr<TestSBClient> client(new TestSBClient); |
933 client->CheckBrowseUrl(bad_url); | 935 client->CheckBrowseUrl(bad_url); |
934 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); | 936 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); |
935 } | 937 } |
936 | 938 |
937 // An unwanted URL also marked as malware should be flagged as malware. | 939 // An unwanted URL also marked as malware should be flagged as malware. |
938 { | 940 { |
939 scoped_refptr<TestSBClient> client(new TestSBClient); | 941 scoped_refptr<TestSBClient> client(new TestSBClient); |
940 | 942 |
941 SBFullHashResult full_hash_result; | 943 SBFullHashResult full_hash_result; |
942 GenUrlFullhashResult( | 944 GenUrlFullhashResult( |
943 bad_url, safe_browsing::MALWARE, &full_hash_result); | 945 bad_url, MALWARE, &full_hash_result); |
mattm
2015/11/12 00:36:06
formatting
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
944 SetupResponseForUrl(bad_url, full_hash_result); | 946 SetupResponseForUrl(bad_url, full_hash_result); |
945 | 947 |
946 client->CheckBrowseUrl(bad_url); | 948 client->CheckBrowseUrl(bad_url); |
947 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | 949 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); |
948 } | 950 } |
949 } | 951 } |
950 | 952 |
951 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckBrowseUrl) { | 953 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckBrowseUrl) { |
952 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); | 954 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); |
953 { | 955 { |
954 scoped_refptr<TestSBClient> client(new TestSBClient); | 956 scoped_refptr<TestSBClient> client(new TestSBClient); |
955 | 957 |
956 // Since bad_url is not in database, it is considered to be | 958 // Since bad_url is not in database, it is considered to be |
957 // safe. | 959 // safe. |
958 client->CheckBrowseUrl(bad_url); | 960 client->CheckBrowseUrl(bad_url); |
959 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 961 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
960 | 962 |
961 SBFullHashResult full_hash_result; | 963 SBFullHashResult full_hash_result; |
962 GenUrlFullhashResult( | 964 GenUrlFullhashResult( |
963 bad_url, safe_browsing::MALWARE, &full_hash_result); | 965 bad_url, MALWARE, &full_hash_result); |
mattm
2015/11/12 00:36:05
formatting
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
964 SetupResponseForUrl(bad_url, full_hash_result); | 966 SetupResponseForUrl(bad_url, full_hash_result); |
965 | 967 |
966 // Now, the bad_url is not safe since it is added to download | 968 // Now, the bad_url is not safe since it is added to download |
967 // database. | 969 // database. |
968 client->CheckBrowseUrl(bad_url); | 970 client->CheckBrowseUrl(bad_url); |
969 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | 971 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); |
970 } | 972 } |
971 | 973 |
972 // The unwantedness should survive across multiple clients. | 974 // The unwantedness should survive across multiple clients. |
973 { | 975 { |
974 scoped_refptr<TestSBClient> client(new TestSBClient); | 976 scoped_refptr<TestSBClient> client(new TestSBClient); |
975 client->CheckBrowseUrl(bad_url); | 977 client->CheckBrowseUrl(bad_url); |
976 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | 978 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); |
977 } | 979 } |
978 | 980 |
979 // Adding the unwanted state to an existing malware URL should have no impact | 981 // Adding the unwanted state to an existing malware URL should have no impact |
980 // (i.e. a malware hit should still prevail). | 982 // (i.e. a malware hit should still prevail). |
981 { | 983 { |
982 scoped_refptr<TestSBClient> client(new TestSBClient); | 984 scoped_refptr<TestSBClient> client(new TestSBClient); |
983 | 985 |
984 SBFullHashResult full_hash_result; | 986 SBFullHashResult full_hash_result; |
985 GenUrlFullhashResult( | 987 GenUrlFullhashResult( |
986 bad_url, safe_browsing::UNWANTEDURL, &full_hash_result); | 988 bad_url, UNWANTEDURL, &full_hash_result); |
mattm
2015/11/12 00:36:06
formatting
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
987 SetupResponseForUrl(bad_url, full_hash_result); | 989 SetupResponseForUrl(bad_url, full_hash_result); |
988 | 990 |
989 client->CheckBrowseUrl(bad_url); | 991 client->CheckBrowseUrl(bad_url); |
990 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | 992 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); |
991 } | 993 } |
992 } | 994 } |
993 | 995 |
994 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckDownloadUrlRedirects) { | 996 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckDownloadUrlRedirects) { |
995 GURL original_url = embedded_test_server()->GetURL(kEmptyPage); | 997 GURL original_url = embedded_test_server()->GetURL(kEmptyPage); |
996 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); | 998 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); |
997 GURL final_url = embedded_test_server()->GetURL(kEmptyPage); | 999 GURL final_url = embedded_test_server()->GetURL(kEmptyPage); |
998 std::vector<GURL> badbin_urls; | 1000 std::vector<GURL> badbin_urls; |
999 badbin_urls.push_back(original_url); | 1001 badbin_urls.push_back(original_url); |
1000 badbin_urls.push_back(badbin_url); | 1002 badbin_urls.push_back(badbin_url); |
1001 badbin_urls.push_back(final_url); | 1003 badbin_urls.push_back(final_url); |
1002 | 1004 |
1003 scoped_refptr<TestSBClient> client(new TestSBClient); | 1005 scoped_refptr<TestSBClient> client(new TestSBClient); |
1004 client->CheckDownloadUrl(badbin_urls); | 1006 client->CheckDownloadUrl(badbin_urls); |
1005 | 1007 |
1006 // Since badbin_url is not in database, it is considered to be safe. | 1008 // Since badbin_url is not in database, it is considered to be safe. |
1007 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 1009 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
1008 | 1010 |
1009 SBFullHashResult full_hash_result; | 1011 SBFullHashResult full_hash_result; |
1010 GenUrlFullhashResult(badbin_url, safe_browsing::BINURL, | 1012 GenUrlFullhashResult(badbin_url, BINURL, |
1011 &full_hash_result); | 1013 &full_hash_result); |
mattm
2015/11/12 00:36:06
formatting
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
1012 SetupResponseForUrl(badbin_url, full_hash_result); | 1014 SetupResponseForUrl(badbin_url, full_hash_result); |
1013 | 1015 |
1014 client->CheckDownloadUrl(badbin_urls); | 1016 client->CheckDownloadUrl(badbin_urls); |
1015 | 1017 |
1016 // Now, the badbin_url is not safe since it is added to download database. | 1018 // Now, the badbin_url is not safe since it is added to download database. |
1017 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); | 1019 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); |
1018 } | 1020 } |
1019 | 1021 |
1020 #if defined(OS_WIN) | 1022 #if defined(OS_WIN) |
1021 // http://crbug.com/396409 | 1023 // http://crbug.com/396409 |
1022 #define MAYBE_CheckDownloadUrlTimedOut DISABLED_CheckDownloadUrlTimedOut | 1024 #define MAYBE_CheckDownloadUrlTimedOut DISABLED_CheckDownloadUrlTimedOut |
1023 #else | 1025 #else |
1024 #define MAYBE_CheckDownloadUrlTimedOut CheckDownloadUrlTimedOut | 1026 #define MAYBE_CheckDownloadUrlTimedOut CheckDownloadUrlTimedOut |
1025 #endif | 1027 #endif |
1026 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, | 1028 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
1027 MAYBE_CheckDownloadUrlTimedOut) { | 1029 MAYBE_CheckDownloadUrlTimedOut) { |
1028 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); | 1030 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); |
1029 std::vector<GURL> badbin_urls(1, badbin_url); | 1031 std::vector<GURL> badbin_urls(1, badbin_url); |
1030 | 1032 |
1031 scoped_refptr<TestSBClient> client(new TestSBClient); | 1033 scoped_refptr<TestSBClient> client(new TestSBClient); |
1032 SBFullHashResult full_hash_result; | 1034 SBFullHashResult full_hash_result; |
1033 GenUrlFullhashResult(badbin_url, safe_browsing::BINURL, | 1035 GenUrlFullhashResult(badbin_url, BINURL, |
1034 &full_hash_result); | 1036 &full_hash_result); |
mattm
2015/11/12 00:36:05
formatting
vakh (old account. dont use)
2015/11/12 09:27:43
Done.
| |
1035 SetupResponseForUrl(badbin_url, full_hash_result); | 1037 SetupResponseForUrl(badbin_url, full_hash_result); |
1036 client->CheckDownloadUrl(badbin_urls); | 1038 client->CheckDownloadUrl(badbin_urls); |
1037 | 1039 |
1038 // badbin_url is not safe since it is added to download database. | 1040 // badbin_url is not safe since it is added to download database. |
1039 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); | 1041 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); |
1040 | 1042 |
1041 // | 1043 // |
1042 // Now introducing delays and we should hit timeout. | 1044 // Now introducing delays and we should hit timeout. |
1043 // | 1045 // |
1044 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 1046 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
1045 base::TimeDelta default_urlcheck_timeout = GetCheckTimeout(sb_service); | 1047 base::TimeDelta default_urlcheck_timeout = GetCheckTimeout(sb_service); |
1046 IntroduceGetHashDelay(base::TimeDelta::FromSeconds(1)); | 1048 IntroduceGetHashDelay(base::TimeDelta::FromSeconds(1)); |
1047 SetCheckTimeout(sb_service, base::TimeDelta::FromMilliseconds(1)); | 1049 SetCheckTimeout(sb_service, base::TimeDelta::FromMilliseconds(1)); |
1048 client->CheckDownloadUrl(badbin_urls); | 1050 client->CheckDownloadUrl(badbin_urls); |
1049 | 1051 |
1050 // There should be a timeout and the hash would be considered as safe. | 1052 // There should be a timeout and the hash would be considered as safe. |
1051 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | 1053 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); |
1052 | 1054 |
1053 // Need to set the timeout back to the default value. | 1055 // Need to set the timeout back to the default value. |
1054 SetCheckTimeout(sb_service, default_urlcheck_timeout); | 1056 SetCheckTimeout(sb_service, default_urlcheck_timeout); |
1055 } | 1057 } |
1056 | 1058 |
1057 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) { | 1059 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, StartAndStop) { |
1058 CreateCSDService(); | 1060 CreateCSDService(); |
1059 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 1061 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
1060 safe_browsing::ClientSideDetectionService* csd_service = | 1062 ClientSideDetectionService* csd_service = |
1061 sb_service->safe_browsing_detection_service(); | 1063 sb_service->safe_browsing_detection_service(); |
1062 PrefService* pref_service = browser()->profile()->GetPrefs(); | 1064 PrefService* pref_service = browser()->profile()->GetPrefs(); |
1063 | 1065 |
1064 ASSERT_TRUE(sb_service != NULL); | 1066 ASSERT_TRUE(sb_service != NULL); |
1065 ASSERT_TRUE(csd_service != NULL); | 1067 ASSERT_TRUE(csd_service != NULL); |
1066 ASSERT_TRUE(pref_service != NULL); | 1068 ASSERT_TRUE(pref_service != NULL); |
1067 | 1069 |
1068 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); | 1070 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); |
1069 | 1071 |
1070 // SBS might still be starting, make sure this doesn't flake. | 1072 // SBS might still be starting, make sure this doesn't flake. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1149 } | 1151 } |
1150 | 1152 |
1151 protected: | 1153 protected: |
1152 Profile* profile2_; | 1154 Profile* profile2_; |
1153 }; | 1155 }; |
1154 | 1156 |
1155 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceShutdownTest, | 1157 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceShutdownTest, |
1156 DontStartAfterShutdown) { | 1158 DontStartAfterShutdown) { |
1157 CreateCSDService(); | 1159 CreateCSDService(); |
1158 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); | 1160 SafeBrowsingService* sb_service = g_browser_process->safe_browsing_service(); |
1159 safe_browsing::ClientSideDetectionService* csd_service = | 1161 ClientSideDetectionService* csd_service = |
1160 sb_service->safe_browsing_detection_service(); | 1162 sb_service->safe_browsing_detection_service(); |
1161 PrefService* pref_service = browser()->profile()->GetPrefs(); | 1163 PrefService* pref_service = browser()->profile()->GetPrefs(); |
1162 | 1164 |
1163 ASSERT_TRUE(sb_service != NULL); | 1165 ASSERT_TRUE(sb_service != NULL); |
1164 ASSERT_TRUE(csd_service != NULL); | 1166 ASSERT_TRUE(csd_service != NULL); |
1165 ASSERT_TRUE(pref_service != NULL); | 1167 ASSERT_TRUE(pref_service != NULL); |
1166 | 1168 |
1167 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); | 1169 EXPECT_TRUE(pref_service->GetBoolean(prefs::kSafeBrowsingEnabled)); |
1168 | 1170 |
1169 // SBS might still be starting, make sure this doesn't flake. | 1171 // SBS might still be starting, make sure this doesn't flake. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1353 content::WindowedNotificationObserver observer( | 1355 content::WindowedNotificationObserver observer( |
1354 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, | 1356 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, |
1355 content::Source<SafeBrowsingDatabaseManager>( | 1357 content::Source<SafeBrowsingDatabaseManager>( |
1356 sb_service_->database_manager().get())); | 1358 sb_service_->database_manager().get())); |
1357 BrowserThread::PostTask( | 1359 BrowserThread::PostTask( |
1358 BrowserThread::IO, | 1360 BrowserThread::IO, |
1359 FROM_HERE, | 1361 FROM_HERE, |
1360 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); | 1362 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, this)); |
1361 observer.Wait(); | 1363 observer.Wait(); |
1362 } | 1364 } |
1365 | |
1366 } // namespace safe_browsing | |
OLD | NEW |