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

Unified 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: Addressing more comments 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/environment_data_collection_win_unittest.cc
diff --git a/chrome/browser/safe_browsing/environment_data_collection_win_unittest.cc b/chrome/browser/safe_browsing/environment_data_collection_win_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a19324fa372a0bb578a229239fec26392de9e10f
--- /dev/null
+++ b/chrome/browser/safe_browsing/environment_data_collection_win_unittest.cc
@@ -0,0 +1,113 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/safe_browsing/environment_data_collection_win.h"
+
+#include <string>
+
+#include "base/files/file_path.h"
+#include "base/scoped_native_library.h"
+#include "chrome/common/safe_browsing/csd.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// Helper function that returns true if a dll with filename |dll_name| is
+// found in |process_report|.
+bool ProcessReportContainsDll(
+ const safe_browsing::ClientIncidentReport_EnvironmentData_Process&
+ process_report,
+ const base::FilePath& dll_name) {
+ for (int i = 0; i < process_report.dll_size(); ++i) {
+ base::FilePath current_dll =
+ base::FilePath::FromUTF8Unsafe(process_report.dll(i).path());
+
+ if (current_dll.BaseName() == dll_name)
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace
+
+TEST(SafeBrowsingEnvironmentDataCollectionWinTest, CollectDlls) {
+ // This test will check if the CollectDlls method works by loading
+ // a dll and then checking if we can find it within the process report.
+ // Pick msvidc32.dll as it is present from WinXP to Win8 and yet rarely used.
+ // msvidc32.dll exists in both 32 and 64 bit version.
grt (UTC plus 2) 2014/06/18 15:42:40 nit: version -> versions
pmonette_google.com 2014/06/18 21:33:29 Done.
+ base::FilePath msvdc32_dll(L"msvidc32.dll");
+
+ safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report;
+ safe_browsing::CollectDlls(&process_report);
+
+ ASSERT_FALSE(ProcessReportContainsDll(process_report, msvdc32_dll));
+
+ // Redo the same verification after loading a new dll.
+ base::ScopedNativeLibrary library(msvdc32_dll);
+
+ process_report.clear_dll();
+ safe_browsing::CollectDlls(&process_report);
+
+ ASSERT_TRUE(ProcessReportContainsDll(process_report, msvdc32_dll));
+}
+
+TEST(SafeBrowsingEnvironmentDataCollectionWinTest, RecordLspFeature) {
+ // Populate our incident report with loaded modules.
+ safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report;
+ safe_browsing::CollectDlls(&process_report);
+
+ // We'll test RecordLspFeatures against a real dll registered as a LSP.
+ std::string lsp_path = "C:\\Windows\\system32\\mswsock.dll";
+ int base_address = 0x77770000;
+ int length = 0x180000;
+
+ // Look for dlls that are registered as a LSP.
+ safe_browsing::RecordLspFeature(&process_report);
+
+ // Look through dll entries and check that none contains the LSP feature.
+ bool lsp_feature_found = false;
+ for (int i = 0; i < process_report.dll_size(); ++i) {
+ if (process_report.dll(i).path() == lsp_path) {
+ // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP
+ // through the features of each dll.
+ for (int j = 0; j < process_report.dll(i).feature_size(); ++j) {
+ if (process_report.dll(i).feature(j) ==
+ safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll::
+ LSP)
+ lsp_feature_found = true;
+ }
+ }
+ }
+
+ ASSERT_FALSE(lsp_feature_found);
+
+ // Manually add an entry to the process report that will get marked as a LSP.
+ safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll* dll =
+ process_report.add_dll();
+ dll->set_path(lsp_path);
+ dll->set_base_address(base_address);
+ dll->set_length(length);
+
+ // Look for dlls that are registered as a LSP.
+ safe_browsing::RecordLspFeature(&process_report);
+
+ // Look through dll entries and check if the one we added contains the LSP
+ // feature.
+ lsp_feature_found = false;
+ for (int i = 0; i < process_report.dll_size(); ++i) {
+ if (process_report.dll(i).path() == lsp_path) {
+ // Look for ClientIncidentReport_EnvironmentData_Process_DLL_Feature_LSP
+ // through the features of each dll.
+ for (int j = 0; j < process_report.dll(i).feature_size(); ++j) {
+ if (process_report.dll(i).feature(j) ==
+ safe_browsing::ClientIncidentReport_EnvironmentData_Process_Dll::
+ LSP)
+ lsp_feature_found = true;
+ }
+ }
+ }
+
+ ASSERT_TRUE(lsp_feature_found);
+}
« no previous file with comments | « chrome/browser/safe_browsing/environment_data_collection_win.cc ('k') | chrome/browser/safe_browsing/path_sanitizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698