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

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: Address review comment, call ContainsWhitelistedHashes to check killswitch Created 7 years, 7 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 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 GURL(std::string("http://good3.com/a/b/c/d/e/f/g/")))); 1356 GURL(std::string("http://good3.com/a/b/c/d/e/f/g/"))));
1357 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1357 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1358 GURL(std::string("http://a.b.good3.com/")))); 1358 GURL(std::string("http://a.b.good3.com/"))));
1359 1359
1360 EXPECT_FALSE(database_->ContainsDownloadWhitelistedString("asdf")); 1360 EXPECT_FALSE(database_->ContainsDownloadWhitelistedString("asdf"));
1361 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString)); 1361 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString));
1362 1362
1363 EXPECT_FALSE(database_->ContainsDownloadWhitelistedUrl( 1363 EXPECT_FALSE(database_->ContainsDownloadWhitelistedUrl(
1364 GURL(std::string("http://www.google.com/")))); 1364 GURL(std::string("http://www.google.com/"))));
1365 1365
1366 // Test only add the malware IP killswitch
1367 csd_chunks.clear();
1368 chunk.hosts.clear();
1369 InsertAddChunkHostFullHashes(
1370 &chunk, 15, "sb-ssl.google.com/",
1371 "sb-ssl.google.com/safebrowsing/csd/killswitch_malware");
1372 csd_chunks.push_back(chunk);
1373 EXPECT_TRUE(database_->UpdateStarted(&lists));
1374 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks);
1375 database_->UpdateFinished(true);
1376
1377 EXPECT_TRUE(database_->MalwareIPMatchKillSwitchOn());
1378
1366 // Test that the kill-switch works as intended. 1379 // Test that the kill-switch works as intended.
1367 csd_chunks.clear(); 1380 csd_chunks.clear();
1368 download_chunks.clear(); 1381 download_chunks.clear();
1369 lists.clear(); 1382 lists.clear();
1370 chunk.hosts.clear(); 1383 chunk.hosts.clear();
1371 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/", 1384 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/",
1372 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1385 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1373 csd_chunks.push_back(chunk); 1386 csd_chunks.push_back(chunk);
1374
1375 chunk.hosts.clear(); 1387 chunk.hosts.clear();
1376 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/", 1388 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/",
1377 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1389 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1378 download_chunks.push_back(chunk); 1390 download_chunks.push_back(chunk);
1379 1391
1380 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1392 EXPECT_TRUE(database_->UpdateStarted(&lists));
1381 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks); 1393 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks);
1382 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList, 1394 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList,
1383 download_chunks); 1395 download_chunks);
1384 database_->UpdateFinished(true); 1396 database_->UpdateFinished(true);
1385 1397
1398 EXPECT_TRUE(database_->MalwareIPMatchKillSwitchOn());
1386 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1399 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1387 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); 1400 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1388 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1401 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1389 GURL(std::string("http://www.google.com/")))); 1402 GURL(std::string("http://www.google.com/"))));
1390 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1403 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1391 GURL(std::string("http://www.phishing_url.com/")))); 1404 GURL(std::string("http://www.phishing_url.com/"))));
1392 1405
1393 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1406 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1394 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); 1407 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1395 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1408 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1396 GURL(std::string("http://www.google.com/")))); 1409 GURL(std::string("http://www.google.com/"))));
1397 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1410 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
1398 GURL(std::string("http://www.phishing_url.com/")))); 1411 GURL(std::string("http://www.phishing_url.com/"))));
1399 1412
1400 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf")); 1413 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf"));
1401 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString)); 1414 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString));
1402 1415
1403 // Remove the kill-switch and verify that we can recover. 1416 // Remove the kill-switch and verify that we can recover.
1404 csd_chunks.clear(); 1417 csd_chunks.clear();
1405 download_chunks.clear(); 1418 download_chunks.clear();
1406 lists.clear(); 1419 lists.clear();
1407 SBChunk sub_chunk; 1420 SBChunk sub_chunk;
1408 InsertSubChunkHostFullHash(&sub_chunk, 1, 5, 1421 InsertSubChunkHostFullHash(&sub_chunk, 1, 5,
1409 "sb-ssl.google.com/", 1422 "sb-ssl.google.com/",
1410 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1423 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1411 csd_chunks.push_back(sub_chunk); 1424 csd_chunks.push_back(sub_chunk);
1412 1425
1413 sub_chunk.hosts.clear(); 1426 sub_chunk.hosts.clear();
1427 InsertSubChunkHostFullHash(
1428 &sub_chunk, 10, 15, "sb-ssl.google.com/",
1429 "sb-ssl.google.com/safebrowsing/csd/killswitch_malware");
1430 csd_chunks.push_back(sub_chunk);
1431
1432 sub_chunk.hosts.clear();
1414 InsertSubChunkHostFullHash(&sub_chunk, 1, 5, 1433 InsertSubChunkHostFullHash(&sub_chunk, 1, 5,
1415 "sb-ssl.google.com/", 1434 "sb-ssl.google.com/",
1416 "sb-ssl.google.com/safebrowsing/csd/killswitch"); 1435 "sb-ssl.google.com/safebrowsing/csd/killswitch");
1417 download_chunks.push_back(sub_chunk); 1436 download_chunks.push_back(sub_chunk);
1418 1437
1419 EXPECT_TRUE(database_->UpdateStarted(&lists)); 1438 EXPECT_TRUE(database_->UpdateStarted(&lists));
1420 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks); 1439 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks);
1421 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList, 1440 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList,
1422 download_chunks); 1441 download_chunks);
1423 database_->UpdateFinished(true); 1442 database_->UpdateFinished(true);
1424 1443
1444 EXPECT_FALSE(database_->MalwareIPMatchKillSwitchOn());
1425 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1445 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1426 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); 1446 GURL(std::string("https://") + kGood1Url2 + "/c.html")));
1427 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( 1447 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl(
1428 GURL(std::string("https://") + kGood2Url1 + "/c/bla"))); 1448 GURL(std::string("https://") + kGood2Url1 + "/c/bla")));
1429 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( 1449 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl(
1430 GURL(std::string("http://www.google.com/")))); 1450 GURL(std::string("http://www.google.com/"))));
1431 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( 1451 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl(
1432 GURL(std::string("http://www.phishing_url.com/")))); 1452 GURL(std::string("http://www.phishing_url.com/"))));
1433 1453
1434 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( 1454 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl(
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 ASSERT_FALSE(file_util::PathExists(filter_file)); 1678 ASSERT_FALSE(file_util::PathExists(filter_file));
1659 database_.reset(new SafeBrowsingDatabaseNew); 1679 database_.reset(new SafeBrowsingDatabaseNew);
1660 database_->Init(database_filename_); 1680 database_->Init(database_filename_);
1661 EXPECT_FALSE(database_->ContainsBrowseUrl( 1681 EXPECT_FALSE(database_->ContainsBrowseUrl(
1662 GURL("http://www.evil.com/malware.html"), 1682 GURL("http://www.evil.com/malware.html"),
1663 &matching_list, &prefix_hits, &full_hashes, now)); 1683 &matching_list, &prefix_hits, &full_hashes, now));
1664 EXPECT_FALSE(database_->ContainsBrowseUrl( 1684 EXPECT_FALSE(database_->ContainsBrowseUrl(
1665 GURL("http://www.good.com/goodware.html"), 1685 GURL("http://www.good.com/goodware.html"),
1666 &matching_list, &prefix_hits, &full_hashes, now)); 1686 &matching_list, &prefix_hits, &full_hashes, now));
1667 } 1687 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698