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

Unified Diff: chrome/browser/safe_browsing/environment_data_collection_win_unittest.cc

Issue 346763003: Adding blacklisted dlls to safe browsing incident reports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@updatedWard2
Patch Set: grt's change and 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
index 50b61cf183a2454e47eedf9e0d0029bbec14111d..51ad73ac037af7b6eee140ce8bfbb8c9cf8b3767 100644
--- a/chrome/browser/safe_browsing/environment_data_collection_win_unittest.cc
+++ b/chrome/browser/safe_browsing/environment_data_collection_win_unittest.cc
@@ -8,11 +8,18 @@
#include "base/files/file_path.h"
#include "base/scoped_native_library.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/test/test_reg_util_win.h"
+#include "base/win/registry.h"
+#include "chrome/browser/safe_browsing/path_sanitizer.h"
#include "chrome/common/safe_browsing/csd.pb.h"
+#include "chrome_elf/chrome_elf_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
+const wchar_t test_dll[] = L"test_name.dll";
+
// Helper function that returns true if a dll with filename |dll_name| is
// found in |process_report|.
bool ProcessReportContainsDll(
@@ -111,3 +118,49 @@ TEST(SafeBrowsingEnvironmentDataCollectionWinTest, RecordLspFeature) {
ASSERT_TRUE(lsp_feature_found);
}
+
+TEST(SafeBrowsingEnvironmentDataCollectionWinTest, CollectDllBlacklistData) {
+ // Ensure that CollectDllBlacklistData correctly adds the set of sanitized dll
+ // names currently stored in the registry to the report.
+ registry_util::RegistryOverrideManager override_manager;
+ override_manager.OverrideRegistry(HKEY_CURRENT_USER, L"safe_browsing_test");
+
+ base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER,
+ blacklist::kRegistryFinchListPath,
+ KEY_QUERY_VALUE | KEY_SET_VALUE);
+
+ // Check that with an empty registry the blacklisted dlls field is left empty.
+ safe_browsing::ClientIncidentReport_EnvironmentData_Process process_report;
+ safe_browsing::CollectDllBlacklistData(&process_report);
+ EXPECT_EQ(0, process_report.blacklisted_dll_size());
+
+ // Check that after adding exactly one dll to the registry it appears in the
+ // process report.
+ blacklist_registry_key.WriteValue(test_dll, test_dll);
+ safe_browsing::CollectDllBlacklistData(&process_report);
+ ASSERT_EQ(1, process_report.blacklisted_dll_size());
+
+ base::string16 process_report_dll =
+ base::UTF8ToWide(process_report.blacklisted_dll(0));
+ EXPECT_EQ(base::string16(test_dll), process_report_dll);
+
+ // Check that if the registry contains the full path to a dll it is properly
+ // sanitized before being reported.
+ blacklist_registry_key.DeleteValue(test_dll);
+ process_report.clear_blacklisted_dll();
+
+ 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.
+ base::string16 path = path_sanitizer.GetHomeDirectory()
+ .Append(FILE_PATH_LITERAL("test_path.dll"))
+ .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.
+ std::string path_expected = base::FilePath(FILE_PATH_LITERAL("~"))
+ .Append(FILE_PATH_LITERAL("test_path.dll"))
+ .AsUTF8Unsafe();
+
+ blacklist_registry_key.WriteValue(path.c_str(), path.c_str());
+ safe_browsing::CollectDllBlacklistData(&process_report);
+
+ ASSERT_EQ(1, process_report.blacklisted_dll_size());
+ std::string process_report_path = process_report.blacklisted_dll(0);
+ EXPECT_EQ(path_expected, process_report_path);
+}
« no previous file with comments | « chrome/browser/safe_browsing/environment_data_collection_win.cc ('k') | chrome/common/safe_browsing/csd.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698