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