Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320)
[chromium-blink-merge.git] / sandbox / win / src / integrity_level_test.cc
blobf962033ca56d07cf6edfc7a6c650afd158127ec5
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <windows.h>
6 #include <atlsecurity.h>
8 #include "base/win/windows_version.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "sandbox/win/src/sandbox.h"
11 #include "sandbox/win/src/sandbox_policy.h"
12 #include "sandbox/win/src/sandbox_factory.h"
13 #include "sandbox/win/tests/common/controller.h"
15 namespace sandbox {
18 SBOX_TESTS_COMMAND int CheckIntegrityLevel(int argc, wchar_t **argv) {
19 ATL::CAccessToken token;
20 if (!token.GetEffectiveToken(TOKEN_READ))
21 return SBOX_TEST_FAILED;
23 char* buffer[100];
24 DWORD buf_size = 100;
25 if (!::GetTokenInformation(token.GetHandle(), TokenIntegrityLevel,
26 reinterpret_cast<void*>(buffer), buf_size,
27 &buf_size))
28 return SBOX_TEST_FAILED;
30 TOKEN_MANDATORY_LABEL* label =
31 reinterpret_cast<TOKEN_MANDATORY_LABEL*>(buffer);
33 PSID sid_low = NULL;
34 if (!::ConvertStringSidToSid(L"S-1-16-4096", &sid_low))
35 return SBOX_TEST_FAILED;
37 BOOL is_low_sid = ::EqualSid(label->Label.Sid, sid_low);
39 ::LocalFree(sid_low);
41 if (is_low_sid)
42 return SBOX_TEST_SUCCEEDED;
44 return SBOX_TEST_DENIED;
47 TEST(IntegrityLevelTest, TestLowILReal) {
48 if (base::win::GetVersion() != base::win::VERSION_VISTA)
49 return;
51 TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE);
53 runner.SetTimeout(INFINITE);
55 runner.GetPolicy()->SetAlternateDesktop(true);
56 runner.GetPolicy()->SetIntegrityLevel(INTEGRITY_LEVEL_LOW);
58 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel"));
60 runner.SetTestState(BEFORE_REVERT);
61 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel"));
64 TEST(DelayedIntegrityLevelTest, TestLowILDelayed) {
65 if (base::win::GetVersion() != base::win::VERSION_VISTA)
66 return;
68 TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE);
70 runner.SetTimeout(INFINITE);
72 runner.GetPolicy()->SetDelayedIntegrityLevel(INTEGRITY_LEVEL_LOW);
74 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel"));
76 runner.SetTestState(BEFORE_REVERT);
77 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"CheckIntegrityLevel"));
80 TEST(IntegrityLevelTest, TestNoILChange) {
81 if (base::win::GetVersion() != base::win::VERSION_VISTA)
82 return;
84 TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE);
86 runner.SetTimeout(INFINITE);
88 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"CheckIntegrityLevel"));
91 } // namespace sandbox