| 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 #include "chrome/browser/safe_browsing/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/sha1.h" | 26 #include "base/sha1.h" |
| 27 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
| 28 #include "base/strings/string_number_conversions.h" | 28 #include "base/strings/string_number_conversions.h" |
| 29 #include "base/threading/sequenced_worker_pool.h" | 29 #include "base/threading/sequenced_worker_pool.h" |
| 30 #include "base/threading/thread_task_runner_handle.h" | 30 #include "base/threading/thread_task_runner_handle.h" |
| 31 #include "chrome/browser/history/history_service_factory.h" | 31 #include "chrome/browser/history/history_service_factory.h" |
| 32 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 32 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
| 33 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" | 33 #include "chrome/browser/safe_browsing/incident_reporting/incident_reporting_ser
vice.h" |
| 34 #include "chrome/browser/safe_browsing/local_database_manager.h" | 34 #include "chrome/browser/safe_browsing/local_database_manager.h" |
| 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 35 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 36 #include "chrome/common/chrome_paths.h" |
| 36 #include "chrome/common/safe_browsing/binary_feature_extractor.h" | 37 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
| 37 #include "chrome/common/safe_browsing/file_type_policies_test_util.h" | 38 #include "chrome/common/safe_browsing/file_type_policies_test_util.h" |
| 38 #include "chrome/test/base/testing_profile.h" | 39 #include "chrome/test/base/testing_profile.h" |
| 39 #include "components/history/core/browser/history_service.h" | 40 #include "components/history/core/browser/history_service.h" |
| 40 #include "components/prefs/pref_service.h" | 41 #include "components/prefs/pref_service.h" |
| 41 #include "components/safe_browsing/common/safe_browsing_prefs.h" | 42 #include "components/safe_browsing/common/safe_browsing_prefs.h" |
| 42 #include "components/safe_browsing/common/safebrowsing_switches.h" | 43 #include "components/safe_browsing/common/safebrowsing_switches.h" |
| 43 #include "components/safe_browsing/csd.pb.h" | 44 #include "components/safe_browsing/csd.pb.h" |
| 44 #include "components/safe_browsing_db/database_manager.h" | 45 #include "components/safe_browsing_db/database_manager.h" |
| 45 #include "components/safe_browsing_db/test_database_manager.h" | 46 #include "components/safe_browsing_db/test_database_manager.h" |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 TEST_F(DownloadProtectionServiceTest, | 1437 TEST_F(DownloadProtectionServiceTest, |
| 1437 CheckClientDownloadReportCorruptZip) { | 1438 CheckClientDownloadReportCorruptZip) { |
| 1438 CheckClientDownloadReportCorruptArchive(ZIP); | 1439 CheckClientDownloadReportCorruptArchive(ZIP); |
| 1439 } | 1440 } |
| 1440 | 1441 |
| 1441 #if defined(OS_MACOSX) | 1442 #if defined(OS_MACOSX) |
| 1442 TEST_F(DownloadProtectionServiceTest, | 1443 TEST_F(DownloadProtectionServiceTest, |
| 1443 CheckClientDownloadReportCorruptDmg) { | 1444 CheckClientDownloadReportCorruptDmg) { |
| 1444 CheckClientDownloadReportCorruptArchive(DMG); | 1445 CheckClientDownloadReportCorruptArchive(DMG); |
| 1445 } | 1446 } |
| 1447 |
| 1448 // Test that downloaded files with no disk image extension that have a 'koly' |
| 1449 // trailer are treated as disk images and processed accordingly. |
| 1450 TEST_F(DownloadProtectionServiceTest, |
| 1451 CheckClientDownloadReportDmgWithoutExtension) { |
| 1452 net::FakeURLFetcherFactory factory(NULL); |
| 1453 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 1454 net::URLRequestStatus::SUCCESS); |
| 1455 |
| 1456 base::FilePath test_data; |
| 1457 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); |
| 1458 test_data = test_data.AppendASCII("chrome") |
| 1459 .AppendASCII("safe_browsing_dmg") |
| 1460 .AppendASCII("mach_o_in_dmg.txt"); |
| 1461 |
| 1462 NiceMockDownloadItem item; |
| 1463 PrepareBasicDownloadItemWithFullPaths( |
| 1464 &item, {"http://www.evil.com/a.dmg"}, // url_chain |
| 1465 "http://www.google.com/", // referrer |
| 1466 test_data, // tmp_path |
| 1467 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.dmg"))); // final_path |
| 1468 |
| 1469 RunLoop run_loop; |
| 1470 download_service_->CheckClientDownload( |
| 1471 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1472 base::Unretained(this), run_loop.QuitClosure())); |
| 1473 run_loop.Run(); |
| 1474 |
| 1475 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1476 EXPECT_TRUE(GetClientDownloadRequest()->archive_valid()); |
| 1477 ClearClientDownloadRequest(); |
| 1478 |
| 1479 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1480 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1481 } |
| 1482 |
| 1483 // Demonstrate that a .dmg file whose a) extension has been changed to .txt and |
| 1484 // b) 'koly' signature has been removed is not processed as a disk image. |
| 1485 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadReportDmgWithoutKoly) { |
| 1486 net::FakeURLFetcherFactory factory(NULL); |
| 1487 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 1488 net::URLRequestStatus::SUCCESS); |
| 1489 |
| 1490 base::FilePath test_data; |
| 1491 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); |
| 1492 test_data = test_data.AppendASCII("chrome") |
| 1493 .AppendASCII("safe_browsing_dmg") |
| 1494 .AppendASCII("mach_o_in_dmg_no_koly_signature.txt"); |
| 1495 |
| 1496 NiceMockDownloadItem item; |
| 1497 PrepareBasicDownloadItemWithFullPaths( |
| 1498 &item, {"http://www.evil.com/a.dmg"}, // url_chain |
| 1499 "http://www.google.com/", // referrer |
| 1500 test_data, // tmp_path |
| 1501 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.dmg"))); // final_path |
| 1502 |
| 1503 RunLoop run_loop; |
| 1504 download_service_->CheckClientDownload( |
| 1505 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1506 base::Unretained(this), run_loop.QuitClosure())); |
| 1507 run_loop.Run(); |
| 1508 |
| 1509 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1510 EXPECT_FALSE(GetClientDownloadRequest()->archive_valid()); |
| 1511 ClearClientDownloadRequest(); |
| 1512 |
| 1513 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1514 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1515 } |
| 1516 |
| 1446 #endif | 1517 #endif |
| 1447 | 1518 |
| 1448 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { | 1519 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { |
| 1449 net::TestURLFetcherFactory factory; | 1520 net::TestURLFetcherFactory factory; |
| 1450 | 1521 |
| 1451 NiceMockDownloadItem item; | 1522 NiceMockDownloadItem item; |
| 1452 PrepareBasicDownloadItem( | 1523 PrepareBasicDownloadItem( |
| 1453 &item, | 1524 &item, |
| 1454 {"http://www.google.com/", | 1525 {"http://www.google.com/", |
| 1455 "http://www.google.com/bla.exe"}, // url_chain | 1526 "http://www.google.com/bla.exe"}, // url_chain |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2345 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2416 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2346 base::Unretained(this), run_loop.QuitClosure())); | 2417 base::Unretained(this), run_loop.QuitClosure())); |
| 2347 run_loop.Run(); | 2418 run_loop.Run(); |
| 2348 | 2419 |
| 2349 EXPECT_FALSE(HasClientDownloadRequest()); | 2420 EXPECT_FALSE(HasClientDownloadRequest()); |
| 2350 // Overriden by flag: | 2421 // Overriden by flag: |
| 2351 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2422 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 2352 } | 2423 } |
| 2353 | 2424 |
| 2354 } // namespace safe_browsing | 2425 } // namespace safe_browsing |
| OLD | NEW |