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 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 CheckClientDownloadReportCorruptZip) { | 1441 CheckClientDownloadReportCorruptZip) { |
1442 CheckClientDownloadReportCorruptArchive(ZIP); | 1442 CheckClientDownloadReportCorruptArchive(ZIP); |
1443 } | 1443 } |
1444 | 1444 |
1445 #if defined(OS_MACOSX) | 1445 #if defined(OS_MACOSX) |
1446 TEST_F(DownloadProtectionServiceTest, | 1446 TEST_F(DownloadProtectionServiceTest, |
1447 CheckClientDownloadReportCorruptDmg) { | 1447 CheckClientDownloadReportCorruptDmg) { |
1448 CheckClientDownloadReportCorruptArchive(DMG); | 1448 CheckClientDownloadReportCorruptArchive(DMG); |
1449 } | 1449 } |
1450 | 1450 |
| 1451 // Tests that signatures get recorded and uploaded for signed DMGs. |
| 1452 TEST_F(DownloadProtectionServiceTest, |
| 1453 CheckClientDownloadReportDmgWithSignature) { |
| 1454 net::FakeURLFetcherFactory factory(NULL); |
| 1455 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 1456 net::URLRequestStatus::SUCCESS); |
| 1457 |
| 1458 base::FilePath signed_dmg; |
| 1459 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg)); |
| 1460 signed_dmg = signed_dmg.AppendASCII("safe_browsing") |
| 1461 .AppendASCII("mach_o") |
| 1462 .AppendASCII("signed-archive.dmg"); |
| 1463 |
| 1464 NiceMockDownloadItem item; |
| 1465 PrepareBasicDownloadItemWithFullPaths( |
| 1466 &item, {"http://www.evil.com/a.dmg"}, // url_chain |
| 1467 "http://www.google.com/", // referrer |
| 1468 signed_dmg, // tmp_path |
| 1469 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.dmg"))); // final_path |
| 1470 |
| 1471 RunLoop run_loop; |
| 1472 download_service_->CheckClientDownload( |
| 1473 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1474 base::Unretained(this), run_loop.QuitClosure())); |
| 1475 run_loop.Run(); |
| 1476 |
| 1477 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1478 EXPECT_TRUE(GetClientDownloadRequest()->has_udif_code_signature()); |
| 1479 EXPECT_EQ(2215u, GetClientDownloadRequest()->udif_code_signature().length()); |
| 1480 |
| 1481 base::FilePath signed_dmg_signature; |
| 1482 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg_signature)); |
| 1483 signed_dmg_signature = signed_dmg_signature.AppendASCII("safe_browsing") |
| 1484 .AppendASCII("mach_o") |
| 1485 .AppendASCII("signed-archive-signature.data"); |
| 1486 |
| 1487 std::string signature; |
| 1488 base::ReadFileToString(signed_dmg_signature, &signature); |
| 1489 EXPECT_EQ(2215u, signature.length()); |
| 1490 EXPECT_EQ(signature, GetClientDownloadRequest()->udif_code_signature()); |
| 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 |
1451 // Test that downloaded files with no disk image extension that have a 'koly' | 1533 // Test that downloaded files with no disk image extension that have a 'koly' |
1452 // trailer are treated as disk images and processed accordingly. | 1534 // trailer are treated as disk images and processed accordingly. |
1453 TEST_F(DownloadProtectionServiceTest, | 1535 TEST_F(DownloadProtectionServiceTest, |
1454 CheckClientDownloadReportDmgWithoutExtension) { | 1536 CheckClientDownloadReportDmgWithoutExtension) { |
1455 net::FakeURLFetcherFactory factory(NULL); | 1537 net::FakeURLFetcherFactory factory(NULL); |
1456 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, | 1538 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
1457 net::URLRequestStatus::SUCCESS); | 1539 net::URLRequestStatus::SUCCESS); |
1458 | 1540 |
1459 base::FilePath test_data; | 1541 base::FilePath test_data; |
1460 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); | 1542 EXPECT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA, &test_data)); |
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2494 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2576 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
2495 base::Unretained(this), run_loop.QuitClosure())); | 2577 base::Unretained(this), run_loop.QuitClosure())); |
2496 run_loop.Run(); | 2578 run_loop.Run(); |
2497 | 2579 |
2498 EXPECT_FALSE(HasClientDownloadRequest()); | 2580 EXPECT_FALSE(HasClientDownloadRequest()); |
2499 // Overriden by flag: | 2581 // Overriden by flag: |
2500 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2582 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
2501 } | 2583 } |
2502 | 2584 |
2503 } // namespace safe_browsing | 2585 } // namespace safe_browsing |
OLD | NEW |