Commit e68816e2 authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Fix FILE_ENCRYPTED usage on Deep Scanning upload

This result now records metrics and events correctly instead of passing
as a SUCCESS result.

Bug: 1049712
Change-Id: Ic104d271e53c13d0b78942dfb57effe59e1ef522
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2042216Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740727}
parent 6ce1d218
...@@ -170,6 +170,12 @@ std::string GetFileMimeType(base::FilePath path) { ...@@ -170,6 +170,12 @@ std::string GetFileMimeType(base::FilePath path) {
return mime_type; return mime_type;
} }
bool AllowEncryptedFiles() {
int state = g_browser_process->local_state()->GetInteger(
prefs::kAllowPasswordProtectedFiles);
return state == ALLOW_UPLOADS || state == ALLOW_UPLOADS_AND_DOWNLOADS;
}
} // namespace } // namespace
// A BinaryUploadService::Request implementation that gets the data to scan // A BinaryUploadService::Request implementation that gets the data to scan
...@@ -269,8 +275,9 @@ bool DeepScanningDialogDelegate::ResultShouldAllowDataUse( ...@@ -269,8 +275,9 @@ bool DeepScanningDialogDelegate::ResultShouldAllowDataUse(
return true; return true;
case BinaryUploadService::Result::FILE_TOO_LARGE: case BinaryUploadService::Result::FILE_TOO_LARGE:
case BinaryUploadService::Result::FILE_ENCRYPTED:
return false; return false;
case BinaryUploadService::Result::FILE_ENCRYPTED:
return AllowEncryptedFiles();
} }
} }
...@@ -555,13 +562,8 @@ void DeepScanningDialogDelegate::AnalyzerCallback( ...@@ -555,13 +562,8 @@ void DeepScanningDialogDelegate::AnalyzerCallback(
// If the file contains encrypted parts and the user is not allowed to use // If the file contains encrypted parts and the user is not allowed to use
// them, fail the request. // them, fail the request.
if (contains_encrypted_parts) { if (contains_encrypted_parts) {
int state = g_browser_process->local_state()->GetInteger( FileRequestCallback(data_.paths[index],
prefs::kAllowPasswordProtectedFiles); BinaryUploadService::Result::FILE_ENCRYPTED,
BinaryUploadService::Result result =
state == ALLOW_UPLOADS || state == ALLOW_UPLOADS_AND_DOWNLOADS
? BinaryUploadService::Result::SUCCESS
: BinaryUploadService::Result::FILE_ENCRYPTED;
FileRequestCallback(data_.paths[index], result,
DeepScanningClientResponse()); DeepScanningClientResponse());
return; return;
} }
......
...@@ -127,6 +127,8 @@ class BaseTest : public testing::Test { ...@@ -127,6 +127,8 @@ class BaseTest : public testing::Test {
TestingProfile* profile_; TestingProfile* profile_;
}; };
} // namespace
using DeepScanningDialogDelegateIsEnabledTest = BaseTest; using DeepScanningDialogDelegateIsEnabledTest = BaseTest;
TEST_F(DeepScanningDialogDelegateIsEnabledTest, NoFeatureNoDMTokenNoPref) { TEST_F(DeepScanningDialogDelegateIsEnabledTest, NoFeatureNoDMTokenNoPref) {
...@@ -1433,6 +1435,28 @@ INSTANTIATE_TEST_SUITE_P( ...@@ -1433,6 +1435,28 @@ INSTANTIATE_TEST_SUITE_P(
BinaryUploadService::Result::UNAUTHORIZED, BinaryUploadService::Result::UNAUTHORIZED,
BinaryUploadService::Result::FILE_ENCRYPTED)); BinaryUploadService::Result::FILE_ENCRYPTED));
} // namespace using DeepScanningDialogDelegatePolicyResultsTest = BaseTest;
TEST_F(DeepScanningDialogDelegatePolicyResultsTest,
AllowPasswordProtectedFiles) {
// The value returned by ResultShouldAllowDataUse for FILE_ENCRYPTED should
// match the AllowPasswordProtectedFiles policy.
SetAllowPasswordPolicy(
AllowPasswordProtectedFilesValues::ALLOW_UPLOADS_AND_DOWNLOADS);
EXPECT_TRUE(DeepScanningDialogDelegate::ResultShouldAllowDataUse(
BinaryUploadService::Result::FILE_ENCRYPTED));
SetAllowPasswordPolicy(AllowPasswordProtectedFilesValues::ALLOW_DOWNLOADS);
EXPECT_FALSE(DeepScanningDialogDelegate::ResultShouldAllowDataUse(
BinaryUploadService::Result::FILE_ENCRYPTED));
SetAllowPasswordPolicy(AllowPasswordProtectedFilesValues::ALLOW_UPLOADS);
EXPECT_TRUE(DeepScanningDialogDelegate::ResultShouldAllowDataUse(
BinaryUploadService::Result::FILE_ENCRYPTED));
SetAllowPasswordPolicy(AllowPasswordProtectedFilesValues::ALLOW_NONE);
EXPECT_FALSE(DeepScanningDialogDelegate::ResultShouldAllowDataUse(
BinaryUploadService::Result::FILE_ENCRYPTED));
}
} // namespace safe_browsing } // namespace safe_browsing
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment