1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/win/src/sid_unittest.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,71 @@ 1.4 +// Copyright (c) 2006-2008 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 +// This file contains unit tests for the sid class. 1.9 + 1.10 +#define _ATL_NO_EXCEPTIONS 1.11 +#include <atlbase.h> 1.12 +#include <atlsecurity.h> 1.13 + 1.14 +#include "sandbox/win/src/sid.h" 1.15 +#include "testing/gtest/include/gtest/gtest.h" 1.16 + 1.17 +namespace sandbox { 1.18 + 1.19 +// Calls ::EqualSid. This function exists only to simplify the calls to 1.20 +// ::EqualSid by removing the need to cast the input params. 1.21 +BOOL EqualSid(const SID *sid1, const SID *sid2) { 1.22 + return ::EqualSid(const_cast<SID*>(sid1), const_cast<SID*>(sid2)); 1.23 +} 1.24 + 1.25 +// Tests the creation if a Sid 1.26 +TEST(SidTest, Constructors) { 1.27 + ATL::CSid sid_world = ATL::Sids::World(); 1.28 + SID *sid_world_pointer = const_cast<SID*>(sid_world.GetPSID()); 1.29 + 1.30 + // Check the SID* constructor 1.31 + Sid sid_sid_star(sid_world_pointer); 1.32 + ASSERT_TRUE(EqualSid(sid_world_pointer, sid_sid_star.GetPSID())); 1.33 + 1.34 + // Check the copy constructor 1.35 + Sid sid_copy(sid_sid_star); 1.36 + ASSERT_TRUE(EqualSid(sid_world_pointer, sid_copy.GetPSID())); 1.37 + 1.38 + // Note that the WELL_KNOWN_SID_TYPE constructor is tested in the GetPSID 1.39 + // test. 1.40 +} 1.41 + 1.42 +// Tests the method GetPSID 1.43 +TEST(SidTest, GetPSID) { 1.44 + // Check for non-null result; 1.45 + ASSERT_NE(static_cast<SID*>(NULL), Sid(::WinLocalSid).GetPSID()); 1.46 + ASSERT_NE(static_cast<SID*>(NULL), Sid(::WinCreatorOwnerSid).GetPSID()); 1.47 + ASSERT_NE(static_cast<SID*>(NULL), Sid(::WinBatchSid).GetPSID()); 1.48 + 1.49 + ASSERT_TRUE(EqualSid(Sid(::WinNullSid).GetPSID(), 1.50 + ATL::Sids::Null().GetPSID())); 1.51 + 1.52 + ASSERT_TRUE(EqualSid(Sid(::WinWorldSid).GetPSID(), 1.53 + ATL::Sids::World().GetPSID())); 1.54 + 1.55 + ASSERT_TRUE(EqualSid(Sid(::WinDialupSid).GetPSID(), 1.56 + ATL::Sids::Dialup().GetPSID())); 1.57 + 1.58 + ASSERT_TRUE(EqualSid(Sid(::WinNetworkSid).GetPSID(), 1.59 + ATL::Sids::Network().GetPSID())); 1.60 + 1.61 + ASSERT_TRUE(EqualSid(Sid(::WinBuiltinAdministratorsSid).GetPSID(), 1.62 + ATL::Sids::Admins().GetPSID())); 1.63 + 1.64 + ASSERT_TRUE(EqualSid(Sid(::WinBuiltinUsersSid).GetPSID(), 1.65 + ATL::Sids::Users().GetPSID())); 1.66 + 1.67 + ASSERT_TRUE(EqualSid(Sid(::WinBuiltinGuestsSid).GetPSID(), 1.68 + ATL::Sids::Guests().GetPSID())); 1.69 + 1.70 + ASSERT_TRUE(EqualSid(Sid(::WinProxySid).GetPSID(), 1.71 + ATL::Sids::Proxy().GetPSID())); 1.72 +} 1.73 + 1.74 +} // namespace sandbox