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

Unified Diff: content/browser/download/quarantine_win_unittest.cc

Issue 2025103002: Use better fallback URLs when calling AVScanFile(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Catch up with upstream changes. Created 4 years, 5 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 | « content/browser/download/quarantine_win.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/quarantine_win_unittest.cc
diff --git a/content/browser/download/quarantine_win_unittest.cc b/content/browser/download/quarantine_win_unittest.cc
index 14b88154e94ce5f7734fef9f793741117f081827..81a11f925860fb588515c1c35cb08a4e78b9addd 100644
--- a/content/browser/download/quarantine_win_unittest.cc
+++ b/content/browser/download/quarantine_win_unittest.cc
@@ -41,23 +41,46 @@ TEST(QuarantineWinTest, MissingFile) {
// verifies this behavior since the other tests in this suite would pass with a
// false positive if local files are being annotated with the MOTW for the
// internet zone.
-TEST(QuarantineWinTest, LocalFileZoneAssumption_DependsOnLocalConfig) {
+TEST(QuarantineWinTest, LocalFile_DependsOnLocalConfig) {
base::HistogramTester histogram_tester;
base::ScopedTempDir test_dir;
ASSERT_TRUE(test_dir.CreateUniqueTempDir());
base::FilePath test_file = test_dir.path().AppendASCII("foo.exe");
- ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u));
- EXPECT_EQ(QuarantineFileResult::OK,
- QuarantineFile(test_file, net::FilePathToFileURL(test_file), GURL(),
- kDummyClientGuid));
- std::string contents;
- EXPECT_FALSE(base::ReadFileToString(
- base::FilePath(test_file.value() + kMotwStreamSuffix), &contents));
+ const char* const kLocalSourceURLs[] = {
+ "http://localhost/foo",
+ "data:text/plain,Foobar",
+ "data:application/octet-stream,Foobar",
+ "file:///some-local-dir/foo.exe"
+ };
+
+ for (const auto source_url : kLocalSourceURLs) {
+ SCOPED_TRACE(::testing::Message() << "Trying URL " << source_url);
+ ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u));
+
+ EXPECT_EQ(
+ QuarantineFileResult::OK,
+ QuarantineFile(test_file, GURL(source_url), GURL(), kDummyClientGuid));
+
+ std::string contents;
+ base::ReadFileToString(
+ base::FilePath(test_file.value() + kMotwStreamSuffix), &contents);
+
+ // These warnings aren't displayed on successful test runs. They are there
+ // so that we can check for deviations in behavior during manual testing.
+ if (!contents.empty()) {
+ LOG(WARNING) << "Unexpected zone marker for file " << test_file.value()
+ << " Source URL:" << source_url;
+ if (contents != kMotwForInternetZone)
+ LOG(WARNING) << "Zone marker contents: " << contents;
+ }
+
+ base::DeleteFile(test_file, false);
+ }
// Bucket 1 is SUCCESS_WITHOUT_MOTW.
histogram_tester.ExpectUniqueSample("Download.AttachmentServices.Result", 1,
- 1);
+ arraysize(kLocalSourceURLs));
}
// A file downloaded from the internet should be annotated with .. something.
@@ -69,11 +92,52 @@ TEST(QuarantineWinTest, DownloadedFile_DependsOnLocalConfig) {
base::ScopedTempDir test_dir;
ASSERT_TRUE(test_dir.CreateUniqueTempDir());
base::FilePath test_file = test_dir.path().AppendASCII("foo.exe");
+
+ const char* const kUnsafeSourceURLs[] = {
+ "http://example.com/foo",
+ "https://exmaple.com/foo",
elawrence 2016/08/02 21:09:22 I *think* "exmaple" is a harmless typo, but maybe
asanka 2016/09/23 01:34:53 Fixed :)
+ "ftp://example.com/foo",
+ "ftp://example.com:2121/foo",
+ "about:internet",
+ ""
+ };
+
+ for (const auto source_url : kUnsafeSourceURLs) {
+ SCOPED_TRACE(::testing::Message() << "Trying URL " << source_url);
+ ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u));
+ EXPECT_EQ(
+ QuarantineFileResult::OK,
+ QuarantineFile(test_file, GURL(source_url), GURL(), kDummyClientGuid));
+ std::string contents;
+ ASSERT_TRUE(base::ReadFileToString(
+ base::FilePath(test_file.value() + kMotwStreamSuffix), &contents));
+ // The actual assigned zone could be anything. So only testing that there is
+ // a zone annotation.
+ EXPECT_FALSE(contents.empty());
+
+ // These warnings aren't displayed on successful test runs. They are there
+ // so that we can check for deviations in behavior during manual testing.
+ if (contents != kMotwForInternetZone)
+ LOG(WARNING) << "Unexpected zone marker: " << contents;
+ base::DeleteFile(test_file, false);
+ }
+
+ // Bucket 0 is SUCCESS_WITH_MOTW.
+ histogram_tester.ExpectUniqueSample("Download.AttachmentServices.Result", 0,
+ arraysize(kUnsafeSourceURLs));
+}
+
+// An empty source URL should result in a file that's treated the same as one
+// downloaded from the internet.
+TEST(QuarantineWinTest, EmptySource_DependsOnLocalConfig) {
+ base::HistogramTester histogram_tester;
+ base::ScopedTempDir test_dir;
+ ASSERT_TRUE(test_dir.CreateUniqueTempDir());
+ base::FilePath test_file = test_dir.path().AppendASCII("foo.exe");
ASSERT_EQ(5, base::WriteFile(test_file, "Hello", 5u));
EXPECT_EQ(QuarantineFileResult::OK,
- QuarantineFile(test_file, GURL(kDummySourceUrl),
- GURL(kDummyReferrerUrl), kDummyClientGuid));
+ QuarantineFile(test_file, GURL(), GURL(), kDummyClientGuid));
std::string contents;
ASSERT_TRUE(base::ReadFileToString(
base::FilePath(test_file.value() + kMotwStreamSuffix), &contents));
« no previous file with comments | « content/browser/download/quarantine_win.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698