| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include <wininet.h> | 7 #include <wininet.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // internet zone. | 61 // internet zone. |
| 62 TEST(QuarantineWinTest, LocalFile_DependsOnLocalConfig) { | 62 TEST(QuarantineWinTest, LocalFile_DependsOnLocalConfig) { |
| 63 base::HistogramTester histogram_tester; | 63 base::HistogramTester histogram_tester; |
| 64 base::ScopedTempDir test_dir; | 64 base::ScopedTempDir test_dir; |
| 65 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); | 65 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); |
| 66 base::FilePath test_file = test_dir.GetPath().AppendASCII("foo.exe"); | 66 base::FilePath test_file = test_dir.GetPath().AppendASCII("foo.exe"); |
| 67 | 67 |
| 68 const char* const kLocalSourceURLs[] = {"http://localhost/foo", | 68 const char* const kLocalSourceURLs[] = {"http://localhost/foo", |
| 69 "file:///C:/some-local-dir/foo.exe"}; | 69 "file:///C:/some-local-dir/foo.exe"}; |
| 70 | 70 |
| 71 for (const auto source_url : kLocalSourceURLs) { | 71 for (const char* source_url : kLocalSourceURLs) { |
| 72 SCOPED_TRACE(::testing::Message() << "Trying URL " << source_url); | 72 SCOPED_TRACE(::testing::Message() << "Trying URL " << source_url); |
| 73 ASSERT_EQ(static_cast<int>(arraysize(kTestData)), | 73 ASSERT_EQ(static_cast<int>(arraysize(kTestData)), |
| 74 base::WriteFile(test_file, kTestData, arraysize(kTestData))); | 74 base::WriteFile(test_file, kTestData, arraysize(kTestData))); |
| 75 | 75 |
| 76 EXPECT_EQ( | 76 EXPECT_EQ( |
| 77 QuarantineFileResult::OK, | 77 QuarantineFileResult::OK, |
| 78 QuarantineFile(test_file, GURL(source_url), GURL(), kDummyClientGuid)); | 78 QuarantineFile(test_file, GURL(source_url), GURL(), kDummyClientGuid)); |
| 79 | 79 |
| 80 std::string motw_contents; | 80 std::string motw_contents; |
| 81 base::ReadFileToString( | 81 base::ReadFileToString( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 101 // A file downloaded from the internet should be annotated with .. something. | 101 // A file downloaded from the internet should be annotated with .. something. |
| 102 // The specific zone assigned to our dummy source URL depends on the local | 102 // The specific zone assigned to our dummy source URL depends on the local |
| 103 // configuration. But no sane configuration should be treating the dummy URL as | 103 // configuration. But no sane configuration should be treating the dummy URL as |
| 104 // a trusted source for anything. | 104 // a trusted source for anything. |
| 105 TEST(QuarantineWinTest, DownloadedFile_DependsOnLocalConfig) { | 105 TEST(QuarantineWinTest, DownloadedFile_DependsOnLocalConfig) { |
| 106 base::HistogramTester histogram_tester; | 106 base::HistogramTester histogram_tester; |
| 107 base::ScopedTempDir test_dir; | 107 base::ScopedTempDir test_dir; |
| 108 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); | 108 ASSERT_TRUE(test_dir.CreateUniqueTempDir()); |
| 109 base::FilePath test_file = test_dir.GetPath().AppendASCII("foo.exe"); | 109 base::FilePath test_file = test_dir.GetPath().AppendASCII("foo.exe"); |
| 110 | 110 |
| 111 for (const auto source_url : kUntrustedURLs) { | 111 for (const char* source_url : kUntrustedURLs) { |
| 112 SCOPED_TRACE(::testing::Message() << "Trying URL " << source_url); | 112 SCOPED_TRACE(::testing::Message() << "Trying URL " << source_url); |
| 113 ASSERT_EQ(static_cast<int>(arraysize(kTestData)), | 113 ASSERT_EQ(static_cast<int>(arraysize(kTestData)), |
| 114 base::WriteFile(test_file, kTestData, arraysize(kTestData))); | 114 base::WriteFile(test_file, kTestData, arraysize(kTestData))); |
| 115 EXPECT_EQ( | 115 EXPECT_EQ( |
| 116 QuarantineFileResult::OK, | 116 QuarantineFileResult::OK, |
| 117 QuarantineFile(test_file, GURL(source_url), GURL(), kDummyClientGuid)); | 117 QuarantineFile(test_file, GURL(source_url), GURL(), kDummyClientGuid)); |
| 118 std::string motw_contents; | 118 std::string motw_contents; |
| 119 ASSERT_TRUE(base::ReadFileToString( | 119 ASSERT_TRUE(base::ReadFileToString( |
| 120 base::FilePath(test_file.value() + kMotwStreamSuffix), &motw_contents)); | 120 base::FilePath(test_file.value() + kMotwStreamSuffix), &motw_contents)); |
| 121 // The actual assigned zone could be anything. So only testing that there is | 121 // The actual assigned zone could be anything. So only testing that there is |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 EXPECT_EQ(QuarantineFileResult::OK, | 254 EXPECT_EQ(QuarantineFileResult::OK, |
| 255 QuarantineFile(test_file, GURL(source_url), GURL(), std::string())); | 255 QuarantineFile(test_file, GURL(source_url), GURL(), std::string())); |
| 256 | 256 |
| 257 std::string motw_contents; | 257 std::string motw_contents; |
| 258 ASSERT_TRUE(base::ReadFileToString( | 258 ASSERT_TRUE(base::ReadFileToString( |
| 259 base::FilePath(test_file.value() + kMotwStreamSuffix), &motw_contents)); | 259 base::FilePath(test_file.value() + kMotwStreamSuffix), &motw_contents)); |
| 260 EXPECT_STREQ(kMotwForInternetZone, motw_contents.c_str()); | 260 EXPECT_STREQ(kMotwForInternetZone, motw_contents.c_str()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 } // content | 263 } // content |
| OLD | NEW |