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 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 CheckClientDownloadReportCorruptZip) { | 1440 CheckClientDownloadReportCorruptZip) { |
1441 CheckClientDownloadReportCorruptArchive(ZIP); | 1441 CheckClientDownloadReportCorruptArchive(ZIP); |
1442 } | 1442 } |
1443 | 1443 |
1444 #if defined(OS_MACOSX) | 1444 #if defined(OS_MACOSX) |
1445 TEST_F(DownloadProtectionServiceTest, | 1445 TEST_F(DownloadProtectionServiceTest, |
1446 CheckClientDownloadReportCorruptDmg) { | 1446 CheckClientDownloadReportCorruptDmg) { |
1447 CheckClientDownloadReportCorruptArchive(DMG); | 1447 CheckClientDownloadReportCorruptArchive(DMG); |
1448 } | 1448 } |
1449 | 1449 |
| 1450 // Tests that signatures get recorded and uploaded for signed DMGs. |
| 1451 TEST_F(DownloadProtectionServiceTest, |
| 1452 CheckClientDownloadReportDmgWithSignature) { |
| 1453 net::FakeURLFetcherFactory factory(NULL); |
| 1454 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 1455 net::URLRequestStatus::SUCCESS); |
| 1456 |
| 1457 base::FilePath signed_dmg; |
| 1458 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg)); |
| 1459 signed_dmg = signed_dmg.AppendASCII("safe_browsing") |
| 1460 .AppendASCII("mach_o") |
| 1461 .AppendASCII("signed-archive.dmg"); |
| 1462 |
| 1463 NiceMockDownloadItem item; |
| 1464 PrepareBasicDownloadItemWithFullPaths( |
| 1465 &item, {"http://www.evil.com/a.dmg"}, // url_chain |
| 1466 "http://www.google.com/", // referrer |
| 1467 signed_dmg, // 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()->has_udif_code_signature()); |
| 1478 EXPECT_EQ(2215u, GetClientDownloadRequest()->udif_code_signature().length()); |
| 1479 |
| 1480 base::FilePath signed_dmg_signature; |
| 1481 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg_signature)); |
| 1482 signed_dmg_signature = signed_dmg_signature.AppendASCII("safe_browsing") |
| 1483 .AppendASCII("mach_o") |
| 1484 .AppendASCII("signed-archive-signature.data"); |
| 1485 |
| 1486 std::string signature; |
| 1487 base::ReadFileToString(signed_dmg_signature, &signature); |
| 1488 EXPECT_EQ(2215u, signature.length()); |
| 1489 EXPECT_EQ(signature, GetClientDownloadRequest()->udif_code_signature()); |
| 1490 |
| 1491 ClearClientDownloadRequest(); |
| 1492 |
| 1493 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1494 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1495 } |
| 1496 |
| 1497 // Tests that no signature gets recorded and uploaded for unsigned DMGs. |
| 1498 TEST_F(DownloadProtectionServiceTest, |
| 1499 CheckClientDownloadReportDmgWithoutSignature) { |
| 1500 net::FakeURLFetcherFactory factory(NULL); |
| 1501 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 1502 net::URLRequestStatus::SUCCESS); |
| 1503 |
| 1504 base::FilePath unsigned_dmg; |
| 1505 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &unsigned_dmg)); |
| 1506 unsigned_dmg = unsigned_dmg.AppendASCII("chrome") |
| 1507 .AppendASCII("safe_browsing_dmg") |
| 1508 .AppendASCII("mach_o_in_dmg.dmg"); |
| 1509 |
| 1510 NiceMockDownloadItem item; |
| 1511 PrepareBasicDownloadItemWithFullPaths( |
| 1512 &item, {"http://www.evil.com/a.dmg"}, // url_chain |
| 1513 "http://www.google.com/", // referrer |
| 1514 unsigned_dmg, // tmp_path |
| 1515 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.dmg"))); // final_path |
| 1516 |
| 1517 RunLoop run_loop; |
| 1518 download_service_->CheckClientDownload( |
| 1519 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1520 base::Unretained(this), run_loop.QuitClosure())); |
| 1521 run_loop.Run(); |
| 1522 |
| 1523 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1524 EXPECT_FALSE(GetClientDownloadRequest()->has_udif_code_signature()); |
| 1525 |
| 1526 ClearClientDownloadRequest(); |
| 1527 |
| 1528 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1529 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1530 } |
| 1531 |
1450 // Test that downloaded files with no disk image extension that have a 'koly' | 1532 // Test that downloaded files with no disk image extension that have a 'koly' |
1451 // trailer are treated as disk images and processed accordingly. | 1533 // trailer are treated as disk images and processed accordingly. |
1452 TEST_F(DownloadProtectionServiceTest, | 1534 TEST_F(DownloadProtectionServiceTest, |
1453 CheckClientDownloadReportDmgWithoutExtension) { | 1535 CheckClientDownloadReportDmgWithoutExtension) { |
1454 net::FakeURLFetcherFactory factory(NULL); | 1536 net::FakeURLFetcherFactory factory(NULL); |
1455 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, | 1537 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
1456 net::URLRequestStatus::SUCCESS); | 1538 net::URLRequestStatus::SUCCESS); |
1457 | 1539 |
1458 base::FilePath test_data; | 1540 base::FilePath test_data; |
1459 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); | 1541 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2462 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2544 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
2463 base::Unretained(this), run_loop.QuitClosure())); | 2545 base::Unretained(this), run_loop.QuitClosure())); |
2464 run_loop.Run(); | 2546 run_loop.Run(); |
2465 | 2547 |
2466 EXPECT_FALSE(HasClientDownloadRequest()); | 2548 EXPECT_FALSE(HasClientDownloadRequest()); |
2467 // Overriden by flag: | 2549 // Overriden by flag: |
2468 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2550 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
2469 } | 2551 } |
2470 | 2552 |
2471 } // namespace safe_browsing | 2553 } // namespace safe_browsing |
OLD | NEW |