Skip to content

Commit d998b04

Browse files
committed
unistd: Add half a test for initgroups
1 parent 5b9a4d8 commit d998b04

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/test_unistd.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,31 @@ fn test_setgroups() {
126126
setgroups(&old_groups).unwrap();
127127
}
128128

129+
#[test]
130+
fn test_initgroups() {
131+
if !Uid::current().is_root() {
132+
// initrgroups(), setgroups() require root
133+
return
134+
}
135+
136+
// Save the existing groups
137+
let old_groups = getgroups().unwrap();
138+
139+
// It doesn't matter if the root user is not called "root" or if a user
140+
// called "root" doesn't exist. We are just checking that the extra,
141+
// made-up group, `123`, is set.
142+
// FIXME: This only tests half of initgroups' functionality.
143+
let user = CString::new("root").unwrap();
144+
let group = Gid::from_raw(123);
145+
initgroups(&user, group).unwrap();
146+
147+
let new_groups = getgroups().unwrap();
148+
assert!(new_groups.contains(&group));
149+
150+
// Revert back to the old groups
151+
setgroups(&old_groups).unwrap();
152+
}
153+
129154
macro_rules! execve_test_factory(
130155
($test_name:ident, $syscall:ident, $unix_sh:expr, $android_sh:expr) => (
131156
#[test]

0 commit comments

Comments
 (0)