mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #2068 from jhscheer/chown_refactor_tests
chown: refactor tests
This commit is contained in:
commit
045eb0088a
1 changed files with 307 additions and 195 deletions
|
@ -4,6 +4,28 @@ use rust_users::get_effective_uid;
|
||||||
|
|
||||||
extern crate chown;
|
extern crate chown;
|
||||||
|
|
||||||
|
// Apparently some CI environments have configuration issues, e.g. with 'whoami' and 'id'.
|
||||||
|
// If we are running inside the CI and "needle" is in "stderr" skipping this test is
|
||||||
|
// considered okay. If we are not inside the CI this calls assert!(result.success).
|
||||||
|
//
|
||||||
|
// From the Logs: "Build (ubuntu-18.04, x86_64-unknown-linux-gnu, feat_os_unix, use-cross)"
|
||||||
|
// stderr: "whoami: cannot find name for user ID 1001"
|
||||||
|
// Maybe: "adduser --uid 1001 username" can put things right?
|
||||||
|
// stderr: "id: cannot find name for group ID 116"
|
||||||
|
fn skipping_test_is_okay(result: &CmdResult, needle: &str) -> bool {
|
||||||
|
if !result.succeeded() {
|
||||||
|
println!("result.stdout = {}", result.stdout_str());
|
||||||
|
println!("result.stderr = {}", result.stderr_str());
|
||||||
|
if is_ci() && result.stderr_str().contains(needle) {
|
||||||
|
println!("test skipped:");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_passgrp {
|
mod test_passgrp {
|
||||||
use super::chown::entries::{gid2grp, grp2gid, uid2usr, usr2uid};
|
use super::chown::entries::{gid2grp, grp2gid, uid2usr, usr2uid};
|
||||||
|
@ -49,116 +71,169 @@ fn test_invalid_option() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chown_myself() {
|
fn test_chown_only_owner() {
|
||||||
// test chown username file.txt
|
// test chown username file.txt
|
||||||
|
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
let result = scene.cmd("whoami").run();
|
let result = scene.cmd("whoami").run();
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") {
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("results {}", result.stdout_str());
|
let user_name = String::from(result.stdout_str().trim());
|
||||||
let username = result.stdout_str().trim_end();
|
assert!(!user_name.is_empty());
|
||||||
|
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
|
||||||
let file1 = "test_install_target_dir_file_a1";
|
|
||||||
|
|
||||||
|
let file1 = "test_chown_file1";
|
||||||
at.touch(file1);
|
at.touch(file1);
|
||||||
let result = ucmd.arg(username).arg(file1).run();
|
|
||||||
println!("results stdout {}", result.stdout_str());
|
// since only superuser can change owner, we have to change from ourself to ourself
|
||||||
println!("results stderr {}", result.stderr_str());
|
let result = scene
|
||||||
if is_ci() && result.stderr_str().contains("invalid user") {
|
.ucmd()
|
||||||
// In the CI, some server are failing to return id.
|
.arg(user_name)
|
||||||
// As seems to be a configuration issue, ignoring it
|
.arg("--verbose")
|
||||||
return;
|
.arg(file1)
|
||||||
}
|
.run();
|
||||||
assert!(result.success);
|
result.stderr_contains(&"retained as");
|
||||||
|
|
||||||
|
// try to change to another existing user, e.g. 'root'
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("root")
|
||||||
|
.arg("--verbose")
|
||||||
|
.arg(file1)
|
||||||
|
.fails()
|
||||||
|
.stderr_contains(&"failed to change");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chown_myself_second() {
|
fn test_chown_only_owner_colon() {
|
||||||
// test chown username: file.txt
|
// test chown username: file.txt
|
||||||
|
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
let result = scene.cmd("whoami").run();
|
let result = scene.cmd("whoami").run();
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") {
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("results {}", result.stdout_str());
|
let user_name = String::from(result.stdout_str().trim());
|
||||||
|
assert!(!user_name.is_empty());
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
|
||||||
let file1 = "test_install_target_dir_file_a1";
|
|
||||||
|
|
||||||
|
let file1 = "test_chown_file1";
|
||||||
at.touch(file1);
|
at.touch(file1);
|
||||||
let result = ucmd
|
|
||||||
.arg(result.stdout_str().trim_end().to_owned() + ":")
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg(format!("{}:", user_name))
|
||||||
|
.arg("--verbose")
|
||||||
.arg(file1)
|
.arg(file1)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
// scene // TODO: uncomment once #2060 is fixed
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
// .ucmd()
|
||||||
assert!(result.success);
|
// .arg("root:")
|
||||||
|
// .arg("--verbose")
|
||||||
|
// .arg(file1)
|
||||||
|
// .fails()
|
||||||
|
// .stderr_contains(&"failed to change");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chown_myself_group() {
|
fn test_chown_only_colon() {
|
||||||
|
// test chown : file.txt
|
||||||
|
|
||||||
|
// TODO: implement once #2060 is fixed
|
||||||
|
// expected:
|
||||||
|
// $ chown -v : file.txt 2>out_err ; echo $? ; cat out_err
|
||||||
|
// ownership of 'file.txt' retained
|
||||||
|
// 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_chown_failed_stdout() {
|
||||||
|
// test chown root file.txt
|
||||||
|
|
||||||
|
// TODO: implement once output "failed to change" to stdout is fixed
|
||||||
|
// expected:
|
||||||
|
// $ chown -v root file.txt 2>out_err ; echo $? ; cat out_err
|
||||||
|
// failed to change ownership of 'file.txt' from jhs to root
|
||||||
|
// 1
|
||||||
|
// chown: changing ownership of 'file.txt': Operation not permitted
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_chown_owner_group() {
|
||||||
// test chown username:group file.txt
|
// test chown username:group file.txt
|
||||||
|
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
let result = scene.cmd("whoami").run();
|
let result = scene.cmd("whoami").run();
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") {
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("user name = {}", result.stdout_str());
|
|
||||||
let username = result.stdout_str().trim_end();
|
let user_name = String::from(result.stdout_str().trim());
|
||||||
|
assert!(!user_name.is_empty());
|
||||||
|
|
||||||
|
let file1 = "test_chown_file1";
|
||||||
|
at.touch(file1);
|
||||||
|
|
||||||
let result = scene.cmd("id").arg("-gn").run();
|
let result = scene.cmd("id").arg("-gn").run();
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("group name = {}", result.stdout_str());
|
let group_name = String::from(result.stdout_str().trim());
|
||||||
let group = result.stdout_str().trim_end();
|
assert!(!group_name.is_empty());
|
||||||
|
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let result = scene
|
||||||
let file1 = "test_install_target_dir_file_a1";
|
.ucmd()
|
||||||
let perm = username.to_owned() + ":" + group;
|
.arg(format!("{}:{}", user_name, group_name))
|
||||||
at.touch(file1);
|
.arg("--verbose")
|
||||||
let result = ucmd.arg(perm).arg(file1).run();
|
.arg(file1)
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
.run();
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
if skipping_test_is_okay(&result, "chown: invalid group:") {
|
||||||
if is_ci() && result.stderr_str().contains("chown: invalid group:") {
|
|
||||||
// With some Ubuntu into the CI, we can get this answer
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert!(result.success);
|
result.stderr_contains(&"retained as");
|
||||||
|
|
||||||
|
// TODO: on macos group name is not recognized correctly: "chown: invalid group: 'root:root'
|
||||||
|
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("root:root")
|
||||||
|
.arg("--verbose")
|
||||||
|
.arg(file1)
|
||||||
|
.fails()
|
||||||
|
.stderr_contains(&"failed to change");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
// TODO: on macos group name is not recognized correctly: "chown: invalid group: ':groupname'
|
||||||
|
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
|
||||||
fn test_chown_only_group() {
|
fn test_chown_only_group() {
|
||||||
// test chown :group file.txt
|
// test chown :group file.txt
|
||||||
|
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
let result = scene.cmd("whoami").run();
|
let result = scene.cmd("whoami").run();
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") {
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("results {}", result.stdout_str());
|
let user_name = String::from(result.stdout_str().trim());
|
||||||
|
assert!(!user_name.is_empty());
|
||||||
|
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let file1 = "test_chown_file1";
|
||||||
let file1 = "test_install_target_dir_file_a1";
|
|
||||||
let perm = ":".to_owned() + result.stdout_str().trim_end();
|
|
||||||
at.touch(file1);
|
at.touch(file1);
|
||||||
let result = ucmd.arg(perm).arg(file1).run();
|
|
||||||
|
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
|
||||||
|
|
||||||
|
let result = scene
|
||||||
|
.ucmd()
|
||||||
|
.arg(format!(":{}", user_name))
|
||||||
|
.arg("--verbose")
|
||||||
|
.arg(file1)
|
||||||
|
.run();
|
||||||
if is_ci() && result.stderr_str().contains("Operation not permitted") {
|
if is_ci() && result.stderr_str().contains("Operation not permitted") {
|
||||||
// With ubuntu with old Rust in the CI, we can get an error
|
// With ubuntu with old Rust in the CI, we can get an error
|
||||||
return;
|
return;
|
||||||
|
@ -167,221 +242,232 @@ fn test_chown_only_group() {
|
||||||
// With mac into the CI, we can get this answer
|
// With mac into the CI, we can get this answer
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert!(result.success);
|
result.stderr_contains(&"retained as");
|
||||||
|
result.success();
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg(":root")
|
||||||
|
.arg("--verbose")
|
||||||
|
.arg(file1)
|
||||||
|
.fails()
|
||||||
|
.stderr_contains(&"failed to change");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chown_only_id() {
|
fn test_chown_only_user_id() {
|
||||||
// test chown 1111 file.txt
|
// test chown 1111 file.txt
|
||||||
let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run();
|
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
let scene = TestScenario::new(util_name!());
|
||||||
// In the CI, some server are failing to return whoami.
|
let at = &scene.fixtures;
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
|
let result = scene.cmd_keepenv("id").arg("-u").run();
|
||||||
|
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
let user_id = String::from(result.stdout_str().trim());
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
assert!(!user_id.is_empty());
|
||||||
let id = String::from(result.stdout_str().trim());
|
|
||||||
|
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
|
||||||
let file1 = "test_install_target_dir_file_a1";
|
|
||||||
|
|
||||||
|
let file1 = "test_chown_file1";
|
||||||
at.touch(file1);
|
at.touch(file1);
|
||||||
let result = ucmd.arg(id).arg(file1).run();
|
|
||||||
|
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
let result = scene.ucmd().arg(user_id).arg("--verbose").arg(file1).run();
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
if skipping_test_is_okay(&result, "invalid user") {
|
||||||
if is_ci() && result.stderr_str().contains("chown: invalid user:") {
|
// From the Logs: "Build (ubuntu-18.04, x86_64-unknown-linux-gnu, feat_os_unix, use-cross)"
|
||||||
// With some Ubuntu into the CI, we can get this answer
|
// stderr: "chown: invalid user: '1001'
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert!(result.success);
|
result.stderr_contains(&"retained as");
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("0")
|
||||||
|
.arg("--verbose")
|
||||||
|
.arg(file1)
|
||||||
|
.fails()
|
||||||
|
.stderr_contains(&"failed to change");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chown_only_group_id() {
|
fn test_chown_only_group_id() {
|
||||||
// test chown :1111 file.txt
|
// test chown :1111 file.txt
|
||||||
let result = TestScenario::new("id").ucmd_keepenv().arg("-g").run();
|
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
let scene = TestScenario::new(util_name!());
|
||||||
// In the CI, some server are failing to return whoami.
|
let at = &scene.fixtures;
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
|
let result = scene.cmd_keepenv("id").arg("-g").run();
|
||||||
|
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
let group_id = String::from(result.stdout_str().trim());
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
assert!(!group_id.is_empty());
|
||||||
let id = String::from(result.stdout_str().trim());
|
|
||||||
|
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
|
||||||
let file1 = "test_install_target_dir_file_a1";
|
|
||||||
|
|
||||||
|
let file1 = "test_chown_file1";
|
||||||
at.touch(file1);
|
at.touch(file1);
|
||||||
let perm = ":".to_owned() + &id;
|
|
||||||
|
|
||||||
let result = ucmd.arg(perm).arg(file1).run();
|
let result = scene
|
||||||
|
.ucmd()
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
.arg(format!(":{}", group_id))
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
.arg("--verbose")
|
||||||
if is_ci() && result.stderr_str().contains("chown: invalid group:") {
|
.arg(file1)
|
||||||
|
.run();
|
||||||
|
if skipping_test_is_okay(&result, "chown: invalid group:") {
|
||||||
// With mac into the CI, we can get this answer
|
// With mac into the CI, we can get this answer
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert!(result.success);
|
result.stderr_contains(&"retained as");
|
||||||
|
|
||||||
|
// Apparently on CI "macos-latest, x86_64-apple-darwin, feat_os_macos"
|
||||||
|
// the process has the rights to change from runner:staff to runner:wheel
|
||||||
|
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg(":0")
|
||||||
|
.arg("--verbose")
|
||||||
|
.arg(file1)
|
||||||
|
.fails()
|
||||||
|
.stderr_contains(&"failed to change");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chown_both_id() {
|
fn test_chown_owner_group_id() {
|
||||||
// test chown 1111:1111 file.txt
|
// test chown 1111:1111 file.txt
|
||||||
let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run();
|
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
let scene = TestScenario::new(util_name!());
|
||||||
// In the CI, some server are failing to return whoami.
|
let at = &scene.fixtures;
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
|
let result = scene.cmd_keepenv("id").arg("-u").run();
|
||||||
|
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
let user_id = String::from(result.stdout_str().trim());
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
assert!(!user_id.is_empty());
|
||||||
let id_user = String::from(result.stdout_str().trim());
|
|
||||||
|
|
||||||
let result = TestScenario::new("id").ucmd_keepenv().arg("-g").run();
|
let result = scene.cmd_keepenv("id").arg("-g").run();
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
let group_id = String::from(result.stdout_str().trim());
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
assert!(!group_id.is_empty());
|
||||||
let id_group = String::from(result.stdout_str().trim());
|
|
||||||
|
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
|
||||||
let file1 = "test_install_target_dir_file_a1";
|
|
||||||
|
|
||||||
|
let file1 = "test_chown_file1";
|
||||||
at.touch(file1);
|
at.touch(file1);
|
||||||
let perm = id_user + &":".to_owned() + &id_group;
|
|
||||||
|
|
||||||
let result = ucmd.arg(perm).arg(file1).run();
|
let result = scene
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
.ucmd()
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
.arg(format!("{}:{}", user_id, group_id))
|
||||||
|
.arg("--verbose")
|
||||||
if is_ci() && result.stderr_str().contains("invalid user") {
|
.arg(file1)
|
||||||
// In the CI, some server are failing to return id.
|
.run();
|
||||||
// As seems to be a configuration issue, ignoring it
|
if skipping_test_is_okay(&result, "invalid user") {
|
||||||
|
// From the Logs: "Build (ubuntu-18.04, x86_64-unknown-linux-gnu, feat_os_unix, use-cross)"
|
||||||
|
// stderr: "chown: invalid user: '1001:116'
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
result.stderr_contains(&"retained as");
|
||||||
|
|
||||||
assert!(result.success);
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("0:0")
|
||||||
|
.arg("--verbose")
|
||||||
|
.arg(file1)
|
||||||
|
.fails()
|
||||||
|
.stderr_contains(&"failed to change");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chown_both_mix() {
|
fn test_chown_owner_group_mix() {
|
||||||
// test chown 1111:1111 file.txt
|
// test chown 1111:group file.txt
|
||||||
let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run();
|
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
|
||||||
let id_user = String::from(result.stdout_str().trim());
|
|
||||||
|
|
||||||
let result = TestScenario::new("id").ucmd_keepenv().arg("-gn").run();
|
let scene = TestScenario::new(util_name!());
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
let at = &scene.fixtures;
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
let result = scene.cmd_keepenv("id").arg("-u").run();
|
||||||
|
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let user_id = String::from(result.stdout_str().trim());
|
||||||
|
assert!(!user_id.is_empty());
|
||||||
|
|
||||||
|
let result = scene.cmd_keepenv("id").arg("-gn").run();
|
||||||
|
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
|
||||||
let group_name = String::from(result.stdout_str().trim());
|
let group_name = String::from(result.stdout_str().trim());
|
||||||
|
assert!(!group_name.is_empty());
|
||||||
|
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let file1 = "test_chown_file1";
|
||||||
let file1 = "test_install_target_dir_file_a1";
|
|
||||||
|
|
||||||
at.touch(file1);
|
at.touch(file1);
|
||||||
let perm = id_user + &":".to_owned() + &group_name;
|
|
||||||
|
|
||||||
let result = ucmd.arg(perm).arg(file1).run();
|
let result = scene
|
||||||
|
.ucmd()
|
||||||
|
.arg(format!("{}:{}", user_id, group_name))
|
||||||
|
.arg("--verbose")
|
||||||
|
.arg(file1)
|
||||||
|
.run();
|
||||||
|
result.stderr_contains(&"retained as");
|
||||||
|
|
||||||
if is_ci() && result.stderr_str().contains("invalid user") {
|
// TODO: on macos group name is not recognized correctly: "chown: invalid group: '0:root'
|
||||||
// In the CI, some server are failing to return id.
|
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
|
||||||
// As seems to be a configuration issue, ignoring it
|
scene
|
||||||
return;
|
.ucmd()
|
||||||
}
|
.arg("0:root")
|
||||||
assert!(result.success);
|
.arg("--verbose")
|
||||||
|
.arg(file1)
|
||||||
|
.fails()
|
||||||
|
.stderr_contains(&"failed to change");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_chown_recursive() {
|
fn test_chown_recursive() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
let result = scene.cmd("whoami").run();
|
let result = scene.cmd("whoami").run();
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") {
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
let user_name = String::from(result.stdout_str().trim());
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
assert!(!user_name.is_empty());
|
||||||
let username = result.stdout_str().trim_end();
|
|
||||||
|
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
at.mkdir_all("a/b/c");
|
||||||
at.mkdir("a");
|
|
||||||
at.mkdir("a/b");
|
|
||||||
at.mkdir("a/b/c");
|
|
||||||
at.mkdir("z");
|
at.mkdir("z");
|
||||||
at.touch(&at.plus_as_string("a/a"));
|
at.touch(&at.plus_as_string("a/a"));
|
||||||
at.touch(&at.plus_as_string("a/b/b"));
|
at.touch(&at.plus_as_string("a/b/b"));
|
||||||
at.touch(&at.plus_as_string("a/b/c/c"));
|
at.touch(&at.plus_as_string("a/b/c/c"));
|
||||||
at.touch(&at.plus_as_string("z/y"));
|
at.touch(&at.plus_as_string("z/y"));
|
||||||
|
|
||||||
let result = ucmd
|
let result = scene
|
||||||
|
.ucmd()
|
||||||
.arg("-R")
|
.arg("-R")
|
||||||
.arg("--verbose")
|
.arg("--verbose")
|
||||||
.arg(username)
|
.arg(user_name)
|
||||||
.arg("a")
|
.arg("a")
|
||||||
.arg("z")
|
.arg("z")
|
||||||
.run();
|
.run();
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
result.stderr_contains(&"ownership of 'a/a' retained as");
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
result.stderr_contains(&"ownership of 'z/y' retained as");
|
||||||
if is_ci() && result.stderr_str().contains("invalid user") {
|
|
||||||
// In the CI, some server are failing to return id.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
.stderr_contains(&"ownership of 'a/a' retained as")
|
|
||||||
.stderr_contains(&"ownership of 'z/y' retained as")
|
|
||||||
.success();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_root_preserve() {
|
fn test_root_preserve() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
||||||
let result = scene.cmd("whoami").run();
|
let result = scene.cmd("whoami").run();
|
||||||
if is_ci() && result.stderr_str().contains("No such user/group") {
|
if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") {
|
||||||
// In the CI, some server are failing to return whoami.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
let user_name = String::from(result.stdout_str().trim());
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
assert!(!user_name.is_empty());
|
||||||
let username = result.stdout_str().trim_end();
|
|
||||||
|
|
||||||
let result = new_ucmd!()
|
let result = scene
|
||||||
|
.ucmd()
|
||||||
.arg("--preserve-root")
|
.arg("--preserve-root")
|
||||||
.arg("-R")
|
.arg("-R")
|
||||||
.arg(username)
|
.arg(user_name)
|
||||||
.arg("/")
|
.arg("/")
|
||||||
.fails();
|
.fails();
|
||||||
println!("result.stdout = {}", result.stdout_str());
|
result.stderr_contains(&"chown: it is dangerous to operate recursively");
|
||||||
println!("result.stderr = {}", result.stderr_str());
|
|
||||||
if is_ci() && result.stderr_str().contains("invalid user") {
|
|
||||||
// In the CI, some server are failing to return id.
|
|
||||||
// As seems to be a configuration issue, ignoring it
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
assert!(result
|
|
||||||
.stderr
|
|
||||||
.contains("chown: it is dangerous to operate recursively"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
@ -398,3 +484,29 @@ fn test_big_p() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_chown_file_notexisting() {
|
||||||
|
// test chown username not_existing
|
||||||
|
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
||||||
|
let result = scene.cmd("whoami").run();
|
||||||
|
if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let user_name = String::from(result.stdout_str().trim());
|
||||||
|
assert!(!user_name.is_empty());
|
||||||
|
|
||||||
|
let _result = scene
|
||||||
|
.ucmd()
|
||||||
|
.arg(user_name)
|
||||||
|
.arg("--verbose")
|
||||||
|
.arg("not_existing")
|
||||||
|
.fails();
|
||||||
|
|
||||||
|
// TODO: uncomment once "failed to change ownership of '{}' to {}" added to stdout
|
||||||
|
// result.stderr_contains(&"retained as");
|
||||||
|
// TODO: uncomment once message changed from "cannot dereference" to "cannot access"
|
||||||
|
// result.stderr_contains(&"cannot access 'not_existing': No such file or directory");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue