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..9ab3c7a1dc2da6e2e0ac0cdb2de7c9a11c4305a1 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( |
@@ -161,7 +162,7 @@ TEST_F(BlacklistTest, LoadBlacklistedLibrary) { |
{ kTestDllName2, kDll2Beacon }, |
{ kTestDllName3, kDll3Beacon } |
}; |
- for (int i = 0 ; i < arraysize(test_data); ++i) { |
+ 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. |
@@ -207,3 +208,81 @@ TEST_F(BlacklistTest, LoadBlacklistedLibrary) { |
EXPECT_EQ(0, num_blocked_dlls); |
} |
} |
+ |
+TEST_F(BlacklistTest, AddDllsFromRegistryToBlacklist) { |
+ base::FilePath current_dir; |
+ ASSERT_TRUE(PathService::Get(base::DIR_EXE, ¤t_dir)); |
+ |
+ // Ensure that the blacklist is loaded. |
+ ASSERT_TRUE(TestDll_IsBlacklistInitialized()); |
+ |
+ base::win::RegKey finch_blacklist_registry_key( |
+ HKEY_CURRENT_USER, |
+ blacklist::kRegistryFinchListPath, |
+ KEY_QUERY_VALUE | KEY_SET_VALUE); |
+ |
+ int num_dlls = finch_blacklist_registry_key.GetValueCount(); |
+ |
+ // Collect any dll names currently stored in the regisry and delete them. |
+ std::vector<std::wstring> dlls(num_dlls); |
+ for (int i = 0; i < num_dlls; ++i) { |
+ std::wstring name; |
+ finch_blacklist_registry_key.GetValueNameAt(i, &name); |
+ |
+ std::wstring value; |
+ finch_blacklist_registry_key.ReadValue(name.c_str(), &value); |
+ |
+ dlls[i] = value; |
robertshield
2014/06/03 03:03:00
prefer dlls.push_back(value);
krstnmnlsn
2014/06/03 19:30:16
Done.
|
+ } |
+ |
+ for (int i = 0; i < num_dlls; ++i) { |
+ finch_blacklist_registry_key.DeleteValue(dlls[i].c_str()); |
+ } |
+ |
+ struct TestData { |
+ const wchar_t* dll_name; |
+ const wchar_t* dll_beacon; |
+ } test_data[] = {{kTestDllName2, kDll2Beacon}, {kTestDllName3, kDll3Beacon}}; |
+ |
+ // Add the test dlls to the registry (with their name as both key and 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()); |
+ |
+ 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()); |
+ EXPECT_EQ(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0)); |
+ dll_blacklisted.Reset(NULL); |
+ |
+ // Ensure that the dll is recorded as blocked. |
+ int array_size = 1; |
+ const wchar_t* blocked_dll = NULL; |
+ TestDll_SuccessfullyBlocked(&blocked_dll, &array_size); |
+ EXPECT_EQ(1, array_size); |
+ EXPECT_EQ(test_data[i].dll_name, base::string16(blocked_dll)); |
+ |
+ // Remove the DLL from the blacklist. Ensure that it loads and that its |
+ // entry point was called. |
+ EXPECT_TRUE(TestDll_RemoveDllFromBlacklist(test_data[i].dll_name)); |
+ base::ScopedNativeLibrary dll(current_dir.Append(test_data[i].dll_name)); |
+ EXPECT_TRUE(dll.is_valid()); |
+ EXPECT_NE(0u, ::GetEnvironmentVariable(test_data[i].dll_beacon, NULL, 0)); |
+ dll.Reset(NULL); |
+ |
+ ::SetEnvironmentVariable(test_data[i].dll_beacon, NULL); |
+ |
+ // 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); |
+ } |
+} |