From 89b705519e34396319fb2869a7102c511543387c Mon Sep 17 00:00:00 2001 From: Jamie Hewland Date: Sun, 27 Aug 2017 20:08:24 +0200 Subject: test_unistd: Add test for getgroups/setgroups() --- test/test_unistd.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 627eb09b..365ec00d 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -122,6 +122,29 @@ mod linux_android { } } +#[test] +// `getgroups()` and `setgroups()` do not behave as expected on Apple platforms +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +fn test_setgroups() { + // Skip this test when not run as root as `setgroups()` requires root. + if !Uid::current().is_root() { + return + } + + // Save the existing groups + let old_groups = getgroups().unwrap(); + + // Set some new made up groups + let groups = [Gid::from_raw(123), Gid::from_raw(456)]; + setgroups(&groups).unwrap(); + + let new_groups = getgroups().unwrap(); + assert_eq!(new_groups, groups); + + // Revert back to the old groups + setgroups(&old_groups).unwrap(); +} + macro_rules! execve_test_factory( ($test_name:ident, $syscall:ident, $exe: expr) => ( #[test] -- cgit v1.2.3