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

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

Issue 7863006: Add a whitelist for the new binary download protection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Matt's comment. Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 EXPECT_EQ(lists[1].adds, "47"); 359 EXPECT_EQ(lists[1].adds, "47");
360 EXPECT_EQ(lists[1].subs, "200-201"); 360 EXPECT_EQ(lists[1].subs, "200-201");
361 } 361 }
362 362
363 TEST_F(SafeBrowsingDatabaseTest, ListNameForBrowseAndDownload) { 363 TEST_F(SafeBrowsingDatabaseTest, ListNameForBrowseAndDownload) {
364 database_.reset(); 364 database_.reset();
365 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 365 MessageLoop loop(MessageLoop::TYPE_DEFAULT);
366 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile(); 366 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile();
367 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile(); 367 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile();
368 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile(); 368 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile();
369 SafeBrowsingStoreFile* download_whitelist_store = new SafeBrowsingStoreFile();
369 database_.reset(new SafeBrowsingDatabaseNew(browse_store, 370 database_.reset(new SafeBrowsingDatabaseNew(browse_store,
370 download_store, 371 download_store,
371 csd_whitelist_store)); 372 csd_whitelist_store,
373 download_whitelist_store));
372 database_->Init(database_filename_); 374 database_->Init(database_filename_);
373 375
374 SBChunkList chunks; 376 SBChunkList chunks;
375 SBChunk chunk; 377 SBChunk chunk;
376 378
377 // Insert malware, phish, binurl and bindownload add chunks. 379 // Insert malware, phish, binurl and bindownload add chunks.
378 InsertAddChunkHostPrefixUrl(&chunk, 1, "www.evil.com/", 380 InsertAddChunkHostPrefixUrl(&chunk, 1, "www.evil.com/",
379 "www.evil.com/malware.html"); 381 "www.evil.com/malware.html");
380 chunks.push_back(chunk); 382 chunks.push_back(chunk);
381 std::vector<SBListChunkRanges> lists; 383 std::vector<SBListChunkRanges> lists;
(...skipping 21 matching lines...) Expand all
403 chunks.push_back(chunk); 405 chunks.push_back(chunk);
404 database_->InsertChunks(safe_browsing_util::kBinHashList, chunks); 406 database_->InsertChunks(safe_browsing_util::kBinHashList, chunks);
405 407
406 chunk.hosts.clear(); 408 chunk.hosts.clear();
407 InsertAddChunkHostFullHashes(&chunk, 5, "www.forwhitelist.com/", 409 InsertAddChunkHostFullHashes(&chunk, 5, "www.forwhitelist.com/",
408 "www.forwhitelist.com/a.html"); 410 "www.forwhitelist.com/a.html");
409 chunks.clear(); 411 chunks.clear();
410 chunks.push_back(chunk); 412 chunks.push_back(chunk);
411 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, chunks); 413 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, chunks);
412 414
415 chunk.hosts.clear();
416 InsertAddChunkHostFullHashes(&chunk, 6, "www.download.com/",
417 "www.download.com/");
418
419 chunks.clear();
420 chunks.push_back(chunk);
421 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList, chunks);
422
413 database_->UpdateFinished(true); 423 database_->UpdateFinished(true);
414 424
415 GetListsInfo(&lists); 425 GetListsInfo(&lists);
416 EXPECT_EQ(5U, lists.size()); 426 EXPECT_EQ(6U, lists.size());
417 EXPECT_TRUE(lists[0].name == safe_browsing_util::kMalwareList); 427 EXPECT_TRUE(lists[0].name == safe_browsing_util::kMalwareList);
418 EXPECT_EQ(lists[0].adds, "1"); 428 EXPECT_EQ(lists[0].adds, "1");
419 EXPECT_TRUE(lists[0].subs.empty()); 429 EXPECT_TRUE(lists[0].subs.empty());
420 EXPECT_TRUE(lists[1].name == safe_browsing_util::kPhishingList); 430 EXPECT_TRUE(lists[1].name == safe_browsing_util::kPhishingList);
421 EXPECT_EQ(lists[1].adds, "2"); 431 EXPECT_EQ(lists[1].adds, "2");
422 EXPECT_TRUE(lists[1].subs.empty()); 432 EXPECT_TRUE(lists[1].subs.empty());
423 EXPECT_TRUE(lists[2].name == safe_browsing_util::kBinUrlList); 433 EXPECT_TRUE(lists[2].name == safe_browsing_util::kBinUrlList);
424 EXPECT_EQ(lists[2].adds, "3"); 434 EXPECT_EQ(lists[2].adds, "3");
425 EXPECT_TRUE(lists[2].subs.empty()); 435 EXPECT_TRUE(lists[2].subs.empty());
426 EXPECT_TRUE(lists[3].name == safe_browsing_util::kBinHashList); 436 EXPECT_TRUE(lists[3].name == safe_browsing_util::kBinHashList);
427 EXPECT_EQ(lists[3].adds, "4"); 437 EXPECT_EQ(lists[3].adds, "4");
428 EXPECT_TRUE(lists[3].subs.empty()); 438 EXPECT_TRUE(lists[3].subs.empty());
429 EXPECT_TRUE(lists[4].name == safe_browsing_util::kCsdWhiteList); 439 EXPECT_TRUE(lists[4].name == safe_browsing_util::kCsdWhiteList);
430 EXPECT_EQ(lists[4].adds, "5"); 440 EXPECT_EQ(lists[4].adds, "5");
431 EXPECT_TRUE(lists[4].subs.empty()); 441 EXPECT_TRUE(lists[4].subs.empty());
442 EXPECT_TRUE(lists[5].name == safe_browsing_util::kDownloadWhiteList);
443 EXPECT_EQ(lists[5].adds, "6");
444 EXPECT_TRUE(lists[5].subs.empty());
432 database_.reset(); 445 database_.reset();
433 } 446 }
434 447
435 // Checks database reading and writing for browse. 448 // Checks database reading and writing for browse.
436 TEST_F(SafeBrowsingDatabaseTest, BrowseDatabase) { 449 TEST_F(SafeBrowsingDatabaseTest, BrowseDatabase) {
437 SBChunkList chunks; 450 SBChunkList chunks;
438 SBChunk chunk; 451 SBChunk chunk;
439 452
440 // Add a simple chunk with one hostkey. 453 // Add a simple chunk with one hostkey.
441 InsertAddChunkHost2PrefixUrls(&chunk, 1, "www.evil.com/", 454 InsertAddChunkHost2PrefixUrls(&chunk, 1, "www.evil.com/",
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 // corruption is detected in the midst of the update. 1058 // corruption is detected in the midst of the update.
1046 // TODO(shess): Disabled until ScopedLogMessageIgnorer resolved. 1059 // TODO(shess): Disabled until ScopedLogMessageIgnorer resolved.
1047 // http://crbug.com/56448 1060 // http://crbug.com/56448
1048 TEST_F(SafeBrowsingDatabaseTest, DISABLED_FileCorruptionHandling) { 1061 TEST_F(SafeBrowsingDatabaseTest, DISABLED_FileCorruptionHandling) {
1049 // Re-create the database in a captive message loop so that we can 1062 // Re-create the database in a captive message loop so that we can
1050 // influence task-posting. Database specifically needs to the 1063 // influence task-posting. Database specifically needs to the
1051 // file-backed. 1064 // file-backed.
1052 database_.reset(); 1065 database_.reset();
1053 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 1066 MessageLoop loop(MessageLoop::TYPE_DEFAULT);
1054 SafeBrowsingStoreFile* store = new SafeBrowsingStoreFile(); 1067 SafeBrowsingStoreFile* store = new SafeBrowsingStoreFile();
1055 database_.reset(new SafeBrowsingDatabaseNew(store, NULL, NULL)); 1068 database_.reset(new SafeBrowsingDatabaseNew(store, NULL, NULL, NULL));
1056 database_->Init(database_filename_); 1069 database_->Init(database_filename_);
1057 1070
1058 // This will cause an empty database to be created. 1071 // This will cause an empty database to be created.
1059 std::vector<SBListChunkRanges> lists; 1072 std::vector<SBListChunkRanges> lists;
1060 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1073 EXPECT_TRUE(database_->UpdateStarted(&lists));
1061 database_->UpdateFinished(true); 1074 database_->UpdateFinished(true);
1062 1075
1063 // Create a sub chunk to insert. 1076 // Create a sub chunk to insert.
1064 SBChunkList chunks; 1077 SBChunkList chunks;
1065 SBChunk chunk; 1078 SBChunk chunk;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 1130
1118 // Checks database reading and writing. 1131 // Checks database reading and writing.
1119 TEST_F(SafeBrowsingDatabaseTest, ContainsDownloadUrl) { 1132 TEST_F(SafeBrowsingDatabaseTest, ContainsDownloadUrl) {
1120 database_.reset(); 1133 database_.reset();
1121 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 1134 MessageLoop loop(MessageLoop::TYPE_DEFAULT);
1122 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile(); 1135 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile();
1123 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile(); 1136 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile();
1124 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile(); 1137 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile();
1125 database_.reset(new SafeBrowsingDatabaseNew(browse_store, 1138 database_.reset(new SafeBrowsingDatabaseNew(browse_store,
1126 download_store, 1139 download_store,
1127 csd_whitelist_store)); 1140 csd_whitelist_store,
1141 NULL));
1128 database_->Init(database_filename_); 1142 database_->Init(database_filename_);
1129 1143
1130 const char kEvil1Host[] = "www.evil1.com/"; 1144 const char kEvil1Host[] = "www.evil1.com/";
1131 const char kEvil1Url1[] = "www.evil1.com/download1/"; 1145 const char kEvil1Url1[] = "www.evil1.com/download1/";
1132 const char kEvil1Url2[] = "www.evil1.com/download2.html"; 1146 const char kEvil1Url2[] = "www.evil1.com/download2.html";
1133 1147
1134 SBChunkList chunks; 1148 SBChunkList chunks;
1135 SBChunk chunk; 1149 SBChunk chunk;
1136 // Add a simple chunk with one hostkey for download url list. 1150 // Add a simple chunk with one hostkey for download url list.
1137 InsertAddChunkHost2PrefixUrls(&chunk, 1, kEvil1Host, 1151 InsertAddChunkHost2PrefixUrls(&chunk, 1, kEvil1Host,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 urls.clear(); 1223 urls.clear();
1210 urls.push_back(GURL(std::string("http://") + kEvil1Url1)); 1224 urls.push_back(GURL(std::string("http://") + kEvil1Url1));
1211 urls.push_back(GURL(std::string("https://") + kEvil1Url2)); 1225 urls.push_back(GURL(std::string("https://") + kEvil1Url2));
1212 EXPECT_TRUE(database_->ContainsDownloadUrl(urls, &prefix_hits)); 1226 EXPECT_TRUE(database_->ContainsDownloadUrl(urls, &prefix_hits));
1213 ASSERT_EQ(prefix_hits.size(), 2U); 1227 ASSERT_EQ(prefix_hits.size(), 2U);
1214 EXPECT_EQ(prefix_hits[0], Sha256Prefix(kEvil1Url1)); 1228 EXPECT_EQ(prefix_hits[0], Sha256Prefix(kEvil1Url1));
1215 EXPECT_EQ(prefix_hits[1], Sha256Prefix(kEvil1Url2)); 1229 EXPECT_EQ(prefix_hits[1], Sha256Prefix(kEvil1Url2));
1216 database_.reset(); 1230 database_.reset();
1217 } 1231 }
1218 1232
1219 // Checks that the csd-whitelist is handled properly. 1233 // Checks that the whitelists are handled properly.
1220 TEST_F(SafeBrowsingDatabaseTest, CsdWhitelist) { 1234 TEST_F(SafeBrowsingDatabaseTest, Whitelists) {
1221 database_.reset(); 1235 database_.reset();
1222 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 1236 MessageLoop loop(MessageLoop::TYPE_DEFAULT);
1223 // We expect all calls to ContainsCsdWhitelistedUrl to be made from the IO 1237 // We expect all calls to ContainsCsdWhitelistedUrl in particular to be made
1224 // thread. 1238 // from the IO thread. In general the whitelist lookups are thread-safe.
1225 BrowserThread io_thread(BrowserThread::IO, &loop); 1239 BrowserThread io_thread(BrowserThread::IO, &loop);
1226 1240
1227 // If the whitelist is disabled everything should match the whitelist. 1241 // If the whitelist is disabled everything should match the whitelist.
1228 database_.reset(new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile(), 1242 database_.reset(new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile(),
1229 NULL, NULL)); 1243 NULL, NULL, NULL));
1230 database_->Init(database_filename_); 1244 database_->Init(database_filename_);
1231 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1245 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1232 GURL(std::string("http://www.phishig.com/")))); 1246 GURL(std::string("http://www.phishing.com/"))));
1247 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1248 GURL(std::string("http://www.phishing.com/"))));
1249 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf"));
1233 1250
1234 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile(); 1251 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile();
1235 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile(); 1252 SafeBrowsingStoreFile* csd_whitelist_store = new SafeBrowsingStoreFile();
1253 SafeBrowsingStoreFile* download_whitelist_store = new SafeBrowsingStoreFile();
1236 database_.reset(new SafeBrowsingDatabaseNew(browse_store, NULL, 1254 database_.reset(new SafeBrowsingDatabaseNew(browse_store, NULL,
1237 csd_whitelist_store)); 1255 csd_whitelist_store,
1256 download_whitelist_store));
1238 database_->Init(database_filename_); 1257 database_->Init(database_filename_);
1239 1258
1240 const char kGood1Host[] = "www.good1.com/"; 1259 const char kGood1Host[] = "www.good1.com/";
1241 const char kGood1Url1[] = "www.good1.com/a/b.html"; 1260 const char kGood1Url1[] = "www.good1.com/a/b.html";
1242 const char kGood1Url2[] = "www.good1.com/b/"; 1261 const char kGood1Url2[] = "www.good1.com/b/";
1243 1262
1244 const char kGood2Host[] = "www.good2.com/"; 1263 const char kGood2Host[] = "www.good2.com/";
1245 const char kGood2Url1[] = "www.good2.com/c"; // Should match '/c/bla'. 1264 const char kGood2Url1[] = "www.good2.com/c"; // Should match '/c/bla'.
1246 1265
1247 SBChunkList chunks; 1266 // good3.com/a/b/c/d/e/f/g/ should match because it's a whitelist.
1267 const char kGood3Host[] = "good3.com/";
1268 const char kGood3Url1[] = "good3.com/";
1269
1270 const char kGoodString[] = "good_string";
1271
1272 SBChunkList download_chunks, csd_chunks;
1248 SBChunk chunk; 1273 SBChunk chunk;
1249 // Add two simple chunks to the csd whitelist. 1274 // Add two simple chunks to the csd whitelist.
1250 InsertAddChunkHost2FullHashes(&chunk, 1, kGood1Host, 1275 InsertAddChunkHost2FullHashes(&chunk, 1, kGood1Host,
1251 kGood1Url1, kGood1Url2); 1276 kGood1Url1, kGood1Url2);
1252 chunks.push_back(chunk); 1277 csd_chunks.push_back(chunk);
1253 1278
1254 chunk.hosts.clear(); 1279 chunk.hosts.clear();
1255 InsertAddChunkHostFullHashes(&chunk, 2, kGood2Host, kGood2Url1); 1280 InsertAddChunkHostFullHashes(&chunk, 2, kGood2Host, kGood2Url1);
1256 chunks.push_back(chunk); 1281 csd_chunks.push_back(chunk);
1282
1283 chunk.hosts.clear();
1284 InsertAddChunkHostFullHashes(&chunk, 2, kGood2Host, kGood2Url1);
1285 download_chunks.push_back(chunk);
1286
1287 chunk.hosts.clear();
1288 InsertAddChunkHostFullHashes(&chunk, 3, kGoodString, kGoodString);
1289 download_chunks.push_back(chunk);
1290
1291 chunk.hosts.clear();
1292 InsertAddChunkHostFullHashes(&chunk, 4, kGood3Host, kGood3Url1);
1293 download_chunks.push_back(chunk);
1257 1294
1258 std::vector<SBListChunkRanges> lists; 1295 std::vector<SBListChunkRanges> lists;
1259 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1296 EXPECT_TRUE(database_->UpdateStarted(&lists));
1260 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, chunks); 1297 database_->InsertChunks(safe_browsing_util::kCsdWhiteList,
1298 csd_chunks);
1299 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList,
1300 download_chunks);
1261 database_->UpdateFinished(true); 1301 database_->UpdateFinished(true);
1262 1302
1263 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( 1303 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl(
1264 GURL(std::string("http://") + kGood1Host))); 1304 GURL(std::string("http://") + kGood1Host)));
1265 1305
1266 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1306 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1267 GURL(std::string("http://") + kGood1Url1))); 1307 GURL(std::string("http://") + kGood1Url1)));
1268 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1308 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1269 GURL(std::string("http://") + kGood1Url1 + "?a=b"))); 1309 GURL(std::string("http://") + kGood1Url1 + "?a=b")));
1270 1310
1271 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1311 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1272 GURL(std::string("http://") + kGood1Url2))); 1312 GURL(std::string("http://") + kGood1Url2)));
1273 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1313 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1274 GURL(std::string("http://") + kGood1Url2 + "/c.html"))); 1314 GURL(std::string("http://") + kGood1Url2 + "/c.html")));
1275 1315
1276 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1316 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1277 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); 1317 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1278 1318
1279 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1319 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1280 GURL(std::string("http://") + kGood2Url1 + "/c"))); 1320 GURL(std::string("http://") + kGood2Url1 + "/c")));
1281 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1321 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1282 GURL(std::string("http://") + kGood2Url1 + "/c?bla"))); 1322 GURL(std::string("http://") + kGood2Url1 + "/c?bla")));
1283 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1323 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1284 GURL(std::string("http://") + kGood2Url1 + "/c/bla"))); 1324 GURL(std::string("http://") + kGood2Url1 + "/c/bla")));
1285 1325
1286 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( 1326 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl(
1287 GURL(std::string("http://www.google.com/")))); 1327 GURL(std::string("http://www.google.com/"))));
1288 1328
1329 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1330 GURL(std::string("http://") + kGood2Url1 + "/c")));
1331 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1332 GURL(std::string("http://") + kGood2Url1 + "/c?bla")));
1333 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1334 GURL(std::string("http://") + kGood2Url1 + "/c/bla")));
1335
1336 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1337 GURL(std::string("http://good3.com/a/b/c/d/e/f/g/"))));
1338 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1339 GURL(std::string("http://a.b.good3.com/"))));
1340
1341 EXPECT_FALSE(database_->ContainsDownloadWhitelistedString("asdf"));
1342 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString));
1343
1344 EXPECT_FALSE(database_->ContainsDownloadWhitelistedUrl(
1345 GURL(std::string("http://www.google.com/"))));
1346
1289 // Test that the kill-switch works as intended. 1347 // Test that the kill-switch works as intended.
1290 chunks.clear(); 1348 csd_chunks.clear();
1349 download_chunks.clear();
1291 lists.clear(); 1350 lists.clear();
1292 SBChunk chunk2; 1351 chunk.hosts.clear();
1293 InsertAddChunkHostFullHashes(&chunk2, 3, "sb-ssl.google.com/", 1352 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/",
1294 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1353 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1295 chunks.push_back(chunk2); 1354 csd_chunks.push_back(chunk);
1355
1356 chunk.hosts.clear();
1357 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/",
1358 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1359 download_chunks.push_back(chunk);
1296 1360
1297 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1361 EXPECT_TRUE(database_->UpdateStarted(&lists));
1298 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, chunks); 1362 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks);
1363 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList,
1364 download_chunks);
1299 database_->UpdateFinished(true); 1365 database_->UpdateFinished(true);
1300 1366
1301 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1367 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1302 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); 1368 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1303 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1369 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1304 GURL(std::string("http://www.google.com/")))); 1370 GURL(std::string("http://www.google.com/"))));
1305 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1371 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1306 GURL(std::string("http://www.phishing_url.com/")))); 1372 GURL(std::string("http://www.phishing_url.com/"))));
1307 1373
1374 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1375 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1376 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1377 GURL(std::string("http://www.google.com/"))));
1378 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1379 GURL(std::string("http://www.phishing_url.com/"))));
1380
1381 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf"));
1382 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString));
1383
1308 // Remove the kill-switch and verify that we can recover. 1384 // Remove the kill-switch and verify that we can recover.
1309 chunks.clear(); 1385 csd_chunks.clear();
1386 download_chunks.clear();
1310 lists.clear(); 1387 lists.clear();
1311 SBChunk sub_chunk; 1388 SBChunk sub_chunk;
1312 InsertSubChunkHostFullHash(&sub_chunk, 1, 3, 1389 InsertSubChunkHostFullHash(&sub_chunk, 1, 5,
1313 "sb-ssl.google.com/", 1390 "sb-ssl.google.com/",
1314 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1391 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1315 chunks.push_back(sub_chunk); 1392 csd_chunks.push_back(sub_chunk);
1393
1394 sub_chunk.hosts.clear();
1395 InsertSubChunkHostFullHash(&sub_chunk, 1, 5,
1396 "sb-ssl.google.com/",
1397 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1398 download_chunks.push_back(sub_chunk);
1316 1399
1317 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1400 EXPECT_TRUE(database_->UpdateStarted(&lists));
1318 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, chunks); 1401 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks);
1402 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList,
1403 download_chunks);
1319 database_->UpdateFinished(true); 1404 database_->UpdateFinished(true);
1320 1405
1321 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1406 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1322 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); 1407 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1323 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1408 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1324 GURL(std::string("https://") + kGood2Url1 + "/c/bla"))); 1409 GURL(std::string("https://") + kGood2Url1 + "/c/bla")));
1325 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( 1410 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl(
1326 GURL(std::string("http://www.google.com/")))); 1411 GURL(std::string("http://www.google.com/"))));
1327 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( 1412 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl(
1328 GURL(std::string("http://www.phishing_url.com/")))); 1413 GURL(std::string("http://www.phishing_url.com/"))));
1329 1414
1415 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1416 GURL(std::string("https://") + kGood2Url1 + "/c/bla")));
1417 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1418 GURL(std::string("https://good3.com/"))));
1419 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString));
1420 EXPECT_FALSE(database_->ContainsDownloadWhitelistedUrl(
1421 GURL(std::string("http://www.google.com/"))));
1422 EXPECT_FALSE(database_->ContainsDownloadWhitelistedUrl(
1423 GURL(std::string("http://www.phishing_url.com/"))));
1424 EXPECT_FALSE(database_->ContainsDownloadWhitelistedString("asdf"));
1425
1330 database_.reset(); 1426 database_.reset();
1331 } 1427 }
1332 1428
1333 // Test to make sure we could insert chunk list that 1429 // Test to make sure we could insert chunk list that
1334 // contains entries for the same host. 1430 // contains entries for the same host.
1335 TEST_F(SafeBrowsingDatabaseTest, SameHostEntriesOkay) { 1431 TEST_F(SafeBrowsingDatabaseTest, SameHostEntriesOkay) {
1336 SBChunk chunk; 1432 SBChunk chunk;
1337 1433
1338 // Add a malware add chunk with two entries of the same host. 1434 // Add a malware add chunk with two entries of the same host.
1339 InsertAddChunkHostPrefixUrl(&chunk, 1, "www.evil.com/", 1435 InsertAddChunkHostPrefixUrl(&chunk, 1, "www.evil.com/",
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 TEST_F(SafeBrowsingDatabaseTest, BinHashInsertLookup) { 1528 TEST_F(SafeBrowsingDatabaseTest, BinHashInsertLookup) {
1433 const SBPrefix kPrefix1 = 0x31313131; 1529 const SBPrefix kPrefix1 = 0x31313131;
1434 const SBPrefix kPrefix2 = 0x32323232; 1530 const SBPrefix kPrefix2 = 0x32323232;
1435 const SBPrefix kPrefix3 = 0x33333333; 1531 const SBPrefix kPrefix3 = 0x33333333;
1436 database_.reset(); 1532 database_.reset();
1437 MessageLoop loop(MessageLoop::TYPE_DEFAULT); 1533 MessageLoop loop(MessageLoop::TYPE_DEFAULT);
1438 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile(); 1534 SafeBrowsingStoreFile* browse_store = new SafeBrowsingStoreFile();
1439 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile(); 1535 SafeBrowsingStoreFile* download_store = new SafeBrowsingStoreFile();
1440 database_.reset(new SafeBrowsingDatabaseNew(browse_store, 1536 database_.reset(new SafeBrowsingDatabaseNew(browse_store,
1441 download_store, 1537 download_store,
1442 NULL)); 1538 NULL, NULL));
1443 database_->Init(database_filename_); 1539 database_->Init(database_filename_);
1444 1540
1445 SBChunkList chunks; 1541 SBChunkList chunks;
1446 SBChunk chunk; 1542 SBChunk chunk;
1447 // Insert one host. 1543 // Insert one host.
1448 InsertAddChunkHostPrefixValue(&chunk, 1, 0, kPrefix1); 1544 InsertAddChunkHostPrefixValue(&chunk, 1, 0, kPrefix1);
1449 // Insert a second host, which has the same host prefix as the first one. 1545 // Insert a second host, which has the same host prefix as the first one.
1450 InsertAddChunkHostPrefixValue(&chunk, 1, 0, kPrefix2); 1546 InsertAddChunkHostPrefixValue(&chunk, 1, 0, kPrefix2);
1451 chunks.push_back(chunk); 1547 chunks.push_back(chunk);
1452 1548
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 1618
1523 // Simply calling |UpdateStarted()| then |UpdateFinished()| does not 1619 // Simply calling |UpdateStarted()| then |UpdateFinished()| does not
1524 // update the database file. 1620 // update the database file.
1525 ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified)); 1621 ASSERT_TRUE(file_util::SetLastModifiedTime(filename, old_last_modified));
1526 ASSERT_TRUE(file_util::GetFileInfo(filename, &before_info)); 1622 ASSERT_TRUE(file_util::GetFileInfo(filename, &before_info));
1527 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1623 EXPECT_TRUE(database_->UpdateStarted(&lists));
1528 database_->UpdateFinished(true); 1624 database_->UpdateFinished(true);
1529 ASSERT_TRUE(file_util::GetFileInfo(filename, &after_info)); 1625 ASSERT_TRUE(file_util::GetFileInfo(filename, &after_info));
1530 EXPECT_EQ(before_info.last_modified, after_info.last_modified); 1626 EXPECT_EQ(before_info.last_modified, after_info.last_modified);
1531 } 1627 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_database.cc ('k') | chrome/browser/safe_browsing/safe_browsing_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698