Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: sandbox/linux/suid/client/setuid_sandbox_client_unittest.cc

Issue 1849323003: Convert //sandbox to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixup nonsfi_sandbox_unittest.cc Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_client.h" 5 #include "sandbox/linux/suid/client/setuid_sandbox_client.h"
6 6
7 #include <memory>
8
7 #include "base/environment.h" 9 #include "base/environment.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
10 #include "sandbox/linux/suid/common/sandbox.h" 11 #include "sandbox/linux/suid/common/sandbox.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace sandbox { 14 namespace sandbox {
14 15
15 TEST(SetuidSandboxClient, SandboxedClientAPI) { 16 TEST(SetuidSandboxClient, SandboxedClientAPI) {
16 scoped_ptr<base::Environment> env(base::Environment::Create()); 17 std::unique_ptr<base::Environment> env(base::Environment::Create());
17 EXPECT_TRUE(env != NULL); 18 EXPECT_TRUE(env != NULL);
18 19
19 scoped_ptr<SetuidSandboxClient> 20 std::unique_ptr<SetuidSandboxClient> sandbox_client(
20 sandbox_client(SetuidSandboxClient::Create()); 21 SetuidSandboxClient::Create());
21 EXPECT_TRUE(sandbox_client != NULL); 22 EXPECT_TRUE(sandbox_client != NULL);
22 23
23 // Set-up a fake environment as if we went through the setuid sandbox. 24 // Set-up a fake environment as if we went through the setuid sandbox.
24 EXPECT_TRUE(env->SetVar(kSandboxEnvironmentApiProvides, 25 EXPECT_TRUE(env->SetVar(kSandboxEnvironmentApiProvides,
25 base::IntToString(kSUIDSandboxApiNumber))); 26 base::IntToString(kSUIDSandboxApiNumber)));
26 EXPECT_TRUE(env->SetVar(kSandboxDescriptorEnvironmentVarName, "1")); 27 EXPECT_TRUE(env->SetVar(kSandboxDescriptorEnvironmentVarName, "1"));
27 EXPECT_TRUE(env->SetVar(kSandboxPIDNSEnvironmentVarName, "1")); 28 EXPECT_TRUE(env->SetVar(kSandboxPIDNSEnvironmentVarName, "1"));
28 EXPECT_TRUE(env->UnSetVar(kSandboxNETNSEnvironmentVarName)); 29 EXPECT_TRUE(env->UnSetVar(kSandboxNETNSEnvironmentVarName));
29 30
30 // Check the API. 31 // Check the API.
31 EXPECT_TRUE(sandbox_client->IsSuidSandboxUpToDate()); 32 EXPECT_TRUE(sandbox_client->IsSuidSandboxUpToDate());
32 EXPECT_TRUE(sandbox_client->IsSuidSandboxChild()); 33 EXPECT_TRUE(sandbox_client->IsSuidSandboxChild());
33 EXPECT_TRUE(sandbox_client->IsInNewPIDNamespace()); 34 EXPECT_TRUE(sandbox_client->IsInNewPIDNamespace());
34 EXPECT_FALSE(sandbox_client->IsInNewNETNamespace()); 35 EXPECT_FALSE(sandbox_client->IsInNewNETNamespace());
35 36
36 // Forge an incorrect API version and check. 37 // Forge an incorrect API version and check.
37 EXPECT_TRUE(env->SetVar(kSandboxEnvironmentApiProvides, 38 EXPECT_TRUE(env->SetVar(kSandboxEnvironmentApiProvides,
38 base::IntToString(kSUIDSandboxApiNumber + 1))); 39 base::IntToString(kSUIDSandboxApiNumber + 1)));
39 EXPECT_FALSE(sandbox_client->IsSuidSandboxUpToDate()); 40 EXPECT_FALSE(sandbox_client->IsSuidSandboxUpToDate());
40 // We didn't go through the actual sandboxing mechanism as it is 41 // We didn't go through the actual sandboxing mechanism as it is
41 // very hard in a unit test. 42 // very hard in a unit test.
42 EXPECT_FALSE(sandbox_client->IsSandboxed()); 43 EXPECT_FALSE(sandbox_client->IsSandboxed());
43 } 44 }
44 45
45 } // namespace sandbox 46 } // namespace sandbox
46 47
OLDNEW
« no previous file with comments | « sandbox/linux/suid/client/setuid_sandbox_client.h ('k') | sandbox/linux/suid/client/setuid_sandbox_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698