security/sandbox/win/src/sid_unittest.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 // This file contains unit tests for the sid class.
michael@0 6
michael@0 7 #define _ATL_NO_EXCEPTIONS
michael@0 8 #include <atlbase.h>
michael@0 9 #include <atlsecurity.h>
michael@0 10
michael@0 11 #include "sandbox/win/src/sid.h"
michael@0 12 #include "testing/gtest/include/gtest/gtest.h"
michael@0 13
michael@0 14 namespace sandbox {
michael@0 15
michael@0 16 // Calls ::EqualSid. This function exists only to simplify the calls to
michael@0 17 // ::EqualSid by removing the need to cast the input params.
michael@0 18 BOOL EqualSid(const SID *sid1, const SID *sid2) {
michael@0 19 return ::EqualSid(const_cast<SID*>(sid1), const_cast<SID*>(sid2));
michael@0 20 }
michael@0 21
michael@0 22 // Tests the creation if a Sid
michael@0 23 TEST(SidTest, Constructors) {
michael@0 24 ATL::CSid sid_world = ATL::Sids::World();
michael@0 25 SID *sid_world_pointer = const_cast<SID*>(sid_world.GetPSID());
michael@0 26
michael@0 27 // Check the SID* constructor
michael@0 28 Sid sid_sid_star(sid_world_pointer);
michael@0 29 ASSERT_TRUE(EqualSid(sid_world_pointer, sid_sid_star.GetPSID()));
michael@0 30
michael@0 31 // Check the copy constructor
michael@0 32 Sid sid_copy(sid_sid_star);
michael@0 33 ASSERT_TRUE(EqualSid(sid_world_pointer, sid_copy.GetPSID()));
michael@0 34
michael@0 35 // Note that the WELL_KNOWN_SID_TYPE constructor is tested in the GetPSID
michael@0 36 // test.
michael@0 37 }
michael@0 38
michael@0 39 // Tests the method GetPSID
michael@0 40 TEST(SidTest, GetPSID) {
michael@0 41 // Check for non-null result;
michael@0 42 ASSERT_NE(static_cast<SID*>(NULL), Sid(::WinLocalSid).GetPSID());
michael@0 43 ASSERT_NE(static_cast<SID*>(NULL), Sid(::WinCreatorOwnerSid).GetPSID());
michael@0 44 ASSERT_NE(static_cast<SID*>(NULL), Sid(::WinBatchSid).GetPSID());
michael@0 45
michael@0 46 ASSERT_TRUE(EqualSid(Sid(::WinNullSid).GetPSID(),
michael@0 47 ATL::Sids::Null().GetPSID()));
michael@0 48
michael@0 49 ASSERT_TRUE(EqualSid(Sid(::WinWorldSid).GetPSID(),
michael@0 50 ATL::Sids::World().GetPSID()));
michael@0 51
michael@0 52 ASSERT_TRUE(EqualSid(Sid(::WinDialupSid).GetPSID(),
michael@0 53 ATL::Sids::Dialup().GetPSID()));
michael@0 54
michael@0 55 ASSERT_TRUE(EqualSid(Sid(::WinNetworkSid).GetPSID(),
michael@0 56 ATL::Sids::Network().GetPSID()));
michael@0 57
michael@0 58 ASSERT_TRUE(EqualSid(Sid(::WinBuiltinAdministratorsSid).GetPSID(),
michael@0 59 ATL::Sids::Admins().GetPSID()));
michael@0 60
michael@0 61 ASSERT_TRUE(EqualSid(Sid(::WinBuiltinUsersSid).GetPSID(),
michael@0 62 ATL::Sids::Users().GetPSID()));
michael@0 63
michael@0 64 ASSERT_TRUE(EqualSid(Sid(::WinBuiltinGuestsSid).GetPSID(),
michael@0 65 ATL::Sids::Guests().GetPSID()));
michael@0 66
michael@0 67 ASSERT_TRUE(EqualSid(Sid(::WinProxySid).GetPSID(),
michael@0 68 ATL::Sids::Proxy().GetPSID()));
michael@0 69 }
michael@0 70
michael@0 71 } // namespace sandbox

mercurial