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

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: Fixing the unit test that was failing on WinXP 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 "net/base/winsock_init.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 // Helper function that returns true if a dll with filename |dll_name| is
18 // found in |process_report|.
19 bool ProcessReportContainsDll(
20 const safe_browsing::ClientIncidentReport_EnvironmentData_Process&
21 process_report,
22 const base::FilePath& dll_name) {
23 for (int i = 0; i < process_report.dll_size(); ++i) {
24 base::FilePath current_dll =
25 base::FilePath::FromUTF8Unsafe(process_report.dll(i).path());
26
27 if (current_dll.BaseName() == dll_name)
28 return true;
29 }
30
31 return false;
32 }
33
34 } // namespace
35
36 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, CollectDlls) {
37 // This test will check if the CollectDlls method works by loading
38 // a dll and then checking if we can find it within the process report.
39 // Pick msvidc32.dll as it is present from WinXP to Win8 and yet rarely used.
40 // msvidc32.dll exists in both 32 and 64 bit versions.
41 base::FilePath msvdc32_dll(L"msvidc32.dll");
42
43 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report;
44 safe_browsing::CollectDlls(&process_report);
45
46 ASSERT_FALSE(ProcessReportContainsDll(process_report, msvdc32_dll));
47
48 // Redo the same verification after loading a new dll.
49 base::ScopedNativeLibrary library(msvdc32_dll);
50
51 process_report.clear_dll();
52 safe_browsing::CollectDlls(&process_report);
53
54 ASSERT_TRUE(ProcessReportContainsDll(process_report, msvdc32_dll));
55 }
56
57 TEST(SafeBrowsingEnvironmentDataCollectionWinTest, RecordLspFeature) {
58 net::EnsureWinsockInit();
59
60 // Populate our incident report with loaded modules.
61 safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report;
62 safe_browsing::CollectDlls(&process_report);
63
64 // We'll test RecordLspFeatures against a real dll registered as a LSP.
65 std::string lsp_path = "C:\\Windows\\system32\\mswsock.dll";
66 int base_address = 0x77770000;
67 int length = 0x180000;
68
69 // Look for dlls that are registered as a LSP.
70 safe_browsing::RecordLspFeature(&process_report);
71
72 // Look through dll entries and check that none contains the LSP feature.
73 bool lsp_feature_found = false;
74 for (int i = 0; i < process_report.dll_size(); ++i) {
75 if (process_report.dll(i).path() == lsp_path) {
76 // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP
77 // through the features of each dll.
78 for (int j = 0; j < process_report.dll(i).feature_size(); ++j) {
79 if (process_report.dll(i).feature(j) ==
80 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll::
81 LSP)
82 lsp_feature_found = true;
83 }
84 }
85 }
86
87 ASSERT_FALSE(lsp_feature_found);
88
89 // Manually add an entry to the process report that will get marked as a LSP.
90 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll* dll =
91 process_report.add_dll();
92 dll->set_path(lsp_path);
93 dll->set_base_address(base_address);
94 dll->set_length(length);
95
96 // Look for dlls that are registered as a LSP.
97 safe_browsing::RecordLspFeature(&process_report);
98
99 // Look through dll entries and check if the one we added contains the LSP
100 // feature.
101 lsp_feature_found = false;
102 for (int i = 0; i < process_report.dll_size(); ++i) {
103 if (process_report.dll(i).path() == lsp_path) {
104 // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP
105 // through the features of each dll.
106 for (int j = 0; j < process_report.dll(i).feature_size(); ++j) {
107 if (process_report.dll(i).feature(j) ==
108 safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll::
109 LSP)
110 lsp_feature_found = true;
111 }
112 }
113 }
114
115 ASSERT_TRUE(lsp_feature_found);
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698