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 "chrome_elf/chrome_elf_util.h" | 5 #include "chrome_elf/chrome_elf_util.h" |
6 | 6 |
7 #include <tuple> | 7 #include <tuple> |
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 18 matching lines...) Expand all Loading... |
29 const wchar_t kCanaryExePath[] = | 29 const wchar_t kCanaryExePath[] = |
30 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application" | 30 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome SxS\\Application" |
31 L"\\chrome.exe"; | 31 L"\\chrome.exe"; |
32 const wchar_t kChromeSystemExePath[] = | 32 const wchar_t kChromeSystemExePath[] = |
33 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; | 33 L"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; |
34 const wchar_t kChromeUserExePath[] = | 34 const wchar_t kChromeUserExePath[] = |
35 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"; | 35 L"C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"; |
36 const wchar_t kChromiumExePath[] = | 36 const wchar_t kChromiumExePath[] = |
37 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe"; | 37 L"C:\\Users\\user\\AppData\\Local\\Chromium\\Application\\chrome.exe"; |
38 | 38 |
| 39 typedef decltype(GetProcessMitigationPolicy)* GetProcessMitigationPolicyFunc; |
| 40 |
| 41 bool IsSecuritySet() { |
| 42 // Check the settings from EarlyBrowserSecurity(). |
| 43 if (::IsWindows8OrGreater()) { |
| 44 GetProcessMitigationPolicyFunc get_process_mitigation_policy = |
| 45 reinterpret_cast<GetProcessMitigationPolicyFunc>(::GetProcAddress( |
| 46 ::GetModuleHandleW(L"kernel32.dll"), "GetProcessMitigationPolicy")); |
| 47 if (!get_process_mitigation_policy) |
| 48 return false; |
| 49 |
| 50 // Check that extension DLLs are disabled. |
| 51 // (Legacy hooking.) |
| 52 PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY policy = {}; |
| 53 if (!get_process_mitigation_policy(::GetCurrentProcess(), |
| 54 ProcessExtensionPointDisablePolicy, |
| 55 &policy, sizeof(policy))) |
| 56 return false; |
| 57 |
| 58 return policy.DisableExtensionPoints; |
| 59 } |
| 60 |
| 61 return true; |
| 62 } |
39 | 63 |
40 TEST(ChromeElfUtilTest, CanaryTest) { | 64 TEST(ChromeElfUtilTest, CanaryTest) { |
41 EXPECT_TRUE(IsCanary(kCanaryExePath)); | 65 EXPECT_TRUE(IsCanary(kCanaryExePath)); |
42 EXPECT_FALSE(IsCanary(kChromeUserExePath)); | 66 EXPECT_FALSE(IsCanary(kChromeUserExePath)); |
43 EXPECT_FALSE(IsCanary(kChromiumExePath)); | 67 EXPECT_FALSE(IsCanary(kChromiumExePath)); |
44 } | 68 } |
45 | 69 |
46 TEST(ChromeElfUtilTest, SystemInstallTest) { | 70 TEST(ChromeElfUtilTest, SystemInstallTest) { |
47 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); | 71 EXPECT_TRUE(IsSystemInstall(kChromeSystemExePath)); |
48 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); | 72 EXPECT_FALSE(IsSystemInstall(kChromeUserExePath)); |
49 } | 73 } |
50 | 74 |
51 TEST(ChromeElfUtilTest, BrowserProcessTest) { | 75 TEST(ChromeElfUtilTest, BrowserProcessTest) { |
52 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); | 76 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); |
53 InitializeProcessType(); | 77 InitializeProcessType(); |
54 EXPECT_FALSE(IsNonBrowserProcess()); | 78 EXPECT_FALSE(IsNonBrowserProcess()); |
55 } | 79 } |
56 | 80 |
| 81 TEST(ChromeElfUtilTest, BrowserProcessSecurityTest) { |
| 82 EarlyBrowserSecurity(); |
| 83 EXPECT_TRUE(IsSecuritySet()); |
| 84 } |
| 85 |
57 // Parameterized test with paramters: | 86 // Parameterized test with paramters: |
58 // 1: product: "canary" or "google" | 87 // 1: product: "canary" or "google" |
59 // 2: install level: "user" or "system" | 88 // 2: install level: "user" or "system" |
60 // 3: install mode: "single" or "multi" | 89 // 3: install mode: "single" or "multi" |
61 class ChromeElfUtilTest : | 90 class ChromeElfUtilTest : |
62 public testing::TestWithParam<std::tuple<const char*, | 91 public testing::TestWithParam<std::tuple<const char*, |
63 const char*, | 92 const char*, |
64 const char*> > { | 93 const char*> > { |
65 protected: | 94 protected: |
66 void SetUp() override { | 95 void SetUp() override { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, | 210 INSTANTIATE_TEST_CASE_P(Canary, ChromeElfUtilTest, |
182 testing::Combine(testing::Values("canary"), | 211 testing::Combine(testing::Values("canary"), |
183 testing::Values("user"), | 212 testing::Values("user"), |
184 testing::Values("single"))); | 213 testing::Values("single"))); |
185 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, | 214 INSTANTIATE_TEST_CASE_P(GoogleChrome, ChromeElfUtilTest, |
186 testing::Combine(testing::Values("google"), | 215 testing::Combine(testing::Values("google"), |
187 testing::Values("user", "system"), | 216 testing::Values("user", "system"), |
188 testing::Values("single", "multi"))); | 217 testing::Values("single", "multi"))); |
189 | 218 |
190 } // namespace | 219 } // namespace |
OLD | NEW |