From 92b7452abd857c565ad3624db6958cb56edd6fc0 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 15 Jan 2021 08:42:08 +0100 Subject: [PATCH 1/3] 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 --- .../tests/ProcessStartInfoTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs index e88bef5138f17a..23b8b87ff1d319 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs @@ -500,10 +500,6 @@ public void TestUserCredentialsPropertiesOnWindows() } finally { - SetAccessControl(username, p.StartInfo.FileName, add: false); // remove the access - - Assert.Equal(Interop.ExitCodes.NERR_Success, Interop.NetUserDel(null, username)); - if (handle != null) handle.Dispose(); @@ -513,6 +509,10 @@ public void TestUserCredentialsPropertiesOnWindows() Assert.True(p.WaitForExit(WaitInMS)); } + + SetAccessControl(username, p.StartInfo.FileName, add: false); // remove the access + + Assert.Equal(Interop.ExitCodes.NERR_Success, Interop.NetUserDel(null, username)); } } From 5727c5e2e5a7c7c291ed48fd5372db7134cc3b0b Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 15 Jan 2021 10:15:22 +0100 Subject: [PATCH 2/3] is UnauthorizedAccessException thrown from finally swallowing a different exception (throw in the catch block)? --- .../tests/ProcessStartInfoTests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs index 23b8b87ff1d319..dd4473234034d4 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs @@ -510,7 +510,10 @@ public void TestUserCredentialsPropertiesOnWindows() Assert.True(p.WaitForExit(WaitInMS)); } - SetAccessControl(username, p.StartInfo.FileName, add: false); // remove the access + if (PlatformDetection.IsNotWindowsServerCore) // for this particular Windows version it fails with Attempted to perform an unauthorized operation (#46619) + { + SetAccessControl(username, p.StartInfo.FileName, add: false); // remove the access + } Assert.Equal(Interop.ExitCodes.NERR_Success, Interop.NetUserDel(null, username)); } From a2ca84872c9f35ded4d67914e78d1bda5c52e9f1 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 15 Jan 2021 11:41:41 +0100 Subject: [PATCH 3/3] I was right, the first call to SetAccessControl was throwing What if we don't give the user rigts to execute it at all? --- .../tests/ProcessStartInfoTests.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs index dd4473234034d4..f3c4f285590e0d 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs @@ -472,8 +472,11 @@ public void TestUserCredentialsPropertiesOnWindows() { p = CreateProcessLong(); - // ensure the new user can access the .exe (otherwise you get Access is denied exception) - SetAccessControl(username, p.StartInfo.FileName, add: true); + if (PlatformDetection.IsNotWindowsServerCore) // for this particular Windows version it fails with Attempted to perform an unauthorized operation (#46619) + { + // ensure the new user can access the .exe (otherwise you get Access is denied exception) + SetAccessControl(username, p.StartInfo.FileName, add: true); + } p.StartInfo.LoadUserProfile = true; p.StartInfo.UserName = username; @@ -510,7 +513,7 @@ public void TestUserCredentialsPropertiesOnWindows() Assert.True(p.WaitForExit(WaitInMS)); } - if (PlatformDetection.IsNotWindowsServerCore) // for this particular Windows version it fails with Attempted to perform an unauthorized operation (#46619) + if (PlatformDetection.IsNotWindowsServerCore) { SetAccessControl(username, p.StartInfo.FileName, add: false); // remove the access }