2021-03-21 15:18:47 +00:00
|
|
|
use crate::common::util::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_missing_operand() {
|
|
|
|
let result = new_ucmd!().run();
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
assert!(result
|
|
|
|
.stderr_str()
|
|
|
|
.starts_with("error: The following required arguments were not provided"));
|
|
|
|
|
|
|
|
assert!(result.stderr_str().contains("<newroot>"));
|
2021-03-21 15:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_enter_chroot_fails() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
at.mkdir("jail");
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
let result = ucmd.arg("jail").fails();
|
2021-03-21 15:18:47 +00:00
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
assert!(result
|
|
|
|
.stderr_str()
|
|
|
|
.starts_with("chroot: error: cannot chroot to jail: Operation not permitted (os error 1)"));
|
2021-03-21 15:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_no_such_directory() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
at.touch(&at.plus_as_string("a"));
|
|
|
|
|
|
|
|
ucmd.arg("a")
|
|
|
|
.fails()
|
|
|
|
.stderr_is("chroot: error: cannot change root directory to `a`: no such directory");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_invalid_user_spec() {
|
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
at.mkdir("a");
|
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
let result = ucmd.arg("a").arg("--userspec=ARABA:").fails();
|
2021-03-21 15:18:47 +00:00
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
assert!(result
|
|
|
|
.stderr_str()
|
|
|
|
.starts_with("chroot: error: invalid userspec"));
|
2021-03-21 15:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_preference_of_userspec() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let result = scene.cmd("whoami").run();
|
2021-04-22 20:37:44 +00:00
|
|
|
if is_ci() && result.stderr_str().contains("No such user/group") {
|
2021-03-21 15:18:47 +00:00
|
|
|
// In the CI, some server are failing to return whoami.
|
|
|
|
// As seems to be a configuration issue, ignoring it
|
|
|
|
return;
|
|
|
|
}
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("result.stdout = {}", result.stdout_str());
|
|
|
|
println!("result.stderr = {}", result.stderr_str());
|
|
|
|
let username = result.stdout_str().trim_end();
|
2021-03-21 15:18:47 +00:00
|
|
|
|
|
|
|
let ts = TestScenario::new("id");
|
|
|
|
let result = ts.cmd("id").arg("-g").arg("-n").run();
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("result.stdout = {}", result.stdout_str());
|
|
|
|
println!("result.stderr = {}", result.stderr_str());
|
2021-03-21 15:18:47 +00:00
|
|
|
|
2021-04-22 20:37:44 +00:00
|
|
|
if is_ci() && result.stderr_str().contains("cannot find name for user ID") {
|
2021-03-21 15:18:47 +00:00
|
|
|
// In the CI, some server are failing to return id.
|
|
|
|
// As seems to be a configuration issue, ignoring it
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-05 20:03:43 +00:00
|
|
|
let group_name = result.stdout_str().trim_end();
|
2021-03-21 15:18:47 +00:00
|
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
|
|
|
|
|
|
at.mkdir("a");
|
|
|
|
|
|
|
|
let result = ucmd
|
|
|
|
.arg("a")
|
|
|
|
.arg("--user")
|
|
|
|
.arg("fake")
|
|
|
|
.arg("-G")
|
|
|
|
.arg("ABC,DEF")
|
|
|
|
.arg(format!("--userspec={}:{}", username, group_name))
|
|
|
|
.run();
|
|
|
|
|
2021-04-05 20:03:43 +00:00
|
|
|
println!("result.stdout = {}", result.stdout_str());
|
|
|
|
println!("result.stderr = {}", result.stderr_str());
|
2021-03-21 15:18:47 +00:00
|
|
|
}
|