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 <stdint.h> | 7 #include <stdint.h> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1071 MessageLoop::current()->Run(); | 1071 MessageLoop::current()->Run(); |
1072 | 1072 |
1073 #if defined(OS_WIN) || defined(OS_MACOSX) | 1073 #if defined(OS_WIN) || defined(OS_MACOSX) |
1074 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 1074 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
1075 EXPECT_TRUE(HasClientDownloadRequest()); | 1075 EXPECT_TRUE(HasClientDownloadRequest()); |
1076 const ClientDownloadRequest& request = *GetClientDownloadRequest(); | 1076 const ClientDownloadRequest& request = *GetClientDownloadRequest(); |
1077 EXPECT_EQ(1, request.archived_binary_size()); | 1077 EXPECT_EQ(1, request.archived_binary_size()); |
1078 const ClientDownloadRequest_ArchivedBinary* archived_binary = | 1078 const ClientDownloadRequest_ArchivedBinary* archived_binary = |
1079 GetRequestArchivedBinary(request, "file.exe"); | 1079 GetRequestArchivedBinary(request, "file.exe"); |
1080 ASSERT_NE(nullptr, archived_binary); | 1080 ASSERT_NE(nullptr, archived_binary); |
1081 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, | 1081 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, |
mattm
2015/07/29 22:53:25
Seems like this case should also be checking reque
asanka
2015/07/31 01:06:33
This is looking at the download type of the binary
| |
1082 archived_binary->download_type()); | 1082 archived_binary->download_type()); |
1083 EXPECT_EQ(static_cast<int64_t>(file_contents.size()), | 1083 EXPECT_EQ(static_cast<int64_t>(file_contents.size()), |
1084 archived_binary->length()); | 1084 archived_binary->length()); |
1085 ClearClientDownloadRequest(); | 1085 ClearClientDownloadRequest(); |
1086 #else | 1086 #else |
1087 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence | 1087 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence |
1088 // the resulting verdict is UNKNOWN. | 1088 // the resulting verdict is UNKNOWN. |
1089 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1089 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1090 EXPECT_FALSE(HasClientDownloadRequest()); | 1090 EXPECT_FALSE(HasClientDownloadRequest()); |
1091 #endif | 1091 #endif |
(...skipping 15 matching lines...) Expand all Loading... | |
1107 | 1107 |
1108 #if defined(OS_WIN) || defined(OS_MACOSX) | 1108 #if defined(OS_WIN) || defined(OS_MACOSX) |
1109 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1109 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
1110 EXPECT_TRUE(HasClientDownloadRequest()); | 1110 EXPECT_TRUE(HasClientDownloadRequest()); |
1111 ClearClientDownloadRequest(); | 1111 ClearClientDownloadRequest(); |
1112 #else | 1112 #else |
1113 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1113 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1114 EXPECT_FALSE(HasClientDownloadRequest()); | 1114 EXPECT_FALSE(HasClientDownloadRequest()); |
1115 #endif | 1115 #endif |
1116 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1116 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
1117 | |
1118 // Repeat the test with an archive inside the zip file. | |
1119 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( | |
1120 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.rar")), | |
1121 file_contents.data(), file_contents.size())); | |
1122 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); | |
mattm
2015/07/29 22:53:25
Isn't this creating a zip with file.txt, file.exe,
asanka
2015/07/31 01:04:42
Indeed. Fixed by testing both with file.exe and wi
| |
1123 | |
1124 EXPECT_CALL(*sb_service_->mock_database_manager(), | |
1125 MatchDownloadWhitelistUrl(_)) | |
1126 .WillRepeatedly(Return(false)); | |
1127 | |
1128 download_service_->CheckClientDownload( | |
1129 &item, | |
1130 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | |
1131 base::Unretained(this))); | |
1132 MessageLoop::current()->Run(); | |
1133 | |
1134 #if defined(OS_WIN) || defined(OS_MACOSX) | |
1135 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | |
1136 EXPECT_TRUE(HasClientDownloadRequest()); | |
1137 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size()); | |
1138 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); | |
1139 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_ARCHIVE, | |
1140 GetClientDownloadRequest()->download_type()); | |
1141 ClearClientDownloadRequest(); | |
1142 #else | |
1143 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence | |
1144 // the resulting verdict is UNKNOWN. | |
1145 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | |
1146 EXPECT_FALSE(HasClientDownloadRequest()); | |
1147 #endif | |
1148 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | |
1117 } | 1149 } |
1118 | 1150 |
1119 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { | 1151 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { |
1120 base::ScopedTempDir download_dir; | 1152 base::ScopedTempDir download_dir; |
1121 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 1153 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
1122 | 1154 |
1123 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); | 1155 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); |
1124 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); | 1156 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); |
1125 std::vector<GURL> url_chain; | 1157 std::vector<GURL> url_chain; |
1126 url_chain.push_back(GURL("http://www.evil.com/a.zip")); | 1158 url_chain.push_back(GURL("http://www.evil.com/a.zip")); |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1889 | 1921 |
1890 EXPECT_CALL(mock_download_item, GetDangerType()) | 1922 EXPECT_CALL(mock_download_item, GetDangerType()) |
1891 .WillOnce(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST)); | 1923 .WillOnce(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST)); |
1892 EXPECT_CALL(mock_page_navigator, OpenURL(OpenURLParamsWithContextValue("7"))); | 1924 EXPECT_CALL(mock_page_navigator, OpenURL(OpenURLParamsWithContextValue("7"))); |
1893 | 1925 |
1894 download_service_->ShowDetailsForDownload(mock_download_item, | 1926 download_service_->ShowDetailsForDownload(mock_download_item, |
1895 &mock_page_navigator); | 1927 &mock_page_navigator); |
1896 } | 1928 } |
1897 | 1929 |
1898 } // namespace safe_browsing | 1930 } // namespace safe_browsing |
OLD | NEW |