@@ -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} ;
@@ -1807,4 +1807,39 @@ fn test_install_symlink_same_file() {
18071807 . stderr_contains ( format ! (
18081808 "'{target_dir}/{file}' and '{target_link}/{file}' are the same file"
18091809 ) ) ;
1810+ /// This test requires user with userid 500 nonexistent
1811+ #[ test]
1812+ #[ cfg( unix) ]
1813+ fn test_install_set_owner_nonexistent_userid ( ) {
1814+ match Command :: new ( "id" )
1815+ . arg ( "500" )
1816+ . stdout ( Stdio :: null ( ) )
1817+ . stderr ( Stdio :: null ( ) )
1818+ . status ( )
1819+ {
1820+ Ok ( ret) if ret. success ( ) => {
1821+ println ! ( "Test skipped; requires user with userid 500 nonexistent" ) ;
1822+ return ;
1823+ }
1824+ Ok ( _) => { }
1825+ Err ( e) => {
1826+ println ! ( "failed to run id command: {}" , e) ;
1827+ return ;
1828+ }
1829+ }
1830+
1831+ let ts = TestScenario :: new ( util_name ! ( ) ) ;
1832+ let at = & ts. fixtures ;
1833+ at. touch ( "a" ) ;
1834+ at. touch ( "c" ) ;
1835+
1836+ if let Ok ( result) = run_ucmd_as_root ( & ts, & [ "-o500" , "a" , "b" ] ) {
1837+ result. success ( ) ;
1838+ assert ! ( at. file_exists( "b" ) ) ;
1839+
1840+ let metadata = fs:: metadata ( at. plus ( "b" ) ) . unwrap ( ) ;
1841+ assert_eq ! ( metadata. uid( ) , 500 ) ;
1842+ } else {
1843+ print ! ( "Test skipped; requires root user" ) ;
1844+ }
18101845}
0 commit comments