1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/win/src/app_container_unittest.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "base/win/windows_version.h" 1.9 +#include "sandbox/win/src/app_container.h" 1.10 +#include "testing/gtest/include/gtest/gtest.h" 1.11 + 1.12 +namespace sandbox { 1.13 + 1.14 +// Tests the low level AppContainer interface. 1.15 +TEST(AppContainerTest, CreateAppContainer) { 1.16 + if (base::win::OSInfo::GetInstance()->version() < base::win::VERSION_WIN8) 1.17 + return; 1.18 + 1.19 + const wchar_t kName[] = L"Test"; 1.20 + const wchar_t kValidSid[] = L"S-1-15-2-12345-234-567-890-123-456-789"; 1.21 + 1.22 + EXPECT_TRUE(LookupAppContainer(kValidSid).empty()); 1.23 + EXPECT_EQ(SBOX_ERROR_GENERIC, DeleteAppContainer(kValidSid)); 1.24 + 1.25 + EXPECT_EQ(SBOX_ALL_OK, CreateAppContainer(kValidSid, kName)); 1.26 + EXPECT_EQ(SBOX_ERROR_GENERIC, CreateAppContainer(kValidSid, kName)); 1.27 + EXPECT_EQ(kName, LookupAppContainer(kValidSid)); 1.28 + EXPECT_EQ(SBOX_ALL_OK, DeleteAppContainer(kValidSid)); 1.29 + 1.30 + EXPECT_TRUE(LookupAppContainer(kValidSid).empty()); 1.31 + EXPECT_EQ(SBOX_ERROR_GENERIC, DeleteAppContainer(kValidSid)); 1.32 + 1.33 + EXPECT_EQ(SBOX_ERROR_INVALID_APP_CONTAINER, 1.34 + CreateAppContainer(L"Foo", kName)); 1.35 +} 1.36 + 1.37 +// Tests handling of security capabilities on the attribute list. 1.38 +TEST(AppContainerTest, SecurityCapabilities) { 1.39 + if (base::win::OSInfo::GetInstance()->version() < base::win::VERSION_WIN8) 1.40 + return; 1.41 + 1.42 + scoped_ptr<AppContainerAttributes> attributes(new AppContainerAttributes); 1.43 + std::vector<string16> capabilities; 1.44 + EXPECT_EQ(SBOX_ERROR_INVALID_APP_CONTAINER, 1.45 + attributes->SetAppContainer(L"S-1-foo", capabilities)); 1.46 + 1.47 + EXPECT_EQ(SBOX_ALL_OK, 1.48 + attributes->SetAppContainer(L"S-1-15-2-12345-234", capabilities)); 1.49 + EXPECT_TRUE(attributes->HasAppContainer()); 1.50 + 1.51 + attributes.reset(new AppContainerAttributes); 1.52 + capabilities.push_back(L"S-1-15-3-12345678-87654321"); 1.53 + capabilities.push_back(L"S-1-15-3-1"); 1.54 + capabilities.push_back(L"S-1-15-3-2"); 1.55 + capabilities.push_back(L"S-1-15-3-3"); 1.56 + EXPECT_EQ(SBOX_ALL_OK, 1.57 + attributes->SetAppContainer(L"S-1-15-2-1-2", capabilities)); 1.58 + EXPECT_TRUE(attributes->HasAppContainer()); 1.59 +} 1.60 + 1.61 +} // namespace sandbox