| 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 <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 19 #include "base/scoped_temp_dir.h" | |
| 20 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 23 #include "chrome/browser/safe_browsing/signature_util.h" | 23 #include "chrome/browser/safe_browsing/signature_util.h" |
| 24 #include "chrome/common/safe_browsing/csd.pb.h" | 24 #include "chrome/common/safe_browsing/csd.pb.h" |
| 25 #include "chrome/common/zip.h" | 25 #include "chrome/common/zip.h" |
| 26 #include "content/public/browser/download_item.h" | 26 #include "content/public/browser/download_item.h" |
| 27 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
| 28 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
| 29 #include "net/base/x509_certificate.h" | 29 #include "net/base/x509_certificate.h" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { | 459 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { |
| 460 ClientDownloadResponse response; | 460 ClientDownloadResponse response; |
| 461 response.set_verdict(ClientDownloadResponse::SAFE); | 461 response.set_verdict(ClientDownloadResponse::SAFE); |
| 462 net::FakeURLFetcherFactory factory; | 462 net::FakeURLFetcherFactory factory; |
| 463 // Empty response means SAFE. | 463 // Empty response means SAFE. |
| 464 factory.SetFakeResponse( | 464 factory.SetFakeResponse( |
| 465 DownloadProtectionService::GetDownloadRequestUrl(), | 465 DownloadProtectionService::GetDownloadRequestUrl(), |
| 466 response.SerializeAsString(), | 466 response.SerializeAsString(), |
| 467 true); | 467 true); |
| 468 | 468 |
| 469 ScopedTempDir download_dir; | 469 base::ScopedTempDir download_dir; |
| 470 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 470 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
| 471 | 471 |
| 472 DownloadProtectionService::DownloadInfo info; | 472 DownloadProtectionService::DownloadInfo info; |
| 473 info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")); | 473 info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")); |
| 474 info.target_file = FilePath(FILE_PATH_LITERAL("a.zip")); | 474 info.target_file = FilePath(FILE_PATH_LITERAL("a.zip")); |
| 475 info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip")); | 475 info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip")); |
| 476 info.referrer_url = GURL("http://www.google.com/"); | 476 info.referrer_url = GURL("http://www.google.com/"); |
| 477 | 477 |
| 478 // Write out a zip archive to the temporary file. In this case, it | 478 // Write out a zip archive to the temporary file. In this case, it |
| 479 // only contains a text file. | 479 // only contains a text file. |
| 480 ScopedTempDir zip_source_dir; | 480 base::ScopedTempDir zip_source_dir; |
| 481 ASSERT_TRUE(zip_source_dir.CreateUniqueTempDir()); | 481 ASSERT_TRUE(zip_source_dir.CreateUniqueTempDir()); |
| 482 std::string file_contents = "dummy file"; | 482 std::string file_contents = "dummy file"; |
| 483 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( | 483 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( |
| 484 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), | 484 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), |
| 485 file_contents.data(), file_contents.size())); | 485 file_contents.data(), file_contents.size())); |
| 486 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false)); | 486 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false)); |
| 487 | 487 |
| 488 download_service_->CheckClientDownload( | 488 download_service_->CheckClientDownload( |
| 489 info, | 489 info, |
| 490 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 490 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 msg_loop_.Run(); | 526 msg_loop_.Run(); |
| 527 #if defined(OS_WIN) | 527 #if defined(OS_WIN) |
| 528 ExpectResult(DownloadProtectionService::DANGEROUS); | 528 ExpectResult(DownloadProtectionService::DANGEROUS); |
| 529 #else | 529 #else |
| 530 ExpectResult(DownloadProtectionService::SAFE); | 530 ExpectResult(DownloadProtectionService::SAFE); |
| 531 #endif | 531 #endif |
| 532 Mock::VerifyAndClearExpectations(signature_util_); | 532 Mock::VerifyAndClearExpectations(signature_util_); |
| 533 } | 533 } |
| 534 | 534 |
| 535 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { | 535 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { |
| 536 ScopedTempDir download_dir; | 536 base::ScopedTempDir download_dir; |
| 537 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 537 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
| 538 | 538 |
| 539 DownloadProtectionService::DownloadInfo info; | 539 DownloadProtectionService::DownloadInfo info; |
| 540 info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")); | 540 info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")); |
| 541 info.target_file = FilePath(FILE_PATH_LITERAL("a.zip")); | 541 info.target_file = FilePath(FILE_PATH_LITERAL("a.zip")); |
| 542 info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip")); | 542 info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip")); |
| 543 info.referrer_url = GURL("http://www.google.com/"); | 543 info.referrer_url = GURL("http://www.google.com/"); |
| 544 | 544 |
| 545 std::string file_contents = "corrupt zip file"; | 545 std::string file_contents = "corrupt zip file"; |
| 546 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( | 546 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); | 870 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); |
| 871 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); | 871 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); |
| 872 | 872 |
| 873 cert = ReadTestCertificate("test_c.pem"); | 873 cert = ReadTestCertificate("test_c.pem"); |
| 874 ASSERT_TRUE(cert.get()); | 874 ASSERT_TRUE(cert.get()); |
| 875 whitelist_strings.clear(); | 875 whitelist_strings.clear(); |
| 876 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); | 876 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); |
| 877 EXPECT_THAT(whitelist_strings, ElementsAre()); | 877 EXPECT_THAT(whitelist_strings, ElementsAre()); |
| 878 } | 878 } |
| 879 } // namespace safe_browsing | 879 } // namespace safe_browsing |
| OLD | NEW |