Added GetState, GetManagedProperties, CreateNetwork methods to WiFiService.
[chromium-blink-merge.git] / sandbox / win / src / integrity_level_test.cc
blob67ea9de252f782d4e7c351f886bd503127133554
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()->SetIntegrityLevel(INTEGRITY_LEVEL_LOW);
57 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel"));
59 runner.SetTestState(BEFORE_REVERT);
60 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel"));
63 TEST(DelayedIntegrityLevelTest, TestLowILDelayed) {
64 if (base::win::GetVersion() != base::win::VERSION_VISTA)
65 return;
67 TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE);
69 runner.SetTimeout(INFINITE);
71 runner.GetPolicy()->SetDelayedIntegrityLevel(INTEGRITY_LEVEL_LOW);
73 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"CheckIntegrityLevel"));
75 runner.SetTestState(BEFORE_REVERT);
76 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"CheckIntegrityLevel"));
79 TEST(IntegrityLevelTest, TestNoILChange) {
80 if (base::win::GetVersion() != base::win::VERSION_VISTA)
81 return;
83 TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE);
85 runner.SetTimeout(INFINITE);
87 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"CheckIntegrityLevel"));
90 } // namespace sandbox