main
cpp 66 lines 2.23 KB
Raw
1 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3 #include "precomp.h"
4
5 using namespace System;
6 using namespace System::Security::Principal;
7 using namespace Xunit;
8 using namespace WixInternal::TestSupport;
9 using namespace WixInternal::TestSupport::XunitExtensions;
10
11 namespace DutilTests
12 {
13 public ref class ProcUtil
14 {
15 public:
16 [Fact]
17 void ProcGetTokenInformationTest()
18 {
19 HRESULT hr = S_OK;
20 TOKEN_USER* pTokenUser = NULL;
21 LPWSTR sczSid = NULL;
22
23 try
24 {
25 hr = ProcGetTokenInformation(::GetCurrentProcess(), TokenUser, reinterpret_cast<LPVOID*>(&pTokenUser));
26 NativeAssert::Succeeded(hr, "Failed to get TokenUser for current process.");
27
28 if (!::ConvertSidToStringSidW(pTokenUser->User.Sid, &sczSid))
29 {
30 hr = HRESULT_FROM_WIN32(::GetLastError());
31 NativeAssert::Succeeded(hr, "Failed to get string SID from TokenUser SID.");
32 }
33
34 Assert::Equal<String^>(WindowsIdentity::GetCurrent()->User->Value, gcnew String(sczSid));
35 }
36 finally
37 {
38 ReleaseMem(pTokenUser);
39 ReleaseStr(sczSid);
40 }
41 }
42
43 [SkippableFact]
44 void ProcHasPrivilegeTest()
45 {
46 HRESULT hr = S_OK;
47 BOOL fHasPrivilege = FALSE;
48
49 hr = ProcHasPrivilege(::GetCurrentProcess(), SE_CREATE_TOKEN_NAME, &fHasPrivilege);
50 NativeAssert::Succeeded(hr, "Failed to check privilege for current process.");
51
52 if (fHasPrivilege)
53 {
54 WixAssert::Skip("Didn't expect process to have SE_CREATE_TOKEN_NAME privilege");
55 }
56
57 hr = ProcHasPrivilege(::GetCurrentProcess(), SE_INC_WORKING_SET_NAME, &fHasPrivilege);
58 NativeAssert::Succeeded(hr, "Failed to check privilege for current process.");
59
60 if (!fHasPrivilege)
61 {
62 WixAssert::Skip("Expected process to have SE_INC_WORKING_SET_NAME privilege");
63 }
64 }
65 };
66 }