Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/safe_browsing/environment_data_collection_win.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/scoped_native_library.h" | |
| 11 #include "chrome/common/safe_browsing/csd.pb.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Helper function that returns true if a dll with filename |dll_name| is | |
| 17 // found in |process_report|. | |
| 18 bool ProcessReportContainsDll( | |
| 19 const safe_browsing::ClientIncidentReport_EnvironmentData_Process& | |
| 20 process_report, | |
| 21 const base::FilePath& dll_name) { | |
| 22 for (int i = 0; i < process_report.dll_size(); ++i) { | |
| 23 base::FilePath current_dll = | |
| 24 base::FilePath::FromUTF8Unsafe(process_report.dll(i).path()); | |
| 25 | |
| 26 if (current_dll.BaseName() == dll_name) | |
| 27 return true; | |
| 28 } | |
| 29 | |
| 30 return false; | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, CollectDlls) { | |
| 36 // This test will check if the CollectDlls method works by loading | |
| 37 // a dll and then checking if we can find it within the process report. | |
| 38 // Pick msvidc32.dll as it is present from WinXP to Win8 and yet rarely used. | |
| 39 base::FilePath msvdc32_dll(L"msvidc32.dll"); | |
|
mattm
2014/06/17 01:28:18
Are these tests portable? It seems like the try ru
pmonette_google.com
2014/06/17 17:48:22
We (Greg and I) investigated this and we found out
mattm
2014/06/17 17:55:51
Ah, thanks. Could you add a comment about it?.
pmonette_google.com
2014/06/18 15:34:18
Done.
| |
| 40 | |
| 41 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report; | |
| 42 safe_browsing::CollectDlls(&process_report); | |
| 43 | |
| 44 ASSERT_FALSE(ProcessReportContainsDll(process_report, msvdc32_dll)); | |
| 45 | |
| 46 // Redo the same verification after loading a new dll. | |
| 47 base::ScopedNativeLibrary library(msvdc32_dll); | |
| 48 | |
| 49 process_report.clear_dll(); | |
| 50 safe_browsing::CollectDlls(&process_report); | |
| 51 | |
| 52 ASSERT_TRUE(ProcessReportContainsDll(process_report, msvdc32_dll)); | |
| 53 } | |
| 54 | |
| 55 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, RecordLspFeature) { | |
| 56 // Populate our incident report with loaded modules. | |
| 57 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report; | |
| 58 safe_browsing::CollectDlls(&process_report); | |
| 59 | |
| 60 // We'll test RecordLspFeatures against a real dll registered as a LSP. | |
| 61 std::string lsp_path = "C:\\Windows\\system32\\mswsock.dll"; | |
| 62 int base_address = 0x77770000; | |
| 63 int length = 0x180000; | |
| 64 | |
| 65 // Look for dlls that are registered as a LSP. | |
| 66 safe_browsing::RecordLspFeature(&process_report); | |
| 67 | |
| 68 // Look through dll entries and check that none contains the LSP feature. | |
| 69 bool lsp_feature_found = false; | |
| 70 for (int i = 0; i < process_report.dll_size(); ++i) { | |
| 71 if (process_report.dll(i).path() == lsp_path) { | |
| 72 // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP | |
| 73 // through the features of each dll. | |
| 74 for (int j = 0; j < process_report.dll(i).feature_size(); ++j) { | |
| 75 if (process_report.dll(i).feature(j) == | |
| 76 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll:: | |
| 77 LSP) | |
| 78 lsp_feature_found = true; | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 ASSERT_FALSE(lsp_feature_found); | |
| 84 | |
| 85 // Manually add an entry to the process report that will get marked as a LSP. | |
| 86 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll* dll = | |
| 87 process_report.add_dll(); | |
| 88 dll->set_path(lsp_path); | |
| 89 dll->set_base_address(base_address); | |
| 90 dll->set_length(length); | |
| 91 | |
| 92 // Look for dlls that are registered as a LSP. | |
| 93 safe_browsing::RecordLspFeature(&process_report); | |
| 94 | |
| 95 // Look through dll entries and check if the one we added contains the LSP | |
| 96 // feature. | |
| 97 lsp_feature_found = false; | |
| 98 for (int i = 0; i < process_report.dll_size(); ++i) { | |
| 99 if (process_report.dll(i).path() == lsp_path) { | |
| 100 // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP | |
| 101 // through the features of each dll. | |
| 102 for (int j = 0; j < process_report.dll(i).feature_size(); ++j) { | |
| 103 if (process_report.dll(i).feature(j) == | |
| 104 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll:: | |
| 105 LSP) | |
| 106 lsp_feature_found = true; | |
| 107 } | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 ASSERT_TRUE(lsp_feature_found); | |
| 112 } | |
| OLD | NEW |