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

Unified Diff: chrome_elf/blacklist/test/blacklist_test.cc

Issue 300933002: Finch Blacklist is now added to the Hardcoded blacklist. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final changes? 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
« no previous file with comments | « chrome_elf/blacklist/blacklist.cc ('k') | chrome_elf/blacklist/test/blacklist_test_main_dll.def » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome_elf/blacklist/test/blacklist_test.cc
diff --git a/chrome_elf/blacklist/test/blacklist_test.cc b/chrome_elf/blacklist/test/blacklist_test.cc
index 05aeb14f1b123611451b66dd3111cc8665f8ef85..1f91956ab72006bf18c72c6a8c59a5d0f532d8c7 100644
--- a/chrome_elf/blacklist/test/blacklist_test.cc
+++ b/chrome_elf/blacklist/test/blacklist_test.cc
@@ -32,6 +32,7 @@ extern "C" {
// When modifying the blacklist in the test process, use the exported test dll
// functions on the test blacklist dll, not the ones linked into the test
// executable itself.
+__declspec(dllimport) bool TestDll_AddDllsFromRegistryToBlacklist();
__declspec(dllimport) bool TestDll_AddDllToBlacklist(const wchar_t* dll_name);
__declspec(dllimport) bool TestDll_IsBlacklistInitialized();
__declspec(dllimport) bool TestDll_RemoveDllFromBlacklist(
@@ -54,6 +55,13 @@ class BlacklistTest : public testing::Test {
}
};
+namespace {
+
+struct TestData {
+ const wchar_t* dll_name;
+ const wchar_t* dll_beacon;
+} test_data[] = {{kTestDllName2, kDll2Beacon}, {kTestDllName3, kDll3Beacon}};
+
TEST_F(BlacklistTest, Beacon) {
registry_util::RegistryOverrideManager override_manager;
override_manager.OverrideRegistry(HKEY_CURRENT_USER, L"beacon_test");
@@ -138,34 +146,14 @@ TEST_F(BlacklistTest, SuccessfullyBlocked) {
}
}
-TEST_F(BlacklistTest, LoadBlacklistedLibrary) {
+void CheckBlacklistedDllsNotLoaded() {
base::FilePath current_dir;
ASSERT_TRUE(PathService::Get(base::DIR_EXE, &current_dir));
- // Ensure that the blacklist is loaded.
- ASSERT_TRUE(TestDll_IsBlacklistInitialized());
-
- // Test that an un-blacklisted DLL can load correctly.
- base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName1));
- EXPECT_TRUE(dll1.is_valid());
- dll1.Reset(NULL);
-
- int num_blocked_dlls = 0;
- TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls);
- EXPECT_EQ(0, num_blocked_dlls);
-
- struct TestData {
- const wchar_t* dll_name;
- const wchar_t* dll_beacon;
- } test_data[] = {
- { kTestDllName2, kDll2Beacon },
- { kTestDllName3, kDll3Beacon }
- };
- for (int i = 0 ; i < arraysize(test_data); ++i) {
- // Add the DLL to the blacklist, ensure that it is not loaded both by
- // inspecting the handle returned by LoadLibrary and by looking for an
- // environment variable that is set when the DLL's entry point is called.
- EXPECT_TRUE(TestDll_AddDllToBlacklist(test_data[i].dll_name));
+ for (int i = 0; i < arraysize(test_data); ++i) {
+ // Ensure that the dll has not been loaded both by inspecting the handle
+ // returned by LoadLibrary and by looking for an environment variable that
+ // is set when the DLL's entry point is called.
base::ScopedNativeLibrary dll_blacklisted(
current_dir.Append(test_data[i].dll_name));
EXPECT_FALSE(dll_blacklisted.is_valid());
@@ -203,7 +191,57 @@ TEST_F(BlacklistTest, LoadBlacklistedLibrary) {
// The blocked dll was removed, so we shouldn't get anything returned
// here.
+ int num_blocked_dlls = 0;
TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls);
EXPECT_EQ(0, num_blocked_dlls);
}
}
+
+TEST_F(BlacklistTest, LoadBlacklistedLibrary) {
+ base::FilePath current_dir;
+ ASSERT_TRUE(PathService::Get(base::DIR_EXE, &current_dir));
+
+ // Ensure that the blacklist is loaded.
+ ASSERT_TRUE(TestDll_IsBlacklistInitialized());
+
+ // Test that an un-blacklisted DLL can load correctly.
+ base::ScopedNativeLibrary dll1(current_dir.Append(kTestDllName1));
+ EXPECT_TRUE(dll1.is_valid());
+ dll1.Reset(NULL);
+
+ int num_blocked_dlls = 0;
+ TestDll_SuccessfullyBlocked(NULL, &num_blocked_dlls);
+ EXPECT_EQ(0, num_blocked_dlls);
+
+ // Add all DLLs to the blacklist then check they are blocked.
+ for (int i = 0; i < arraysize(test_data); ++i) {
+ EXPECT_TRUE(TestDll_AddDllToBlacklist(test_data[i].dll_name));
+ }
+ CheckBlacklistedDllsNotLoaded();
+}
+
+TEST_F(BlacklistTest, AddDllsFromRegistryToBlacklist) {
+ // Ensure that the blacklist is loaded.
+ ASSERT_TRUE(TestDll_IsBlacklistInitialized());
+
+ // Delete the finch registry key to clear its values.
+ base::win::RegKey key(HKEY_CURRENT_USER,
+ blacklist::kRegistryFinchListPath,
+ KEY_QUERY_VALUE | KEY_SET_VALUE);
+ key.DeleteKey(L"");
+
+ // Add the test dlls to the registry (with their name as both key and value).
+ base::win::RegKey finch_blacklist_registry_key(
+ HKEY_CURRENT_USER,
+ blacklist::kRegistryFinchListPath,
+ KEY_QUERY_VALUE | KEY_SET_VALUE);
+ for (int i = 0; i < arraysize(test_data); ++i) {
+ finch_blacklist_registry_key.WriteValue(test_data[i].dll_name,
+ test_data[i].dll_name);
+ }
+
+ EXPECT_TRUE(TestDll_AddDllsFromRegistryToBlacklist());
+ CheckBlacklistedDllsNotLoaded();
+}
+
+} // namespace
« no previous file with comments | « chrome_elf/blacklist/blacklist.cc ('k') | chrome_elf/blacklist/test/blacklist_test_main_dll.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698