1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

chown: support '.' as 'user.group' separator (like ':') (#2638)

* chown: support '.' as 'user.group' separator (like ':')

It also manages the case:
user.name:group (valid too)

Should fix:
gnu/tests/chown/separator.sh
This commit is contained in:
Sylvestre Ledru 2021-09-10 08:15:23 +02:00 committed by GitHub
parent ed258e3c9c
commit 75e5c42e40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 153 additions and 18 deletions

View file

@ -139,6 +139,14 @@ fn test_chown_only_owner_colon() {
.succeeds()
.stderr_contains(&"retained as");
scene
.ucmd()
.arg(format!("{}.", user_name))
.arg("--verbose")
.arg(file1)
.succeeds()
.stderr_contains(&"retained as");
scene
.ucmd()
.arg("root:")
@ -180,6 +188,14 @@ fn test_chown_only_colon() {
.arg(file1)
.fails()
.stderr_contains(&"invalid group: '::'");
scene
.ucmd()
.arg("..")
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"invalid group: '..'");
}
#[test]
@ -232,6 +248,22 @@ fn test_chown_owner_group() {
}
result.stderr_contains(&"retained as");
scene
.ucmd()
.arg("root:root:root")
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"invalid group");
scene
.ucmd()
.arg("root.root.root")
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"invalid group");
// TODO: on macos group name is not recognized correctly: "chown: invalid group: 'root:root'
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
scene
@ -243,6 +275,67 @@ fn test_chown_owner_group() {
.stderr_contains(&"failed to change");
}
#[test]
// FixME: Fails on freebsd because of chown: invalid group: 'root:root'
#[cfg(not(target_os = "freebsd"))]
fn test_chown_various_input() {
// test chown username:group file.txt
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
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 file1 = "test_chown_file1";
at.touch(file1);
let result = scene.cmd("id").arg("-gn").run();
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
return;
}
let group_name = String::from(result.stdout_str().trim());
assert!(!group_name.is_empty());
let result = scene
.ucmd()
.arg(format!("{}:{}", user_name, group_name))
.arg("--verbose")
.arg(file1)
.run();
if skipping_test_is_okay(&result, "chown: invalid group:") {
return;
}
result.stderr_contains(&"retained as");
// check that username.groupname is understood
let result = scene
.ucmd()
.arg(format!("{}.{}", user_name, group_name))
.arg("--verbose")
.arg(file1)
.run();
if skipping_test_is_okay(&result, "chown: invalid group:") {
return;
}
result.stderr_contains(&"retained as");
// Fails as user.name doesn't exist in the CI
// but it is valid
scene
.ucmd()
.arg(format!("{}:{}", "user.name", "groupname"))
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"chown: invalid user: 'user.name:groupname'");
}
#[test]
// FixME: on macos & freebsd group name is not recognized correctly: "chown: invalid group: ':groupname'
#[cfg(any(
@ -405,6 +498,19 @@ fn test_chown_owner_group_id() {
}
result.stderr_contains(&"retained as");
let result = scene
.ucmd()
.arg(format!("{}.{}", user_id, group_id))
.arg("--verbose")
.arg(file1)
.run();
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;
}
result.stderr_contains(&"retained as");
scene
.ucmd()
.arg("0:0")