Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service_unittest.cc

Issue 2934373002: Record Code Signature of Downloaded DMG files (Closed)
Patch Set: adjusted test file path names Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 // Tests that signatures get recorded and uploaded for signed DMGs.
1449 TEST_F(DownloadProtectionServiceTest,
1450 CheckClientDownloadReportDmgWithSignature) {
1451 net::FakeURLFetcherFactory factory(NULL);
1452 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK,
1453 net::URLRequestStatus::SUCCESS);
1454
1455 base::FilePath signed_dmg;
1456 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg));
1457 signed_dmg = signed_dmg.AppendASCII("safe_browsing")
1458 .AppendASCII("download_protection")
1459 .AppendASCII("googlechrome.dmg");
1460
1461 NiceMockDownloadItem item;
1462 PrepareBasicDownloadItemWithFullPaths(
1463 &item, {"http://www.evil.com/a.dmg"}, // url_chain
1464 "http://www.google.com/", // referrer
1465 signed_dmg, // tmp_path
1466 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.dmg"))); // final_path
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()->has_udif_code_signature());
1476 EXPECT_EQ(GetClientDownloadRequest()->udif_code_signature().length(),
1477 (uint64_t)9454);
1478
1479 base::FilePath signed_dmg_signature;
1480 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg_signature));
1481 signed_dmg_signature = signed_dmg_signature.AppendASCII("safe_browsing")
1482 .AppendASCII("download_protection")
1483 .AppendASCII("googlechrome_signature.data");
1484
1485 std::string signature;
1486 base::ReadFileToString(signed_dmg_signature, &signature);
1487 EXPECT_EQ(signature.length(), (uint64_t)9454);
1488
1489 EXPECT_EQ(
1490 GetClientDownloadRequest()->udif_code_signature().compare(signature), 0);
1491
1492 ClearClientDownloadRequest();
1493
1494 Mock::VerifyAndClearExpectations(sb_service_.get());
1495 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
1496 }
1497
1498 // Tests that no signature gets recorded and uploaded for unsigned DMGs.
1499 TEST_F(DownloadProtectionServiceTest,
1500 CheckClientDownloadReportDmgWithoutSignature) {
1501 net::FakeURLFetcherFactory factory(NULL);
1502 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK,
1503 net::URLRequestStatus::SUCCESS);
1504
1505 base::FilePath unsigned_dmg;
1506 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &unsigned_dmg));
1507 unsigned_dmg = unsigned_dmg.AppendASCII("chrome")
1508 .AppendASCII("safe_browsing_dmg")
1509 .AppendASCII("mach_o_in_dmg.dmg");
1510
1511 NiceMockDownloadItem item;
1512 PrepareBasicDownloadItemWithFullPaths(
1513 &item, {"http://www.evil.com/a.dmg"}, // url_chain
1514 "http://www.google.com/", // referrer
1515 unsigned_dmg, // tmp_path
1516 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.dmg"))); // final_path
1517
1518 RunLoop run_loop;
1519 download_service_->CheckClientDownload(
1520 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1521 base::Unretained(this), run_loop.QuitClosure()));
1522 run_loop.Run();
1523
1524 ASSERT_TRUE(HasClientDownloadRequest());
1525 EXPECT_FALSE(GetClientDownloadRequest()->has_udif_code_signature());
1526
1527 ClearClientDownloadRequest();
1528
1529 Mock::VerifyAndClearExpectations(sb_service_.get());
1530 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
1531 }
1532
1446 #endif 1533 #endif
1447 1534
1448 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { 1535 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) {
1449 net::TestURLFetcherFactory factory; 1536 net::TestURLFetcherFactory factory;
1450 1537
1451 NiceMockDownloadItem item; 1538 NiceMockDownloadItem item;
1452 PrepareBasicDownloadItem( 1539 PrepareBasicDownloadItem(
1453 &item, 1540 &item,
1454 {"http://www.google.com/", 1541 {"http://www.google.com/",
1455 "http://www.google.com/bla.exe"}, // url_chain 1542 "http://www.google.com/bla.exe"}, // url_chain
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2432 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2346 base::Unretained(this), run_loop.QuitClosure())); 2433 base::Unretained(this), run_loop.QuitClosure()));
2347 run_loop.Run(); 2434 run_loop.Run();
2348 2435
2349 EXPECT_FALSE(HasClientDownloadRequest()); 2436 EXPECT_FALSE(HasClientDownloadRequest());
2350 // Overriden by flag: 2437 // Overriden by flag:
2351 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 2438 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
2352 } 2439 }
2353 2440
2354 } // namespace safe_browsing 2441 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698