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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database_unittest.cc

Issue 1643573002: Add a ModuleLoadAnalyzer which checks modules against a whitelist (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only enable for extended reporting AND feature flag. Add unit test. 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 unified diff | Download patch
OLDNEW
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 // Unit tests for the SafeBrowsing storage system. 5 // Unit tests for the SafeBrowsing storage system.
6 6
7 #include "chrome/browser/safe_browsing/safe_browsing_database.h" 7 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <utility> 10 #include <utility>
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 SafeBrowsingStoreFile* download_whitelist_store = 273 SafeBrowsingStoreFile* download_whitelist_store =
274 new SafeBrowsingStoreFile(task_runner_); 274 new SafeBrowsingStoreFile(task_runner_);
275 SafeBrowsingStoreFile* inclusion_whitelist_store = 275 SafeBrowsingStoreFile* inclusion_whitelist_store =
276 new SafeBrowsingStoreFile(task_runner_); 276 new SafeBrowsingStoreFile(task_runner_);
277 SafeBrowsingStoreFile* extension_blacklist_store = 277 SafeBrowsingStoreFile* extension_blacklist_store =
278 new SafeBrowsingStoreFile(task_runner_); 278 new SafeBrowsingStoreFile(task_runner_);
279 SafeBrowsingStoreFile* ip_blacklist_store = 279 SafeBrowsingStoreFile* ip_blacklist_store =
280 new SafeBrowsingStoreFile(task_runner_); 280 new SafeBrowsingStoreFile(task_runner_);
281 SafeBrowsingStoreFile* unwanted_software_store = 281 SafeBrowsingStoreFile* unwanted_software_store =
282 new SafeBrowsingStoreFile(task_runner_); 282 new SafeBrowsingStoreFile(task_runner_);
283 SafeBrowsingStoreFile* module_whitelist_store =
284 new SafeBrowsingStoreFile(task_runner_);
283 database_.reset(new SafeBrowsingDatabaseNew( 285 database_.reset(new SafeBrowsingDatabaseNew(
284 task_runner_, browse_store, download_store, csd_whitelist_store, 286 task_runner_, browse_store, download_store, csd_whitelist_store,
285 download_whitelist_store, inclusion_whitelist_store, 287 download_whitelist_store, inclusion_whitelist_store,
286 extension_blacklist_store, ip_blacklist_store, 288 extension_blacklist_store, ip_blacklist_store, unwanted_software_store,
287 unwanted_software_store)); 289 module_whitelist_store));
288 database_->Init(database_filename_); 290 database_->Init(database_filename_);
289 } 291 }
290 292
291 bool ContainsDownloadUrl(const std::vector<GURL>& urls, 293 bool ContainsDownloadUrl(const std::vector<GURL>& urls,
292 std::vector<SBPrefix>* prefix_hits) { 294 std::vector<SBPrefix>* prefix_hits) {
293 std::vector<SBPrefix> prefixes; 295 std::vector<SBPrefix> prefixes;
294 SafeBrowsingDatabase::GetDownloadUrlPrefixes(urls, &prefixes); 296 SafeBrowsingDatabase::GetDownloadUrlPrefixes(urls, &prefixes);
295 return database_->ContainsDownloadUrlPrefixes(prefixes, prefix_hits); 297 return database_->ContainsDownloadUrlPrefixes(prefixes, prefix_hits);
296 } 298 }
297 299
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 chunks); 435 chunks);
434 436
435 chunks.clear(); 437 chunks.clear();
436 chunks.push_back(AddChunkHashedIpValue(10, "::ffff:192.168.1.0", 120)); 438 chunks.push_back(AddChunkHashedIpValue(10, "::ffff:192.168.1.0", 120));
437 database_->InsertChunks(kIPBlacklist, chunks); 439 database_->InsertChunks(kIPBlacklist, chunks);
438 440
439 chunks.clear(); 441 chunks.clear();
440 chunks.push_back(AddChunkPrefixValue(11, "www.unwanted.com/software.html")); 442 chunks.push_back(AddChunkPrefixValue(11, "www.unwanted.com/software.html"));
441 database_->InsertChunks(kUnwantedUrlList, chunks); 443 database_->InsertChunks(kUnwantedUrlList, chunks);
442 444
445 chunks.clear();
446 chunks.push_back(AddChunkPrefixValue(12, "chrome.dll"));
447 database_->InsertChunks(kModuleWhitelist, chunks);
448
443 database_->UpdateFinished(true); 449 database_->UpdateFinished(true);
444 450
445 GetListsInfo(&lists); 451 GetListsInfo(&lists);
446 ASSERT_EQ(9U, lists.size()); 452 ASSERT_EQ(10U, lists.size());
447 EXPECT_EQ(kMalwareList, lists[0].name); 453 EXPECT_EQ(kMalwareList, lists[0].name);
448 EXPECT_EQ("1", lists[0].adds); 454 EXPECT_EQ("1", lists[0].adds);
449 EXPECT_TRUE(lists[0].subs.empty()); 455 EXPECT_TRUE(lists[0].subs.empty());
450 EXPECT_EQ(kPhishingList, lists[1].name); 456 EXPECT_EQ(kPhishingList, lists[1].name);
451 EXPECT_EQ("2", lists[1].adds); 457 EXPECT_EQ("2", lists[1].adds);
452 EXPECT_TRUE(lists[1].subs.empty()); 458 EXPECT_TRUE(lists[1].subs.empty());
453 EXPECT_EQ(kBinUrlList, lists[2].name); 459 EXPECT_EQ(kBinUrlList, lists[2].name);
454 EXPECT_EQ("3", lists[2].adds); 460 EXPECT_EQ("3", lists[2].adds);
455 EXPECT_TRUE(lists[2].subs.empty()); 461 EXPECT_TRUE(lists[2].subs.empty());
456 EXPECT_EQ(kCsdWhiteList, lists[3].name); 462 EXPECT_EQ(kCsdWhiteList, lists[3].name);
457 EXPECT_EQ("5", lists[3].adds); 463 EXPECT_EQ("5", lists[3].adds);
458 EXPECT_TRUE(lists[3].subs.empty()); 464 EXPECT_TRUE(lists[3].subs.empty());
459 EXPECT_EQ(kDownloadWhiteList, lists[4].name); 465 EXPECT_EQ(kDownloadWhiteList, lists[4].name);
460 EXPECT_EQ("6", lists[4].adds); 466 EXPECT_EQ("6", lists[4].adds);
461 EXPECT_TRUE(lists[4].subs.empty()); 467 EXPECT_TRUE(lists[4].subs.empty());
462 EXPECT_EQ(kInclusionWhitelist, lists[5].name); 468 EXPECT_EQ(kInclusionWhitelist, lists[5].name);
463 EXPECT_EQ("7", lists[5].adds); 469 EXPECT_EQ("7", lists[5].adds);
464 EXPECT_TRUE(lists[5].subs.empty()); 470 EXPECT_TRUE(lists[5].subs.empty());
465 EXPECT_EQ(kExtensionBlacklist, lists[6].name); 471 EXPECT_EQ(kExtensionBlacklist, lists[6].name);
466 EXPECT_EQ("8", lists[6].adds); 472 EXPECT_EQ("8", lists[6].adds);
467 EXPECT_TRUE(lists[6].subs.empty()); 473 EXPECT_TRUE(lists[6].subs.empty());
468 EXPECT_EQ(kIPBlacklist, lists[7].name); 474 EXPECT_EQ(kIPBlacklist, lists[7].name);
469 EXPECT_EQ("10", lists[7].adds); 475 EXPECT_EQ("10", lists[7].adds);
470 EXPECT_TRUE(lists[7].subs.empty()); 476 EXPECT_TRUE(lists[7].subs.empty());
471 EXPECT_EQ(kUnwantedUrlList, lists[8].name); 477 EXPECT_EQ(kUnwantedUrlList, lists[8].name);
472 EXPECT_EQ("11", lists[8].adds); 478 EXPECT_EQ("11", lists[8].adds);
473 EXPECT_TRUE(lists[8].subs.empty()); 479 EXPECT_TRUE(lists[8].subs.empty());
480 EXPECT_EQ(kModuleWhitelist, lists[9].name);
481 EXPECT_EQ("12", lists[9].adds);
482 EXPECT_TRUE(lists[9].subs.empty());
474 483
475 database_.reset(); 484 database_.reset();
476 } 485 }
477 486
478 // Checks database reading and writing for browse and unwanted PrefixSets. 487 // Checks database reading and writing for browse and unwanted PrefixSets.
479 TEST_F(SafeBrowsingDatabaseTest, BrowseAndUnwantedDatabasesAndPrefixSets) { 488 TEST_F(SafeBrowsingDatabaseTest, BrowseAndUnwantedDatabasesAndPrefixSets) {
480 489
481 struct TestCase { 490 struct TestCase {
482 using TestListContainsBadUrl = bool (SafeBrowsingDatabase::*)( 491 using TestListContainsBadUrl = bool (SafeBrowsingDatabase::*)(
483 const GURL& url, 492 const GURL& url,
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 // TODO(shess): Disabled until ScopedLogMessageIgnorer resolved. 1155 // TODO(shess): Disabled until ScopedLogMessageIgnorer resolved.
1147 // http://crbug.com/56448 1156 // http://crbug.com/56448
1148 TEST_F(SafeBrowsingDatabaseTest, DISABLED_FileCorruptionHandling) { 1157 TEST_F(SafeBrowsingDatabaseTest, DISABLED_FileCorruptionHandling) {
1149 // Re-create the database in a captive message loop so that we can 1158 // Re-create the database in a captive message loop so that we can
1150 // influence task-posting. Database specifically needs to the 1159 // influence task-posting. Database specifically needs to the
1151 // file-backed. 1160 // file-backed.
1152 database_.reset(); 1161 database_.reset();
1153 base::MessageLoop loop; 1162 base::MessageLoop loop;
1154 SafeBrowsingStoreFile* store = new SafeBrowsingStoreFile(task_runner_); 1163 SafeBrowsingStoreFile* store = new SafeBrowsingStoreFile(task_runner_);
1155 database_.reset(new SafeBrowsingDatabaseNew( 1164 database_.reset(new SafeBrowsingDatabaseNew(
1156 task_runner_, store, NULL, NULL, NULL, NULL, NULL, NULL, NULL)); 1165 task_runner_, store, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));
1157 database_->Init(database_filename_); 1166 database_->Init(database_filename_);
1158 1167
1159 // This will cause an empty database to be created. 1168 // This will cause an empty database to be created.
1160 std::vector<SBListChunkRanges> lists; 1169 std::vector<SBListChunkRanges> lists;
1161 ASSERT_TRUE(database_->UpdateStarted(&lists)); 1170 ASSERT_TRUE(database_->UpdateStarted(&lists));
1162 database_->UpdateFinished(true); 1171 database_->UpdateFinished(true);
1163 1172
1164 // Create a sub chunk to insert. 1173 // Create a sub chunk to insert.
1165 std::vector<scoped_ptr<SBChunkData>> chunks; 1174 std::vector<scoped_ptr<SBChunkData>> chunks;
1166 chunks.push_back(SubChunkPrefixValue(7, 1175 chunks.push_back(SubChunkPrefixValue(7,
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 &SafeBrowsingDatabase::ContainsDownloadWhitelistedUrl, 1330 &SafeBrowsingDatabase::ContainsDownloadWhitelistedUrl,
1322 &SafeBrowsingDatabase::ContainsDownloadWhitelistedString}, 1331 &SafeBrowsingDatabase::ContainsDownloadWhitelistedString},
1323 {kInclusionWhitelist, 1332 {kInclusionWhitelist,
1324 &SafeBrowsingDatabase::ContainsInclusionWhitelistedUrl, 1333 &SafeBrowsingDatabase::ContainsInclusionWhitelistedUrl,
1325 nullptr}, 1334 nullptr},
1326 }; 1335 };
1327 1336
1328 // If the whitelist is disabled everything should match the whitelist. 1337 // If the whitelist is disabled everything should match the whitelist.
1329 database_.reset(new SafeBrowsingDatabaseNew( 1338 database_.reset(new SafeBrowsingDatabaseNew(
1330 task_runner_, new SafeBrowsingStoreFile(task_runner_), NULL, NULL, NULL, 1339 task_runner_, new SafeBrowsingStoreFile(task_runner_), NULL, NULL, NULL,
1331 NULL, NULL, NULL, NULL)); 1340 NULL, NULL, NULL, NULL, NULL));
1332 database_->Init(database_filename_); 1341 database_->Init(database_filename_);
1333 for (const auto& test_case : kTestCases) { 1342 for (const auto& test_case : kTestCases) {
1334 SCOPED_TRACE(std::string("Tested list at fault => ") + 1343 SCOPED_TRACE(std::string("Tested list at fault => ") +
1335 test_case.test_list_name); 1344 test_case.test_list_name);
1336 1345
1337 EXPECT_TRUE( 1346 EXPECT_TRUE(
1338 (database_.get()->*test_case.test_list_contains_whitelisted_url)( 1347 (database_.get()->*test_case.test_list_contains_whitelisted_url)(
1339 GURL(std::string("http://www.phishing.com/")))); 1348 GURL(std::string("http://www.phishing.com/"))));
1340 if (test_case.TestStrings()) { 1349 if (test_case.TestStrings()) {
1341 EXPECT_TRUE( 1350 EXPECT_TRUE(
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 ASSERT_EQ(1U, prefix_hits.size()); 2286 ASSERT_EQ(1U, prefix_hits.size());
2278 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]); 2287 EXPECT_EQ(SBPrefixForString(kExampleCollision), prefix_hits[0]);
2279 EXPECT_TRUE(cache_hits.empty()); 2288 EXPECT_TRUE(cache_hits.empty());
2280 2289
2281 // This prefix collides, but no full hash match. 2290 // This prefix collides, but no full hash match.
2282 EXPECT_FALSE(database_->ContainsBrowseUrl( 2291 EXPECT_FALSE(database_->ContainsBrowseUrl(
2283 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits)); 2292 GURL(std::string("http://") + kExampleFine), &prefix_hits, &cache_hits));
2284 } 2293 }
2285 2294
2286 } // namespace safe_browsing 2295 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698