File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,31 @@ fn test_setgroups() {
126
126
setgroups ( & old_groups) . unwrap ( ) ;
127
127
}
128
128
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
+
129
154
macro_rules! execve_test_factory(
130
155
( $test_name: ident, $syscall: ident, $unix_sh: expr, $android_sh: expr) => (
131
156
#[ test]
You can’t perform that action at this time.
0 commit comments