| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <tuple> | 5 #include <tuple> |
| 6 #include <windows.h> | 6 #include <windows.h> |
| 7 #include <versionhelpers.h> // windows.h must be before. | 7 #include <versionhelpers.h> // windows.h must be before. |
| 8 | 8 |
| 9 #include "base/test/test_reg_util_win.h" | 9 #include "base/test/test_reg_util_win.h" |
| 10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 EXPECT_TRUE(SetSecurityFinchFlag(true)); | 114 EXPECT_TRUE(SetSecurityFinchFlag(true)); |
| 115 elf_security::EarlyBrowserSecurity(); | 115 elf_security::EarlyBrowserSecurity(); |
| 116 EXPECT_FALSE(IsSecuritySet()); | 116 EXPECT_FALSE(IsSecuritySet()); |
| 117 EXPECT_TRUE(SetSecurityFinchFlag(false)); | 117 EXPECT_TRUE(SetSecurityFinchFlag(false)); |
| 118 | 118 |
| 119 // Second, test that the process mitigation is set when no finch signal. | 119 // Second, test that the process mitigation is set when no finch signal. |
| 120 elf_security::EarlyBrowserSecurity(); | 120 elf_security::EarlyBrowserSecurity(); |
| 121 EXPECT_TRUE(IsSecuritySet()); | 121 EXPECT_TRUE(IsSecuritySet()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 //------------------------------------------------------------------------------ | |
| 125 // NT registry API tests (chrome_elf_reg) | |
| 126 //------------------------------------------------------------------------------ | |
| 127 | |
| 128 TEST(ChromeElfUtilTest, NTRegistry) { | |
| 129 HANDLE key_handle; | |
| 130 const wchar_t* dword_val_name = L"DwordTestValue"; | |
| 131 DWORD dword_val = 1234; | |
| 132 const wchar_t* sz_val_name = L"SzTestValue"; | |
| 133 base::string16 sz_val = L"blah de blah de blahhhhh."; | |
| 134 const wchar_t* sz_val_name2 = L"SzTestValueEmpty"; | |
| 135 base::string16 sz_val2 = L""; | |
| 136 const wchar_t* multisz_val_name = L"SzmultiTestValue"; | |
| 137 std::vector<base::string16> multisz_val; | |
| 138 base::string16 multi1 = L"one"; | |
| 139 base::string16 multi2 = L"two"; | |
| 140 base::string16 multi3 = L"three"; | |
| 141 const wchar_t* multisz_val_name2 = L"SzmultiTestValueBad"; | |
| 142 base::string16 multi_empty = L""; | |
| 143 const wchar_t* sz_new_key_1 = L"test\\new\\subkey"; | |
| 144 const wchar_t* sz_new_key_2 = L"test\\new\\subkey\\blah\\"; | |
| 145 const wchar_t* sz_new_key_3 = L"\\test\\new\\subkey\\\\blah2"; | |
| 146 | |
| 147 // Set up registry override for this test. | |
| 148 registry_util::RegistryOverrideManager override_manager; | |
| 149 RegRedirect(nt::HKCU, override_manager); | |
| 150 | |
| 151 // Create a temp key to play under. | |
| 152 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, elf_sec::kRegSecurityPath, | |
| 153 KEY_ALL_ACCESS, &key_handle)); | |
| 154 | |
| 155 // Exercise the supported getter & setter functions. | |
| 156 EXPECT_TRUE(nt::SetRegValueDWORD(key_handle, dword_val_name, dword_val)); | |
| 157 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name, sz_val)); | |
| 158 EXPECT_TRUE(nt::SetRegValueSZ(key_handle, sz_val_name2, sz_val2)); | |
| 159 | |
| 160 DWORD get_dword = 0; | |
| 161 base::string16 get_sz; | |
| 162 EXPECT_TRUE(nt::QueryRegValueDWORD(key_handle, dword_val_name, &get_dword) && | |
| 163 get_dword == dword_val); | |
| 164 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name, &get_sz) && | |
| 165 get_sz.compare(sz_val) == 0); | |
| 166 EXPECT_TRUE(nt::QueryRegValueSZ(key_handle, sz_val_name2, &get_sz) && | |
| 167 get_sz.compare(sz_val2) == 0); | |
| 168 | |
| 169 multisz_val.push_back(multi1); | |
| 170 multisz_val.push_back(multi2); | |
| 171 multisz_val.push_back(multi3); | |
| 172 EXPECT_TRUE( | |
| 173 nt::SetRegValueMULTISZ(key_handle, multisz_val_name, multisz_val)); | |
| 174 multisz_val.clear(); | |
| 175 multisz_val.push_back(multi_empty); | |
| 176 EXPECT_TRUE( | |
| 177 nt::SetRegValueMULTISZ(key_handle, multisz_val_name2, multisz_val)); | |
| 178 multisz_val.clear(); | |
| 179 | |
| 180 EXPECT_TRUE( | |
| 181 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name, &multisz_val)); | |
| 182 if (multisz_val.size() == 3) { | |
| 183 EXPECT_TRUE(multi1.compare(multisz_val.at(0)) == 0); | |
| 184 EXPECT_TRUE(multi2.compare(multisz_val.at(1)) == 0); | |
| 185 EXPECT_TRUE(multi3.compare(multisz_val.at(2)) == 0); | |
| 186 } else { | |
| 187 EXPECT_TRUE(false); | |
| 188 } | |
| 189 multisz_val.clear(); | |
| 190 | |
| 191 EXPECT_TRUE( | |
| 192 nt::QueryRegValueMULTISZ(key_handle, multisz_val_name2, &multisz_val)); | |
| 193 if (multisz_val.size() == 1) { | |
| 194 EXPECT_TRUE(multi_empty.compare(multisz_val.at(0)) == 0); | |
| 195 } else { | |
| 196 EXPECT_TRUE(false); | |
| 197 } | |
| 198 multisz_val.clear(); | |
| 199 | |
| 200 // Clean up | |
| 201 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); | |
| 202 nt::CloseRegKey(key_handle); | |
| 203 | |
| 204 // More tests for CreateRegKey recursion. | |
| 205 ASSERT_TRUE( | |
| 206 nt::CreateRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, nullptr)); | |
| 207 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_1, KEY_ALL_ACCESS, | |
| 208 &key_handle, nullptr)); | |
| 209 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); | |
| 210 nt::CloseRegKey(key_handle); | |
| 211 | |
| 212 ASSERT_TRUE( | |
| 213 nt::CreateRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, nullptr)); | |
| 214 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, sz_new_key_2, KEY_ALL_ACCESS, | |
| 215 &key_handle, nullptr)); | |
| 216 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); | |
| 217 nt::CloseRegKey(key_handle); | |
| 218 | |
| 219 ASSERT_TRUE( | |
| 220 nt::CreateRegKey(nt::HKCU, sz_new_key_3, KEY_ALL_ACCESS, nullptr)); | |
| 221 EXPECT_TRUE(nt::OpenRegKey(nt::HKCU, L"test\\new\\subkey\\blah2", | |
| 222 KEY_ALL_ACCESS, &key_handle, nullptr)); | |
| 223 EXPECT_TRUE(nt::DeleteRegKey(key_handle)); | |
| 224 nt::CloseRegKey(key_handle); | |
| 225 | |
| 226 ASSERT_TRUE(nt::CreateRegKey(nt::HKCU, nullptr, KEY_ALL_ACCESS, &key_handle)); | |
| 227 nt::CloseRegKey(key_handle); | |
| 228 } | |
| 229 | |
| 230 // Parameterized test with paramters: | 124 // Parameterized test with paramters: |
| 231 // 1: product: "canary" or "google" | 125 // 1: product: "canary" or "google" |
| 232 // 2: install level: "user" or "system" | 126 // 2: install level: "user" or "system" |
| 233 // 3: install mode: "single" or "multi" | 127 // 3: install mode: "single" or "multi" |
| 234 class ChromeElfUtilTest | 128 class ChromeElfUtilTest |
| 235 : public testing::TestWithParam< | 129 : public testing::TestWithParam< |
| 236 std::tuple<const char*, const char*, const char*>> { | 130 std::tuple<const char*, const char*, const char*>> { |
| 237 protected: | 131 protected: |
| 238 void SetUp() override { | 132 void SetUp() override { |
| 239 // Set up registry override for these tests. | 133 // Set up registry override for these tests. |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 testing::Combine(testing::Values("canary"), | 498 testing::Combine(testing::Values("canary"), |
| 605 testing::Values("user"), | 499 testing::Values("user"), |
| 606 testing::Values("single"))); | 500 testing::Values("single"))); |
| 607 INSTANTIATE_TEST_CASE_P(GoogleChrome, | 501 INSTANTIATE_TEST_CASE_P(GoogleChrome, |
| 608 ChromeElfUtilTest, | 502 ChromeElfUtilTest, |
| 609 testing::Combine(testing::Values("google"), | 503 testing::Combine(testing::Values("google"), |
| 610 testing::Values("user", "system"), | 504 testing::Values("user", "system"), |
| 611 testing::Values("single", "multi"))); | 505 testing::Values("single", "multi"))); |
| 612 | 506 |
| 613 } // namespace | 507 } // namespace |
| OLD | NEW |