Chromium Code Reviews| 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 "chrome/browser/safe_browsing/safe_browsing_service.h" | 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 using content::InterstitialPage; | 91 using content::InterstitialPage; |
| 92 using content::WebContents; | 92 using content::WebContents; |
| 93 using ::testing::_; | 93 using ::testing::_; |
| 94 using ::testing::Mock; | 94 using ::testing::Mock; |
| 95 using ::testing::StrictMock; | 95 using ::testing::StrictMock; |
| 96 | 96 |
| 97 namespace safe_browsing { | 97 namespace safe_browsing { |
| 98 | 98 |
| 99 namespace { | 99 namespace { |
| 100 | 100 |
| 101 const char kBlacklistResource[] = "/blacklisted/script.js"; | |
| 101 const char kEmptyPage[] = "/empty.html"; | 102 const char kEmptyPage[] = "/empty.html"; |
| 103 const char kMaliciousResource[] = "/malware/script.js"; | |
| 102 const char kMalwareFile[] = "/downloads/dangerous/dangerous.exe"; | 104 const char kMalwareFile[] = "/downloads/dangerous/dangerous.exe"; |
| 103 const char kMalwarePage[] = "/safe_browsing/malware.html"; | 105 const char kMalwarePage[] = "/safe_browsing/malware.html"; |
| 104 const char kMalwareDelayedLoadsPage[] = | 106 const char kMalwareDelayedLoadsPage[] = |
| 105 "/safe_browsing/malware_delayed_loads.html"; | 107 "/safe_browsing/malware_delayed_loads.html"; |
| 106 const char kMalwareIFrame[] = "/safe_browsing/malware_iframe.html"; | 108 const char kMalwareIFrame[] = "/safe_browsing/malware_iframe.html"; |
| 107 const char kMalwareImg[] = "/safe_browsing/malware_image.png"; | 109 const char kMalwareImg[] = "/safe_browsing/malware_image.png"; |
| 108 const char kNeverCompletesPath[] = "/never_completes"; | 110 const char kNeverCompletesPath[] = "/never_completes"; |
| 109 const char kPrefetchMalwarePage[] = "/safe_browsing/prefetch_malware.html"; | 111 const char kPrefetchMalwarePage[] = "/safe_browsing/prefetch_malware.html"; |
| 110 | 112 |
| 111 class MockSubresourceFilterDriver | 113 class MockSubresourceFilterDriver |
| (...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1432 GenUrlFullHashResult(badbin_url, BINURL, &full_hash_result); | 1434 GenUrlFullHashResult(badbin_url, BINURL, &full_hash_result); |
| 1433 SetupResponseForUrl(badbin_url, full_hash_result); | 1435 SetupResponseForUrl(badbin_url, full_hash_result); |
| 1434 | 1436 |
| 1435 client->CheckDownloadUrl(badbin_urls); | 1437 client->CheckDownloadUrl(badbin_urls); |
| 1436 | 1438 |
| 1437 // Now, the badbin_url is not safe since it is added to download database. | 1439 // Now, the badbin_url is not safe since it is added to download database. |
| 1438 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); | 1440 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); |
| 1439 } | 1441 } |
| 1440 | 1442 |
| 1441 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckResourceUrl) { | 1443 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckResourceUrl) { |
| 1442 const char* kBlacklistResource = "/blacklisted/script.js"; | |
| 1443 GURL blacklist_resource = embedded_test_server()->GetURL(kBlacklistResource); | 1444 GURL blacklist_resource = embedded_test_server()->GetURL(kBlacklistResource); |
| 1444 std::string blacklist_resource_hash; | 1445 std::string blacklist_resource_hash; |
| 1445 const char* kMaliciousResource = "/malware/script.js"; | |
| 1446 GURL malware_resource = embedded_test_server()->GetURL(kMaliciousResource); | 1446 GURL malware_resource = embedded_test_server()->GetURL(kMaliciousResource); |
| 1447 std::string malware_resource_hash; | 1447 std::string malware_resource_hash; |
| 1448 | 1448 |
| 1449 { | 1449 { |
| 1450 SBFullHashResult full_hash; | 1450 SBFullHashResult full_hash; |
| 1451 GenUrlFullHashResult(blacklist_resource, RESOURCEBLACKLIST, &full_hash); | 1451 GenUrlFullHashResult(blacklist_resource, RESOURCEBLACKLIST, &full_hash); |
| 1452 SetupResponseForUrl(blacklist_resource, full_hash); | 1452 SetupResponseForUrl(blacklist_resource, full_hash); |
| 1453 blacklist_resource_hash = std::string(full_hash.hash.full_hash, | 1453 blacklist_resource_hash = std::string(full_hash.hash.full_hash, |
| 1454 full_hash.hash.full_hash + 32); | 1454 full_hash.hash.full_hash + 32); |
| 1455 } | 1455 } |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1810 base::Unretained(this))); | 1810 base::Unretained(this))); |
| 1811 observer.Wait(); | 1811 observer.Wait(); |
| 1812 } | 1812 } |
| 1813 | 1813 |
| 1814 class TestV4Store : public V4Store { | 1814 class TestV4Store : public V4Store { |
| 1815 public: | 1815 public: |
| 1816 TestV4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 1816 TestV4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 1817 const base::FilePath& store_path) | 1817 const base::FilePath& store_path) |
| 1818 : V4Store(task_runner, store_path, 0) {} | 1818 : V4Store(task_runner, store_path, 0) {} |
| 1819 | 1819 |
| 1820 bool HasValidData() const override { return true; } | |
| 1821 | |
| 1820 void MarkPrefixAsBad(HashPrefix prefix) { | 1822 void MarkPrefixAsBad(HashPrefix prefix) { |
| 1821 hash_prefix_map_[prefix.size()] = prefix; | 1823 hash_prefix_map_[prefix.size()] = prefix; |
| 1822 } | 1824 } |
| 1823 }; | 1825 }; |
| 1824 | 1826 |
| 1825 class TestV4StoreFactory : public V4StoreFactory { | 1827 class TestV4StoreFactory : public V4StoreFactory { |
| 1826 public: | 1828 public: |
| 1827 V4Store* CreateV4Store( | 1829 V4Store* CreateV4Store( |
| 1828 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 1830 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 1829 const base::FilePath& store_path) override { | 1831 const base::FilePath& store_path) override { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1907 class V4SafeBrowsingServiceTest : public SafeBrowsingServiceTest { | 1909 class V4SafeBrowsingServiceTest : public SafeBrowsingServiceTest { |
| 1908 public: | 1910 public: |
| 1909 V4SafeBrowsingServiceTest() : SafeBrowsingServiceTest() {} | 1911 V4SafeBrowsingServiceTest() : SafeBrowsingServiceTest() {} |
| 1910 | 1912 |
| 1911 void SetUp() override { | 1913 void SetUp() override { |
| 1912 sb_factory_ = base::MakeUnique<TestSafeBrowsingServiceFactory>( | 1914 sb_factory_ = base::MakeUnique<TestSafeBrowsingServiceFactory>( |
| 1913 V4FeatureList::V4UsageStatus::V4_ONLY); | 1915 V4FeatureList::V4UsageStatus::V4_ONLY); |
| 1914 sb_factory_->SetTestUIManager(new FakeSafeBrowsingUIManager()); | 1916 sb_factory_->SetTestUIManager(new FakeSafeBrowsingUIManager()); |
| 1915 SafeBrowsingService::RegisterFactory(sb_factory_.get()); | 1917 SafeBrowsingService::RegisterFactory(sb_factory_.get()); |
| 1916 | 1918 |
| 1919 store_factory_ = new TestV4StoreFactory(); | |
| 1920 V4Database::RegisterStoreFactoryForTest(base::WrapUnique(store_factory_)); | |
| 1921 | |
| 1917 v4_db_factory_ = new TestV4DatabaseFactory(); | 1922 v4_db_factory_ = new TestV4DatabaseFactory(); |
| 1918 V4Database::RegisterDatabaseFactoryForTest( | 1923 V4Database::RegisterDatabaseFactoryForTest( |
| 1919 base::WrapUnique(v4_db_factory_)); | 1924 base::WrapUnique(v4_db_factory_)); |
| 1920 | 1925 |
| 1921 v4_get_hash_factory_ = new TestV4GetHashProtocolManagerFactory(); | 1926 v4_get_hash_factory_ = new TestV4GetHashProtocolManagerFactory(); |
| 1922 V4GetHashProtocolManager::RegisterFactory( | 1927 V4GetHashProtocolManager::RegisterFactory( |
| 1923 base::WrapUnique(v4_get_hash_factory_)); | 1928 base::WrapUnique(v4_get_hash_factory_)); |
| 1929 | |
| 1924 InProcessBrowserTest::SetUp(); | 1930 InProcessBrowserTest::SetUp(); |
| 1925 } | 1931 } |
| 1926 | 1932 |
| 1927 void TearDown() override { | 1933 void TearDown() override { |
| 1928 InProcessBrowserTest::TearDown(); | 1934 InProcessBrowserTest::TearDown(); |
| 1929 | 1935 |
| 1930 // Unregister test factories after InProcessBrowserTest::TearDown | 1936 // Unregister test factories after InProcessBrowserTest::TearDown |
| 1931 // (which destructs SafeBrowsingService). | 1937 // (which destructs SafeBrowsingService). |
| 1932 V4GetHashProtocolManager::RegisterFactory(nullptr); | 1938 V4GetHashProtocolManager::RegisterFactory(nullptr); |
| 1933 V4Database::RegisterDatabaseFactoryForTest(nullptr); | 1939 V4Database::RegisterDatabaseFactoryForTest(nullptr); |
| 1940 V4Database::RegisterStoreFactoryForTest(nullptr); | |
| 1934 SafeBrowsingService::RegisterFactory(nullptr); | 1941 SafeBrowsingService::RegisterFactory(nullptr); |
| 1935 } | 1942 } |
| 1936 | 1943 |
| 1937 // Returns a FullHashInfo info for the basic host+path pattern for a given URL | 1944 // Returns a FullHash for the basic host+path pattern for a given URL after |
| 1938 // after canonicalization. | 1945 // canonicalization. |
| 1939 FullHashInfo GetFullHashInfo(const GURL& url, const ListIdentifier& list_id) { | 1946 FullHash GetFullHash(const GURL& url) { |
| 1940 std::string host; | 1947 std::string host; |
| 1941 std::string path; | 1948 std::string path; |
| 1942 V4ProtocolManagerUtil::CanonicalizeUrl(url, &host, &path, nullptr); | 1949 V4ProtocolManagerUtil::CanonicalizeUrl(url, &host, &path, nullptr); |
| 1943 | 1950 |
| 1944 return FullHashInfo(crypto::SHA256HashString(host + path), list_id, | 1951 return crypto::SHA256HashString(host + path); |
| 1952 } | |
| 1953 | |
| 1954 // Returns FullHashInfo object for the basic host+path pattern for a given URL | |
| 1955 // after canonicalization. | |
| 1956 FullHashInfo GetFullHashInfo(const GURL& url, const ListIdentifier& list_id) { | |
| 1957 return FullHashInfo(GetFullHash(url), list_id, | |
| 1945 base::Time::Now() + base::TimeDelta::FromMinutes(5)); | 1958 base::Time::Now() + base::TimeDelta::FromMinutes(5)); |
| 1946 } | 1959 } |
| 1947 | 1960 |
| 1948 // Returns a FullHashInfo info for the basic host+path pattern for a given URL | 1961 // Returns a FullHashInfo info for the basic host+path pattern for a given URL |
| 1949 // after canonicalization. Also adds metadata information to the FullHashInfo | 1962 // after canonicalization. Also adds metadata information to the FullHashInfo |
| 1950 // object. | 1963 // object. |
| 1951 FullHashInfo GetFullHashInfoWithMetadata( | 1964 FullHashInfo GetFullHashInfoWithMetadata( |
| 1952 const GURL& url, | 1965 const GURL& url, |
| 1953 const ListIdentifier& list_id, | 1966 const ListIdentifier& list_id, |
| 1954 ThreatPatternType threat_pattern_type) { | 1967 ThreatPatternType threat_pattern_type) { |
| 1955 FullHashInfo fhi = GetFullHashInfo(url, list_id); | 1968 FullHashInfo fhi = GetFullHashInfo(url, list_id); |
| 1956 fhi.metadata.threat_pattern_type = threat_pattern_type; | 1969 fhi.metadata.threat_pattern_type = threat_pattern_type; |
| 1957 return fhi; | 1970 return fhi; |
| 1958 } | 1971 } |
| 1959 | 1972 |
| 1960 // Sets up the prefix database and the full hash cache to match one of the | 1973 // Sets up the prefix database and the full hash cache to match one of the |
| 1961 // prefixes for the given URL and metadata. | 1974 // prefixes for the given URL and metadata. |
| 1962 void MarkUrlForMalwareUnexpired( | 1975 void MarkUrlForMalwareUnexpired( |
| 1963 const GURL& bad_url, | 1976 const GURL& bad_url, |
| 1964 ThreatPatternType threat_pattern_type = ThreatPatternType::NONE) { | 1977 ThreatPatternType threat_pattern_type = ThreatPatternType::NONE) { |
| 1965 FullHashInfo full_hash_info = GetFullHashInfoWithMetadata( | 1978 FullHashInfo full_hash_info = GetFullHashInfoWithMetadata( |
| 1966 bad_url, GetUrlMalwareId(), threat_pattern_type); | 1979 bad_url, GetUrlMalwareId(), threat_pattern_type); |
| 1967 | 1980 |
| 1968 v4_db_factory_->MarkPrefixAsBad(GetUrlMalwareId(), | 1981 v4_db_factory_->MarkPrefixAsBad(GetUrlMalwareId(), |
| 1969 full_hash_info.full_hash); | 1982 full_hash_info.full_hash); |
| 1970 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); | 1983 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); |
| 1971 } | 1984 } |
| 1972 | 1985 |
| 1973 // Sets up the prefix database and the full hash cache to match one of the | 1986 // Sets up the prefix database and the full hash cache to match one of the |
| 1974 // prefixes for the given URL. | 1987 // prefixes for the given URL in the UwS store. |
| 1975 void MarkUrlForUwsUnexpired(const GURL& bad_url) { | 1988 void MarkUrlForUwsUnexpired(const GURL& bad_url) { |
| 1976 FullHashInfo full_hash_info = GetFullHashInfo(bad_url, GetUrlUwsId()); | 1989 FullHashInfo full_hash_info = GetFullHashInfo(bad_url, GetUrlUwsId()); |
| 1977 v4_db_factory_->MarkPrefixAsBad(GetUrlUwsId(), full_hash_info.full_hash); | 1990 v4_db_factory_->MarkPrefixAsBad(GetUrlUwsId(), full_hash_info.full_hash); |
| 1978 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); | 1991 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); |
| 1979 } | 1992 } |
| 1980 | 1993 |
| 1994 // Sets up the prefix database and the full hash cache to match one of the | |
| 1995 // prefixes for the given URL in the phishing store. | |
| 1981 void MarkUrlForPhishingUnexpired(const GURL& bad_url, | 1996 void MarkUrlForPhishingUnexpired(const GURL& bad_url, |
| 1982 ThreatPatternType threat_pattern_type) { | 1997 ThreatPatternType threat_pattern_type) { |
| 1983 FullHashInfo full_hash_info = GetFullHashInfoWithMetadata( | 1998 FullHashInfo full_hash_info = GetFullHashInfoWithMetadata( |
| 1984 bad_url, GetUrlSocEngId(), threat_pattern_type); | 1999 bad_url, GetUrlSocEngId(), threat_pattern_type); |
| 1985 | 2000 |
| 1986 v4_db_factory_->MarkPrefixAsBad(GetUrlSocEngId(), full_hash_info.full_hash); | 2001 v4_db_factory_->MarkPrefixAsBad(GetUrlSocEngId(), full_hash_info.full_hash); |
| 1987 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); | 2002 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); |
| 1988 } | 2003 } |
| 1989 | 2004 |
| 2005 // Sets up the prefix database and the full hash cache to match one of the | |
| 2006 // prefixes for the given URL in the malware binary store. | |
| 2007 void MarkUrlForMalwareBinaryUnexpired(const GURL& bad_url) { | |
| 2008 FullHashInfo full_hash_info = GetFullHashInfo(bad_url, GetUrlMalBinId()); | |
| 2009 v4_db_factory_->MarkPrefixAsBad(GetUrlMalBinId(), full_hash_info.full_hash); | |
| 2010 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); | |
| 2011 } | |
| 2012 | |
| 2013 // Sets up the prefix database and the full hash cache to match one of the | |
| 2014 // prefixes for the given URL in the client incident store. | |
| 2015 void MarkUrlForResourceUnexpired(const GURL& bad_url) { | |
| 2016 FullHashInfo full_hash_info = | |
| 2017 GetFullHashInfo(bad_url, GetChromeUrlClientIncidentId()); | |
| 2018 v4_db_factory_->MarkPrefixAsBad(GetChromeUrlClientIncidentId(), | |
| 2019 full_hash_info.full_hash); | |
| 2020 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); | |
| 2021 } | |
| 2022 | |
| 1990 private: | 2023 private: |
| 1991 // Owned by the V4Database. | 2024 // Owned by the V4Database. |
| 1992 TestV4DatabaseFactory* v4_db_factory_; | 2025 TestV4DatabaseFactory* v4_db_factory_; |
| 1993 // Owned by the V4GetHashProtocolManager. | 2026 // Owned by the V4GetHashProtocolManager. |
| 1994 TestV4GetHashProtocolManagerFactory* v4_get_hash_factory_; | 2027 TestV4GetHashProtocolManagerFactory* v4_get_hash_factory_; |
| 2028 // Owned by the V4Database. | |
| 2029 TestV4StoreFactory* store_factory_; | |
|
Nathan Parker
2017/02/14 00:03:49
This isn't really owned... more of "leaked," ya? N
vakh (use Gerrit instead)
2017/02/14 00:07:19
Sort of, yes. From the perspective of this code, i
| |
| 1995 | 2030 |
| 1996 DISALLOW_COPY_AND_ASSIGN(V4SafeBrowsingServiceTest); | 2031 DISALLOW_COPY_AND_ASSIGN(V4SafeBrowsingServiceTest); |
| 1997 }; | 2032 }; |
| 1998 | 2033 |
| 1999 // Ensures that if an image is marked as UwS, the main page doesn't show an | 2034 // Ensures that if an image is marked as UwS, the main page doesn't show an |
| 2000 // interstitial. | 2035 // interstitial. |
| 2001 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, UnwantedImgIgnored) { | 2036 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, UnwantedImgIgnored) { |
| 2002 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); | 2037 GURL main_url = embedded_test_server()->GetURL(kMalwarePage); |
| 2003 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); | 2038 GURL img_url = embedded_test_server()->GetURL(kMalwareImg); |
| 2004 | 2039 |
| 2005 // Add the img url as coming from a site serving UwS and then load the parent | 2040 // Add the img url as coming from a site serving UwS and then load the parent |
| 2006 // page. | 2041 // page. |
| 2007 MarkUrlForUwsUnexpired(img_url); | 2042 MarkUrlForUwsUnexpired(img_url); |
| 2008 | 2043 |
| 2009 ui_test_utils::NavigateToURL(browser(), main_url); | 2044 ui_test_utils::NavigateToURL(browser(), main_url); |
| 2010 | 2045 |
| 2011 EXPECT_FALSE(ShowingInterstitialPage()); | 2046 EXPECT_FALSE(ShowingInterstitialPage()); |
| 2012 EXPECT_FALSE(got_hit_report()); | 2047 EXPECT_FALSE(got_hit_report()); |
| 2013 } | 2048 } |
| 2014 | 2049 |
| 2050 // Proceeding through an interstitial should cause it to get whitelisted for | |
| 2051 // that user. | |
| 2015 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, MalwareWithWhitelist) { | 2052 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, MalwareWithWhitelist) { |
| 2016 GURL url = embedded_test_server()->GetURL(kEmptyPage); | 2053 GURL url = embedded_test_server()->GetURL(kEmptyPage); |
| 2017 | 2054 |
| 2018 // After adding the url to safebrowsing database and getfullhash result, | 2055 // After adding the URL to SafeBrowsing database and full hash cache, we |
| 2019 // we should see the interstitial page. | 2056 // should see the interstitial page. |
| 2020 MarkUrlForMalwareUnexpired(url); | 2057 MarkUrlForMalwareUnexpired(url); |
| 2021 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1); | 2058 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(1); |
| 2022 | 2059 |
| 2023 ui_test_utils::NavigateToURL(browser(), url); | 2060 ui_test_utils::NavigateToURL(browser(), url); |
| 2024 Mock::VerifyAndClearExpectations(&observer_); | 2061 Mock::VerifyAndClearExpectations(&observer_); |
| 2025 // There should be an InterstitialPage. | 2062 // There should be an InterstitialPage. |
| 2026 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 2063 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2027 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); | 2064 InterstitialPage* interstitial_page = contents->GetInterstitialPage(); |
| 2028 ASSERT_TRUE(interstitial_page); | 2065 ASSERT_TRUE(interstitial_page); |
| 2029 // Proceed through it. | 2066 // Proceed through it. |
| 2030 content::WindowedNotificationObserver load_stop_observer( | 2067 content::WindowedNotificationObserver load_stop_observer( |
| 2031 content::NOTIFICATION_LOAD_STOP, | 2068 content::NOTIFICATION_LOAD_STOP, |
| 2032 content::Source<content::NavigationController>( | 2069 content::Source<content::NavigationController>( |
| 2033 &contents->GetController())); | 2070 &contents->GetController())); |
| 2034 interstitial_page->Proceed(); | 2071 interstitial_page->Proceed(); |
| 2035 load_stop_observer.Wait(); | 2072 load_stop_observer.Wait(); |
| 2036 EXPECT_FALSE(ShowingInterstitialPage()); | 2073 EXPECT_FALSE(ShowingInterstitialPage()); |
| 2037 | 2074 |
| 2038 // Navigate to kEmptyPage again -- should hit the whitelist this time. | 2075 // Navigate to kEmptyPage again -- should hit the whitelist this time. |
| 2039 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(0); | 2076 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(url))).Times(0); |
| 2040 ui_test_utils::NavigateToURL(browser(), url); | 2077 ui_test_utils::NavigateToURL(browser(), url); |
| 2041 EXPECT_FALSE(ShowingInterstitialPage()); | 2078 EXPECT_FALSE(ShowingInterstitialPage()); |
| 2042 } | 2079 } |
| 2043 | 2080 |
| 2044 // This test confirms that prefetches don't themselves get the | 2081 // This test confirms that prefetches don't themselves get the interstitial |
| 2045 // interstitial treatment. | 2082 // treatment. |
| 2046 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, Prefetch) { | 2083 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, Prefetch) { |
| 2047 GURL url = embedded_test_server()->GetURL(kPrefetchMalwarePage); | 2084 GURL url = embedded_test_server()->GetURL(kPrefetchMalwarePage); |
| 2048 GURL malware_url = embedded_test_server()->GetURL(kMalwarePage); | 2085 GURL malware_url = embedded_test_server()->GetURL(kMalwarePage); |
| 2049 | 2086 |
| 2050 // Even though we have added this URI to the SafeBrowsing database and | 2087 // Even though we have added this URI to the SafeBrowsing database and |
| 2051 // full hash result, we should not see the interstitial page since the | 2088 // full hash result, we should not see the interstitial page since the |
| 2052 // only malware was a prefetch target. | 2089 // only malware was a prefetch target. |
| 2053 MarkUrlForMalwareUnexpired(malware_url); | 2090 MarkUrlForMalwareUnexpired(malware_url); |
| 2054 | 2091 |
| 2055 ui_test_utils::NavigateToURL(browser(), url); | 2092 ui_test_utils::NavigateToURL(browser(), url); |
| 2056 EXPECT_FALSE(ShowingInterstitialPage()); | 2093 EXPECT_FALSE(ShowingInterstitialPage()); |
| 2057 EXPECT_FALSE(got_hit_report()); | 2094 EXPECT_FALSE(got_hit_report()); |
| 2058 Mock::VerifyAndClear(&observer_); | 2095 Mock::VerifyAndClear(&observer_); |
| 2059 | 2096 |
| 2060 // However, when we navigate to the malware page, we should still get | 2097 // However, when we navigate to the malware page, we should still get |
| 2061 // the interstitial. | 2098 // the interstitial. |
| 2062 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(malware_url))) | 2099 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(malware_url))) |
| 2063 .Times(1); | 2100 .Times(1); |
| 2064 ui_test_utils::NavigateToURL(browser(), malware_url); | 2101 ui_test_utils::NavigateToURL(browser(), malware_url); |
| 2065 EXPECT_TRUE(ShowingInterstitialPage()); | 2102 EXPECT_TRUE(ShowingInterstitialPage()); |
| 2066 EXPECT_TRUE(got_hit_report()); | 2103 EXPECT_TRUE(got_hit_report()); |
| 2067 Mock::VerifyAndClear(&observer_); | 2104 Mock::VerifyAndClear(&observer_); |
| 2068 } | 2105 } |
| 2069 | 2106 |
| 2107 // Ensure that the referrer information is preserved in the hit report. | |
| 2070 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, MainFrameHitWithReferrer) { | 2108 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, MainFrameHitWithReferrer) { |
| 2071 GURL first_url = embedded_test_server()->GetURL(kEmptyPage); | 2109 GURL first_url = embedded_test_server()->GetURL(kEmptyPage); |
| 2072 GURL bad_url = embedded_test_server()->GetURL(kMalwarePage); | 2110 GURL bad_url = embedded_test_server()->GetURL(kMalwarePage); |
| 2073 | 2111 |
| 2074 MarkUrlForMalwareUnexpired(bad_url); | 2112 MarkUrlForMalwareUnexpired(bad_url); |
| 2075 | 2113 |
| 2076 // Navigate to first, safe page. | 2114 // Navigate to first, safe page. |
| 2077 ui_test_utils::NavigateToURL(browser(), first_url); | 2115 ui_test_utils::NavigateToURL(browser(), first_url); |
| 2078 EXPECT_FALSE(ShowingInterstitialPage()); | 2116 EXPECT_FALSE(ShowingInterstitialPage()); |
| 2079 EXPECT_FALSE(got_hit_report()); | 2117 EXPECT_FALSE(got_hit_report()); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2355 | 2393 |
| 2356 // Proceed through it. | 2394 // Proceed through it. |
| 2357 InterstitialPage* interstitial_page = new_tab_contents->GetInterstitialPage(); | 2395 InterstitialPage* interstitial_page = new_tab_contents->GetInterstitialPage(); |
| 2358 ASSERT_TRUE(interstitial_page); | 2396 ASSERT_TRUE(interstitial_page); |
| 2359 interstitial_page->Proceed(); | 2397 interstitial_page->Proceed(); |
| 2360 | 2398 |
| 2361 content::WaitForInterstitialDetach(new_tab_contents); | 2399 content::WaitForInterstitialDetach(new_tab_contents); |
| 2362 EXPECT_FALSE(ShowingInterstitialPage()); | 2400 EXPECT_FALSE(ShowingInterstitialPage()); |
| 2363 } | 2401 } |
| 2364 | 2402 |
| 2403 /////////////////////////////////////////////////////////////////////////////// | |
| 2404 // START: These tests use SafeBrowsingService::Client to directly interact with | |
| 2405 // SafeBrowsingService. | |
| 2406 /////////////////////////////////////////////////////////////////////////////// | |
| 2407 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, CheckDownloadUrl) { | |
| 2408 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); | |
|
Nathan Parker
2017/02/14 00:03:49
What in these tests points it at Pver4 impl?
vakh (use Gerrit instead)
2017/02/14 00:07:19
void SetUp() override {
sb_factory_ = base::Ma
| |
| 2409 std::vector<GURL> badbin_urls(1, badbin_url); | |
| 2410 | |
| 2411 scoped_refptr<TestSBClient> client(new TestSBClient); | |
| 2412 client->CheckDownloadUrl(badbin_urls); | |
| 2413 | |
| 2414 // Since badbin_url is not in database, it is considered to be safe. | |
| 2415 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | |
| 2416 | |
| 2417 MarkUrlForMalwareBinaryUnexpired(badbin_url); | |
| 2418 | |
| 2419 client->CheckDownloadUrl(badbin_urls); | |
| 2420 | |
| 2421 // Now, the badbin_url is not safe since it is added to download database. | |
| 2422 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); | |
| 2423 } | |
| 2424 | |
| 2425 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, CheckUnwantedSoftwareUrl) { | |
| 2426 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); | |
| 2427 { | |
| 2428 scoped_refptr<TestSBClient> client(new TestSBClient); | |
| 2429 | |
| 2430 // Since bad_url is not in database, it is considered to be | |
| 2431 // safe. | |
| 2432 client->CheckBrowseUrl(bad_url); | |
| 2433 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | |
| 2434 | |
| 2435 MarkUrlForUwsUnexpired(bad_url); | |
| 2436 | |
| 2437 // Now, the bad_url is not safe since it is added to download | |
| 2438 // database. | |
| 2439 client->CheckBrowseUrl(bad_url); | |
| 2440 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); | |
| 2441 } | |
| 2442 | |
| 2443 // The unwantedness should survive across multiple clients. | |
| 2444 { | |
| 2445 scoped_refptr<TestSBClient> client(new TestSBClient); | |
| 2446 client->CheckBrowseUrl(bad_url); | |
| 2447 EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED, client->GetThreatType()); | |
| 2448 } | |
| 2449 | |
| 2450 // An unwanted URL also marked as malware should be flagged as malware. | |
| 2451 { | |
| 2452 scoped_refptr<TestSBClient> client(new TestSBClient); | |
| 2453 | |
| 2454 MarkUrlForMalwareUnexpired(bad_url); | |
| 2455 | |
| 2456 client->CheckBrowseUrl(bad_url); | |
| 2457 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | |
| 2458 } | |
| 2459 } | |
| 2460 | |
| 2461 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, CheckBrowseUrl) { | |
| 2462 const GURL bad_url = embedded_test_server()->GetURL(kMalwareFile); | |
| 2463 { | |
| 2464 scoped_refptr<TestSBClient> client(new TestSBClient); | |
| 2465 | |
| 2466 // Since bad_url is not in database, it is considered to be | |
| 2467 // safe. | |
| 2468 client->CheckBrowseUrl(bad_url); | |
| 2469 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | |
| 2470 | |
| 2471 MarkUrlForMalwareUnexpired(bad_url); | |
| 2472 | |
| 2473 // Now, the bad_url is not safe since it is added to download | |
| 2474 // database. | |
| 2475 client->CheckBrowseUrl(bad_url); | |
| 2476 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | |
| 2477 } | |
| 2478 | |
| 2479 // The unwantedness should survive across multiple clients. | |
| 2480 { | |
| 2481 scoped_refptr<TestSBClient> client(new TestSBClient); | |
| 2482 client->CheckBrowseUrl(bad_url); | |
| 2483 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | |
| 2484 } | |
| 2485 | |
| 2486 // Adding the unwanted state to an existing malware URL should have no impact | |
| 2487 // (i.e. a malware hit should still prevail). | |
| 2488 { | |
| 2489 scoped_refptr<TestSBClient> client(new TestSBClient); | |
| 2490 | |
| 2491 MarkUrlForUwsUnexpired(bad_url); | |
| 2492 | |
| 2493 client->CheckBrowseUrl(bad_url); | |
| 2494 EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE, client->GetThreatType()); | |
| 2495 } | |
| 2496 } | |
| 2497 | |
| 2498 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, CheckDownloadUrlRedirects) { | |
| 2499 GURL original_url = embedded_test_server()->GetURL(kEmptyPage); | |
| 2500 GURL badbin_url = embedded_test_server()->GetURL(kMalwareFile); | |
| 2501 GURL final_url = embedded_test_server()->GetURL(kEmptyPage); | |
| 2502 std::vector<GURL> badbin_urls; | |
| 2503 badbin_urls.push_back(original_url); | |
| 2504 badbin_urls.push_back(badbin_url); | |
| 2505 badbin_urls.push_back(final_url); | |
| 2506 | |
| 2507 scoped_refptr<TestSBClient> client(new TestSBClient); | |
| 2508 client->CheckDownloadUrl(badbin_urls); | |
| 2509 | |
| 2510 // Since badbin_url is not in database, it is considered to be safe. | |
| 2511 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | |
| 2512 | |
| 2513 MarkUrlForMalwareBinaryUnexpired(badbin_url); | |
| 2514 | |
| 2515 client->CheckDownloadUrl(badbin_urls); | |
| 2516 | |
| 2517 // Now, the badbin_url is not safe since it is added to download database. | |
| 2518 EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType()); | |
| 2519 } | |
| 2520 | |
| 2521 #if defined(GOOGLE_CHROME_BUILD) | |
| 2522 // This test is only enabled when GOOGLE_CHROME_BUILD is true because the store | |
| 2523 // that this test uses is only populated on GOOGLE_CHROME_BUILD builds. | |
| 2524 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, CheckResourceUrl) { | |
| 2525 GURL blacklist_url = embedded_test_server()->GetURL(kBlacklistResource); | |
| 2526 GURL malware_url = embedded_test_server()->GetURL(kMaliciousResource); | |
| 2527 std::string blacklist_url_hash, malware_url_hash; | |
| 2528 | |
| 2529 scoped_refptr<TestSBClient> client(new TestSBClient); | |
| 2530 { | |
| 2531 MarkUrlForResourceUnexpired(blacklist_url); | |
| 2532 blacklist_url_hash = GetFullHash(blacklist_url); | |
| 2533 | |
| 2534 client->CheckResourceUrl(blacklist_url); | |
| 2535 EXPECT_EQ(SB_THREAT_TYPE_BLACKLISTED_RESOURCE, client->GetThreatType()); | |
| 2536 EXPECT_EQ(blacklist_url_hash, client->GetThreatHash()); | |
| 2537 } | |
| 2538 { | |
| 2539 MarkUrlForMalwareUnexpired(malware_url); | |
| 2540 MarkUrlForResourceUnexpired(malware_url); | |
| 2541 malware_url_hash = GetFullHash(malware_url); | |
| 2542 | |
| 2543 // Since we're checking a resource url, we should receive result that it's | |
| 2544 // a blacklisted resource, not a malware. | |
| 2545 client = new TestSBClient; | |
| 2546 client->CheckResourceUrl(malware_url); | |
| 2547 EXPECT_EQ(SB_THREAT_TYPE_BLACKLISTED_RESOURCE, client->GetThreatType()); | |
| 2548 EXPECT_EQ(malware_url_hash, client->GetThreatHash()); | |
| 2549 } | |
| 2550 | |
| 2551 client->CheckResourceUrl(embedded_test_server()->GetURL(kEmptyPage)); | |
| 2552 EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType()); | |
| 2553 } | |
| 2554 #endif | |
| 2555 /////////////////////////////////////////////////////////////////////////////// | |
| 2556 // END: These tests use SafeBrowsingService::Client to directly interact with | |
| 2557 // SafeBrowsingService. | |
| 2558 /////////////////////////////////////////////////////////////////////////////// | |
| 2559 | |
| 2365 // TODO(vakh): Add test for UnwantedMainFrame. | 2560 // TODO(vakh): Add test for UnwantedMainFrame. |
| 2366 | 2561 |
| 2367 class V4SafeBrowsingServiceMetadataTest | 2562 class V4SafeBrowsingServiceMetadataTest |
| 2368 : public V4SafeBrowsingServiceTest, | 2563 : public V4SafeBrowsingServiceTest, |
| 2369 public ::testing::WithParamInterface<ThreatPatternType> { | 2564 public ::testing::WithParamInterface<ThreatPatternType> { |
| 2370 public: | 2565 public: |
| 2371 V4SafeBrowsingServiceMetadataTest() {} | 2566 V4SafeBrowsingServiceMetadataTest() {} |
| 2372 | 2567 |
| 2373 private: | 2568 private: |
| 2374 DISALLOW_COPY_AND_ASSIGN(V4SafeBrowsingServiceMetadataTest); | 2569 DISALLOW_COPY_AND_ASSIGN(V4SafeBrowsingServiceMetadataTest); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2462 } | 2657 } |
| 2463 | 2658 |
| 2464 INSTANTIATE_TEST_CASE_P( | 2659 INSTANTIATE_TEST_CASE_P( |
| 2465 MaybeSetMetadata, | 2660 MaybeSetMetadata, |
| 2466 V4SafeBrowsingServiceMetadataTest, | 2661 V4SafeBrowsingServiceMetadataTest, |
| 2467 testing::Values(ThreatPatternType::NONE, | 2662 testing::Values(ThreatPatternType::NONE, |
| 2468 ThreatPatternType::MALWARE_LANDING, | 2663 ThreatPatternType::MALWARE_LANDING, |
| 2469 ThreatPatternType::MALWARE_DISTRIBUTION)); | 2664 ThreatPatternType::MALWARE_DISTRIBUTION)); |
| 2470 | 2665 |
| 2471 } // namespace safe_browsing | 2666 } // namespace safe_browsing |
| OLD | NEW |