Use file name rather than file path in Android download protection
The primary use of DownloadItem::GetTargetFilePath() in DownloadRequestMaker is to obtain a file *name*, which is then populated into the request proto and also used to determine the file type from the filename extension. The file path may be a content-URI on Android, which does not contain the filename extension. Therefore, use the human-readable file name (display name) rather than the target file path on Android. Also cleans up download_type_util and aligns file_analyzer with this convention (file name rather than file path). Bug: 397407934 Change-Id: I52530313235b784b5713632c6c0abf5adf8b6ebd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6306003 Commit-Queue: Lily Chen <chlily@chromium.org> Reviewed-by: Daniel Rubery <drubery@chromium.org> Cr-Commit-Position: refs/heads/main@{#1425346}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
487f46f8f8
commit
d5db2fffda
chrome
browser
safe_browsing
common
@ -106,9 +106,13 @@ DownloadRequestMaker::CreateFromDownloadItem(
|
||||
binary_feature_extractor,
|
||||
content::DownloadItemUtils::GetBrowserContext(item),
|
||||
TabUrls{item->GetTabUrl(), item->GetTabReferrerUrl()},
|
||||
item->GetTargetFilePath(), item->GetFullPath(), item->GetURL(),
|
||||
item->GetHash(), item->GetReceivedBytes(), resources,
|
||||
item->HasUserGesture(),
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
/*target_file_name=*/item->GetFileNameToReportUser(),
|
||||
#else
|
||||
/*target_file_name=*/item->GetTargetFilePath(),
|
||||
#endif
|
||||
item->GetFullPath(), item->GetURL(), item->GetHash(),
|
||||
item->GetReceivedBytes(), resources, item->HasUserGesture(),
|
||||
static_cast<ReferrerChainData*>(
|
||||
item->GetUserData(ReferrerChainData::kDownloadReferrerChainDataKey)),
|
||||
password, DownloadProtectionService::GetDownloadPingToken(item),
|
||||
@ -151,7 +155,7 @@ DownloadRequestMaker::DownloadRequestMaker(
|
||||
scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor,
|
||||
content::BrowserContext* browser_context,
|
||||
TabUrls tab_urls,
|
||||
base::FilePath target_file_path,
|
||||
base::FilePath target_file_name,
|
||||
base::FilePath full_path,
|
||||
GURL source_url,
|
||||
std::string sha256_hash,
|
||||
@ -166,7 +170,7 @@ DownloadRequestMaker::DownloadRequestMaker(
|
||||
request_(std::make_unique<ClientDownloadRequest>()),
|
||||
binary_feature_extractor_(binary_feature_extractor),
|
||||
tab_urls_(tab_urls),
|
||||
target_file_path_(target_file_path),
|
||||
target_file_name_(target_file_name),
|
||||
full_path_(full_path),
|
||||
password_(password.CopyAsOptional()),
|
||||
on_results_callback_(std::move(on_results_callback)) {
|
||||
@ -210,12 +214,12 @@ void DownloadRequestMaker::Start(DownloadRequestMaker::Callback callback) {
|
||||
}
|
||||
request_->set_request_ap_verdicts(is_under_advanced_protection);
|
||||
request_->set_locale(g_browser_process->GetApplicationLocale());
|
||||
request_->set_file_basename(target_file_path_.BaseName().AsUTF8Unsafe());
|
||||
request_->set_file_basename(target_file_name_.BaseName().AsUTF8Unsafe());
|
||||
|
||||
PopulateTailoredInfo();
|
||||
|
||||
file_analyzer_->Start(
|
||||
target_file_path_, full_path_, password_,
|
||||
target_file_name_, full_path_, password_,
|
||||
base::BindOnce(&DownloadRequestMaker::OnFileFeatureExtractionDone,
|
||||
weakptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class DownloadRequestMaker {
|
||||
scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor,
|
||||
content::BrowserContext* browser_context,
|
||||
TabUrls tab_urls,
|
||||
base::FilePath target_file_path,
|
||||
base::FilePath target_file_name,
|
||||
base::FilePath full_path,
|
||||
GURL source_url,
|
||||
std::string sha256_hash,
|
||||
@ -94,8 +94,13 @@ class DownloadRequestMaker {
|
||||
// referrer.
|
||||
TabUrls tab_urls_;
|
||||
|
||||
// The ultimate destination for the download.
|
||||
const base::FilePath target_file_path_;
|
||||
// The ultimate destination/filename for the download. This is used to
|
||||
// determine the filetype and populate request fields requiring a
|
||||
// human-readable filename. On platforms where the target file *path* does not
|
||||
// contain file name but is instead a different identifier (e.g. a content-URI
|
||||
// on Android), this should be populated with the file *name* i.e. a display
|
||||
// name for the download.
|
||||
const base::FilePath target_file_name_;
|
||||
|
||||
// The current path to the file contents.
|
||||
const base::FilePath full_path_;
|
||||
|
@ -45,9 +45,9 @@ TEST_F(DownloadRequestMakerTest, PopulatesUrl) {
|
||||
base::FilePath tmp_path(FILE_PATH_LITERAL("temp_path"));
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL("https://example.com/download"),
|
||||
/*hash=*/"",
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/0,
|
||||
/*resources=*/std::vector<ClientDownloadRequest::Resource>(),
|
||||
/*is_user_initiated=*/true,
|
||||
@ -80,9 +80,9 @@ TEST_F(DownloadRequestMakerTest, PopulatesHash) {
|
||||
base::FilePath tmp_path(FILE_PATH_LITERAL("temp_path"));
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*hash=*/"sha256_hash",
|
||||
/*sha256_hash=*/"sha256_hash",
|
||||
/*length=*/0,
|
||||
/*resources=*/std::vector<ClientDownloadRequest::Resource>(),
|
||||
/*is_user_initiated=*/true,
|
||||
@ -115,9 +115,9 @@ TEST_F(DownloadRequestMakerTest, PopulatesLength) {
|
||||
base::FilePath tmp_path(FILE_PATH_LITERAL("temp_path"));
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*hash=*/"",
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/123,
|
||||
/*resources=*/std::vector<ClientDownloadRequest::Resource>(),
|
||||
/*is_user_initiated=*/true,
|
||||
@ -162,9 +162,9 @@ TEST_F(DownloadRequestMakerTest, PopulatesResources) {
|
||||
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*hash=*/"",
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/0,
|
||||
/*resources=*/resources,
|
||||
/*is_user_initiated=*/true,
|
||||
@ -203,9 +203,9 @@ TEST_F(DownloadRequestMakerTest, PopulatesUserInitiated) {
|
||||
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*hash=*/"",
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/0,
|
||||
/*resources=*/std::vector<ClientDownloadRequest::Resource>(),
|
||||
/*is_user_initiated=*/true,
|
||||
@ -252,9 +252,9 @@ TEST_F(DownloadRequestMakerTest, PopulatesReferrerChain) {
|
||||
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*hash=*/"",
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/0,
|
||||
/*resources=*/std::vector<ClientDownloadRequest::Resource>(),
|
||||
/*is_user_initiated=*/true,
|
||||
@ -298,9 +298,9 @@ TEST_F(DownloadRequestMakerTest, PopulatesStandardProtection) {
|
||||
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*hash=*/"",
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/0,
|
||||
/*resources=*/std::vector<ClientDownloadRequest::Resource>(),
|
||||
/*is_user_initiated=*/true,
|
||||
@ -338,9 +338,9 @@ TEST_F(DownloadRequestMakerTest, PopulatesEnhancedProtection) {
|
||||
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*hash=*/"",
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/0,
|
||||
/*resources=*/std::vector<ClientDownloadRequest::Resource>(),
|
||||
/*is_user_initiated=*/true,
|
||||
@ -375,7 +375,7 @@ TEST_F(DownloadRequestMakerTest, PopulateTailoredInfo) {
|
||||
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_file_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/0,
|
||||
@ -410,10 +410,10 @@ TEST_F(DownloadRequestMakerTest, PopulatesFileBasename) {
|
||||
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(FILE_PATH_LITERAL("target_path.exe")),
|
||||
tmp_path,
|
||||
/*target_file_name=*/
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_name.exe")), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*hash=*/"",
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/0,
|
||||
/*resources=*/std::vector<ClientDownloadRequest::Resource>(),
|
||||
/*is_user_initiated=*/true,
|
||||
@ -438,7 +438,7 @@ TEST_F(DownloadRequestMakerTest, PopulatesFileBasename) {
|
||||
run_loop.Run();
|
||||
|
||||
ASSERT_NE(request, nullptr);
|
||||
EXPECT_EQ(request->file_basename(), "target_path.exe");
|
||||
EXPECT_EQ(request->file_basename(), "target_file_name.exe");
|
||||
}
|
||||
|
||||
TEST_F(DownloadRequestMakerTest, CreatesFromDownloadItem) {
|
||||
@ -451,9 +451,18 @@ TEST_F(DownloadRequestMakerTest, CreatesFromDownloadItem) {
|
||||
.WillOnce(ReturnRefOfCopy(GURL("https://example.com/tab_url")));
|
||||
EXPECT_CALL(mock_download_item, GetTabReferrerUrl())
|
||||
.WillOnce(ReturnRefOfCopy(GURL("https://example.com/tab_referrer_url")));
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
ON_CALL(mock_download_item, GetTargetFilePath())
|
||||
.WillByDefault(ReturnRefOfCopy(
|
||||
base::FilePath(FILE_PATH_LITERAL("content://media/123"))));
|
||||
EXPECT_CALL(mock_download_item, GetFileNameToReportUser())
|
||||
.WillOnce(
|
||||
Return(base::FilePath(FILE_PATH_LITERAL("target_file_name.exe"))));
|
||||
#else
|
||||
EXPECT_CALL(mock_download_item, GetTargetFilePath())
|
||||
.WillOnce(ReturnRefOfCopy(
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_path.exe"))));
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_name.exe"))));
|
||||
#endif
|
||||
EXPECT_CALL(mock_download_item, GetFullPath())
|
||||
.WillOnce(
|
||||
ReturnRefOfCopy(base::FilePath(FILE_PATH_LITERAL("full_path.exe"))));
|
||||
@ -496,6 +505,7 @@ TEST_F(DownloadRequestMakerTest, CreatesFromDownloadItem) {
|
||||
|
||||
ASSERT_NE(request, nullptr);
|
||||
EXPECT_EQ(request->url(), "https://example.com/url");
|
||||
EXPECT_EQ(request->file_basename(), "target_file_name.exe");
|
||||
EXPECT_EQ(request->digests().sha256(), "hash");
|
||||
EXPECT_EQ(request->resources_size(), 3);
|
||||
EXPECT_EQ(request->length(), 123);
|
||||
@ -504,7 +514,8 @@ TEST_F(DownloadRequestMakerTest, CreatesFromDownloadItem) {
|
||||
|
||||
TEST_F(DownloadRequestMakerTest, CreatesFromFileSystemAccess) {
|
||||
content::FileSystemAccessWriteItem item;
|
||||
item.target_file_path = base::FilePath(FILE_PATH_LITERAL("target_path.exe"));
|
||||
item.target_file_path =
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_name.exe"));
|
||||
item.full_path = base::FilePath(FILE_PATH_LITERAL("full_path.exe"));
|
||||
item.sha256_hash = "sha256_hash";
|
||||
item.size = 123;
|
||||
@ -552,9 +563,9 @@ TEST_F(DownloadRequestMakerTest, NotifiesCallback) {
|
||||
|
||||
DownloadRequestMaker request_maker(
|
||||
mock_feature_extractor_, &profile_, DownloadRequestMaker::TabUrls(),
|
||||
/*target_path=*/base::FilePath(), tmp_path,
|
||||
/*target_file_name=*/base::FilePath(), tmp_path,
|
||||
/*source_url=*/GURL(),
|
||||
/*hash=*/"",
|
||||
/*sha256_hash=*/"",
|
||||
/*length=*/0,
|
||||
/*resources=*/std::vector<ClientDownloadRequest::Resource>(),
|
||||
/*is_user_initiated=*/true,
|
||||
@ -598,7 +609,7 @@ TEST_F(DownloadRequestMakerTest, SetsIsEncrypted) {
|
||||
.WillOnce(ReturnRefOfCopy(GURL("https://example.com/tab_referrer_url")));
|
||||
EXPECT_CALL(mock_download_item, GetTargetFilePath())
|
||||
.WillOnce(ReturnRefOfCopy(
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_path.zip"))));
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_name.zip"))));
|
||||
EXPECT_CALL(mock_download_item, GetFullPath())
|
||||
.WillOnce(ReturnRefOfCopy(test_zip));
|
||||
EXPECT_CALL(mock_download_item, GetURL())
|
||||
@ -649,7 +660,7 @@ TEST_F(DownloadRequestMakerTest, UsesPassword) {
|
||||
.WillOnce(ReturnRefOfCopy(GURL("https://example.com/tab_referrer_url")));
|
||||
EXPECT_CALL(mock_download_item, GetTargetFilePath())
|
||||
.WillOnce(ReturnRefOfCopy(
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_path.zip"))));
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_name.zip"))));
|
||||
EXPECT_CALL(mock_download_item, GetFullPath())
|
||||
.WillOnce(ReturnRefOfCopy(test_zip));
|
||||
EXPECT_CALL(mock_download_item, GetURL())
|
||||
@ -701,7 +712,7 @@ TEST_F(DownloadRequestMakerTest, SetsFullyExtractedArchive) {
|
||||
.WillOnce(ReturnRefOfCopy(GURL("https://example.com/tab_referrer_url")));
|
||||
EXPECT_CALL(mock_download_item, GetTargetFilePath())
|
||||
.WillOnce(ReturnRefOfCopy(
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_path.zip"))));
|
||||
base::FilePath(FILE_PATH_LITERAL("target_file_name.zip"))));
|
||||
EXPECT_CALL(mock_download_item, GetFullPath())
|
||||
.WillOnce(ReturnRefOfCopy(test_zip));
|
||||
EXPECT_CALL(mock_download_item, GetURL())
|
||||
|
@ -55,13 +55,13 @@ FileAnalyzer::FileAnalyzer(
|
||||
|
||||
FileAnalyzer::~FileAnalyzer() = default;
|
||||
|
||||
void FileAnalyzer::Start(const base::FilePath& target_path,
|
||||
void FileAnalyzer::Start(const base::FilePath& target_file_name,
|
||||
const base::FilePath& tmp_path,
|
||||
base::optional_ref<const std::string> password,
|
||||
base::OnceCallback<void(Results)> callback) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
||||
target_path_ = target_path;
|
||||
target_file_name_ = target_file_name;
|
||||
tmp_path_ = tmp_path;
|
||||
password_ = password.CopyAsOptional();
|
||||
callback_ = std::move(callback);
|
||||
@ -70,7 +70,7 @@ void FileAnalyzer::Start(const base::FilePath& target_path,
|
||||
#if !BUILDFLAG(IS_ANDROID)
|
||||
DownloadFileType::InspectionType inspection_type =
|
||||
FileTypePolicies::GetInstance()
|
||||
->PolicyForFile(target_path_, GURL{}, nullptr)
|
||||
->PolicyForFile(target_file_name_, GURL{}, nullptr)
|
||||
.inspection_type();
|
||||
|
||||
if (inspection_type == DownloadFileType::ZIP) {
|
||||
@ -125,7 +125,7 @@ void FileAnalyzer::StartExtractFileFeatures() {
|
||||
|
||||
void FileAnalyzer::OnFileAnalysisFinished(FileAnalyzer::Results results) {
|
||||
LogAnalysisDurationWithAndWithoutSuffix("Executable");
|
||||
results.type = download_type_util::GetDownloadType(target_path_);
|
||||
results.type = download_type_util::GetDownloadType(target_file_name_);
|
||||
std::move(callback_).Run(results);
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ void FileAnalyzer::OnZipAnalysisFinished(
|
||||
// unpacked by other archive tools, so they may be a real threat.
|
||||
results_.type = ClientDownloadRequest::INVALID_ZIP;
|
||||
} else {
|
||||
results_.type = download_type_util::GetDownloadType(target_path_);
|
||||
results_.type = download_type_util::GetDownloadType(target_file_name_);
|
||||
}
|
||||
|
||||
results_.archive_summary.set_file_count(archive_results.file_count);
|
||||
@ -240,7 +240,7 @@ void FileAnalyzer::OnRarAnalysisFinished(
|
||||
// other archive tools, so they may be a real threat.
|
||||
results_.type = ClientDownloadRequest::INVALID_RAR;
|
||||
} else {
|
||||
results_.type = download_type_util::GetDownloadType(target_path_);
|
||||
results_.type = download_type_util::GetDownloadType(target_file_name_);
|
||||
}
|
||||
|
||||
results_.archive_summary.set_file_count(archive_results.file_count);
|
||||
@ -379,7 +379,7 @@ void FileAnalyzer::OnSevenZipAnalysisFinished(
|
||||
// unpacked by other archive tools, so they may be a real threat.
|
||||
results_.type = ClientDownloadRequest::INVALID_SEVEN_ZIP;
|
||||
} else {
|
||||
results_.type = download_type_util::GetDownloadType(target_path_);
|
||||
results_.type = download_type_util::GetDownloadType(target_file_name_);
|
||||
}
|
||||
|
||||
results_.archive_summary.set_file_count(archive_results.file_count);
|
||||
|
@ -86,7 +86,7 @@ class FileAnalyzer {
|
||||
explicit FileAnalyzer(
|
||||
scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor);
|
||||
~FileAnalyzer();
|
||||
void Start(const base::FilePath& target_path,
|
||||
void Start(const base::FilePath& target_file_name,
|
||||
const base::FilePath& tmp_path,
|
||||
base::optional_ref<const std::string> password,
|
||||
base::OnceCallback<void(Results)> callback);
|
||||
@ -118,8 +118,14 @@ class FileAnalyzer {
|
||||
|
||||
void LogAnalysisDurationWithAndWithoutSuffix(const std::string& suffix);
|
||||
|
||||
base::FilePath target_path_;
|
||||
// The ultimate destination/filename for the download. This is used to
|
||||
// determine the filetype from the filename extension/suffix, and should be a
|
||||
// human-readable filename (i.e. not a content-URI, on Android).
|
||||
base::FilePath target_file_name_;
|
||||
|
||||
// The current path to the file contents.
|
||||
base::FilePath tmp_path_;
|
||||
|
||||
std::optional<std::string> password_;
|
||||
scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_;
|
||||
base::OnceCallback<void(Results)> callback_;
|
||||
|
@ -68,7 +68,7 @@ TEST_F(FileAnalyzerTest, TypeWinExecutable) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.exe"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.exe"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -77,7 +77,7 @@ TEST_F(FileAnalyzerTest, TypeWinExecutable) {
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -92,7 +92,7 @@ TEST_F(FileAnalyzerTest, TypeChromeExtension) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.crx"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.crx"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -101,7 +101,7 @@ TEST_F(FileAnalyzerTest, TypeChromeExtension) {
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -116,7 +116,7 @@ TEST_F(FileAnalyzerTest, TypeAndroidApk) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.apk"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.apk"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -125,7 +125,7 @@ TEST_F(FileAnalyzerTest, TypeAndroidApk) {
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -142,7 +142,7 @@ TEST_F(FileAnalyzerTest, TypeZippedExecutable) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -156,7 +156,7 @@ TEST_F(FileAnalyzerTest, TypeZippedExecutable) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -172,7 +172,7 @@ TEST_F(FileAnalyzerTest, TypeMacExecutable) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.pkg"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.pkg"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -181,7 +181,7 @@ TEST_F(FileAnalyzerTest, TypeMacExecutable) {
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -198,7 +198,7 @@ TEST_F(FileAnalyzerTest, TypeZippedArchive) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -212,7 +212,7 @@ TEST_F(FileAnalyzerTest, TypeZippedArchive) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -227,7 +227,7 @@ TEST_F(FileAnalyzerTest, TypeInvalidZip) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -235,7 +235,7 @@ TEST_F(FileAnalyzerTest, TypeInvalidZip) {
|
||||
ASSERT_TRUE(base::WriteFile(tmp_path, file_contents));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -255,7 +255,7 @@ TEST_F(FileAnalyzerTest, TypeInvalidDmg) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.dmg"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.dmg"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -263,7 +263,7 @@ TEST_F(FileAnalyzerTest, TypeInvalidDmg) {
|
||||
ASSERT_TRUE(base::WriteFile(tmp_path, file_contents));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -283,7 +283,7 @@ TEST_F(FileAnalyzerTest, ArchiveIsValidSetForValidArchive) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -297,7 +297,7 @@ TEST_F(FileAnalyzerTest, ArchiveIsValidSetForValidArchive) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -313,7 +313,7 @@ TEST_F(FileAnalyzerTest, ArchiveIsValidSetForInvalidArchive) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -321,7 +321,7 @@ TEST_F(FileAnalyzerTest, ArchiveIsValidSetForInvalidArchive) {
|
||||
ASSERT_TRUE(base::WriteFile(tmp_path, file_contents));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -337,7 +337,7 @@ TEST_F(FileAnalyzerTest, ArchivedExecutableSetForZipWithExecutable) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -351,7 +351,7 @@ TEST_F(FileAnalyzerTest, ArchivedExecutableSetForZipWithExecutable) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -366,7 +366,7 @@ TEST_F(FileAnalyzerTest, ArchivedExecutableFalseForZipNoExecutable) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -380,7 +380,7 @@ TEST_F(FileAnalyzerTest, ArchivedExecutableFalseForZipNoExecutable) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -395,7 +395,7 @@ TEST_F(FileAnalyzerTest, ArchivedArchiveSetForZipWithArchive) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -409,7 +409,7 @@ TEST_F(FileAnalyzerTest, ArchivedArchiveSetForZipWithArchive) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -424,7 +424,7 @@ TEST_F(FileAnalyzerTest, ArchivedArchiveSetForZipNoArchive) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -438,7 +438,7 @@ TEST_F(FileAnalyzerTest, ArchivedArchiveSetForZipNoArchive) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -453,7 +453,7 @@ TEST_F(FileAnalyzerTest, ArchivedBinariesHasArchiveAndExecutable) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -470,7 +470,7 @@ TEST_F(FileAnalyzerTest, ArchivedBinariesHasArchiveAndExecutable) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -485,7 +485,7 @@ TEST_F(FileAnalyzerTest, ArchivedBinariesSkipsSafeFiles) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -499,7 +499,7 @@ TEST_F(FileAnalyzerTest, ArchivedBinariesSkipsSafeFiles) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -521,7 +521,7 @@ TEST_F(FileAnalyzerTest, ArchivedBinariesRespectsPolicyMaximum) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -538,7 +538,7 @@ TEST_F(FileAnalyzerTest, ArchivedBinariesRespectsPolicyMaximum) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -554,7 +554,7 @@ TEST_F(FileAnalyzerTest, ExtractsFileSignatureForExe) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.exe"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.exe"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -567,7 +567,7 @@ TEST_F(FileAnalyzerTest, ExtractsFileSignatureForExe) {
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -583,7 +583,7 @@ TEST_F(FileAnalyzerTest, ExtractsImageHeadersForExe) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.exe"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.exe"));
|
||||
base::FilePath tmp_path(FILE_PATH_LITERAL("tmp.exe"));
|
||||
|
||||
ClientDownloadRequest::ImageHeaders image_headers;
|
||||
@ -594,7 +594,7 @@ TEST_F(FileAnalyzerTest, ExtractsImageHeadersForExe) {
|
||||
.WillRepeatedly(DoAll(SetArgPointee<2>(image_headers), Return(true)));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -612,7 +612,7 @@ TEST_F(FileAnalyzerTest, ExtractsSignatureForDmg) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.dmg"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.dmg"));
|
||||
base::FilePath signed_dmg;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg));
|
||||
signed_dmg = signed_dmg.AppendASCII("safe_browsing")
|
||||
@ -620,7 +620,7 @@ TEST_F(FileAnalyzerTest, ExtractsSignatureForDmg) {
|
||||
.AppendASCII("signed-archive.dmg");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, signed_dmg, /*password=*/std::nullopt,
|
||||
target_file_name, signed_dmg, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -648,7 +648,7 @@ TEST_F(FileAnalyzerTest, TypeSniffsDmgWithoutExtension) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.dmg"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.dmg"));
|
||||
base::FilePath dmg_no_extension;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &dmg_no_extension));
|
||||
dmg_no_extension = dmg_no_extension.AppendASCII("safe_browsing")
|
||||
@ -657,7 +657,7 @@ TEST_F(FileAnalyzerTest, TypeSniffsDmgWithoutExtension) {
|
||||
.AppendASCII("mach_o_in_dmg.txt");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, dmg_no_extension, /*password=*/std::nullopt,
|
||||
target_file_name, dmg_no_extension, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -678,7 +678,7 @@ TEST_F(FileAnalyzerTest, SmallRarHasContentInspection) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("has_exe.rar"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("has_exe.rar"));
|
||||
base::FilePath rar_path;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &rar_path));
|
||||
rar_path = rar_path.AppendASCII("safe_browsing")
|
||||
@ -687,7 +687,7 @@ TEST_F(FileAnalyzerTest, SmallRarHasContentInspection) {
|
||||
|
||||
// Analyze the RAR with default size limit
|
||||
analyzer.Start(
|
||||
target_path, rar_path, /*password=*/std::nullopt,
|
||||
target_file_name, rar_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -720,7 +720,7 @@ TEST_F(FileAnalyzerTest, LargeRarSkipsContentInspection) {
|
||||
}
|
||||
overlay.SwapConfig(config);
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("has_exe.rar"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("has_exe.rar"));
|
||||
base::FilePath rar_path;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &rar_path));
|
||||
rar_path = rar_path.AppendASCII("safe_browsing")
|
||||
@ -728,7 +728,7 @@ TEST_F(FileAnalyzerTest, LargeRarSkipsContentInspection) {
|
||||
.AppendASCII("has_exe.rar");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, rar_path, /*password=*/std::nullopt,
|
||||
target_file_name, rar_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -746,7 +746,7 @@ TEST_F(FileAnalyzerTest, ZipFilesGetFileCount) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -761,7 +761,7 @@ TEST_F(FileAnalyzerTest, ZipFilesGetFileCount) {
|
||||
false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -777,7 +777,7 @@ TEST_F(FileAnalyzerTest, ZipFilesGetDirectoryCount) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -790,7 +790,7 @@ TEST_F(FileAnalyzerTest, ZipFilesGetDirectoryCount) {
|
||||
false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -806,7 +806,7 @@ TEST_F(FileAnalyzerTest, RarFilesGetFileCount) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("has_exe.rar"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("has_exe.rar"));
|
||||
base::FilePath rar_path;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &rar_path));
|
||||
rar_path = rar_path.AppendASCII("safe_browsing")
|
||||
@ -814,7 +814,7 @@ TEST_F(FileAnalyzerTest, RarFilesGetFileCount) {
|
||||
.AppendASCII("has_exe.rar");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, rar_path, /*password=*/std::nullopt,
|
||||
target_file_name, rar_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -830,7 +830,7 @@ TEST_F(FileAnalyzerTest, RarFilesGetDirectoryCount) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("has_folder.rar"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("has_folder.rar"));
|
||||
base::FilePath rar_path;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &rar_path));
|
||||
rar_path = rar_path.AppendASCII("safe_browsing")
|
||||
@ -838,7 +838,7 @@ TEST_F(FileAnalyzerTest, RarFilesGetDirectoryCount) {
|
||||
.AppendASCII("has_folder.rar");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, rar_path, /*password=*/std::nullopt,
|
||||
target_file_name, rar_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -865,7 +865,7 @@ TEST_F(FileAnalyzerTest, LargeZipSkipsContentInspection) {
|
||||
}
|
||||
overlay.SwapConfig(config);
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -879,7 +879,7 @@ TEST_F(FileAnalyzerTest, LargeZipSkipsContentInspection) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -898,7 +898,7 @@ TEST_F(FileAnalyzerTest, ZipAnalysisResultMetric) {
|
||||
base::HistogramTester histogram_tester;
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.zip"));
|
||||
base::FilePath tmp_path =
|
||||
temp_dir_.GetPath().Append(FILE_PATH_LITERAL("tmp.crdownload"));
|
||||
|
||||
@ -912,7 +912,7 @@ TEST_F(FileAnalyzerTest, ZipAnalysisResultMetric) {
|
||||
/* include_hidden_files= */ false));
|
||||
|
||||
analyzer.Start(
|
||||
target_path, tmp_path, /*password=*/std::nullopt,
|
||||
target_file_name, tmp_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -930,7 +930,7 @@ TEST_F(FileAnalyzerTest, RarAnalysisResultMetric) {
|
||||
base::HistogramTester histogram_tester;
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("has_exe.rar"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("has_exe.rar"));
|
||||
base::FilePath rar_path;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &rar_path));
|
||||
rar_path = rar_path.AppendASCII("safe_browsing")
|
||||
@ -938,7 +938,7 @@ TEST_F(FileAnalyzerTest, RarAnalysisResultMetric) {
|
||||
.AppendASCII("has_exe.rar");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, rar_path, /*password=*/std::nullopt,
|
||||
target_file_name, rar_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
|
||||
@ -958,7 +958,7 @@ TEST_F(FileAnalyzerTest, DmgAnalysisResultMetric) {
|
||||
base::HistogramTester histogram_tester;
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("target.dmg"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("target.dmg"));
|
||||
base::FilePath signed_dmg;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &signed_dmg));
|
||||
signed_dmg = signed_dmg.AppendASCII("safe_browsing")
|
||||
@ -966,7 +966,7 @@ TEST_F(FileAnalyzerTest, DmgAnalysisResultMetric) {
|
||||
.AppendASCII("signed-archive.dmg");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, signed_dmg, /*password=*/std::nullopt,
|
||||
target_file_name, signed_dmg, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
|
||||
@ -985,7 +985,7 @@ TEST_F(FileAnalyzerTest, EncryptedEntriesDoNotHaveHashOrLength) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("encrypted.zip"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("encrypted.zip"));
|
||||
base::FilePath zip_path;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &zip_path));
|
||||
zip_path = zip_path.AppendASCII("safe_browsing")
|
||||
@ -993,7 +993,7 @@ TEST_F(FileAnalyzerTest, EncryptedEntriesDoNotHaveHashOrLength) {
|
||||
.AppendASCII("encrypted.zip");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, zip_path, /*password=*/std::nullopt,
|
||||
target_file_name, zip_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -1011,7 +1011,7 @@ TEST_F(FileAnalyzerTest, RarDirectoriesNotReported) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("file_and_folder.rar"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("file_and_folder.rar"));
|
||||
base::FilePath rar_path;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &rar_path));
|
||||
rar_path = rar_path.AppendASCII("safe_browsing")
|
||||
@ -1019,7 +1019,7 @@ TEST_F(FileAnalyzerTest, RarDirectoriesNotReported) {
|
||||
.AppendASCII("file_and_folder.rar");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, rar_path, /*password=*/std::nullopt,
|
||||
target_file_name, rar_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
@ -1037,7 +1037,7 @@ TEST_F(FileAnalyzerTest, ZeroLengthSevenZipEntriesSupported) {
|
||||
FileAnalyzer analyzer(extractor);
|
||||
base::RunLoop run_loop;
|
||||
|
||||
base::FilePath target_path(FILE_PATH_LITERAL("file_and_empty.7z"));
|
||||
base::FilePath target_file_name(FILE_PATH_LITERAL("file_and_empty.7z"));
|
||||
base::FilePath sevenz_path;
|
||||
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &sevenz_path));
|
||||
sevenz_path = sevenz_path.AppendASCII("safe_browsing")
|
||||
@ -1045,7 +1045,7 @@ TEST_F(FileAnalyzerTest, ZeroLengthSevenZipEntriesSupported) {
|
||||
.AppendASCII("file_and_empty.7z");
|
||||
|
||||
analyzer.Start(
|
||||
target_path, sevenz_path, /*password=*/std::nullopt,
|
||||
target_file_name, sevenz_path, /*password=*/std::nullopt,
|
||||
base::BindOnce(&FileAnalyzerTest::DoneCallback, base::Unretained(this),
|
||||
run_loop.QuitClosure()));
|
||||
run_loop.Run();
|
||||
|
@ -4,28 +4,26 @@
|
||||
|
||||
#include "chrome/common/safe_browsing/download_type_util.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/feature_list.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "components/safe_browsing/content/common/file_type_policies.h"
|
||||
#include "components/safe_browsing/core/common/features.h"
|
||||
|
||||
namespace safe_browsing {
|
||||
namespace download_type_util {
|
||||
|
||||
ClientDownloadRequest::DownloadType GetDownloadType(
|
||||
const base::FilePath& file) {
|
||||
base::FilePath::StringType ext = file.Extension();
|
||||
const base::FilePath& file_name) {
|
||||
base::FilePath::StringType ext = file_name.Extension();
|
||||
|
||||
// TODO(nparker): Put all of this logic into the FileTypePolicies
|
||||
// protobuf.
|
||||
if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".apk")))
|
||||
if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".apk"))) {
|
||||
return ClientDownloadRequest::ANDROID_APK;
|
||||
else if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".crx")))
|
||||
}
|
||||
if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".crx"))) {
|
||||
return ClientDownloadRequest::CHROME_EXTENSION;
|
||||
else if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".zip")))
|
||||
}
|
||||
if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".zip"))) {
|
||||
// DownloadProtectionService doesn't send a ClientDownloadRequest for ZIP
|
||||
// files unless they contain either executables or archives. The resulting
|
||||
// DownloadType is either ZIPPED_EXECUTABLE or ZIPPED_ARCHIVE respectively.
|
||||
@ -33,73 +31,77 @@ ClientDownloadRequest::DownloadType GetDownloadType(
|
||||
// placeholder. The correct DownloadType will be determined based on the
|
||||
// result of analyzing the ZIP file.
|
||||
return ClientDownloadRequest::ZIPPED_EXECUTABLE;
|
||||
else if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".rar")))
|
||||
}
|
||||
if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".rar"))) {
|
||||
// See the comment for .zip files.
|
||||
return ClientDownloadRequest::RAR_COMPRESSED_EXECUTABLE;
|
||||
else if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dmg")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".img")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".iso")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pkg")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".mpkg")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".smi")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".app")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".cdr")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext,
|
||||
FILE_PATH_LITERAL(".dmgpart")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dvdr")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dart")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dc42")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext,
|
||||
FILE_PATH_LITERAL(".diskcopy42")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext,
|
||||
FILE_PATH_LITERAL(".imgpart")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ndif")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".udif")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".toast")) ||
|
||||
base::EqualsCaseInsensitiveASCII(
|
||||
ext, FILE_PATH_LITERAL(".sparsebundle")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext,
|
||||
FILE_PATH_LITERAL(".sparseimage")))
|
||||
}
|
||||
if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dmg")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".img")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".iso")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pkg")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".mpkg")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".smi")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".app")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".cdr")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dmgpart")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dvdr")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dart")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dc42")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".diskcopy42")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".imgpart")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ndif")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".udif")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".toast")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext,
|
||||
FILE_PATH_LITERAL(".sparsebundle")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext,
|
||||
FILE_PATH_LITERAL(".sparseimage"))) {
|
||||
return ClientDownloadRequest::MAC_EXECUTABLE;
|
||||
else if (FileTypePolicies::GetInstance()->IsArchiveFile(file))
|
||||
}
|
||||
if (FileTypePolicies::GetInstance()->IsArchiveFile(file_name)) {
|
||||
return ClientDownloadRequest::ARCHIVE;
|
||||
else if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pdf")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".doc")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".docx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".docm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".docb")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dot")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dotm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dotx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xls")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlsb")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlt")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlsx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xldm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xltx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xltm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xla")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlam")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xll")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlw")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ppt")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pot")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pps")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pptx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pptm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".potx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".potm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ppam")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ppsx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ppsm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".sldx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".rtf")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".wll")))
|
||||
}
|
||||
if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pdf")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".doc")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".docx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".docm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".docb")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dot")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dotm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".dotx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xls")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlsb")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlt")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlsx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xldm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xltx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xltm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xla")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlam")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xll")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".xlw")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ppt")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pot")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pps")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pptx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".pptm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".potx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".potm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ppam")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ppsx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".ppsm")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".sldx")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".rtf")) ||
|
||||
base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".wll"))) {
|
||||
return ClientDownloadRequest::DOCUMENT;
|
||||
else if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".7z")))
|
||||
}
|
||||
if (base::EqualsCaseInsensitiveASCII(ext, FILE_PATH_LITERAL(".7z"))) {
|
||||
return ClientDownloadRequest::SEVEN_ZIP_COMPRESSED_EXECUTABLE;
|
||||
}
|
||||
|
||||
// TODO(chlily): There should be a separate unspecified/default value.
|
||||
return ClientDownloadRequest::WIN_EXECUTABLE;
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,11 @@
|
||||
namespace safe_browsing {
|
||||
namespace download_type_util {
|
||||
|
||||
// Returns the DownloadType of the file at |path|. This function is only valid
|
||||
// for paths that satisfy IsSupportedBinaryFile() above.
|
||||
ClientDownloadRequest::DownloadType GetDownloadType(const base::FilePath& file);
|
||||
// Returns the DownloadType of the file named `file_name`, based on the filename
|
||||
// extension. `file_name` should be a human-readable file name and not e.g. a
|
||||
// content-URI.
|
||||
ClientDownloadRequest::DownloadType GetDownloadType(
|
||||
const base::FilePath& file_name);
|
||||
|
||||
} // namespace download_type_util
|
||||
} // namespace safe_browsing
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace safe_browsing {
|
||||
namespace download_type_util {
|
||||
|
||||
TEST(DownloadProtectionUtilTest, KnownValues) {
|
||||
TEST(DownloadTypeUtilTest, KnownValues) {
|
||||
EXPECT_EQ(ClientDownloadRequest::WIN_EXECUTABLE,
|
||||
GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.exe"))));
|
||||
EXPECT_EQ(ClientDownloadRequest::CHROME_EXTENSION,
|
||||
@ -27,5 +27,16 @@ TEST(DownloadProtectionUtilTest, KnownValues) {
|
||||
GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.apk"))));
|
||||
}
|
||||
|
||||
TEST(DownloadTypeUtilTest, UnknownValues) {
|
||||
// TODO(chlily): There should be a separate unspecified/default value.
|
||||
EXPECT_EQ(ClientDownloadRequest::WIN_EXECUTABLE,
|
||||
GetDownloadType(base::FilePath(FILE_PATH_LITERAL("blah"))));
|
||||
EXPECT_EQ(ClientDownloadRequest::WIN_EXECUTABLE,
|
||||
GetDownloadType(base::FilePath(FILE_PATH_LITERAL("foo.unknown"))));
|
||||
EXPECT_EQ(ClientDownloadRequest::WIN_EXECUTABLE,
|
||||
GetDownloadType(
|
||||
base::FilePath(FILE_PATH_LITERAL("content://media/123"))));
|
||||
}
|
||||
|
||||
} // namespace download_type_util
|
||||
} // namespace safe_browsing
|
||||
|
Reference in New Issue
Block a user