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

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

Issue 1270823003: [Merge M45][SafeBrowsing] Send pings for Zip files that contain other archives. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2454
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 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 download_service_->CheckClientDownload( 1064 download_service_->CheckClientDownload(
1065 &item, 1065 &item,
1066 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 1066 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1067 base::Unretained(this))); 1067 base::Unretained(this)));
1068 MessageLoop::current()->Run(); 1068 MessageLoop::current()->Run();
1069 1069
1070 #if defined(OS_WIN) || defined(OS_MACOSX) 1070 #if defined(OS_WIN) || defined(OS_MACOSX)
1071 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 1071 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
1072 EXPECT_TRUE(HasClientDownloadRequest()); 1072 EXPECT_TRUE(HasClientDownloadRequest());
1073 const ClientDownloadRequest& request = *GetClientDownloadRequest(); 1073 const ClientDownloadRequest& request = *GetClientDownloadRequest();
1074 EXPECT_TRUE(request.has_download_type());
1075 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE,
1076 request.download_type());
1074 EXPECT_EQ(1, request.archived_binary_size()); 1077 EXPECT_EQ(1, request.archived_binary_size());
1075 const ClientDownloadRequest_ArchivedBinary* archived_binary = 1078 const ClientDownloadRequest_ArchivedBinary* archived_binary =
1076 GetRequestArchivedBinary(request, "file.exe"); 1079 GetRequestArchivedBinary(request, "file.exe");
1077 ASSERT_NE(nullptr, archived_binary); 1080 ASSERT_NE(nullptr, archived_binary);
1078 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, 1081 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE,
1079 archived_binary->download_type()); 1082 archived_binary->download_type());
1080 EXPECT_EQ(static_cast<int64_t>(file_contents.size()), 1083 EXPECT_EQ(static_cast<int64_t>(file_contents.size()),
1081 archived_binary->length()); 1084 archived_binary->length());
1082 ClearClientDownloadRequest(); 1085 ClearClientDownloadRequest();
1083 #else 1086 #else
(...skipping 20 matching lines...) Expand all
1104 1107
1105 #if defined(OS_WIN) || defined(OS_MACOSX) 1108 #if defined(OS_WIN) || defined(OS_MACOSX)
1106 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 1109 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
1107 EXPECT_TRUE(HasClientDownloadRequest()); 1110 EXPECT_TRUE(HasClientDownloadRequest());
1108 ClearClientDownloadRequest(); 1111 ClearClientDownloadRequest();
1109 #else 1112 #else
1110 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); 1113 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
1111 EXPECT_FALSE(HasClientDownloadRequest()); 1114 EXPECT_FALSE(HasClientDownloadRequest());
1112 #endif 1115 #endif
1113 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 in addition to the
1119 // executable.
1120 ASSERT_EQ(static_cast<int>(file_contents.size()),
1121 base::WriteFile(
1122 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.rar")),
1123 file_contents.data(), file_contents.size()));
1124 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
1125
1126 download_service_->CheckClientDownload(
1127 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1128 base::Unretained(this)));
1129 MessageLoop::current()->Run();
1130
1131 #if defined(OS_WIN) || defined(OS_MACOSX)
1132 ASSERT_TRUE(HasClientDownloadRequest());
1133 EXPECT_EQ(1, GetClientDownloadRequest()->archived_binary_size());
1134 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type());
1135 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE,
1136 GetClientDownloadRequest()->download_type());
1137 ClearClientDownloadRequest();
1138 #else
1139 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence
1140 // the resulting verdict is UNKNOWN.
1141 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
1142 EXPECT_FALSE(HasClientDownloadRequest());
1143 #endif
1144 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
1145
1146 // Repeat the test with just the archive inside the zip file.
1147 ASSERT_TRUE(
1148 base::DeleteFile(zip_source_dir.path().AppendASCII("file.exe"), false));
1149 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
1150
1151 download_service_->CheckClientDownload(
1152 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1153 base::Unretained(this)));
1154 MessageLoop::current()->Run();
1155
1156 #if defined(OS_WIN) || defined(OS_MACOSX)
1157 ASSERT_TRUE(HasClientDownloadRequest());
1158 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size());
1159 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type());
1160 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_ARCHIVE,
1161 GetClientDownloadRequest()->download_type());
1162 ClearClientDownloadRequest();
1163 #else
1164 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence
1165 // the resulting verdict is UNKNOWN.
1166 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
1167 EXPECT_FALSE(HasClientDownloadRequest());
1168 #endif
1169 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
1114 } 1170 }
1115 1171
1116 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { 1172 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) {
1117 base::ScopedTempDir download_dir; 1173 base::ScopedTempDir download_dir;
1118 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); 1174 ASSERT_TRUE(download_dir.CreateUniqueTempDir());
1119 1175
1120 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); 1176 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")));
1121 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); 1177 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip"));
1122 std::vector<GURL> url_chain; 1178 std::vector<GURL> url_chain;
1123 url_chain.push_back(GURL("http://www.evil.com/a.zip")); 1179 url_chain.push_back(GURL("http://www.evil.com/a.zip"));
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 1909 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
1854 1910
1855 cert = ReadTestCertificate("test_c.pem"); 1911 cert = ReadTestCertificate("test_c.pem");
1856 ASSERT_TRUE(cert.get()); 1912 ASSERT_TRUE(cert.get());
1857 whitelist_strings.clear(); 1913 whitelist_strings.clear();
1858 GetCertificateWhitelistStrings( 1914 GetCertificateWhitelistStrings(
1859 *cert.get(), *issuer_cert.get(), &whitelist_strings); 1915 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1860 EXPECT_THAT(whitelist_strings, ElementsAre()); 1916 EXPECT_THAT(whitelist_strings, ElementsAre());
1861 } 1917 }
1862 } // namespace safe_browsing 1918 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698