| 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/incident_reporting/environment_data_colle
ction_win.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/environment_data_colle
ction_win.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/safe_browsing/path_sanitizer.h" | 22 #include "chrome/browser/safe_browsing/path_sanitizer.h" |
| 23 #include "chrome/common/safe_browsing/csd.pb.h" | 23 #include "chrome/common/safe_browsing/csd.pb.h" |
| 24 #include "chrome_elf/chrome_elf_constants.h" | 24 #include "chrome_elf/chrome_elf_constants.h" |
| 25 #include "net/base/winsock_init.h" | 25 #include "net/base/winsock_init.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 namespace safe_browsing { | 28 namespace safe_browsing { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 const wchar_t test_dll[] = L"test_name.dll"; | |
| 33 | |
| 34 // Returns true if a dll with filename |dll_name| is found in |process_report|, | 32 // Returns true if a dll with filename |dll_name| is found in |process_report|, |
| 35 // providing a copy of it in |result|. | 33 // providing a copy of it in |result|. |
| 36 bool GetProcessReportDll( | 34 bool GetProcessReportDll( |
| 37 const ClientIncidentReport_EnvironmentData_Process& process_report, | 35 const ClientIncidentReport_EnvironmentData_Process& process_report, |
| 38 const base::FilePath& dll_name, | 36 const base::FilePath& dll_name, |
| 39 ClientIncidentReport_EnvironmentData_Process_Dll* result) { | 37 ClientIncidentReport_EnvironmentData_Process_Dll* result) { |
| 40 for (const auto& dll : process_report.dll()) { | 38 for (const auto& dll : process_report.dll()) { |
| 41 if (base::FilePath::FromUTF8Unsafe(dll.path()).BaseName() == dll_name) { | 39 if (base::FilePath::FromUTF8Unsafe(dll.path()).BaseName() == dll_name) { |
| 42 result->CopyFrom(dll); | 40 result->CopyFrom(dll); |
| 43 return true; | 41 return true; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 116 |
| 119 RecordLspFeature(&process_report); | 117 RecordLspFeature(&process_report); |
| 120 | 118 |
| 121 // Return successfully if LSP feature is found. | 119 // Return successfully if LSP feature is found. |
| 122 if (DllEntryContainsLspFeature(process_report, lsp)) | 120 if (DllEntryContainsLspFeature(process_report, lsp)) |
| 123 return; | 121 return; |
| 124 | 122 |
| 125 FAIL() << "No LSP feature found for " << lsp; | 123 FAIL() << "No LSP feature found for " << lsp; |
| 126 } | 124 } |
| 127 | 125 |
| 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); | |
| 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 ClientIncidentReport_EnvironmentData_Process process_report; | |
| 140 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 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 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 } | |
| 174 | |
| 175 #if !defined(_WIN64) | 126 #if !defined(_WIN64) |
| 176 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, VerifyLoadedModules) { | 127 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, VerifyLoadedModules) { |
| 177 // Load the test modules. | 128 // Load the test modules. |
| 178 std::vector<base::ScopedNativeLibrary> test_dlls(kTestDllNamesCount); | 129 std::vector<base::ScopedNativeLibrary> test_dlls(kTestDllNamesCount); |
| 179 for (size_t i = 0; i < kTestDllNamesCount; ++i) { | 130 for (size_t i = 0; i < kTestDllNamesCount; ++i) { |
| 180 test_dlls[i].Reset( | 131 test_dlls[i].Reset( |
| 181 LoadNativeLibrary(base::FilePath(kTestDllNames[i]), NULL)); | 132 LoadNativeLibrary(base::FilePath(kTestDllNames[i]), NULL)); |
| 182 } | 133 } |
| 183 | 134 |
| 184 // Edit the first byte of the function exported by the first module. Calling | 135 // Edit the first byte of the function exported by the first module. Calling |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, | 263 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, |
| 313 CollectDomainEnrollmentData) { | 264 CollectDomainEnrollmentData) { |
| 314 // The test may or may not be running on a domain-enrolled machine, so all we | 265 // The test may or may not be running on a domain-enrolled machine, so all we |
| 315 // can check is that some value is filled in. | 266 // can check is that some value is filled in. |
| 316 ClientIncidentReport_EnvironmentData_OS os_data; | 267 ClientIncidentReport_EnvironmentData_OS os_data; |
| 317 CollectDomainEnrollmentData(&os_data); | 268 CollectDomainEnrollmentData(&os_data); |
| 318 EXPECT_TRUE(os_data.has_is_enrolled_to_domain()); | 269 EXPECT_TRUE(os_data.has_is_enrolled_to_domain()); |
| 319 } | 270 } |
| 320 | 271 |
| 321 } // namespace safe_browsing | 272 } // namespace safe_browsing |
| OLD | NEW |