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

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

Issue 14999008: Add a killswitch for CSD malware IP match and report feature. Use a new killswitch whitelist URL wh… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix the bug of 'and' -> && Created 7 years, 6 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) 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 "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 GURL(std::string("http://good3.com/a/b/c/d/e/f/g/")))); 1360 GURL(std::string("http://good3.com/a/b/c/d/e/f/g/"))));
1361 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1361 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1362 GURL(std::string("http://a.b.good3.com/")))); 1362 GURL(std::string("http://a.b.good3.com/"))));
1363 1363
1364 EXPECT_FALSE(database_->ContainsDownloadWhitelistedString("asdf")); 1364 EXPECT_FALSE(database_->ContainsDownloadWhitelistedString("asdf"));
1365 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString)); 1365 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString));
1366 1366
1367 EXPECT_FALSE(database_->ContainsDownloadWhitelistedUrl( 1367 EXPECT_FALSE(database_->ContainsDownloadWhitelistedUrl(
1368 GURL(std::string("http://www.google.com/")))); 1368 GURL(std::string("http://www.google.com/"))));
1369 1369
1370 // Test only add the malware IP killswitch
1371 csd_chunks.clear();
1372 chunk.hosts.clear();
1373 InsertAddChunkHostFullHashes(
1374 &chunk, 15, "sb-ssl.google.com/",
1375 "sb-ssl.google.com/safebrowsing/csd/killswitch_malware");
1376 csd_chunks.push_back(chunk);
1377 EXPECT_TRUE(database_->UpdateStarted(&lists));
1378 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks);
1379 database_->UpdateFinished(true);
1380
1381 EXPECT_TRUE(database_->MalwareIPMatchKillSwitchOn());
1382
1370 // Test that the kill-switch works as intended. 1383 // Test that the kill-switch works as intended.
1371 csd_chunks.clear(); 1384 csd_chunks.clear();
1372 download_chunks.clear(); 1385 download_chunks.clear();
1373 lists.clear(); 1386 lists.clear();
1374 chunk.hosts.clear(); 1387 chunk.hosts.clear();
1375 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/", 1388 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/",
1376 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1389 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1377 csd_chunks.push_back(chunk); 1390 csd_chunks.push_back(chunk);
1378
1379 chunk.hosts.clear(); 1391 chunk.hosts.clear();
1380 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/", 1392 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/",
1381 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1393 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1382 download_chunks.push_back(chunk); 1394 download_chunks.push_back(chunk);
1383 1395
1384 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1396 EXPECT_TRUE(database_->UpdateStarted(&lists));
1385 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks); 1397 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks);
1386 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList, 1398 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList,
1387 download_chunks); 1399 download_chunks);
1388 database_->UpdateFinished(true); 1400 database_->UpdateFinished(true);
1389 1401
1402 EXPECT_TRUE(database_->MalwareIPMatchKillSwitchOn());
1390 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1403 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1391 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); 1404 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1392 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1405 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1393 GURL(std::string("http://www.google.com/")))); 1406 GURL(std::string("http://www.google.com/"))));
1394 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1407 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1395 GURL(std::string("http://www.phishing_url.com/")))); 1408 GURL(std::string("http://www.phishing_url.com/"))));
1396 1409
1397 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1410 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1398 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); 1411 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1399 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1412 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1400 GURL(std::string("http://www.google.com/")))); 1413 GURL(std::string("http://www.google.com/"))));
1401 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1414 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1402 GURL(std::string("http://www.phishing_url.com/")))); 1415 GURL(std::string("http://www.phishing_url.com/"))));
1403 1416
1404 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf")); 1417 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf"));
1405 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString)); 1418 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString));
1406 1419
1407 // Remove the kill-switch and verify that we can recover. 1420 // Remove the kill-switch and verify that we can recover.
1408 csd_chunks.clear(); 1421 csd_chunks.clear();
1409 download_chunks.clear(); 1422 download_chunks.clear();
1410 lists.clear(); 1423 lists.clear();
1411 SBChunk sub_chunk; 1424 SBChunk sub_chunk;
1412 InsertSubChunkHostFullHash(&sub_chunk, 1, 5, 1425 InsertSubChunkHostFullHash(&sub_chunk, 1, 5,
1413 "sb-ssl.google.com/", 1426 "sb-ssl.google.com/",
1414 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1427 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1415 csd_chunks.push_back(sub_chunk); 1428 csd_chunks.push_back(sub_chunk);
1416 1429
1417 sub_chunk.hosts.clear(); 1430 sub_chunk.hosts.clear();
1431 InsertSubChunkHostFullHash(
1432 &sub_chunk, 10, 15, "sb-ssl.google.com/",
1433 "sb-ssl.google.com/safebrowsing/csd/killswitch_malware");
1434 csd_chunks.push_back(sub_chunk);
1435
1436 sub_chunk.hosts.clear();
1418 InsertSubChunkHostFullHash(&sub_chunk, 1, 5, 1437 InsertSubChunkHostFullHash(&sub_chunk, 1, 5,
1419 "sb-ssl.google.com/", 1438 "sb-ssl.google.com/",
1420 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1439 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1421 download_chunks.push_back(sub_chunk); 1440 download_chunks.push_back(sub_chunk);
1422 1441
1423 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1442 EXPECT_TRUE(database_->UpdateStarted(&lists));
1424 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks); 1443 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks);
1425 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList, 1444 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList,
1426 download_chunks); 1445 download_chunks);
1427 database_->UpdateFinished(true); 1446 database_->UpdateFinished(true);
1428 1447
1448 EXPECT_FALSE(database_->MalwareIPMatchKillSwitchOn());
1429 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1449 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1430 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); 1450 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1431 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1451 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1432 GURL(std::string("https://") + kGood2Url1 + "/c/bla"))); 1452 GURL(std::string("https://") + kGood2Url1 + "/c/bla")));
1433 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( 1453 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl(
1434 GURL(std::string("http://www.google.com/")))); 1454 GURL(std::string("http://www.google.com/"))));
1435 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( 1455 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl(
1436 GURL(std::string("http://www.phishing_url.com/")))); 1456 GURL(std::string("http://www.phishing_url.com/"))));
1437 1457
1438 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1458 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 ASSERT_FALSE(file_util::PathExists(filter_file)); 1682 ASSERT_FALSE(file_util::PathExists(filter_file));
1663 database_.reset(new SafeBrowsingDatabaseNew); 1683 database_.reset(new SafeBrowsingDatabaseNew);
1664 database_->Init(database_filename_); 1684 database_->Init(database_filename_);
1665 EXPECT_FALSE(database_->ContainsBrowseUrl( 1685 EXPECT_FALSE(database_->ContainsBrowseUrl(
1666 GURL("http://www.evil.com/malware.html"), 1686 GURL("http://www.evil.com/malware.html"),
1667 &matching_list, &prefix_hits, &full_hashes, now)); 1687 &matching_list, &prefix_hits, &full_hashes, now));
1668 EXPECT_FALSE(database_->ContainsBrowseUrl( 1688 EXPECT_FALSE(database_->ContainsBrowseUrl(
1669 GURL("http://www.good.com/goodware.html"), 1689 GURL("http://www.good.com/goodware.html"),
1670 &matching_list, &prefix_hits, &full_hashes, now)); 1690 &matching_list, &prefix_hits, &full_hashes, now));
1671 } 1691 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698