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