From 46629f9447a527ea99dbed8b27b22a70aedc1e63 Mon Sep 17 00:00:00 2001 From: Greg Thompson Date: Sat, 11 Apr 2015 20:17:25 -0400 Subject: [PATCH] Fix inclusion of archived binaries in client download requests BUG=475925 R=mattm@chromium.org Review URL: https://codereview.chromium.org/1076243002 Cr-Commit-Position: refs/heads/master@{#324725} (cherry picked from commit f0710b99cffc58e9c777e6bcfd063fe522f22c79) TBR=grt@chromium.org Review URL: https://codereview.chromium.org/1083523004 Cr-Commit-Position: refs/branch-heads/2357@{#51} Cr-Branched-From: 59d4494849b405682265ed5d3f5164573b9a939b-refs/heads/master@{#323860} --- .../download_protection_service.cc | 4 ++-- .../download_protection_service_unittest.cc | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/chrome/browser/safe_browsing/download_protection_service.cc b/chrome/browser/safe_browsing/download_protection_service.cc index ee01b97dc79e9..1460b2f7606f2 100644 --- a/chrome/browser/safe_browsing/download_protection_service.cc +++ b/chrome/browser/safe_browsing/download_protection_service.cc @@ -771,12 +771,12 @@ class DownloadProtectionService::CheckClientDownloadRequest request.mutable_signature()->CopyFrom(signature_info_); if (image_headers_) request.set_allocated_image_headers(image_headers_.release()); + if (zipped_executable_) + request.mutable_archived_binary()->Swap(&archived_binary_); if (!request.SerializeToString(&client_download_request_data_)) { FinishRequest(UNKNOWN, REASON_INVALID_REQUEST_PROTO); return; } - if (zipped_executable_) - request.mutable_archived_binary()->Swap(&archived_binary_); service_->client_download_request_callbacks_.Notify(item_, &request); DVLOG(2) << "Sending a request for URL: " diff --git a/chrome/browser/safe_browsing/download_protection_service_unittest.cc b/chrome/browser/safe_browsing/download_protection_service_unittest.cc index bc1568f292abf..2044d65b5aecd 100644 --- a/chrome/browser/safe_browsing/download_protection_service_unittest.cc +++ b/chrome/browser/safe_browsing/download_protection_service_unittest.cc @@ -4,6 +4,7 @@ #include "chrome/browser/safe_browsing/download_protection_service.h" +#include #include #include @@ -279,6 +280,16 @@ class DownloadProtectionServiceTest : public testing::Test { return false; } + static const ClientDownloadRequest_ArchivedBinary* GetRequestArchivedBinary( + const ClientDownloadRequest& request, + const std::string& file_basename) { + for (const auto& archived_binary : request.archived_binary()) { + if (archived_binary.file_basename() == file_basename) + return &archived_binary; + } + return nullptr; + } + // Flushes any pending tasks in the message loops of all threads. void FlushThreadMessageLoops() { BrowserThread::GetBlockingPool()->FlushForTesting(); @@ -1113,6 +1124,15 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { #if defined(OS_WIN) || defined(OS_MACOSX) // OSX sends pings for evaluation purposes. EXPECT_TRUE(HasClientDownloadRequest()); + const ClientDownloadRequest& request = *GetClientDownloadRequest(); + EXPECT_EQ(1, request.archived_binary_size()); + const ClientDownloadRequest_ArchivedBinary* archived_binary = + GetRequestArchivedBinary(request, "file.exe"); + ASSERT_NE(nullptr, archived_binary); + EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, + archived_binary->download_type()); + EXPECT_EQ(static_cast(file_contents.size()), + archived_binary->length()); ClearClientDownloadRequest(); #else EXPECT_FALSE(HasClientDownloadRequest());