OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/safe_browsing/environment_data_collection_win.h" | 5 #include "chrome/browser/safe_browsing/environment_data_collection_win.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "base/base_paths.h" |
9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/path_service.h" |
10 #include "base/scoped_native_library.h" | 12 #include "base/scoped_native_library.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/test_reg_util_win.h" |
| 15 #include "base/win/registry.h" |
| 16 #include "chrome/browser/safe_browsing/path_sanitizer.h" |
11 #include "chrome/common/safe_browsing/csd.pb.h" | 17 #include "chrome/common/safe_browsing/csd.pb.h" |
| 18 #include "chrome_elf/chrome_elf_constants.h" |
12 #include "net/base/winsock_init.h" | 19 #include "net/base/winsock_init.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
14 | 21 |
15 namespace { | 22 namespace { |
16 | 23 |
| 24 const wchar_t test_dll[] = L"test_name.dll"; |
| 25 |
17 // Helper function that returns true if a dll with filename |dll_name| is | 26 // Helper function that returns true if a dll with filename |dll_name| is |
18 // found in |process_report|. | 27 // found in |process_report|. |
19 bool ProcessReportContainsDll( | 28 bool ProcessReportContainsDll( |
20 const safe_browsing::ClientIncidentReport_EnvironmentData_Process& | 29 const safe_browsing::ClientIncidentReport_EnvironmentData_Process& |
21 process_report, | 30 process_report, |
22 const base::FilePath& dll_name) { | 31 const base::FilePath& dll_name) { |
23 for (int i = 0; i < process_report.dll_size(); ++i) { | 32 for (int i = 0; i < process_report.dll_size(); ++i) { |
24 base::FilePath current_dll = | 33 base::FilePath current_dll = |
25 base::FilePath::FromUTF8Unsafe(process_report.dll(i).path()); | 34 base::FilePath::FromUTF8Unsafe(process_report.dll(i).path()); |
26 | 35 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 if (process_report.dll(i).feature(j) == | 117 if (process_report.dll(i).feature(j) == |
109 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll:: | 118 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll:: |
110 LSP) | 119 LSP) |
111 lsp_feature_found = true; | 120 lsp_feature_found = true; |
112 } | 121 } |
113 } | 122 } |
114 } | 123 } |
115 | 124 |
116 ASSERT_TRUE(lsp_feature_found); | 125 ASSERT_TRUE(lsp_feature_found); |
117 } | 126 } |
| 127 |
| 128 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, CollectDllBlacklistData) { |
| 129 // Ensure that CollectDllBlacklistData correctly adds the set of sanitized dll |
| 130 // names currently stored in the registry to the report. |
| 131 registry_util::RegistryOverrideManager override_manager; |
| 132 override_manager.OverrideRegistry(HKEY_CURRENT_USER, L"safe_browsing_test"); |
| 133 |
| 134 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER, |
| 135 blacklist::kRegistryFinchListPath, |
| 136 KEY_QUERY_VALUE | KEY_SET_VALUE); |
| 137 |
| 138 // Check that with an empty registry the blacklisted dlls field is left empty. |
| 139 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report; |
| 140 safe_browsing::CollectDllBlacklistData(&process_report); |
| 141 EXPECT_EQ(0, process_report.blacklisted_dll_size()); |
| 142 |
| 143 // Check that after adding exactly one dll to the registry it appears in the |
| 144 // process report. |
| 145 blacklist_registry_key.WriteValue(test_dll, test_dll); |
| 146 safe_browsing::CollectDllBlacklistData(&process_report); |
| 147 ASSERT_EQ(1, process_report.blacklisted_dll_size()); |
| 148 |
| 149 base::string16 process_report_dll = |
| 150 base::UTF8ToWide(process_report.blacklisted_dll(0)); |
| 151 EXPECT_EQ(base::string16(test_dll), process_report_dll); |
| 152 |
| 153 // Check that if the registry contains the full path to a dll it is properly |
| 154 // sanitized before being reported. |
| 155 blacklist_registry_key.DeleteValue(test_dll); |
| 156 process_report.clear_blacklisted_dll(); |
| 157 |
| 158 base::FilePath path; |
| 159 ASSERT_TRUE(PathService::Get(base::DIR_HOME, &path)); |
| 160 base::string16 input_path = |
| 161 path.Append(FILE_PATH_LITERAL("test_path.dll")).value(); |
| 162 |
| 163 std::string path_expected = base::FilePath(FILE_PATH_LITERAL("~")) |
| 164 .Append(FILE_PATH_LITERAL("test_path.dll")) |
| 165 .AsUTF8Unsafe(); |
| 166 |
| 167 blacklist_registry_key.WriteValue(input_path.c_str(), input_path.c_str()); |
| 168 safe_browsing::CollectDllBlacklistData(&process_report); |
| 169 |
| 170 ASSERT_EQ(1, process_report.blacklisted_dll_size()); |
| 171 std::string process_report_path = process_report.blacklisted_dll(0); |
| 172 EXPECT_EQ(path_expected, process_report_path); |
| 173 } |
OLD | NEW |