Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit c2b2639

Browse files
committed
Fix System.IO.Pipes test on 64-bit
A test is trying to use NamedPipeServerStream.GetImpersonationUserName and is failing when run in a 64-bit process. The client stream is being created with TokenImpersonalLevel.Identification, but MSDN states that the underlying GetNamedPipeHandleState being used to get the name will only allow retrieval of the name if SECURITY_IMPERSONATION is used, e.g. TokenImpersonationLevel.Impersonation. Changing the TokenImpersonationLevel allows the test to pass, on both 32-bit and 64-bit. This commit does that. What's strange is that the test passes as-is on 32-bit with Identification rather than Impersonation. This is true on desktop as well, e.g. this program runs fine in a 32-bit process but fails with an exception in a 64-bit process: ```C# using System; using System.IO.Pipes; using System.Security.Principal; using System.Threading.Tasks; class Program { static void Main() { string pipeName = Guid.NewGuid().ToString("N"); using (var server = new NamedPipeServerStream(pipeName, PipeDirection.InOut)) using (var client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Identification)) { Task t = server.WaitForConnectionAsync(); client.Connect(); t.Wait(); Console.WriteLine(server.GetImpersonationUserName()); // succeeds 32-bit, fails 64-bit } } } ``` Something to follow-up on separately.
1 parent 72059f6 commit c2b2639

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.Specific.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Runtime.InteropServices;
5+
using System.Security.Principal;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using Xunit;
@@ -89,7 +90,7 @@ public void Windows_MessagePipeTransissionMode()
8990

9091
using (NamedPipeServerStream server = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Message))
9192
{
92-
using (NamedPipeClientStream client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, Security.Principal.TokenImpersonationLevel.Identification))
93+
using (NamedPipeClientStream client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation))
9394
{
9495
server.ReadMode = PipeTransmissionMode.Message;
9596
Assert.Equal(PipeTransmissionMode.Message, server.ReadMode);

src/System.IO.Pipes/tests/System.IO.Pipes.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
<ProjectGuid>{142469EC-D665-4FE2-845A-FDA69F9CC557}</ProjectGuid>
1212
<NuGetPackageImportStamp>d2615b94</NuGetPackageImportStamp>
1313
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
14-
<!-- Temporary workaround until tests are fixed on x64 -->
15-
<TestArchitecture>x86</TestArchitecture>
1614
</PropertyGroup>
1715
<!-- Default configurations to help VS understand the configurations -->
1816
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

0 commit comments

Comments
 (0)