8000 tests/test: Ensure the test fixture files have the expected gid by n1000 · Pull Request #5455 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tests/test: Ensure the test fixture files have the expected gid #5455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions tests/by-util/test_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,17 +667,40 @@ fn test_nonexistent_file_not_owned_by_euid() {
}

#[test]
#[cfg(all(not(windows), not(target_os = "freebsd")))]
#[cfg(not(windows))]
fn test_file_not_owned_by_euid() {
new_ucmd!()
.args(&["-f", "/bin/sh", "-a", "!", "-O", "/bin/sh"])
.succeeds();
}

#[test]
#[cfg(all(not(windows), not(target_os = "freebsd")))]
#[cfg(not(windows))]
fn test_file_owned_by_egid() {
new_ucmd!().args(&["-G", "regular_file"]).succeeds();
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

// On some platforms (mostly the BSDs) the test fixture files copied to the
// /tmp directory will have a different gid than the current egid (due to
// the sticky bit set on the /tmp directory). Fix this before running the
// test command.
use std::ffi::CString;
use std::os::unix::ffi::OsStrExt;
use std::os::unix::fs::MetadataExt;
use uucore::process::getegid;

let metadata = at.metadata("regular_file");
let file_gid = metadata.gid();
let user_gid = getegid();

if user_gid != file_gid {
let file_uid = metadata.uid();
let path = CString::new(at.plus("regular_file").as_os_str().as_bytes()).expect("bad path");
let r = unsafe { libc::chown(path.as_ptr().into(), file_uid, user_gid) };
assert_ne!(r, -1);
}

scene.ucmd().args(&["-G", "regular_file"]).succeeds();
}

#[test]
Expand All @@ -690,10 +713,19 @@ fn test_nonexistent_file_not_owned_by_egid() {
}

#[test]
#[cfg(all(not(windows), not(target_os = "freebsd")))]
#[cfg(not(windows))]
fn test_file_not_owned_by_egid() {
let target_file = if cfg!(target_os = "freebsd") {
// The coreutils test runner user has a primary group id of "wheel",
// which matches the gid of /bin/sh, so use /sbin/shutdown which has gid
// of "operator".
"/sbin/shutdown"
} else {
"/bin/sh"
};

new_ucmd!()
.args(&["-f", "/bin/sh", "-a", "!", "-G", "/bin/sh"])
.args(&["-f", target_file, "-a", "!", "-G", target_file])
.succeeds();
}

Expand Down
0