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