Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service_unittest.cc

Issue 1262753002: [SafeBrowsing] Send pings for Zip files that contain other archives. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 download_service_->CheckClientDownload( 1067 download_service_->CheckClientDownload(
1068 &item, 1068 &item,
1069 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 1069 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1070 base::Unretained(this))); 1070 base::Unretained(this)));
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_TRUE(request.has_download_type());
1078 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE,
1079 request.download_type());
1077 EXPECT_EQ(1, request.archived_binary_size()); 1080 EXPECT_EQ(1, request.archived_binary_size());
1078 const ClientDownloadRequest_ArchivedBinary* archived_binary = 1081 const ClientDownloadRequest_ArchivedBinary* archived_binary =
1079 GetRequestArchivedBinary(request, "file.exe"); 1082 GetRequestArchivedBinary(request, "file.exe");
1080 ASSERT_NE(nullptr, archived_binary); 1083 ASSERT_NE(nullptr, archived_binary);
1081 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, 1084 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE,
1082 archived_binary->download_type()); 1085 archived_binary->download_type());
1083 EXPECT_EQ(static_cast<int64_t>(file_contents.size()), 1086 EXPECT_EQ(static_cast<int64_t>(file_contents.size()),
1084 archived_binary->length()); 1087 archived_binary->length());
1085 ClearClientDownloadRequest(); 1088 ClearClientDownloadRequest();
1086 #else 1089 #else
(...skipping 20 matching lines...) Expand all
1107 1110
1108 #if defined(OS_WIN) || defined(OS_MACOSX) 1111 #if defined(OS_WIN) || defined(OS_MACOSX)
1109 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 1112 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
1110 EXPECT_TRUE(HasClientDownloadRequest()); 1113 EXPECT_TRUE(HasClientDownloadRequest());
1111 ClearClientDownloadRequest(); 1114 ClearClientDownloadRequest();
1112 #else 1115 #else
1113 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); 1116 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
1114 EXPECT_FALSE(HasClientDownloadRequest()); 1117 EXPECT_FALSE(HasClientDownloadRequest());
1115 #endif 1118 #endif
1116 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); 1119 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
1120
1121 // Repeat the test with an archive inside the zip file in addition to the
1122 // executable.
1123 ASSERT_EQ(static_cast<int>(file_contents.size()),
1124 base::WriteFile(
1125 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.rar")),
1126 file_contents.data(), file_contents.size()));
1127 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
1128
1129 download_service_->CheckClientDownload(
1130 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1131 base::Unretained(this)));
1132 MessageLoop::current()->Run();
1133
1134 #if defined(OS_WIN) || defined(OS_MACOSX)
1135 ASSERT_TRUE(HasClientDownloadRequest());
1136 EXPECT_EQ(1, GetClientDownloadRequest()->archived_binary_size());
1137 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type());
1138 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE,
1139 GetClientDownloadRequest()->download_type());
1140 ClearClientDownloadRequest();
1141 #else
1142 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence
1143 // the resulting verdict is UNKNOWN.
1144 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
1145 EXPECT_FALSE(HasClientDownloadRequest());
1146 #endif
1147 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
1148
1149 // Repeat the test with just the archive inside the zip file.
1150 ASSERT_TRUE(
1151 base::DeleteFile(zip_source_dir.path().AppendASCII("file.exe"), false));
1152 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
1153
1154 download_service_->CheckClientDownload(
1155 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1156 base::Unretained(this)));
1157 MessageLoop::current()->Run();
1158
1159 #if defined(OS_WIN) || defined(OS_MACOSX)
1160 ASSERT_TRUE(HasClientDownloadRequest());
1161 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size());
1162 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type());
1163 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_ARCHIVE,
1164 GetClientDownloadRequest()->download_type());
1165 ClearClientDownloadRequest();
1166 #else
1167 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence
1168 // the resulting verdict is UNKNOWN.
1169 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
1170 EXPECT_FALSE(HasClientDownloadRequest());
1171 #endif
1172 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
1117 } 1173 }
1118 1174
1119 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { 1175 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) {
1120 base::ScopedTempDir download_dir; 1176 base::ScopedTempDir download_dir;
1121 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); 1177 ASSERT_TRUE(download_dir.CreateUniqueTempDir());
1122 1178
1123 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); 1179 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")));
1124 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); 1180 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip"));
1125 std::vector<GURL> url_chain; 1181 std::vector<GURL> url_chain;
1126 url_chain.push_back(GURL("http://www.evil.com/a.zip")); 1182 url_chain.push_back(GURL("http://www.evil.com/a.zip"));
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 1945
1890 EXPECT_CALL(mock_download_item, GetDangerType()) 1946 EXPECT_CALL(mock_download_item, GetDangerType())
1891 .WillOnce(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST)); 1947 .WillOnce(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST));
1892 EXPECT_CALL(mock_page_navigator, OpenURL(OpenURLParamsWithContextValue("7"))); 1948 EXPECT_CALL(mock_page_navigator, OpenURL(OpenURLParamsWithContextValue("7")));
1893 1949
1894 download_service_->ShowDetailsForDownload(mock_download_item, 1950 download_service_->ShowDetailsForDownload(mock_download_item,
1895 &mock_page_navigator); 1951 &mock_page_navigator);
1896 } 1952 }
1897 1953
1898 } // namespace safe_browsing 1954 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698