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