summaryrefslogtreecommitdiff
path: root/src/libs/dutil/test/DUtilUnitTest/ProcUtilTest.cpp
blob: 297d90f44c3ffbdeeee57b81bc33cd47947b0e9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// 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.

#include "precomp.h"

using namespace System;
using namespace System::Security::Principal;
using namespace Xunit;
using namespace WixBuildTools::TestSupport;

namespace DutilTests
{
    public ref class ProcUtil
    {
    public:
        [Fact]
        void ProcTokenUserTest()
        {
            HRESULT hr = S_OK;
            TOKEN_USER* pTokenUser = NULL;
            LPWSTR sczSid = NULL;

            try
            {
                hr = ProcTokenUser(::GetCurrentProcess(), &pTokenUser);
                NativeAssert::Succeeded(hr, "Failed to get TokenUser for current process.");

                if (!::ConvertSidToStringSidW(pTokenUser->User.Sid, &sczSid))
                {
                    hr = HRESULT_FROM_WIN32(::GetLastError());
                    NativeAssert::Succeeded(hr, "Failed to get string SID from TokenUser SID.");
                }

                Assert::Equal<String^>(WindowsIdentity::GetCurrent()->User->Value, gcnew String(sczSid));
            }
            finally
            {
                ReleaseMem(pTokenUser);
                ReleaseStr(sczSid);
            }
        }
    };
}