Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: chrome/browser/safe_browsing/environment_data_collection_win_unittest.cc

Issue 323953002: Support for recording registered LSPs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@grt
Patch Set: Modifications based on feedback received Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.dlls_size(); ++i) {
23 base::FilePath current_dll =
24 base::FilePath::FromUTF8Unsafe(process_report.dlls(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");
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_dlls();
50 safe_browsing::CollectDlls(&process_report);
51
52 ASSERT_TRUE(ProcessReportContainsDll(process_report, msvdc32_dll));
53 }
54
55 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, RecordLspFeatures) {
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::RecordLspFeatures(&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.dlls_size(); ++i) {
71 if (process_report.dlls(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.dlls(i).features_size(); ++j) {
75 if (process_report.dlls(i).features(j) ==
76 safe_browsing::
77 ClientIncidentReport_EnvironmentData_Process_Dll_Feature_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_dlls();
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::RecordLspFeatures(&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.dlls_size(); ++i) {
99 if (process_report.dlls(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.dlls(i).features_size(); ++j) {
103 if (process_report.dlls(i).features(j) ==
104 safe_browsing::
105 ClientIncidentReport_EnvironmentData_Process_Dll_Feature_LSP)
grt (UTC plus 2) 2014/06/10 20:57:53 ClientIncidentReport_EnvironmentData_Process_Dll::
pmonette_google.com 2014/06/10 21:39:04 Done.
106 lsp_feature_found = true;
107 }
108 }
109 }
110
111 ASSERT_TRUE(lsp_feature_found);
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698