diff options
author | Jamie Hewland <jhewland@gmail.com> | 2017-08-27 20:08:24 +0200 |
---|---|---|
committer | Jamie Hewland <jhewland@gmail.com> | 2017-11-12 10:56:58 +0200 |
commit | 89b705519e34396319fb2869a7102c511543387c (patch) | |
tree | 622aa0d233323ba1f121e6b50a1c9708081600f8 /test/test_unistd.rs | |
parent | 5ff0c35998e1bfd9907e2e9c73681acc99143431 (diff) | |
download | nix-89b705519e34396319fb2869a7102c511543387c.zip |
test_unistd: Add test for getgroups/setgroups()
Diffstat (limited to 'test/test_unistd.rs')
-rw-r--r-- | test/test_unistd.rs | 23 |
1 files changed, 23 insertions, 0 deletions
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] |