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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc

Issue 1673733002: Support new Safe Browsing list "goog-badresource-shavar" in SafeBrowsingDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Post-merge test fix Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc
diff --git a/chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc b/chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc
index 73f66552fa9a109eee5e7f66b835b2ee11237e8c..8807d14920f9bb253726f0d8bc8fcfa7c4d9bf92 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc
@@ -263,6 +263,13 @@ class TestSafeBrowsingDatabase : public SafeBrowsingDatabase {
bool ContainsMalwareIP(const std::string& ip_address) override {
return true;
}
+ bool ContainsResourceUrlPrefixes(
+ const std::vector<SBPrefix>& prefixes,
+ std::vector<SBPrefix>* prefix_hits) override {
+ prefix_hits->clear();
+ return ContainsUrlPrefixes(RESOURCEBLACKLIST, RESOURCEBLACKLIST,
+ prefixes, prefix_hits);
+ }
bool UpdateStarted(std::vector<SBListChunkRanges>* lists) override {
ADD_FAILURE() << "Not implemented.";
return false;
@@ -1141,6 +1148,8 @@ class TestSBClient : public base::RefCountedThreadSafe<TestSBClient>,
SBThreatType GetThreatType() const { return threat_type_; }
+ std::string GetThreatHash() const { return threat_hash_; }
+
void CheckDownloadUrl(const std::vector<GURL>& url_chain) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -1155,6 +1164,13 @@ class TestSBClient : public base::RefCountedThreadSafe<TestSBClient>,
content::RunMessageLoop(); // Will stop in OnCheckBrowseUrlResult.
}
+ void CheckResourceUrl(const GURL& url) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&TestSBClient::CheckResourceUrlOnIOThread, this, url));
+ content::RunMessageLoop(); // Will stop in OnCheckResourceUrlResult.
+ }
+
private:
friend class base::RefCountedThreadSafe<TestSBClient>;
~TestSBClient() override {}
@@ -1182,6 +1198,16 @@ class TestSBClient : public base::RefCountedThreadSafe<TestSBClient>,
}
}
+ void CheckResourceUrlOnIOThread(const GURL& url) {
+ bool synchronous_safe_signal =
+ safe_browsing_service_->database_manager()->CheckResourceUrl(url, this);
+ if (synchronous_safe_signal) {
+ threat_type_ = SB_THREAT_TYPE_SAFE;
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&TestSBClient::CheckDone, this));
+ }
+ }
+
// Called when the result of checking a download URL is known.
void OnCheckDownloadUrlResult(const std::vector<GURL>& /* url_chain */,
SBThreatType threat_type) override {
@@ -1199,9 +1225,20 @@ class TestSBClient : public base::RefCountedThreadSafe<TestSBClient>,
base::Bind(&TestSBClient::CheckDone, this));
}
+ // Called when the result of checking a resource URL is known.
+ void OnCheckResourceUrlResult(const GURL& /* url */,
+ SBThreatType threat_type,
+ const std::string& threat_hash) override {
+ threat_type_ = threat_type;
+ threat_hash_ = threat_hash;
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&TestSBClient::CheckDone, this));
+ }
+
void CheckDone() { base::MessageLoopForUI::current()->QuitWhenIdle(); }
SBThreatType threat_type_;
+ std::string threat_hash_;
SafeBrowsingService* safe_browsing_service_;
DISALLOW_COPY_AND_ASSIGN(TestSBClient);
@@ -1337,6 +1374,47 @@ IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckDownloadUrlRedirects) {
EXPECT_EQ(SB_THREAT_TYPE_BINARY_MALWARE_URL, client->GetThreatType());
}
+IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, CheckResourceUrl) {
+ const char* kBlacklistResource = "/blacklisted/script.js";
+ GURL blacklist_resource = embedded_test_server()->GetURL(kBlacklistResource);
+ std::string blacklist_resource_hash;
+ const char* kMaliciousResource = "/malware/script.js";
+ GURL malware_resource = embedded_test_server()->GetURL(kMaliciousResource);
+ std::string malware_resource_hash;
+
+ {
+ SBFullHashResult full_hash;
+ GenUrlFullhashResult(blacklist_resource, RESOURCEBLACKLIST, &full_hash);
+ SetupResponseForUrl(blacklist_resource, full_hash);
+ blacklist_resource_hash = std::string(full_hash.hash.full_hash,
+ full_hash.hash.full_hash + 32);
+ }
+ {
+ SBFullHashResult full_hash;
+ GenUrlFullhashResult(malware_resource, MALWARE, &full_hash);
+ SetupResponseForUrl(malware_resource, full_hash);
+ full_hash.list_id = RESOURCEBLACKLIST;
+ SetupResponseForUrl(malware_resource, full_hash);
+ malware_resource_hash = std::string(full_hash.hash.full_hash,
+ full_hash.hash.full_hash + 32);
+ }
+
+ scoped_refptr<TestSBClient> client(new TestSBClient);
+ client->CheckResourceUrl(blacklist_resource);
+ EXPECT_EQ(SB_THREAT_TYPE_BLACKLISTED_RESOURCE, client->GetThreatType());
+ EXPECT_EQ(blacklist_resource_hash, client->GetThreatHash());
+
+ // Since we're checking a resource url, we should receive result that it's
+ // a blacklisted resource, not a malware.
+ client = new TestSBClient;
+ client->CheckResourceUrl(malware_resource);
+ EXPECT_EQ(SB_THREAT_TYPE_BLACKLISTED_RESOURCE, client->GetThreatType());
+ EXPECT_EQ(malware_resource_hash, client->GetThreatHash());
+
+ client->CheckResourceUrl(embedded_test_server()->GetURL(kEmptyPage));
+ EXPECT_EQ(SB_THREAT_TYPE_SAFE, client->GetThreatType());
+}
+
#if defined(OS_WIN)
// http://crbug.com/396409
#define MAYBE_CheckDownloadUrlTimedOut DISABLED_CheckDownloadUrlTimedOut

Powered by Google App Engine
This is Rietveld 408576698