@@ -9,7 +9,7 @@ use filetime::FileTime;
99use std:: fs;
1010use std:: os:: unix:: fs:: { MetadataExt , PermissionsExt } ;
1111#[ cfg( not( windows) ) ]
12- use std:: process:: Command ;
12+ use std:: process:: { Command , Stdio } ;
1313#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
1414use std:: thread:: sleep;
1515use uucore:: process:: { getegid, geteuid} ;
@@ -1764,3 +1764,40 @@ fn test_install_from_stdin() {
17641764 assert ! ( at. file_exists( target) ) ;
17651765 assert_eq ! ( at. read( target) , test_string) ;
17661766}
1767+
1768+ /// This test requires user with userid 500 nonexistent
1769+ #[ test]
1770+ #[ cfg( unix) ]
1771+ fn test_install_set_owner_nonexistent_userid ( ) {
1772+ match Command :: new ( "id" )
1773+ . args ( [ "-g" , "500" ] )
1774+ . stdout ( Stdio :: null ( ) )
1775+ . stderr ( Stdio :: null ( ) )
1776+ . status ( )
1777+ {
1778+ Ok ( ret) if ret. success ( ) => {
1779+ println ! ( "Test skipped; requires user with userid 500 nonexistent" ) ;
1780+ return ;
1781+ }
1782+ Ok ( _) => { }
1783+ Err ( e) => {
1784+ println ! ( "failed to run id command: {}" , e) ;
1785+ return ;
1786+ }
1787+ }
1788+
1789+ let ts = TestScenario :: new ( util_name ! ( ) ) ;
1790+ let at = & ts. fixtures ;
1791+ at. touch ( "a" ) ;
1792+ at. touch ( "c" ) ;
1793+
1794+ if let Ok ( result) = run_ucmd_as_root ( & ts, & [ "-o500" , "a" , "b" ] ) {
1795+ result. success ( ) ;
1796+ assert ! ( at. file_exists( "b" ) ) ;
1797+
1798+ let metadata = fs:: metadata ( at. plus ( "b" ) ) . unwrap ( ) ;
1799+ assert_eq ! ( metadata. uid( ) , 500 ) ;
1800+ } else {
1801+ print ! ( "Test skipped; requires root user" ) ;
1802+ }
1803+ }
0 commit comments