| 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 if (archived_binary.file_basename() == file_basename) | 349 if (archived_binary.file_basename() == file_basename) |
| 349 return &archived_binary; | 350 return &archived_binary; |
| 350 } | 351 } |
| 351 return nullptr; | 352 return nullptr; |
| 352 } | 353 } |
| 353 | 354 |
| 354 // Flushes any pending tasks in the message loops of all threads. | 355 // Flushes any pending tasks in the message loops of all threads. |
| 355 void FlushThreadMessageLoops() { | 356 void FlushThreadMessageLoops() { |
| 356 BrowserThread::GetBlockingPool()->FlushForTesting(); | 357 BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 357 FlushMessageLoop(BrowserThread::IO); | 358 FlushMessageLoop(BrowserThread::IO); |
| 359 FlushMessageLoop(BrowserThread::FILE); |
| 358 RunLoop().RunUntilIdle(); | 360 RunLoop().RunUntilIdle(); |
| 359 } | 361 } |
| 360 | 362 |
| 361 // Proxy for private method. | 363 // Proxy for private method. |
| 362 static void GetCertificateWhitelistStrings( | 364 static void GetCertificateWhitelistStrings( |
| 363 const net::X509Certificate& certificate, | 365 const net::X509Certificate& certificate, |
| 364 const net::X509Certificate& issuer, | 366 const net::X509Certificate& issuer, |
| 365 std::vector<std::string>* whitelist_strings) { | 367 std::vector<std::string>* whitelist_strings) { |
| 366 DownloadProtectionService::GetCertificateWhitelistStrings( | 368 DownloadProtectionService::GetCertificateWhitelistStrings( |
| 367 certificate, issuer, whitelist_strings); | 369 certificate, issuer, whitelist_strings); |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 TEST_F(DownloadProtectionServiceTest, | 1438 TEST_F(DownloadProtectionServiceTest, |
| 1437 CheckClientDownloadReportCorruptZip) { | 1439 CheckClientDownloadReportCorruptZip) { |
| 1438 CheckClientDownloadReportCorruptArchive(ZIP); | 1440 CheckClientDownloadReportCorruptArchive(ZIP); |
| 1439 } | 1441 } |
| 1440 | 1442 |
| 1441 #if defined(OS_MACOSX) | 1443 #if defined(OS_MACOSX) |
| 1442 TEST_F(DownloadProtectionServiceTest, | 1444 TEST_F(DownloadProtectionServiceTest, |
| 1443 CheckClientDownloadReportCorruptDmg) { | 1445 CheckClientDownloadReportCorruptDmg) { |
| 1444 CheckClientDownloadReportCorruptArchive(DMG); | 1446 CheckClientDownloadReportCorruptArchive(DMG); |
| 1445 } | 1447 } |
| 1446 #endif | 1448 |
| 1449 // Test that downloaded files with no disk image extension that have a 'koly' |
| 1450 // trailer are treated as disk images and processed accordingly. |
| 1451 TEST_F(DownloadProtectionServiceTest, |
| 1452 CheckClientDownloadReportDmgWithoutExtension) { |
| 1453 net::FakeURLFetcherFactory factory(NULL); |
| 1454 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 1455 net::URLRequestStatus::SUCCESS); |
| 1456 |
| 1457 base::FilePath test_data; |
| 1458 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); |
| 1459 test_data = test_data.AppendASCII("chrome") |
| 1460 .AppendASCII("safe_browsing_dmg") |
| 1461 .AppendASCII("mach_o_in_dmg.txt"); |
| 1462 |
| 1463 NiceMockDownloadItem item; |
| 1464 PrepareBasicDownloadItemWithFullPaths( |
| 1465 &item, {"http://www.evil.com/a.dmg"}, // url_chain |
| 1466 "http://www.google.com/", // referrer |
| 1467 test_data, // tmp_path |
| 1468 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.dmg"))); // final_path |
| 1469 |
| 1470 RunLoop run_loop; |
| 1471 download_service_->CheckClientDownload( |
| 1472 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1473 base::Unretained(this), run_loop.QuitClosure())); |
| 1474 run_loop.Run(); |
| 1475 |
| 1476 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1477 EXPECT_TRUE(GetClientDownloadRequest()->archive_valid()); |
| 1478 ClearClientDownloadRequest(); |
| 1479 |
| 1480 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1481 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1482 } |
| 1483 |
| 1484 // Demonstrate that a .dmg file whose a) extension has been changed to .txt and |
| 1485 // b) 'koly' signature has been removed is not processed as a disk image. |
| 1486 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadReportDmgWithoutKoly) { |
| 1487 net::FakeURLFetcherFactory factory(NULL); |
| 1488 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 1489 net::URLRequestStatus::SUCCESS); |
| 1490 |
| 1491 base::FilePath test_data; |
| 1492 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); |
| 1493 test_data = test_data.AppendASCII("chrome") |
| 1494 .AppendASCII("safe_browsing_dmg") |
| 1495 .AppendASCII("mach_o_in_dmg_no_koly_signature.txt"); |
| 1496 |
| 1497 NiceMockDownloadItem item; |
| 1498 PrepareBasicDownloadItemWithFullPaths( |
| 1499 &item, {"http://www.evil.com/a.dmg"}, // url_chain |
| 1500 "http://www.google.com/", // referrer |
| 1501 test_data, // tmp_path |
| 1502 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.dmg"))); // final_path |
| 1503 |
| 1504 RunLoop run_loop; |
| 1505 download_service_->CheckClientDownload( |
| 1506 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1507 base::Unretained(this), run_loop.QuitClosure())); |
| 1508 run_loop.Run(); |
| 1509 |
| 1510 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1511 EXPECT_FALSE(GetClientDownloadRequest()->archive_valid()); |
| 1512 ClearClientDownloadRequest(); |
| 1513 |
| 1514 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1515 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1516 } |
| 1517 |
| 1518 #endif // OS_MACOSX |
| 1447 | 1519 |
| 1448 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { | 1520 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { |
| 1449 net::TestURLFetcherFactory factory; | 1521 net::TestURLFetcherFactory factory; |
| 1450 | 1522 |
| 1523 #if defined(OS_MACOSX) |
| 1524 std::string download_file_path("ftp://www.google.com/bla.dmg"); |
| 1525 #else |
| 1526 std::string download_file_path("ftp://www.google.com/bla.exe"); |
| 1527 #endif // OS_MACOSX |
| 1528 |
| 1451 NiceMockDownloadItem item; | 1529 NiceMockDownloadItem item; |
| 1530 #if defined(OS_MACOSX) |
| 1452 PrepareBasicDownloadItem( | 1531 PrepareBasicDownloadItem( |
| 1453 &item, | 1532 &item, {"http://www.google.com/", download_file_path}, // url_chain |
| 1454 {"http://www.google.com/", | 1533 "http://www.google.com/", // referrer |
| 1455 "http://www.google.com/bla.exe"}, // url_chain | 1534 FILE_PATH_LITERAL("bla.tmp"), // tmp_path |
| 1456 "http://www.google.com/", // referrer | 1535 FILE_PATH_LITERAL("bla.dmg")); // final_path |
| 1457 FILE_PATH_LITERAL("bla.tmp"), // tmp_path | 1536 #else |
| 1458 FILE_PATH_LITERAL("bla.exe")); // final_path | 1537 PrepareBasicDownloadItem( |
| 1538 &item, {"http://www.google.com/", download_file_path}, // url_chain |
| 1539 "http://www.google.com/", // referrer |
| 1540 FILE_PATH_LITERAL("bla.tmp"), // tmp_path |
| 1541 FILE_PATH_LITERAL("bla.exe")); // final_path |
| 1542 #endif // OS_MACOSX |
| 1459 | 1543 |
| 1460 std::string remote_address = "10.11.12.13"; | 1544 std::string remote_address = "10.11.12.13"; |
| 1461 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); | 1545 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); |
| 1462 | 1546 |
| 1463 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1547 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1464 MatchDownloadWhitelistUrl(_)) | 1548 MatchDownloadWhitelistUrl(_)) |
| 1465 .WillRepeatedly(Return(false)); | 1549 .WillRepeatedly(Return(false)); |
| 1550 #if !defined(OS_MACOSX) |
| 1466 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) | 1551 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) |
| 1467 .WillOnce(SetCertificateContents("dummy cert data")); | 1552 .WillOnce(SetCertificateContents("dummy cert data")); |
| 1468 EXPECT_CALL( | 1553 EXPECT_CALL( |
| 1469 *binary_feature_extractor_.get(), | 1554 *binary_feature_extractor_.get(), |
| 1470 ExtractImageFeatures(tmp_path_, BinaryFeatureExtractor::kDefaultOptions, | 1555 ExtractImageFeatures(tmp_path_, BinaryFeatureExtractor::kDefaultOptions, |
| 1471 _, _)) | 1556 _, _)) |
| 1472 .WillOnce(SetDosHeaderContents("dummy dos header")); | 1557 .WillOnce(SetDosHeaderContents("dummy dos header")); |
| 1558 #endif // OS_MACOSX |
| 1473 RunLoop run_loop; | 1559 RunLoop run_loop; |
| 1474 download_service_->CheckClientDownload( | 1560 download_service_->CheckClientDownload( |
| 1475 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1561 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1476 base::Unretained(this), run_loop.QuitClosure())); | 1562 base::Unretained(this), run_loop.QuitClosure())); |
| 1477 | 1563 |
| 1478 // Run the message loop(s) until SendRequest is called. | 1564 // Run the message loop(s) until SendRequest is called. |
| 1479 FlushThreadMessageLoops(); | 1565 FlushThreadMessageLoops(); |
| 1480 EXPECT_TRUE(HasClientDownloadRequest()); | 1566 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1481 ClearClientDownloadRequest(); | 1567 ClearClientDownloadRequest(); |
| 1482 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1568 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1483 ASSERT_TRUE(fetcher); | 1569 ASSERT_TRUE(fetcher); |
| 1484 ClientDownloadRequest request; | 1570 ClientDownloadRequest request; |
| 1485 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); | 1571 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); |
| 1486 EXPECT_EQ("http://www.google.com/bla.exe", request.url()); | 1572 EXPECT_EQ(download_file_path, request.url()); |
| 1487 EXPECT_EQ(hash_, request.digests().sha256()); | 1573 EXPECT_EQ(hash_, request.digests().sha256()); |
| 1488 EXPECT_EQ(item.GetReceivedBytes(), request.length()); | 1574 EXPECT_EQ(item.GetReceivedBytes(), request.length()); |
| 1489 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); | 1575 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); |
| 1490 EXPECT_TRUE(RequestContainsServerIp(request, remote_address)); | 1576 EXPECT_TRUE(RequestContainsServerIp(request, remote_address)); |
| 1491 EXPECT_EQ(2, request.resources_size()); | 1577 EXPECT_EQ(2, request.resources_size()); |
| 1492 EXPECT_TRUE(RequestContainsResource(request, | 1578 EXPECT_TRUE(RequestContainsResource(request, |
| 1493 ClientDownloadRequest::DOWNLOAD_REDIRECT, | 1579 ClientDownloadRequest::DOWNLOAD_REDIRECT, |
| 1494 "http://www.google.com/", "")); | 1580 "http://www.google.com/", "")); |
| 1495 EXPECT_TRUE(RequestContainsResource(request, | 1581 EXPECT_TRUE(RequestContainsResource(request, |
| 1496 ClientDownloadRequest::DOWNLOAD_URL, | 1582 ClientDownloadRequest::DOWNLOAD_URL, |
| 1497 "http://www.google.com/bla.exe", | 1583 download_file_path, referrer_.spec())); |
| 1498 referrer_.spec())); | |
| 1499 EXPECT_TRUE(request.has_signature()); | 1584 EXPECT_TRUE(request.has_signature()); |
| 1585 #if !defined(OS_MACOSX) |
| 1500 ASSERT_EQ(1, request.signature().certificate_chain_size()); | 1586 ASSERT_EQ(1, request.signature().certificate_chain_size()); |
| 1501 const ClientDownloadRequest_CertificateChain& chain = | 1587 const ClientDownloadRequest_CertificateChain& chain = |
| 1502 request.signature().certificate_chain(0); | 1588 request.signature().certificate_chain(0); |
| 1503 ASSERT_EQ(1, chain.element_size()); | 1589 ASSERT_EQ(1, chain.element_size()); |
| 1504 EXPECT_EQ("dummy cert data", chain.element(0).certificate()); | 1590 EXPECT_EQ("dummy cert data", chain.element(0).certificate()); |
| 1505 EXPECT_TRUE(request.has_image_headers()); | 1591 EXPECT_TRUE(request.has_image_headers()); |
| 1506 const ClientDownloadRequest_ImageHeaders& headers = | 1592 const ClientDownloadRequest_ImageHeaders& headers = |
| 1507 request.image_headers(); | 1593 request.image_headers(); |
| 1508 EXPECT_TRUE(headers.has_pe_headers()); | 1594 EXPECT_TRUE(headers.has_pe_headers()); |
| 1509 EXPECT_TRUE(headers.pe_headers().has_dos_header()); | 1595 EXPECT_TRUE(headers.pe_headers().has_dos_header()); |
| 1510 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header()); | 1596 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header()); |
| 1597 #endif // OS_MACOSX |
| 1511 | 1598 |
| 1512 // Simulate the request finishing. | 1599 // Simulate the request finishing. |
| 1513 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1600 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1514 FROM_HERE, | 1601 FROM_HERE, |
| 1515 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete, | 1602 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete, |
| 1516 base::Unretained(this), fetcher)); | 1603 base::Unretained(this), fetcher)); |
| 1517 run_loop.Run(); | 1604 run_loop.Run(); |
| 1518 } | 1605 } |
| 1519 | 1606 |
| 1520 // Similar to above, but with an unsigned binary. | 1607 // Similar to above, but with an unsigned binary. |
| 1521 TEST_F(DownloadProtectionServiceTest, | 1608 TEST_F(DownloadProtectionServiceTest, |
| 1522 CheckClientDownloadValidateRequestNoSignature) { | 1609 CheckClientDownloadValidateRequestNoSignature) { |
| 1523 net::TestURLFetcherFactory factory; | 1610 net::TestURLFetcherFactory factory; |
| 1524 | 1611 |
| 1612 #if defined(OS_MACOSX) |
| 1613 std::string download_file_path("ftp://www.google.com/bla.dmg"); |
| 1614 #else |
| 1615 std::string download_file_path("ftp://www.google.com/bla.exe"); |
| 1616 #endif // OS_MACOSX |
| 1617 |
| 1525 NiceMockDownloadItem item; | 1618 NiceMockDownloadItem item; |
| 1619 #if defined(OS_MACOSX) |
| 1526 PrepareBasicDownloadItem( | 1620 PrepareBasicDownloadItem( |
| 1527 &item, | 1621 &item, {"http://www.google.com/", download_file_path}, // url_chain |
| 1528 {"http://www.google.com/", | 1622 "http://www.google.com/", // referrer |
| 1529 "ftp://www.google.com/bla.exe"}, // url_chain | 1623 FILE_PATH_LITERAL("bla.tmp"), // tmp_path |
| 1530 "http://www.google.com/", // referrer | 1624 FILE_PATH_LITERAL("bla.dmg")); // final_path |
| 1531 FILE_PATH_LITERAL("bla.tmp"), // tmp_path | 1625 #else |
| 1532 FILE_PATH_LITERAL("bla.exe")); // final_path | 1626 PrepareBasicDownloadItem( |
| 1627 &item, {"http://www.google.com/", download_file_path}, // url_chain |
| 1628 "http://www.google.com/", // referrer |
| 1629 FILE_PATH_LITERAL("bla.tmp"), // tmp_path |
| 1630 FILE_PATH_LITERAL("bla.exe")); // final_path |
| 1631 #endif // OS_MACOSX |
| 1632 |
| 1533 std::string remote_address = "10.11.12.13"; | 1633 std::string remote_address = "10.11.12.13"; |
| 1534 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); | 1634 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); |
| 1535 | |
| 1536 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1635 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1537 MatchDownloadWhitelistUrl(_)) | 1636 MatchDownloadWhitelistUrl(_)) |
| 1538 .WillRepeatedly(Return(false)); | 1637 .WillRepeatedly(Return(false)); |
| 1638 #if !defined(OS_MACOSX) |
| 1539 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); | 1639 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); |
| 1540 EXPECT_CALL(*binary_feature_extractor_.get(), | 1640 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 1541 ExtractImageFeatures(tmp_path_, | 1641 ExtractImageFeatures(tmp_path_, |
| 1542 BinaryFeatureExtractor::kDefaultOptions, | 1642 BinaryFeatureExtractor::kDefaultOptions, |
| 1543 _, _)); | 1643 _, _)); |
| 1644 #endif // OS_MACOSX |
| 1645 |
| 1544 RunLoop run_loop; | 1646 RunLoop run_loop; |
| 1545 download_service_->CheckClientDownload( | 1647 download_service_->CheckClientDownload( |
| 1546 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1648 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1547 base::Unretained(this), run_loop.QuitClosure())); | 1649 base::Unretained(this), run_loop.QuitClosure())); |
| 1548 | 1650 |
| 1549 // Run the message loop(s) until SendRequest is called. | 1651 // Run the message loop(s) until SendRequest is called. |
| 1550 FlushThreadMessageLoops(); | 1652 FlushThreadMessageLoops(); |
| 1551 EXPECT_TRUE(HasClientDownloadRequest()); | 1653 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1552 ClearClientDownloadRequest(); | 1654 ClearClientDownloadRequest(); |
| 1553 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1655 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1554 ASSERT_TRUE(fetcher); | 1656 ASSERT_TRUE(fetcher); |
| 1555 ClientDownloadRequest request; | 1657 ClientDownloadRequest request; |
| 1556 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); | 1658 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); |
| 1557 EXPECT_EQ("ftp://www.google.com/bla.exe", request.url()); | 1659 EXPECT_EQ(download_file_path, request.url()); |
| 1558 EXPECT_EQ(hash_, request.digests().sha256()); | 1660 EXPECT_EQ(hash_, request.digests().sha256()); |
| 1559 EXPECT_EQ(item.GetReceivedBytes(), request.length()); | 1661 EXPECT_EQ(item.GetReceivedBytes(), request.length()); |
| 1560 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); | 1662 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); |
| 1561 EXPECT_EQ(2, request.resources_size()); | 1663 EXPECT_EQ(2, request.resources_size()); |
| 1562 EXPECT_TRUE(RequestContainsResource(request, | 1664 EXPECT_TRUE(RequestContainsResource(request, |
| 1563 ClientDownloadRequest::DOWNLOAD_REDIRECT, | 1665 ClientDownloadRequest::DOWNLOAD_REDIRECT, |
| 1564 "http://www.google.com/", "")); | 1666 "http://www.google.com/", "")); |
| 1565 EXPECT_TRUE(RequestContainsResource(request, | 1667 EXPECT_TRUE(RequestContainsResource(request, |
| 1566 ClientDownloadRequest::DOWNLOAD_URL, | 1668 ClientDownloadRequest::DOWNLOAD_URL, |
| 1567 "ftp://www.google.com/bla.exe", | 1669 download_file_path, referrer_.spec())); |
| 1568 referrer_.spec())); | |
| 1569 EXPECT_TRUE(request.has_signature()); | 1670 EXPECT_TRUE(request.has_signature()); |
| 1570 EXPECT_EQ(0, request.signature().certificate_chain_size()); | 1671 EXPECT_EQ(0, request.signature().certificate_chain_size()); |
| 1571 | 1672 |
| 1572 // Simulate the request finishing. | 1673 // Simulate the request finishing. |
| 1573 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1674 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1574 FROM_HERE, | 1675 FROM_HERE, |
| 1575 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete, | 1676 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete, |
| 1576 base::Unretained(this), fetcher)); | 1677 base::Unretained(this), fetcher)); |
| 1577 run_loop.Run(); | 1678 run_loop.Run(); |
| 1578 } | 1679 } |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 &item, | 1950 &item, |
| 1850 {"http://www.evil.com/bla.exe"}, // url_chain | 1951 {"http://www.evil.com/bla.exe"}, // url_chain |
| 1851 "http://www.google.com/", // referrer | 1952 "http://www.google.com/", // referrer |
| 1852 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1953 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
| 1853 FILE_PATH_LITERAL("a.exe")); // final_path | 1954 FILE_PATH_LITERAL("a.exe")); // final_path |
| 1854 GURL tab_url("http://www.google.com/tab"); | 1955 GURL tab_url("http://www.google.com/tab"); |
| 1855 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); | 1956 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); |
| 1856 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1957 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1857 MatchDownloadWhitelistUrl(_)) | 1958 MatchDownloadWhitelistUrl(_)) |
| 1858 .WillRepeatedly(Return(false)); | 1959 .WillRepeatedly(Return(false)); |
| 1960 |
| 1961 #if defined(OS_MACOSX) |
| 1962 // Expects that MockDownloadItem will go out of scope while asynchronous |
| 1963 // processing is parsing file metadata, and thus ExtractFileOrDmgFeatures() |
| 1964 // will return rather than continuing to process the download. |
| 1965 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) |
| 1966 .Times(0); |
| 1967 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 1968 ExtractImageFeatures( |
| 1969 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
| 1970 .Times(0); |
| 1971 #else |
| 1972 // Expects synchronous processing that continues to extract features from |
| 1973 // download even after MockDownloadItem goes out of scope. |
| 1859 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); | 1974 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); |
| 1860 EXPECT_CALL(*binary_feature_extractor_.get(), | 1975 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 1861 ExtractImageFeatures( | 1976 ExtractImageFeatures( |
| 1862 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)); | 1977 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)); |
| 1978 #endif |
| 1863 | 1979 |
| 1864 download_service_->CheckClientDownload( | 1980 download_service_->CheckClientDownload( |
| 1865 &item, | 1981 &item, |
| 1866 base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback, | 1982 base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback, |
| 1867 base::Unretained(this))); | 1983 base::Unretained(this))); |
| 1868 // MockDownloadItem going out of scope triggers the OnDownloadDestroyed | 1984 // MockDownloadItem going out of scope triggers the OnDownloadDestroyed |
| 1869 // notification. | 1985 // notification. |
| 1870 } | 1986 } |
| 1871 | 1987 |
| 1872 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1988 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2345 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2461 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2346 base::Unretained(this), run_loop.QuitClosure())); | 2462 base::Unretained(this), run_loop.QuitClosure())); |
| 2347 run_loop.Run(); | 2463 run_loop.Run(); |
| 2348 | 2464 |
| 2349 EXPECT_FALSE(HasClientDownloadRequest()); | 2465 EXPECT_FALSE(HasClientDownloadRequest()); |
| 2350 // Overriden by flag: | 2466 // Overriden by flag: |
| 2351 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2467 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 2352 } | 2468 } |
| 2353 | 2469 |
| 2354 } // namespace safe_browsing | 2470 } // namespace safe_browsing |
| OLD | NEW |