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

Unified Diff: chrome/browser/safe_browsing/download_protection_service_unittest.cc

Issue 10382113: Add SafeBrowsing support for checking downloaded zip files that contain executables. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix FilePath printf format on Windows Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.cc ('k') | chrome/common/safe_browsing/csd.proto » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/safe_browsing/download_protection_service_unittest.cc
diff --git a/chrome/browser/safe_browsing/download_protection_service_unittest.cc b/chrome/browser/safe_browsing/download_protection_service_unittest.cc
index c67ae599736c20f4dd6e643d0a7eda29e083160c..40a32b6dc111119e1064137d6972a912b49c7547 100644
--- a/chrome/browser/safe_browsing/download_protection_service_unittest.cc
+++ b/chrome/browser/safe_browsing/download_protection_service_unittest.cc
@@ -16,11 +16,13 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/path_service.h"
+#include "base/scoped_temp_dir.h"
#include "base/string_number_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/safe_browsing/signature_util.h"
#include "chrome/common/safe_browsing/csd.pb.h"
+#include "chrome/common/zip.h"
#include "content/public/browser/download_item.h"
#include "content/public/common/url_fetcher_delegate.h"
#include "content/test/test_browser_thread.h"
@@ -432,6 +434,107 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
#endif
}
+TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
+ ClientDownloadResponse response;
+ response.set_verdict(ClientDownloadResponse::SAFE);
+ FakeURLFetcherFactory factory;
+ // Empty response means SAFE.
+ factory.SetFakeResponse(
+ DownloadProtectionService::kDownloadRequestUrl,
+ response.SerializeAsString(),
+ true);
+
+ ScopedTempDir download_dir;
+ ASSERT_TRUE(download_dir.CreateUniqueTempDir());
+
+ DownloadProtectionService::DownloadInfo info;
+ info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"));
+ info.target_file = FilePath(FILE_PATH_LITERAL("a.zip"));
+ info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip"));
+ info.referrer_url = GURL("http://www.google.com/");
+
+ // Write out a zip archive to the temporary file. In this case, it
+ // only contains a text file.
+ ScopedTempDir zip_source_dir;
+ ASSERT_TRUE(zip_source_dir.CreateUniqueTempDir());
+ std::string file_contents = "dummy file";
+ ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile(
+ zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")),
+ file_contents.data(), file_contents.size()));
+ ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false));
+
+ download_service_->CheckClientDownload(
+ info,
+ base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
+ base::Unretained(this)));
+ msg_loop_.Run();
+ ExpectResult(DownloadProtectionService::SAFE);
+ Mock::VerifyAndClearExpectations(sb_service_);
+ Mock::VerifyAndClearExpectations(signature_util_);
+
+ // Now check with an executable in the zip file as well.
+ ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile(
+ zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")),
+ file_contents.data(), file_contents.size()));
+ ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false));
+
+ EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
+ .WillRepeatedly(Return(false));
+
+ download_service_->CheckClientDownload(
+ info,
+ base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
+ base::Unretained(this)));
+ msg_loop_.Run();
+ ExpectResult(DownloadProtectionService::SAFE);
+ Mock::VerifyAndClearExpectations(signature_util_);
+
+ // If the response is dangerous the result should also be marked as
+ // dangerous.
+ response.set_verdict(ClientDownloadResponse::DANGEROUS);
+ factory.SetFakeResponse(
+ DownloadProtectionService::kDownloadRequestUrl,
+ response.SerializeAsString(),
+ true);
+
+ download_service_->CheckClientDownload(
+ info,
+ base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
+ base::Unretained(this)));
+ msg_loop_.Run();
+#if defined(OS_WIN)
+ ExpectResult(DownloadProtectionService::DANGEROUS);
+#else
+ ExpectResult(DownloadProtectionService::SAFE);
+#endif
+ Mock::VerifyAndClearExpectations(signature_util_);
+}
+
+TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) {
+ ScopedTempDir download_dir;
+ ASSERT_TRUE(download_dir.CreateUniqueTempDir());
+
+ DownloadProtectionService::DownloadInfo info;
+ info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"));
+ info.target_file = FilePath(FILE_PATH_LITERAL("a.zip"));
+ info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip"));
+ info.referrer_url = GURL("http://www.google.com/");
+
+ std::string file_contents = "corrupt zip file";
+ ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile(
+ download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")),
+ file_contents.data(), file_contents.size()));
+
+ download_service_->CheckClientDownload(
+ info,
+ base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
+ base::Unretained(this)));
+ msg_loop_.Run();
+ ExpectResult(DownloadProtectionService::SAFE);
+ Mock::VerifyAndClearExpectations(sb_service_);
+ Mock::VerifyAndClearExpectations(signature_util_);
+}
+
TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) {
ClientDownloadResponse response;
// Even if the server verdict is dangerous we should return SAFE because
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.cc ('k') | chrome/common/safe_browsing/csd.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698