2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2020-11-16 21:54:41 +00:00
|
|
|
use rust_users::*;
|
2020-11-17 21:13:58 +00:00
|
|
|
use std::os::unix::fs::PermissionsExt;
|
2016-07-12 18:56:21 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_help() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (_, mut ucmd) = at_and_ucmd!();
|
2016-07-12 18:56:21 +00:00
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
assert!(ucmd
|
|
|
|
.arg("--help")
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr()
|
|
|
|
.stdout
|
2020-11-13 17:20:57 +00:00
|
|
|
.contains("FLAGS:"));
|
2016-07-12 18:56:21 +00:00
|
|
|
}
|
2016-07-12 20:58:44 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_basic() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let dir = "target_dir";
|
|
|
|
let file1 = "source_file1";
|
|
|
|
let file2 = "source_file2";
|
2016-07-12 20:58:44 +00:00
|
|
|
|
2016-07-13 10:27:11 +00:00
|
|
|
at.touch(file1);
|
|
|
|
at.touch(file2);
|
2016-07-12 20:58:44 +00:00
|
|
|
at.mkdir(dir);
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(file1).arg(file2).arg(dir).succeeds().no_stderr();
|
2016-07-12 20:58:44 +00:00
|
|
|
|
2016-07-13 10:27:11 +00:00
|
|
|
assert!(at.file_exists(file1));
|
|
|
|
assert!(at.file_exists(file2));
|
|
|
|
assert!(at.file_exists(&format!("{}/{}", dir, file1)));
|
|
|
|
assert!(at.file_exists(&format!("{}/{}", dir, file2)));
|
2016-07-12 20:58:44 +00:00
|
|
|
}
|
2016-07-13 08:37:08 +00:00
|
|
|
|
2020-11-29 15:31:26 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_twice_dir() {
|
2021-03-20 18:31:52 +00:00
|
|
|
let dir = "dir";
|
2020-11-29 15:31:26 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
|
|
|
|
scene.ucmd().arg("-d").arg(dir).succeeds();
|
|
|
|
scene.ucmd().arg("-d").arg(dir).succeeds();
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
|
|
|
|
assert!(at.dir_exists(dir));
|
|
|
|
}
|
|
|
|
|
2017-12-27 08:31:19 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_failing_not_dir() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let file1 = "file1";
|
|
|
|
let file2 = "file2";
|
|
|
|
let file3 = "file3";
|
2017-12-27 08:31:19 +00:00
|
|
|
|
|
|
|
at.touch(file1);
|
|
|
|
at.touch(file2);
|
|
|
|
at.touch(file3);
|
2020-04-13 18:36:03 +00:00
|
|
|
assert!(ucmd
|
|
|
|
.arg(file1)
|
|
|
|
.arg(file2)
|
|
|
|
.arg(file3)
|
|
|
|
.fails()
|
|
|
|
.stderr
|
|
|
|
.contains("not a directory"));
|
2017-12-27 08:31:19 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 08:37:08 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_unimplemented_arg() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let dir = "target_dir";
|
|
|
|
let file = "source_file";
|
2016-07-13 08:37:08 +00:00
|
|
|
let context_arg = "--context";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2020-04-13 18:36:03 +00:00
|
|
|
assert!(ucmd
|
|
|
|
.arg(context_arg)
|
|
|
|
.arg(file)
|
|
|
|
.arg(dir)
|
|
|
|
.fails()
|
|
|
|
.stderr
|
|
|
|
.contains("Unimplemented"));
|
2016-07-13 08:37:08 +00:00
|
|
|
|
|
|
|
assert!(!at.file_exists(&format!("{}/{}", dir, file)));
|
|
|
|
}
|
2016-07-13 10:53:22 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_component_directories() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let component1 = "component1";
|
|
|
|
let component2 = "component2";
|
|
|
|
let component3 = "component3";
|
2016-07-13 10:53:22 +00:00
|
|
|
let directories_arg = "-d";
|
|
|
|
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.args(&[directories_arg, component1, component2, component3])
|
2020-04-13 18:36:03 +00:00
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
2016-07-13 10:53:22 +00:00
|
|
|
|
|
|
|
assert!(at.dir_exists(component1));
|
|
|
|
assert!(at.dir_exists(component2));
|
|
|
|
assert!(at.dir_exists(component3));
|
|
|
|
}
|
|
|
|
|
2016-07-13 13:29:24 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_mode_numeric() {
|
2020-12-17 22:41:52 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
2021-03-20 18:31:52 +00:00
|
|
|
let dir = "dir1";
|
|
|
|
let dir2 = "dir2";
|
2020-12-17 22:41:52 +00:00
|
|
|
|
2021-03-20 18:31:52 +00:00
|
|
|
let file = "file";
|
2016-07-13 13:29:24 +00:00
|
|
|
let mode_arg = "--mode=333";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2020-12-17 22:41:52 +00:00
|
|
|
scene
|
|
|
|
.ucmd()
|
|
|
|
.arg(file)
|
|
|
|
.arg(dir)
|
|
|
|
.arg(mode_arg)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
2016-07-13 13:29:24 +00:00
|
|
|
|
|
|
|
let dest_file = &format!("{}/{}", dir, file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(dest_file));
|
|
|
|
let permissions = at.metadata(dest_file).permissions();
|
2017-12-05 22:53:40 +00:00
|
|
|
assert_eq!(0o100333 as u32, PermissionsExt::mode(&permissions));
|
2020-12-17 22:41:52 +00:00
|
|
|
|
|
|
|
let mode_arg = "-m 0333";
|
|
|
|
at.mkdir(dir2);
|
|
|
|
|
|
|
|
let result = scene.ucmd().arg(mode_arg).arg(file).arg(dir2).run();
|
|
|
|
|
|
|
|
println!("stderr = {:?}", result.stderr);
|
|
|
|
println!("stdout = {:?}", result.stdout);
|
|
|
|
|
|
|
|
assert!(result.success);
|
|
|
|
let dest_file = &format!("{}/{}", dir2, file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(dest_file));
|
|
|
|
let permissions = at.metadata(dest_file).permissions();
|
|
|
|
assert_eq!(0o100333 as u32, PermissionsExt::mode(&permissions));
|
2016-07-13 13:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_mode_symbolic() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let dir = "target_dir";
|
|
|
|
let file = "source_file";
|
2016-07-13 13:29:24 +00:00
|
|
|
let mode_arg = "--mode=o+wx";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2016-08-13 21:59:21 +00:00
|
|
|
ucmd.arg(file).arg(dir).arg(mode_arg).succeeds().no_stderr();
|
2016-07-13 13:29:24 +00:00
|
|
|
|
|
|
|
let dest_file = &format!("{}/{}", dir, file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(dest_file));
|
|
|
|
let permissions = at.metadata(dest_file).permissions();
|
2017-12-05 22:53:40 +00:00
|
|
|
assert_eq!(0o100003 as u32, PermissionsExt::mode(&permissions));
|
2016-07-13 13:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_mode_failing() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let dir = "target_dir";
|
|
|
|
let file = "source_file";
|
2016-07-13 13:29:24 +00:00
|
|
|
let mode_arg = "--mode=999";
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2020-04-13 18:36:03 +00:00
|
|
|
assert!(ucmd
|
|
|
|
.arg(file)
|
|
|
|
.arg(dir)
|
|
|
|
.arg(mode_arg)
|
|
|
|
.fails()
|
|
|
|
.stderr
|
|
|
|
.contains("Invalid mode string: invalid digit found in string"));
|
2016-07-13 13:29:24 +00:00
|
|
|
|
|
|
|
let dest_file = &format!("{}/{}", dir, file);
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(!at.file_exists(dest_file));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_mode_directories() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let component = "component";
|
2016-07-13 13:29:24 +00:00
|
|
|
let directories_arg = "-d";
|
|
|
|
let mode_arg = "--mode=333";
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.arg(directories_arg)
|
|
|
|
.arg(component)
|
|
|
|
.arg(mode_arg)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
2016-07-13 13:29:24 +00:00
|
|
|
|
|
|
|
assert!(at.dir_exists(component));
|
|
|
|
let permissions = at.metadata(component).permissions();
|
2017-12-05 22:53:40 +00:00
|
|
|
assert_eq!(0o040333 as u32, PermissionsExt::mode(&permissions));
|
2016-07-13 13:29:24 +00:00
|
|
|
}
|
2017-12-27 08:31:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_target_file() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let file1 = "source_file";
|
|
|
|
let file2 = "target_file";
|
2017-12-27 08:31:19 +00:00
|
|
|
|
|
|
|
at.touch(file1);
|
|
|
|
at.touch(file2);
|
|
|
|
ucmd.arg(file1).arg(file2).succeeds().no_stderr();
|
|
|
|
|
|
|
|
assert!(at.file_exists(file1));
|
|
|
|
assert!(at.file_exists(file2));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_target_new_file() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let file = "file";
|
|
|
|
let dir = "target_dir";
|
2017-12-27 08:31:19 +00:00
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2020-04-13 18:36:03 +00:00
|
|
|
ucmd.arg(file)
|
|
|
|
.arg(format!("{}/{}", dir, file))
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
2017-12-27 08:31:19 +00:00
|
|
|
|
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(&format!("{}/{}", dir, file)));
|
|
|
|
}
|
|
|
|
|
2020-11-16 21:54:41 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_target_new_file_with_group() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let file = "file";
|
|
|
|
let dir = "target_dir";
|
2020-11-16 21:54:41 +00:00
|
|
|
let gid = get_effective_gid();
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2020-11-19 21:28:13 +00:00
|
|
|
let result = ucmd
|
|
|
|
.arg(file)
|
2020-11-16 21:54:41 +00:00
|
|
|
.arg("--group")
|
|
|
|
.arg(gid.to_string())
|
|
|
|
.arg(format!("{}/{}", dir, file))
|
2020-11-19 21:28:13 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
println!("stderr = {:?}", result.stderr);
|
|
|
|
println!("stdout = {:?}", result.stdout);
|
|
|
|
|
|
|
|
if is_ci() && result.stderr.contains("error: no such group:") {
|
|
|
|
// In the CI, some server are failing to return the group.
|
|
|
|
// As seems to be a configuration issue, ignoring it
|
|
|
|
return;
|
|
|
|
}
|
2020-11-16 21:54:41 +00:00
|
|
|
|
2020-11-19 21:28:13 +00:00
|
|
|
assert!(result.success);
|
2020-11-16 21:54:41 +00:00
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(&format!("{}/{}", dir, file)));
|
|
|
|
}
|
|
|
|
|
2020-11-17 21:13:58 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_target_new_file_with_owner() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let file = "file";
|
|
|
|
let dir = "target_dir";
|
2020-11-17 21:13:58 +00:00
|
|
|
let uid = get_effective_uid();
|
|
|
|
|
|
|
|
at.touch(file);
|
|
|
|
at.mkdir(dir);
|
2020-11-19 21:28:13 +00:00
|
|
|
let result = ucmd
|
|
|
|
.arg(file)
|
2020-11-17 21:13:58 +00:00
|
|
|
.arg("--owner")
|
|
|
|
.arg(uid.to_string())
|
|
|
|
.arg(format!("{}/{}", dir, file))
|
2020-11-19 21:28:13 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
println!("stderr = {:?}", result.stderr);
|
|
|
|
println!("stdout = {:?}", result.stdout);
|
|
|
|
|
|
|
|
if is_ci() && result.stderr.contains("error: no such user:") {
|
|
|
|
// In the CI, some server are failing to return the user id.
|
|
|
|
// As seems to be a configuration issue, ignoring it
|
|
|
|
return;
|
|
|
|
}
|
2020-11-17 21:13:58 +00:00
|
|
|
|
2020-11-19 21:28:13 +00:00
|
|
|
assert!(result.success);
|
2020-11-17 21:13:58 +00:00
|
|
|
assert!(at.file_exists(file));
|
|
|
|
assert!(at.file_exists(&format!("{}/{}", dir, file)));
|
|
|
|
}
|
2020-11-16 21:54:41 +00:00
|
|
|
|
2017-12-27 08:31:19 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_target_new_file_failing_nonexistent_parent() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let file1 = "source_file";
|
|
|
|
let file2 = "target_file";
|
|
|
|
let dir = "target_dir";
|
2017-12-27 08:31:19 +00:00
|
|
|
|
|
|
|
at.touch(file1);
|
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
let err = ucmd
|
|
|
|
.arg(file1)
|
|
|
|
.arg(format!("{}/{}", dir, file2))
|
|
|
|
.fails()
|
|
|
|
.stderr;
|
2017-12-27 08:31:19 +00:00
|
|
|
|
|
|
|
assert!(err.contains("not a directory"))
|
|
|
|
}
|
2020-11-25 12:48:00 +00:00
|
|
|
|
2021-03-12 21:51:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_install_preserve_timestamps() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let file1 = "source_file";
|
|
|
|
let file2 = "target_file";
|
2021-03-12 21:51:47 +00:00
|
|
|
at.touch(file1);
|
|
|
|
|
|
|
|
ucmd.arg(file1).arg(file2).arg("-p").succeeds().no_stderr();
|
|
|
|
|
|
|
|
assert!(at.file_exists(file1));
|
|
|
|
assert!(at.file_exists(file2));
|
|
|
|
|
|
|
|
let file1_metadata = at.metadata(file1);
|
|
|
|
let file2_metadata = at.metadata(file2);
|
|
|
|
|
2021-03-15 15:00:30 +00:00
|
|
|
assert_eq!(
|
|
|
|
file1_metadata.accessed().ok(),
|
|
|
|
file2_metadata.accessed().ok()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
file1_metadata.modified().ok(),
|
|
|
|
file2_metadata.modified().ok()
|
|
|
|
);
|
2021-03-12 21:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 12:48:00 +00:00
|
|
|
// These two tests are failing but should work
|
|
|
|
#[test]
|
|
|
|
fn test_install_copy_file() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let file1 = "source_file";
|
|
|
|
let file2 = "target_file";
|
2020-11-25 12:48:00 +00:00
|
|
|
|
|
|
|
at.touch(file1);
|
|
|
|
ucmd.arg(file1).arg(file2).succeeds().no_stderr();
|
|
|
|
|
|
|
|
assert!(at.file_exists(file1));
|
2020-11-26 20:46:03 +00:00
|
|
|
assert!(at.file_exists(file2));
|
2020-11-25 12:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn test_install_target_file_dev_null() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file1 = "/dev/null";
|
2021-03-20 18:31:52 +00:00
|
|
|
let file2 = "target_file";
|
2020-11-25 12:48:00 +00:00
|
|
|
|
|
|
|
ucmd.arg(file1).arg(file2).succeeds().no_stderr();
|
|
|
|
assert!(at.file_exists(file2));
|
2020-11-26 20:46:03 +00:00
|
|
|
}
|
2021-03-20 12:49:53 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-03-20 18:07:19 +00:00
|
|
|
fn test_install_nested_paths_copy_file() {
|
2021-03-20 12:49:53 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
2021-03-20 18:31:52 +00:00
|
|
|
let file1 = "source_file";
|
|
|
|
let dir1 = "source_dir";
|
|
|
|
let dir2 = "target_dir";
|
2021-03-20 12:49:53 +00:00
|
|
|
|
|
|
|
at.mkdir(dir1);
|
|
|
|
at.mkdir(dir2);
|
|
|
|
at.touch(&format!("{}/{}", dir1, file1));
|
|
|
|
|
2021-03-20 13:44:41 +00:00
|
|
|
ucmd.arg(format!("{}/{}", dir1, file1))
|
|
|
|
.arg(dir2)
|
|
|
|
.succeeds()
|
|
|
|
.no_stderr();
|
2021-03-20 12:49:53 +00:00
|
|
|
assert!(at.file_exists(&format!("{}/{}", dir2, file1)));
|
|
|
|
}
|
2021-03-20 18:07:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_failing_omitting_directory() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file1 = "source_file";
|
2021-03-20 18:31:52 +00:00
|
|
|
let dir1 = "source_dir";
|
2021-03-20 18:07:19 +00:00
|
|
|
let dir2 = "target_dir";
|
|
|
|
|
|
|
|
at.mkdir(dir1);
|
|
|
|
at.mkdir(dir2);
|
|
|
|
at.touch(file1);
|
|
|
|
|
|
|
|
let r = ucmd.arg(dir1).arg(file1).arg(dir2).run();
|
|
|
|
assert!(r.code == Some(1));
|
|
|
|
assert!(r.stderr.contains("omitting directory"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_install_failing_no_such_file() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
let file1 = "source_file";
|
|
|
|
let file2 = "inexistent_file";
|
|
|
|
let dir1 = "target_dir";
|
|
|
|
|
|
|
|
at.mkdir(dir1);
|
|
|
|
at.touch(file1);
|
|
|
|
|
|
|
|
let r = ucmd.arg(file1).arg(file2).arg(dir1).run();
|
|
|
|
assert!(r.code == Some(1));
|
|
|
|
assert!(r.stderr.contains("No such file or directory"));
|
|
|
|
}
|