summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJamie Hewland <jhewland@gmail.com>2017-08-27 20:10:27 +0200
committerJamie Hewland <jhewland@gmail.com>2017-11-12 10:56:58 +0200
commit688667eff8fe2fd9c5d3d91e4bf53e99284d894e (patch)
tree452a7343853e5b91af4ffe18ad3d1abbae03be87 /test
parent4a2d65ea65b0394921eb81f051e1efc6b89f5c93 (diff)
downloadnix-688667eff8fe2fd9c5d3d91e4bf53e99284d894e.zip
test_unistd: Add test for getgrouplist/initgroups()
Diffstat (limited to 'test')
-rw-r--r--test/test_unistd.rs31
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]