diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs index 99272c05f0c2e3..c6da2b1bbc7501 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs @@ -530,18 +530,17 @@ private static int CheckUserAndGroupIds(string userId, string groupId, string gr if (bool.Parse(checkGroupsExact)) { - AssertExtensions.Equal(expectedGroups, GetGroups()); + AssertExtensions.Equal(expectedGroups, GetCurrentUserGroupIds()); } else { - Assert.Subset(expectedGroups, GetGroups()); + Assert.Subset(expectedGroups, GetCurrentUserGroupIds()); } return RemoteExecutor.SuccessExitCode; } [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/28922", TestPlatforms.AnyUnix)] public unsafe void TestCheckChildProcessUserAndGroupIds() { string userName = GetCurrentRealUserName(); @@ -620,10 +619,17 @@ private static string GetUserGroupId(string username) private static string GetUserGroupIds(string username) { string[] groupIds = StartAndReadToEnd("id", new[] { "-G", username }) - .Split(new[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries); + .Split(new[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries); return string.Join(",", groupIds.Select(s => uint.Parse(s)).OrderBy(id => id)); } + private static HashSet GetCurrentUserGroupIds() + { + string[] groupIds = StartAndReadToEnd("id", new[] { "-G" }) + .Split(new[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries); + return new HashSet(groupIds.Select(s => uint.Parse(s))); + } + private static string GetCurrentRealUserName() { string realUserName = geteuid() == 0 ? @@ -906,27 +912,6 @@ private static void ChMod(string filename, string mode) [DllImport("libc")] private static extern uint getgid(); - [DllImport("libc", SetLastError = true)] - private static extern unsafe int getgroups(int size, uint* list); - - private static unsafe HashSet GetGroups() - { - int maxSize = 128; - Span groups = stackalloc uint[maxSize]; - fixed (uint* pGroups = groups) - { - int rv = getgroups(maxSize, pGroups); - if (rv == -1) - { - // If this throws with EINVAL, maxSize should be increased. - throw new Win32Exception(); - } - - // Return this as a HashSet to filter out duplicates. - return new HashSet(groups.Slice(0, rv).ToArray()); - } - } - [DllImport("libc")] private static extern int seteuid(uint euid);