Skip to content

Commit 8241168

Browse files
authored
make TestUserCredentialsPropertiesOnWindows stable on Windows Server Core (#47031)
* kill the process first, then remove the access and then remove the user this is to try to make TestUserCredentialsPropertiesOnWindows stable on Windows Server Core * is UnauthorizedAccessException thrown from finally swallowing a different exception (throw in the catch block)? * I was right, the first call to SetAccessControl was throwing What if we don't give the user rigts to execute it at all?
1 parent ea0d37c commit 8241168

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,11 @@ public void TestUserCredentialsPropertiesOnWindows()
472472
{
473473
p = CreateProcessLong();
474474

475-
// ensure the new user can access the .exe (otherwise you get Access is denied exception)
476-
SetAccessControl(username, p.StartInfo.FileName, add: true);
475+
if (PlatformDetection.IsNotWindowsServerCore) // for this particular Windows version it fails with Attempted to perform an unauthorized operation (#46619)
476+
{
477+
// ensure the new user can access the .exe (otherwise you get Access is denied exception)
478+
SetAccessControl(username, p.StartInfo.FileName, add: true);
479+
}
477480

478481
p.StartInfo.LoadUserProfile = true;
479482
p.StartInfo.UserName = username;
@@ -500,10 +503,6 @@ public void TestUserCredentialsPropertiesOnWindows()
500503
}
501504
finally
502505
{
503-
SetAccessControl(username, p.StartInfo.FileName, add: false); // remove the access
504-
505-
Assert.Equal(Interop.ExitCodes.NERR_Success, Interop.NetUserDel(null, username));
506-
507506
if (handle != null)
508507
handle.Dispose();
509508

@@ -513,6 +512,13 @@ public void TestUserCredentialsPropertiesOnWindows()
513512

514513
Assert.True(p.WaitForExit(WaitInMS));
515514
}
515+
516+
if (PlatformDetection.IsNotWindowsServerCore)
517+
{
518+
SetAccessControl(username, p.StartInfo.FileName, add: false); // remove the access
519+
}
520+
521+
Assert.Equal(Interop.ExitCodes.NERR_Success, Interop.NetUserDel(null, username));
516522
}
517523
}
518524

0 commit comments

Comments
 (0)