| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "sandbox/linux/suid/client/setuid_sandbox_host.h" | 5 #include "sandbox/linux/suid/client/setuid_sandbox_host.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 | 9 |
| 9 #include "base/environment.h" | 10 #include "base/environment.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "sandbox/linux/suid/common/sandbox.h" | 13 #include "sandbox/linux/suid/common/sandbox.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace sandbox { | 16 namespace sandbox { |
| 17 | 17 |
| 18 TEST(SetuidSandboxHost, SetupLaunchEnvironment) { | 18 TEST(SetuidSandboxHost, SetupLaunchEnvironment) { |
| 19 const char kTestValue[] = "This is a test"; | 19 const char kTestValue[] = "This is a test"; |
| 20 scoped_ptr<base::Environment> env(base::Environment::Create()); | 20 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 21 EXPECT_TRUE(env != NULL); | 21 EXPECT_TRUE(env != NULL); |
| 22 | 22 |
| 23 std::string saved_ld_preload; | 23 std::string saved_ld_preload; |
| 24 bool environment_had_ld_preload; | 24 bool environment_had_ld_preload; |
| 25 // First, back-up the real LD_PRELOAD if any. | 25 // First, back-up the real LD_PRELOAD if any. |
| 26 environment_had_ld_preload = env->GetVar("LD_PRELOAD", &saved_ld_preload); | 26 environment_had_ld_preload = env->GetVar("LD_PRELOAD", &saved_ld_preload); |
| 27 // Setup environment variables to save or not save. | 27 // Setup environment variables to save or not save. |
| 28 EXPECT_TRUE(env->SetVar("LD_PRELOAD", kTestValue)); | 28 EXPECT_TRUE(env->SetVar("LD_PRELOAD", kTestValue)); |
| 29 EXPECT_TRUE(env->UnSetVar("LD_ORIGIN_PATH")); | 29 EXPECT_TRUE(env->UnSetVar("LD_ORIGIN_PATH")); |
| 30 | 30 |
| 31 scoped_ptr<SetuidSandboxHost> sandbox_host(SetuidSandboxHost::Create()); | 31 std::unique_ptr<SetuidSandboxHost> sandbox_host(SetuidSandboxHost::Create()); |
| 32 EXPECT_TRUE(sandbox_host != NULL); | 32 EXPECT_TRUE(sandbox_host != NULL); |
| 33 | 33 |
| 34 // Make sure the environment is clean. | 34 // Make sure the environment is clean. |
| 35 EXPECT_TRUE(env->UnSetVar(kSandboxEnvironmentApiRequest)); | 35 EXPECT_TRUE(env->UnSetVar(kSandboxEnvironmentApiRequest)); |
| 36 EXPECT_TRUE(env->UnSetVar(kSandboxEnvironmentApiProvides)); | 36 EXPECT_TRUE(env->UnSetVar(kSandboxEnvironmentApiProvides)); |
| 37 | 37 |
| 38 sandbox_host->SetupLaunchEnvironment(); | 38 sandbox_host->SetupLaunchEnvironment(); |
| 39 | 39 |
| 40 // Check if the requested API environment was set. | 40 // Check if the requested API environment was set. |
| 41 std::string api_request; | 41 std::string api_request; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 if (environment_had_ld_preload) { | 57 if (environment_had_ld_preload) { |
| 58 EXPECT_TRUE(env->SetVar("LD_PRELOAD", saved_ld_preload)); | 58 EXPECT_TRUE(env->SetVar("LD_PRELOAD", saved_ld_preload)); |
| 59 } else { | 59 } else { |
| 60 EXPECT_TRUE(env->UnSetVar("LD_PRELOAD")); | 60 EXPECT_TRUE(env->UnSetVar("LD_PRELOAD")); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 // This test doesn't accomplish much, but will make sure that analysis tools | 64 // This test doesn't accomplish much, but will make sure that analysis tools |
| 65 // will run this codepath. | 65 // will run this codepath. |
| 66 TEST(SetuidSandboxHost, GetSandboxBinaryPath) { | 66 TEST(SetuidSandboxHost, GetSandboxBinaryPath) { |
| 67 scoped_ptr<SetuidSandboxHost> setuid_sandbox_host( | 67 std::unique_ptr<SetuidSandboxHost> setuid_sandbox_host( |
| 68 SetuidSandboxHost::Create()); | 68 SetuidSandboxHost::Create()); |
| 69 ignore_result(setuid_sandbox_host->GetSandboxBinaryPath()); | 69 ignore_result(setuid_sandbox_host->GetSandboxBinaryPath()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 } // namespace sandbox | 72 } // namespace sandbox |
| OLD | NEW |