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