| Index: chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
|
| diff --git a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
|
| index 70d2b019dceb9a39589e4ed38430fcb456eada17..cae2a8b7d55aa21442dad8053f0a2c1fcc777073 100644
|
| --- a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
|
| +++ b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
|
| @@ -41,6 +41,19 @@ std::string HashedIpPrefix(const std::string& ip_prefix, size_t prefix_size) {
|
| return hash;
|
| }
|
|
|
| +// Add a host-level entry.
|
| +void InsertAddChunkHostPrefix(SBChunk* chunk,
|
| + int chunk_number,
|
| + const std::string& host_name) {
|
| + chunk->chunk_number = chunk_number;
|
| + chunk->is_add = true;
|
| + SBChunkHost host;
|
| + host.host = SBPrefixForString(host_name);
|
| + host.entry = SBEntry::Create(SBEntry::ADD_PREFIX, 0);
|
| + host.entry->set_chunk_id(chunk->chunk_number);
|
| + chunk->hosts.push_back(host);
|
| +}
|
| +
|
| // Same as InsertAddChunkHostPrefixUrl, but with pre-computed
|
| // prefix values.
|
| void InsertAddChunkHostPrefixValue(SBChunk* chunk,
|
| @@ -1822,3 +1835,89 @@ TEST_F(SafeBrowsingDatabaseTest, MalwareIpBlacklist) {
|
| EXPECT_TRUE(database_->ContainsMalwareIP("192.1.255.255"));
|
| EXPECT_FALSE(database_->ContainsMalwareIP("192.2.0.0"));
|
| }
|
| +
|
| +TEST_F(SafeBrowsingDatabaseTest, ContainsBrowseURL) {
|
| + std::vector<SBListChunkRanges> lists;
|
| + EXPECT_TRUE(database_->UpdateStarted(&lists));
|
| +
|
| + // Add a host-level hit.
|
| + {
|
| + SBChunkList chunks;
|
| + SBChunk chunk;
|
| + InsertAddChunkHostPrefix(&chunk, 1, "www.evil.com/");
|
| + chunks.push_back(chunk);
|
| + database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
|
| + }
|
| +
|
| + // Add a specific fullhash.
|
| + static const char kWhateverMalware[] = "www.whatever.com/malware.html";
|
| + {
|
| + SBChunkList chunks;
|
| + SBChunk chunk;
|
| + InsertAddChunkHostFullHashes(&chunk, 2, "www.whatever.com/",
|
| + kWhateverMalware);
|
| + chunks.push_back(chunk);
|
| + database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
|
| + }
|
| +
|
| + // Add a fullhash which has a prefix collision for a known url.
|
| + static const char kExampleFine[] = "www.example.com/fine.html";
|
| + static const char kExampleCollision[] =
|
| + "www.example.com/3123364814/malware.htm";
|
| + ASSERT_EQ(SBPrefixForString(kExampleFine),
|
| + SBPrefixForString(kExampleCollision));
|
| + {
|
| + SBChunkList chunks;
|
| + SBChunk chunk;
|
| + InsertAddChunkHostFullHashes(&chunk, 3, "www.example.com/",
|
| + kExampleCollision);
|
| + chunks.push_back(chunk);
|
| + database_->InsertChunks(safe_browsing_util::kMalwareList, chunks);
|
| + }
|
| +
|
| + database_->UpdateFinished(true);
|
| +
|
| + const Time now = Time::Now();
|
| + std::vector<SBFullHashResult> full_hashes;
|
| + std::vector<SBPrefix> prefix_hits;
|
| + std::string matching_list;
|
| +
|
| + // Anything will hit the host prefix.
|
| + EXPECT_TRUE(database_->ContainsBrowseUrl(
|
| + GURL("http://www.evil.com/malware.html"),
|
| + &matching_list, &prefix_hits,
|
| + &full_hashes, now));
|
| + ASSERT_EQ(1U, prefix_hits.size());
|
| + EXPECT_EQ(SBPrefixForString("www.evil.com/"), prefix_hits[0]);
|
| + EXPECT_TRUE(full_hashes.empty());
|
| +
|
| + // Hit the specific URL prefix.
|
| + EXPECT_TRUE(database_->ContainsBrowseUrl(
|
| + GURL(std::string("http://") + kWhateverMalware),
|
| + &matching_list, &prefix_hits,
|
| + &full_hashes, now));
|
| + ASSERT_EQ(1U, prefix_hits.size());
|
| + EXPECT_EQ(SBPrefixForString(kWhateverMalware), prefix_hits[0]);
|
| + ASSERT_EQ(1U, full_hashes.size());
|
| + EXPECT_TRUE(SBFullHashEqual(full_hashes[0].hash,
|
| + SBFullHashForString(kWhateverMalware)));
|
| +
|
| + // Other URLs at that host are fine.
|
| + EXPECT_FALSE(database_->ContainsBrowseUrl(
|
| + GURL("http://www.whatever.com/fine.html"),
|
| + &matching_list, &prefix_hits,
|
| + &full_hashes, now));
|
| + EXPECT_TRUE(prefix_hits.empty());
|
| + EXPECT_TRUE(full_hashes.empty());
|
| +
|
| + // Hit the prefix, which returns a fullhash hit for something else.
|
| + EXPECT_TRUE(database_->ContainsBrowseUrl(
|
| + GURL(std::string("http://") + kExampleFine),
|
| + &matching_list, &prefix_hits,
|
| + &full_hashes, now));
|
| + ASSERT_EQ(1U, prefix_hits.size());
|
| + EXPECT_EQ(SBPrefixForString(kExampleFine), prefix_hits[0]);
|
| + ASSERT_EQ(1U, full_hashes.size());
|
| + EXPECT_TRUE(SBFullHashEqual(full_hashes[0].hash,
|
| + SBFullHashForString(kExampleCollision)));
|
| +}
|
|
|