Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add asynchronous overload of WindowsIdentity.RunImpersonated #1152

Merged
merged 13 commits into from
Jan 22, 2020
Merged

Add asynchronous overload of WindowsIdentity.RunImpersonated #1152

merged 13 commits into from
Jan 22, 2020

Conversation

MarcoRossignoli
Copy link
Member

@MarcoRossignoli MarcoRossignoli commented Dec 25, 2019

closes https://github.com/dotnet/corefx/issues/24977

On issue there is #nullable enable on review comment, but I don't know what it mean, this namespaces seem not annotated yet.

At the moment there is not "real" test on "another" user token, I've added some plumbing to test with new win user, took idea from https://github.com/dotnet/runtime/blob/4f9ae42d861fcb4be2fcd5d3d55d5f227d30e723/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CurrentUserOnly.Windows.cs maybe we could at the end merge helper inside Common.
Let me know if it's too much and I'll remove all and will add only simple "same access token current user" test.
Folded two api test in one to reuse assertions and also because the test are pretty the same.

cc: @stephentoub @bartonjs @GrabYourPitchforks

Merry Christmas to all team!

@MarcoRossignoli MarcoRossignoli changed the title Add asynchronous overload of WindowsIdentity.RunImpersonated [WIP]Add asynchronous overload of WindowsIdentity.RunImpersonated Dec 25, 2019
@MarcoRossignoli MarcoRossignoli changed the title [WIP]Add asynchronous overload of WindowsIdentity.RunImpersonated Add asynchronous overload of WindowsIdentity.RunImpersonated Dec 25, 2019
@MarcoRossignoli
Copy link
Member Author

@ViktorHofer @safern is this expected?Am I missing something?Maybe worflow is changed a bit
I want to run netfx test on my local
Ran

D:\git\runtime (asyncrunimpersonated -> origin)
λ libraries.cmd -framework netfx

And after

D:\git\runtime\src\libraries\System.Security.Principal.Windows\tests (asyncrunimpersonated -> origin)
λ msbuild /t:rebuildandtest /p:TargetGroup=netfx /v:m
Microsoft (R) Build Engine version 16.5.0-preview-19562-03+d72e25031 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  CoreFx.Private.TestUtilities -> D:\git\runtime\artifacts\bin\CoreFx.Private.TestUtilities\netfx-Debug\CoreFx.Private.TestUtilities.dll
D:\git\runtime\eng\testing\xunit\xunit.console.targets(67,86): error MSB4184: The expression "[System.IO.Path]::GetDirectoryName('')" cannot be evaluated. The path is not of a legal form. [D:\git\runtime\src\
libraries\System.Security.Principal.Windows\tests\System.Security.Principal.Windows.Tests.csproj]

@MarcoRossignoli
Copy link
Member Author

/azp list

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 1152 in repo dotnet/runtime

@safern
Copy link
Member

safern commented Jan 6, 2020

@ViktorHofer @safern is this expected?Am I missing something?Maybe worflow is changed a bit
I want to run netfx test on my local

I believe this is a bug introduced when moving the corefx testing targets from arcade into the consolidated repo.

I believe we should condition this line to only execute when TargetsNetcoreApp == true.

@safern
Copy link
Member

safern commented Jan 6, 2020

I believe we should condition this line to only execute when TargetsNetcoreApp == true.

Actually it seems like the XunitConsoleNetCore21AppPath is wrong and it is not defined, that's why you're getting an empty path. Those properties seem to be defined by the xunit nuget package, and it seems like the property name is: XunitConsoleNetCore2AppPath

