File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,29 @@ mod linux_android {
122
122
}
123
123
}
124
124
125
+ #[ test]
126
+ // `getgroups()` and `setgroups()` do not behave as expected on Apple platforms
127
+ #[ cfg( not( any( target_os = "ios" , target_os = "macos" ) ) ) ]
128
+ fn test_setgroups ( ) {
129
+ // Skip this test when not run as root as `setgroups()` requires root.
130
+ if !Uid :: current ( ) . is_root ( ) {
131
+ return
132
+ }
133
+
134
+ // Save the existing groups
135
+ let old_groups = getgroups ( ) . unwrap ( ) ;
136
+
137
+ // Set some new made up groups
138
+ let groups = [ Gid :: from_raw ( 123 ) , Gid :: from_raw ( 456 ) ] ;
139
+ setgroups ( & groups) . unwrap ( ) ;
140
+
141
+ let new_groups = getgroups ( ) . unwrap ( ) ;
142
+ assert_eq ! ( new_groups, groups) ;
143
+
144
+ // Revert back to the old groups
145
+ setgroups ( & old_groups) . unwrap ( ) ;
146
+ }
147
+
125
148
macro_rules! execve_test_factory(
126
149
( $test_name: ident, $syscall: ident, $exe: expr) => (
127
150
#[ test]
You can’t perform that action at this time.
0 commit comments