From 924d40867c0839b6bf6b4c5da7511db4b1f4e520 Mon Sep 17 00:00:00 2001 From: Anirban Halder Date: Sun, 12 Jan 2025 01:08:38 +0530 Subject: [PATCH] chroot: make group option self overwriting --- src/uu/chroot/src/chroot.rs | 1 + tests/by-util/test_chroot.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index f348d0c55..4ea5db653 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -254,6 +254,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::GROUPS) .long(options::GROUPS) + .overrides_with(options::GROUPS) .help("Comma-separated list of groups to switch to") .value_name("GROUP1,GROUP2..."), ) diff --git a/tests/by-util/test_chroot.rs b/tests/by-util/test_chroot.rs index 711dd0943..022822c6b 100644 --- a/tests/by-util/test_chroot.rs +++ b/tests/by-util/test_chroot.rs @@ -53,6 +53,22 @@ fn test_no_such_directory() { .code_is(125); } +#[test] +fn test_multiple_group_args() { + let ts = TestScenario::new(util_name!()); + let at = &ts.fixtures; + at.mkdir("id"); + + if let Ok(result) = run_ucmd_as_root( + &ts, + &["--groups='invalid ignored'", "--groups=''", "/", "id", "-G"], + ) { + result.success().stdout_is("0"); + } else { + print!("Test skipped; requires root user"); + } +} + #[test] fn test_invalid_user_spec() { let ts = TestScenario::new(util_name!());