<PropertyGroup>
    <!-- Lowest supported version -->
    <XunitConsolePath>$(MSBuildThisFileDirectory)..\tools\net452\xunit.console.exe</XunitConsolePath>
    <XunitConsolePathX86>$(MSBuildThisFileDirectory)..\tools\net452\xunit.console.x86.exe</XunitConsolePathX86>

    <!-- Version specific -->
    <XunitConsole452Path>$(MSBuildThisFileDirectory)..\tools\net452\xunit.console.exe</XunitConsole452Path>
    <XunitConsole452PathX86>$(MSBuildThisFileDirectory)..\tools\net452\xunit.console.x86.exe</XunitConsole452PathX86>
    <XunitConsole46Path>$(MSBuildThisFileDirectory)..\tools\net46\xunit.console.exe</XunitConsole46Path>
    <XunitConsole46PathX86>$(MSBuildThisFileDirectory)..\tools\net46\xunit.console.x86.exe</XunitConsole46PathX86>
    <XunitConsole461Path>$(MSBuildThisFileDirectory)..\tools\net461\xunit.console.exe</XunitConsole461Path>
    <XunitConsole461PathX86>$(MSBuildThisFileDirectory)..\tools\net461\xunit.console.x86.exe</XunitConsole461PathX86>
    <XunitConsole462Path>$(MSBuildThisFileDirectory)..\tools\net462\xunit.console.exe</XunitConsole462Path>
    <XunitConsole462PathX86>$(MSBuildThisFileDirectory)..\tools\net462\xunit.console.x86.exe</XunitConsole462PathX86>
    <XunitConsole47Path>$(MSBuildThisFileDirectory)..\tools\net47\xunit.console.exe</XunitConsole47Path>
    <XunitConsole47PathX86>$(MSBuildThisFileDirectory)..\tools\net47\xunit.console.x86.exe</XunitConsole47PathX86>
    <XunitConsole471Path>$(MSBuildThisFileDirectory)..\tools\net471\xunit.console.exe</XunitConsole471Path>
    <XunitConsole471PathX86>$(MSBuildThisFileDirectory)..\tools\net471\xunit.console.x86.exe</XunitConsole471PathX86>
    <XunitConsole472Path>$(MSBuildThisFileDirectory)..\tools\net472\xunit.console.exe</XunitConsole472Path>
    <XunitConsole472PathX86>$(MSBuildThisFileDirectory)..\tools\net472\xunit.console.x86.exe</XunitConsole472PathX86>

    <!-- Lowest supported version -->
    <XunitConsoleNetCoreAppPath>$(MSBuildThisFileDirectory)..\tools\netcoreapp1.0\xunit.console.dll</XunitConsoleNetCoreAppPath>

    <!-- Version specific -->
    <XunitConsoleNetCore1AppPath>$(MSBuildThisFileDirectory)..\tools\netcoreapp1.0\xunit.console.dll</XunitConsoleNetCore1AppPath>
    <XunitConsoleNetCore2AppPath>$(MSBuildThisFileDirectory)..\tools\netcoreapp2.0\xunit.console.dll</XunitConsoleNetCore2AppPath>
  </PropertyGroup>

@MarcoRossignoli
Copy link
Member Author

/azp list

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 1152 in repo dotnet/runtime

@ViktorHofer
Copy link
Member

Actually it seems like the XunitConsoleNetCore21AppPath is wrong and it is not defined, that's why you're getting an empty path. Those properties seem to be defined by the xunit nuget package, and it seems like the property name is: XunitConsoleNetCore2AppPath

@safern this is a custom property defined in our own xunit console runner: https://github.com/dotnet/arcade/blob/master/src/Microsoft.DotNet.XUnitConsoleRunner/src/build/Microsoft.DotNet.XUnitConsoleRunner.props#L4.

I assume this isn't working because netcoreapp wasn't restored correctly or the design time imports failed for some reason. To guard against that we should add '$(XunitConsoleNetCore21AppPath)' != '' in eng\testing\xunit\xunit.console.targets:L67.

@ViktorHofer
Copy link
Member

Submitted #1715 to guard against such case.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

RunImpersonatedInternal(safeAccessTokenHandle, () => result = func());
return result;
}

/// <summary>
/// Runs the specified asynchronous action as the impersonated Windows identity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Runs the specified asynchronous action as the impersonated Windows identity
/// Runs the specified asynchronous action as the impersonated Windows identity.

=> RunImpersonated(safeAccessTokenHandle, func);

/// <summary>
/// Runs the specified asynchronous action as the impersonated Windows identity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Runs the specified asynchronous action as the impersonated Windows identity
/// Runs the specified asynchronous action as the impersonated Windows identity.

@stephentoub stephentoub merged commit beff8ab into dotnet:master Jan 22, 2020
@MarcoRossignoli MarcoRossignoli deleted the asyncrunimpersonated branch January 23, 2020 07:08
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants