| 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_F(DownloadProtectionServiceTest, |
| 1449 CheckClientDownloadReportDmgWithoutExtension) { |
| 1450 net::FakeURLFetcherFactory factory(NULL); |
| 1451 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 1452 net::URLRequestStatus::SUCCESS); |
| 1453 |
| 1454 base::FilePath test_data; |
| 1455 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); |
| 1456 test_data = test_data.AppendASCII("chrome") |
| 1457 .AppendASCII("safe_browsing_dmg") |
| 1458 .AppendASCII("mach_o_in_dmg.txt"); |
| 1459 |
| 1460 NiceMockDownloadItem item; |
| 1461 PrepareBasicDownloadItem(&item, {"http://www.evil.com/a.dmg"}, // url_chain |
| 1462 "http://www.google.com/", // referrer |
| 1463 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
| 1464 FILE_PATH_LITERAL("a.dmg")); // final_path |
| 1465 |
| 1466 tmp_path_ = test_data; |
| 1467 |
| 1468 RunLoop run_loop; |
| 1469 download_service_->CheckClientDownload( |
| 1470 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1471 base::Unretained(this), run_loop.QuitClosure())); |
| 1472 run_loop.Run(); |
| 1473 |
| 1474 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1475 EXPECT_TRUE(GetClientDownloadRequest()->archive_valid()); |
| 1476 ClearClientDownloadRequest(); |
| 1477 |
| 1478 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1479 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1480 } |
| 1481 |
| 1482 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadReportDmgWithoutKoly) { |
| 1483 net::FakeURLFetcherFactory factory(NULL); |
| 1484 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 1485 net::URLRequestStatus::SUCCESS); |
| 1486 |
| 1487 base::FilePath test_data; |
| 1488 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); |
| 1489 test_data = test_data.AppendASCII("chrome") |
| 1490 .AppendASCII("safe_browsing_dmg") |
| 1491 .AppendASCII("mach_o_in_dmg_no_koly_signature.txt"); |
| 1492 |
| 1493 NiceMockDownloadItem item; |
| 1494 PrepareBasicDownloadItem(&item, {"http://www.evil.com/a.dmg"}, // url_chain |
| 1495 "http://www.google.com/", // referrer |
| 1496 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
| 1497 FILE_PATH_LITERAL("a.dmg")); // final_path |
| 1498 |
| 1499 tmp_path_ = test_data; |
| 1500 |
| 1501 RunLoop run_loop; |
| 1502 download_service_->CheckClientDownload( |
| 1503 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1504 base::Unretained(this), run_loop.QuitClosure())); |
| 1505 run_loop.Run(); |
| 1506 |
| 1507 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1508 EXPECT_FALSE(GetClientDownloadRequest()->archive_valid()); |
| 1509 ClearClientDownloadRequest(); |
| 1510 |
| 1511 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1512 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1513 } |
| 1514 |
| 1446 #endif | 1515 #endif |
| 1447 | 1516 |
| 1448 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { | 1517 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { |
| 1449 net::TestURLFetcherFactory factory; | 1518 net::TestURLFetcherFactory factory; |
| 1450 | 1519 |
| 1451 NiceMockDownloadItem item; | 1520 NiceMockDownloadItem item; |
| 1452 PrepareBasicDownloadItem( | 1521 PrepareBasicDownloadItem( |
| 1453 &item, | 1522 &item, |
| 1454 {"http://www.google.com/", | 1523 {"http://www.google.com/", |
| 1455 "http://www.google.com/bla.exe"}, // url_chain | 1524 "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, | 2414 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2346 base::Unretained(this), run_loop.QuitClosure())); | 2415 base::Unretained(this), run_loop.QuitClosure())); |
| 2347 run_loop.Run(); | 2416 run_loop.Run(); |
| 2348 | 2417 |
| 2349 EXPECT_FALSE(HasClientDownloadRequest()); | 2418 EXPECT_FALSE(HasClientDownloadRequest()); |
| 2350 // Overriden by flag: | 2419 // Overriden by flag: |
| 2351 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2420 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 2352 } | 2421 } |
| 2353 | 2422 |
| 2354 } // namespace safe_browsing | 2423 } // namespace safe_browsing |
| OLD | NEW |