| OLD | NEW |
| 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 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 GURL(std::string("http://www.google.com/")))); | 1364 GURL(std::string("http://www.google.com/")))); |
| 1365 | 1365 |
| 1366 // Test that the kill-switch works as intended. | 1366 // Test that the kill-switch works as intended. |
| 1367 csd_chunks.clear(); | 1367 csd_chunks.clear(); |
| 1368 download_chunks.clear(); | 1368 download_chunks.clear(); |
| 1369 lists.clear(); | 1369 lists.clear(); |
| 1370 chunk.hosts.clear(); | 1370 chunk.hosts.clear(); |
| 1371 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/", | 1371 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/", |
| 1372 "sb-ssl.google.com/safebrowsing/csd/killswitch"); | 1372 "sb-ssl.google.com/safebrowsing/csd/killswitch"); |
| 1373 csd_chunks.push_back(chunk); | 1373 csd_chunks.push_back(chunk); |
| 1374 chunk.hosts.clear(); |
| 1375 InsertAddChunkHostFullHashes( |
| 1376 &chunk, 15, "sb-ssl.google.com/", |
| 1377 "sb-ssl.google.com/safebrowsing/csd/killswitch_malware"); |
| 1378 csd_chunks.push_back(chunk); |
| 1374 | 1379 |
| 1375 chunk.hosts.clear(); | 1380 chunk.hosts.clear(); |
| 1376 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/", | 1381 InsertAddChunkHostFullHashes(&chunk, 5, "sb-ssl.google.com/", |
| 1377 "sb-ssl.google.com/safebrowsing/csd/killswitch"); | 1382 "sb-ssl.google.com/safebrowsing/csd/killswitch"); |
| 1378 download_chunks.push_back(chunk); | 1383 download_chunks.push_back(chunk); |
| 1379 | 1384 |
| 1380 EXPECT_TRUE(database_->UpdateStarted(&lists)); | 1385 EXPECT_TRUE(database_->UpdateStarted(&lists)); |
| 1381 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks); | 1386 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks); |
| 1382 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList, | 1387 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList, |
| 1383 download_chunks); | 1388 download_chunks); |
| 1384 database_->UpdateFinished(true); | 1389 database_->UpdateFinished(true); |
| 1385 | 1390 |
| 1391 EXPECT_TRUE(database_->MalwareIPMatchKillSwitchOn()); |
| 1386 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( | 1392 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( |
| 1387 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); | 1393 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); |
| 1388 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( | 1394 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( |
| 1389 GURL(std::string("http://www.google.com/")))); | 1395 GURL(std::string("http://www.google.com/")))); |
| 1390 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( | 1396 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( |
| 1391 GURL(std::string("http://www.phishing_url.com/")))); | 1397 GURL(std::string("http://www.phishing_url.com/")))); |
| 1392 | 1398 |
| 1393 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( | 1399 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( |
| 1394 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); | 1400 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); |
| 1395 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( | 1401 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( |
| 1396 GURL(std::string("http://www.google.com/")))); | 1402 GURL(std::string("http://www.google.com/")))); |
| 1397 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( | 1403 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( |
| 1398 GURL(std::string("http://www.phishing_url.com/")))); | 1404 GURL(std::string("http://www.phishing_url.com/")))); |
| 1399 | 1405 |
| 1400 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf")); | 1406 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString("asdf")); |
| 1401 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString)); | 1407 EXPECT_TRUE(database_->ContainsDownloadWhitelistedString(kGoodString)); |
| 1402 | 1408 |
| 1403 // Remove the kill-switch and verify that we can recover. | 1409 // Remove the kill-switch and verify that we can recover. |
| 1404 csd_chunks.clear(); | 1410 csd_chunks.clear(); |
| 1405 download_chunks.clear(); | 1411 download_chunks.clear(); |
| 1406 lists.clear(); | 1412 lists.clear(); |
| 1407 SBChunk sub_chunk; | 1413 SBChunk sub_chunk; |
| 1408 InsertSubChunkHostFullHash(&sub_chunk, 1, 5, | 1414 InsertSubChunkHostFullHash(&sub_chunk, 1, 5, |
| 1409 "sb-ssl.google.com/", | 1415 "sb-ssl.google.com/", |
| 1410 "sb-ssl.google.com/safebrowsing/csd/killswitch"); | 1416 "sb-ssl.google.com/safebrowsing/csd/killswitch"); |
| 1411 csd_chunks.push_back(sub_chunk); | 1417 csd_chunks.push_back(sub_chunk); |
| 1412 | 1418 |
| 1413 sub_chunk.hosts.clear(); | 1419 sub_chunk.hosts.clear(); |
| 1420 InsertSubChunkHostFullHash( |
| 1421 &sub_chunk, 10, 15, "sb-ssl.google.com/", |
| 1422 "sb-ssl.google.com/safebrowsing/csd/killswitch_malware"); |
| 1423 csd_chunks.push_back(sub_chunk); |
| 1424 |
| 1425 sub_chunk.hosts.clear(); |
| 1414 InsertSubChunkHostFullHash(&sub_chunk, 1, 5, | 1426 InsertSubChunkHostFullHash(&sub_chunk, 1, 5, |
| 1415 "sb-ssl.google.com/", | 1427 "sb-ssl.google.com/", |
| 1416 "sb-ssl.google.com/safebrowsing/csd/killswitch"); | 1428 "sb-ssl.google.com/safebrowsing/csd/killswitch"); |
| 1417 download_chunks.push_back(sub_chunk); | 1429 download_chunks.push_back(sub_chunk); |
| 1418 | 1430 |
| 1419 EXPECT_TRUE(database_->UpdateStarted(&lists)); | 1431 EXPECT_TRUE(database_->UpdateStarted(&lists)); |
| 1420 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks); | 1432 database_->InsertChunks(safe_browsing_util::kCsdWhiteList, csd_chunks); |
| 1421 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList, | 1433 database_->InsertChunks(safe_browsing_util::kDownloadWhiteList, |
| 1422 download_chunks); | 1434 download_chunks); |
| 1423 database_->UpdateFinished(true); | 1435 database_->UpdateFinished(true); |
| 1424 | 1436 |
| 1437 EXPECT_FALSE(database_->MalwareIPMatchKillSwitchOn()); |
| 1425 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( | 1438 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( |
| 1426 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); | 1439 GURL(std::string("https://") + kGood1Url2 + "/c.html"))); |
| 1427 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( | 1440 EXPECT_TRUE(database_->ContainsCsdWhitelistedUrl( |
| 1428 GURL(std::string("https://") + kGood2Url1 + "/c/bla"))); | 1441 GURL(std::string("https://") + kGood2Url1 + "/c/bla"))); |
| 1429 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( | 1442 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( |
| 1430 GURL(std::string("http://www.google.com/")))); | 1443 GURL(std::string("http://www.google.com/")))); |
| 1431 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( | 1444 EXPECT_FALSE(database_->ContainsCsdWhitelistedUrl( |
| 1432 GURL(std::string("http://www.phishing_url.com/")))); | 1445 GURL(std::string("http://www.phishing_url.com/")))); |
| 1433 | 1446 |
| 1434 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( | 1447 EXPECT_TRUE(database_->ContainsDownloadWhitelistedUrl( |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 ASSERT_FALSE(file_util::PathExists(filter_file)); | 1671 ASSERT_FALSE(file_util::PathExists(filter_file)); |
| 1659 database_.reset(new SafeBrowsingDatabaseNew); | 1672 database_.reset(new SafeBrowsingDatabaseNew); |
| 1660 database_->Init(database_filename_); | 1673 database_->Init(database_filename_); |
| 1661 EXPECT_FALSE(database_->ContainsBrowseUrl( | 1674 EXPECT_FALSE(database_->ContainsBrowseUrl( |
| 1662 GURL("http://www.evil.com/malware.html"), | 1675 GURL("http://www.evil.com/malware.html"), |
| 1663 &matching_list, &prefix_hits, &full_hashes, now)); | 1676 &matching_list, &prefix_hits, &full_hashes, now)); |
| 1664 EXPECT_FALSE(database_->ContainsBrowseUrl( | 1677 EXPECT_FALSE(database_->ContainsBrowseUrl( |
| 1665 GURL("http://www.good.com/goodware.html"), | 1678 GURL("http://www.good.com/goodware.html"), |
| 1666 &matching_list, &prefix_hits, &full_hashes, now)); | 1679 &matching_list, &prefix_hits, &full_hashes, now)); |
| 1667 } | 1680 } |
| OLD | NEW |