diff options
-rw-r--r-- | test/test_unistd.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 365ec00d..73e8b8ab 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -145,6 +145,37 @@ fn test_setgroups() { setgroups(&old_groups).unwrap(); } +#[test] +// `getgroups()` and `setgroups()` do not behave as expected on Apple platforms +#[cfg(not(any(target_os = "ios", target_os = "macos")))] +fn test_initgroups() { + // Skip this test when not run as root as `initgroups()` and `setgroups()` + // require root. + if !Uid::current().is_root() { + return + } + + // Save the existing groups + let old_groups = getgroups().unwrap(); + + // It doesn't matter if the root user is not called "root" or if a user + // called "root" doesn't exist. We are just checking that the extra, + // made-up group, `123`, is set. + // FIXME: This only tests half of initgroups' functionality. + let user = CString::new("root").unwrap(); + let group = Gid::from_raw(123); + let group_list = getgrouplist(&user, group).unwrap(); + assert!(group_list.contains(&group)); + + initgroups(&user, group).unwrap(); + + let new_groups = getgroups().unwrap(); + assert_eq!(new_groups, group_list); + + // Revert back to the old groups + setgroups(&old_groups).unwrap(); +} + macro_rules! execve_test_factory( ($test_name:ident, $syscall:ident, $exe: expr) => ( #[test] |