@@ -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} ;
@@ -1778,3 +1778,40 @@ fn test_install_failing_copy_file_to_target_contain_subdir_with_same_name() {
17781778 . fails ( )
17791779 . stderr_contains ( "cannot overwrite directory" ) ;
17801780}
1781+
1782+ /// This test requires user with userid 500 nonexistent
1783+ #[ test]
1784+ #[ cfg( unix) ]
1785+ fn test_install_set_owner_nonexistent_userid ( ) {
1786+ match Command :: new ( "id" )
1787+ . arg ( "500" )
1788+ . stdout ( Stdio :: null ( ) )
1789+ . stderr ( Stdio :: null ( ) )
1790+ . status ( )
1791+ {
1792+ Ok ( ret) if ret. success ( ) => {
1793+ println ! ( "Test skipped; requires user with userid 500 nonexistent" ) ;
1794+ return ;
1795+ }
1796+ Ok ( _) => { }
1797+ Err ( e) => {
1798+ println ! ( "failed to run id command: {}" , e) ;
1799+ return ;
1800+ }
1801+ }
1802+
1803+ let ts = TestScenario :: new ( util_name ! ( ) ) ;
1804+ let at = & ts. fixtures ;
1805+ at. touch ( "a" ) ;
1806+ at. touch ( "c" ) ;
1807+
1808+ if let Ok ( result) = run_ucmd_as_root ( & ts, & [ "-o500" , "a" , "b" ] ) {
1809+ result. success ( ) ;
1810+ assert ! ( at. file_exists( "b" ) ) ;
1811+
1812+ let metadata = fs:: metadata ( at. plus ( "b" ) ) . unwrap ( ) ;
1813+ assert_eq ! ( metadata. uid( ) , 500 ) ;
1814+ } else {
1815+ print ! ( "Test skipped; requires root user" ) ;
1816+ }
1817+ }
0 commit comments