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_util.h" | 13 #include "base/file_util.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted_memory.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
22 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
23 #include "chrome/browser/safe_browsing/database_manager.h" | 23 #include "chrome/browser/safe_browsing/database_manager.h" |
24 #include "chrome/browser/safe_browsing/download_feedback_service.h" | 24 #include "chrome/browser/safe_browsing/download_feedback_service.h" |
25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
26 #include "chrome/browser/safe_browsing/signature_util.h" | 26 #include "chrome/browser/safe_browsing/signature_util.h" |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip)); | 700 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip)); |
701 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 701 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
702 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | 702 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
703 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); | 703 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); |
704 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); | 704 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); |
705 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); | 705 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); |
706 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); | 706 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); |
707 | 707 |
708 // Write out a zip archive to the temporary file. In this case, it | 708 // Write out a zip archive to the temporary file. In this case, it |
709 // only contains a text file. | 709 // only contains a text file. |
710 base::ScopedTempDir zip_source_dir; | 710 zip::ZipContents zip_contents; |
711 ASSERT_TRUE(zip_source_dir.CreateUniqueTempDir()); | 711 zip_contents[base::FilePath(FILE_PATH_LITERAL("file.txt"))] = |
712 std::string file_contents = "dummy file"; | 712 new base::RefCountedStaticMemory("dummy file", 10); |
713 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( | 713 ASSERT_TRUE(zip::ZipFromMemory(a_tmp, zip_contents, false)); |
714 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), | |
715 file_contents.data(), file_contents.size())); | |
716 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); | |
717 | 714 |
718 download_service_->CheckClientDownload( | 715 download_service_->CheckClientDownload( |
719 &item, | 716 &item, |
720 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 717 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
721 base::Unretained(this))); | 718 base::Unretained(this))); |
722 MessageLoop::current()->Run(); | 719 MessageLoop::current()->Run(); |
723 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 720 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
724 Mock::VerifyAndClearExpectations(sb_service_.get()); | 721 Mock::VerifyAndClearExpectations(sb_service_.get()); |
725 Mock::VerifyAndClearExpectations(signature_util_.get()); | 722 Mock::VerifyAndClearExpectations(signature_util_.get()); |
726 | 723 |
727 // Now check with an executable in the zip file as well. | 724 // Now check with an executable in the zip file as well. |
728 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( | 725 zip_contents[base::FilePath(FILE_PATH_LITERAL("file.exe"))] = |
729 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), | 726 new base::RefCountedStaticMemory("dummy file", 10); |
730 file_contents.data(), file_contents.size())); | 727 ASSERT_TRUE(zip::ZipFromMemory(a_tmp, zip_contents, false)); |
731 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); | |
732 | 728 |
733 EXPECT_CALL(*sb_service_->mock_database_manager(), | 729 EXPECT_CALL(*sb_service_->mock_database_manager(), |
734 MatchDownloadWhitelistUrl(_)) | 730 MatchDownloadWhitelistUrl(_)) |
735 .WillRepeatedly(Return(false)); | 731 .WillRepeatedly(Return(false)); |
736 | 732 |
737 download_service_->CheckClientDownload( | 733 download_service_->CheckClientDownload( |
738 &item, | 734 &item, |
739 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 735 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
740 base::Unretained(this))); | 736 base::Unretained(this))); |
741 MessageLoop::current()->Run(); | 737 MessageLoop::current()->Run(); |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); | 1212 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); |
1217 | 1213 |
1218 cert = ReadTestCertificate("test_c.pem"); | 1214 cert = ReadTestCertificate("test_c.pem"); |
1219 ASSERT_TRUE(cert.get()); | 1215 ASSERT_TRUE(cert.get()); |
1220 whitelist_strings.clear(); | 1216 whitelist_strings.clear(); |
1221 GetCertificateWhitelistStrings( | 1217 GetCertificateWhitelistStrings( |
1222 *cert.get(), *issuer_cert.get(), &whitelist_strings); | 1218 *cert.get(), *issuer_cert.get(), &whitelist_strings); |
1223 EXPECT_THAT(whitelist_strings, ElementsAre()); | 1219 EXPECT_THAT(whitelist_strings, ElementsAre()); |
1224 } | 1220 } |
1225 } // namespace safe_browsing | 1221 } // namespace safe_browsing |
OLD | NEW |